On Fri, 28 Aug 2026 03:47:02 GMT, Ioi Lam <[email protected]> wrote:

> `FieldClosure` is used for iterating fields in an object. For Valhalla, it 
> has been enhanced to handle fields that are inside inlined fields. However, 
> the current implementation has two problems:
> 
> [1] It type casts the address of an inlined field into an `oop` pointer. This 
> is unsafe as many operations, such as getting the header of an `oop`, will 
> not work with such an `oop` pointer:
> 
> https://github.com/openjdk/jdk/blob/b1f975efa481bd5e20c1b7d58a87d0866df205e6/src/hotspot/share/runtime/fieldDescriptor.cpp#L216
> 
> [2] The parameter `base_offset` is used in many functions. Its meaning is 
> unclear and inconsistent.
> 
> https://github.com/openjdk/jdk/blob/b1f975efa481bd5e20c1b7d58a87d0866df205e6/src/hotspot/share/runtime/fieldDescriptor.cpp#L159
> 
> https://github.com/openjdk/jdk/blob/b1f975efa481bd5e20c1b7d58a87d0866df205e6/src/hotspot/share/oops/instanceKlass.hpp#L99-L101
> 
> This RFE refactors `FieldClosure` to avoid the above problems. `FieldClosure` 
> now carries information about inlined fields. This information can be used by 
> various field iteration code to simplify their operations. See 
> `FieldClosure::inline_klass()` and `FieldClosure::inline_offset()`.
> 
> As a result, users of `FieldClosure` and `FieldDescriptor()` no longer need 
> to perform obscure arithmetics with `InlineKlass::payload_offset()`.
> 
> This RFE also moves a few common operations into utility functions to avoid 
> code duplication.
> 
> Also:
> - Fixed a bug in `FlatArrayKlass::oop_print_elements_on()` in the handling of 
> nullable elements.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

src/hotspot/share/runtime/fieldDescriptor.cpp line 132:

> 130:     //     vk                    : InstanceKlass java/lang/Integer (we 
> are printing a field in an inlined Integer)
> 131:     //     vk->payload_offset()  : 8 (the payload starts at 8 bytes 
> above a regular Integer heap oop)
> 132:     //     inline_offset         : 16 (this inlined Integer starts at 
> offset 16 of obj

The 16 bytes offset looks strange.
Here's the layout of class Point with the default VM configuration (COH on):

Layout of class Point@0x7f5140300790 extends java/lang/Object@0x7f514007c030
Instance fields:
 @0 RESERVED 8/-
 @8 FLAT 4/4 "x" Ljava/lang/Integer; java/lang/Integer@0x7f514007c030 
NULL_FREE_NON_ATOMIC_FLAT
 @12 FLAT 4/4 "y" Ljava/lang/Integer; java/lang/Integer@0x7f514007c030 
NULL_FREE_NON_ATOMIC_FLAT
 @16 NULL_MARKER 1/1 
Static fields:
 @0 RESERVED 120/-
 @120 REGULAR 4/4 ".null_reset" Ljava/lang/Object;
 @124 REGULAR 4/4 ".acmp_maps" [I
Instance size = 24 bytes
First field offset = 8
BUFFERED layout: 9/8
NULL_FREE_NON_ATOMIC_FLAT layout: -/-
NULL_FREE_ATOMIC_FLAT layout: 8/8
NULLABLE_ATOMIC_FLAT layout: -/-
NULLABLE_NON_ATOMIC_FLAT layout: 9/4
Null marker offset = 16
Non-oop acmp map <offset,size>: <8,8> 
oop acmp map:

src/hotspot/share/runtime/fieldDescriptor.cpp line 176:

> 174:   st->print(" (fields 0x%08x) ", field_flags().as_uint());
> 175:   signature()->print_value_on(st);
> 176:   if (fc == nullptr) {

Suggested change:

st->print(" @%d ", fc == nullptr ? offset() : field_offset_in_obj(fc));

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/32565#discussion_r3924302479
PR Review Comment: https://git.openjdk.org/jdk/pull/32565#discussion_r3924320725

Reply via email to