[lworld] RFR: 8341757: Field layout computation allowing atomic and nullable flattening

Frederic Parain fparain at openjdk.org
Wed Oct 23 12:16:28 UTC 2024


On Mon, 21 Oct 2024 18:43:41 GMT, Dan Heidinga <heidinga at openjdk.org> wrote:

>> JavaClasses::check_offsets() verifies the offset of the boxing classes. The code used to handle two offsets, one taken rom j.l.Integer and used for Byte, Char, Short, Int and Float, and another one taken from j.l.Long for Long and Double. If you think of an object with compress class pointer, the first group has its field aligned on a 32bits boundary, and the second group has a field aligned on a 64bits boundary. The addition of ATOMIC_NULLABLE_FLAT layout changes of the layout of j.l.Integer and j.l.Float which now must have their field aligned on a 64bits boundary to be copiable atomically with their null marker. The new code now uses the j.l.Byte class as a reference for Byte, Char and Short, and has special cases to handle j.l.Integer and j.l.Float.
>
> Sorry, I may be slow today but I would expect j.l.Byte and j.l.Short/Char to have different field layouts - given a 12byte header, the `value` field of j.l.Byte can start at the first free byte.  Using hand-hacked versions of the print fields output:
> 
>  @0 RESERVED 12/-
>  @12 REGULAR 1/1 "value" B
> 
> and the `value` field of a j.l.Short needs additional alignment:
> 
>  @0 RESERVED 12/-
>  @12 PADDING 4/1
>  @16 REGULAR 2/2 "value" S
> 
> 
> What am I missing?

I don't know why, but we don't have the same layouts.
Here's the ones I have without support for NULLABLE_ATOMIC_FLAT:


Layout of class java/lang/Byte at 0x7eae3c1357a0 extends java/lang/Number at 0x7eae3c1357a0
Instance fields:
 @0 RESERVED 12/-
 @12 REGULAR 1/1 "value" B



Layout of class java/lang/Short at 0x7eae3c1357a0 extends java/lang/Number at 0x7eae3c1357a0
Instance fields:
 @0 RESERVED 12/-
 @12 REGULAR 2/2 "value" S



Layout of class java/lang/Integer at 0x7eae3c1357a0 extends java/lang/Number at 0x7eae3c1357a0
Instance fields:
 @0 RESERVED 12/-
 @12 REGULAR 4/4 "value" I


And the layouts of the same classes with NULLABLE_ATOMIC_FLAT enabled:


Layout of class java/lang/Byte at 0x7bd87c1357a0 extends java/lang/Number at 0x7bd87c1357a0
Instance fields:
 @0 RESERVED 12/-
 @12 REGULAR 1/1 "value" B
 @13 NULL_MARKER 1/1



Layout of class java/lang/Short at 0x7bd87c1357a0 extends java/lang/Number at 0x7bd87c1357a0
Instance fields:
 @0 RESERVED 12/-
 @12 REGULAR 2/2 "value" S
 @14 NULL_MARKER 1/1



Layout of class java/lang/Integer at 0x7bd87c1357a0 extends java/lang/Number at 0x7bd87c1357a0
Instance fields:
 @0 RESERVED 12/-
 @12 PADDING 4/1
 @16 REGULAR 4/4 "value" I
 @20 NULL_MARKER 1/1

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

PR Review Comment: https://git.openjdk.org/valhalla/pull/1275#discussion_r1809537292


More information about the valhalla-dev mailing list