RFR: 8139457: Array bases are aligned at HeapWord granularity [v52]
Roman Kennke
rkennke at openjdk.org
Tue Aug 22 11:58:50 UTC 2023
On Tue, 22 Aug 2023 11:52:33 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 one additional commit since the last revision:
>
> Move away arrayOopDesc::header_size()
> [b1f7665](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.
>
> [844bd7e](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. [pr/11044...xmas92:jdk:array_align_testing](https://github.com/openjdk/jdk/compare/pr/11044...xmas92:jdk:array_align_testing)
Thanks, this looks great! I'm going to give it a try. This could now also subsume the filling of the klass-gap from initialize_header(), right?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/11044#issuecomment-1688042724
More information about the hotspot-dev
mailing list