RFR: 8139457: Array bases are aligned at HeapWord granularity [v51]

Axel Boldt-Christmas aboldtch at openjdk.org
Fri Aug 18 14:42:47 UTC 2023


On Thu, 17 Aug 2023 19:07:36 GMT, Roman Kennke <rkennke at openjdk.org> wrote:

>> See [JDK-8139457](https://bugs.openjdk.org/browse/JDK-8139457) for details.
>> 
>> Basically, when running with -XX:-UseCompressedClassPointers, arrays will have a gap between the length field and the first array element, because array elements will only start at word-aligned offsets. This is not necessary for smaller-than-word elements.
>> 
>> Also, while it is not very important now, it will become very important with Lilliput, which eliminates the Klass field and would always put the length field at offset 8, and leave a gap between offset 12 and 16.
>> 
>> Testing:
>>  - [x] runtime/FieldLayout/ArrayBaseOffsets.java (x86_64, x86_32, aarch64, arm, riscv, s390)
>>  - [x] bootcycle (x86_64, x86_32, aarch64, arm, riscv, s390)
>>  - [x] tier1 (x86_64, x86_32, aarch64, riscv)
>>  - [x] tier2 (x86_64, aarch64, riscv)
>>  - [x] tier3 (x86_64, riscv)
>
> Roman Kennke has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Move alignment-gap-clearing into allocate_array() (aarch64)
>  - Move header_size_in_bytes closer to length_offset_in_bytes

https://github.com/openjdk/jdk/commit/b1f76655514c0371b10748f05ba9596ff38ee56c
I had a look at this and tried to move the whole payload initialisation into `initialize_body`. This makes the C1 changes more one-to-one with how the runtime allocates. That is, make `initialize_header` do what the `ObjArrayAllocator` would do with `do_zero = false`. Which is to initialise the Object up to `arrayOopDesc::header_size_in_bytes()`. Then have  `initialize_body` initialise `base_offset_in_bytes` to the end of the object, leaving the potential alignment gap uninitialised. 

It is curious that we align the end to the padding instead of the smallest word containing the payload and just leave the end padding uninitialised like with the header gap. But I guess running with larger than BytesPerWord MinObjectAlignment is not common (on 64bit). 

There are also some mismatches in the current pr between parameter names in the header files and cpp files. Which I fixed.

https://github.com/openjdk/jdk/commit/844bd7e6390caf42aad1b4eef9d1adfd3df66b2e
I also looked at rewriting the ZObjArrayAllocator so that the extra unaligned write is only done for the segmented case as the normal call to `ObjArrayAllocator::initialize(mem);` already handles it.

All patches, includes some more things I'm testing on-top of this. 
https://github.com/openjdk/jdk/compare/pr/11044...xmas92:jdk:array_align_testing

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

PR Comment: https://git.openjdk.org/jdk/pull/11044#issuecomment-1684019678


More information about the hotspot-dev mailing list