On Mon, 21 Sep 2026 08:47:44 GMT, Stefan Karlsson <[email protected]> wrote:
>> Johan Sjölen has updated the pull request incrementally with one additional
>> commit since the last revision:
>>
>> StefanK comments and a bug fix
>
> src/hotspot/share/classfile/fieldLayoutBuilder.cpp line 1159:
>
>> 1157: assert(_is_abstract_value, "Concrete value types must have at
>> least one field");
>> 1158: layouts().set_payload_offset(_layout->blocks()->size());
>> 1159: layouts().set_size_in_bytes_of(LayoutKind::BUFFERED, 0);
>
> Does this mean that the `_size[BUFFERED]` has taken on the role to hold the
> payload size, but we still have `_payload_alignment` and `_payload_offset` in
> the `LayoutDescriptors`?
>
> I can say that I was surprised by this when reading other parts of the code.
> the code incorrectly because of that.
>
> Take a look at this code:
>
> layouts().set_payload_alignment(required_alignment);
> ...
>
> layouts().set_size_in_bytes_of(LayoutKind::BUFFERED,
> largest_layout_of(LayoutKind::BUFFERED,
>
> LayoutKind::NULLABLE_ATOMIC_FLAT,
>
> LayoutKind::NULLABLE_NON_ATOMIC_FLAT,
>
> LayoutKind::NULL_FREE_ATOMIC_FLAT));
>
>
> It is not clear that the second the payload_alignment and the buffered size
> goes hand-in-hand here.
>
> I'm asking myself why we don't create an array of alignments for for all the
> layout kinds, get rid of `_payload_size`, `_payload_alignment`, and
> `_non_atomic_alignment`. The `payload_size()` / `payload_alignment()`
> functions would query the array, and the `alignment_of` function would be
> simplified from:
>
>
> int alignment_of(LayoutKind lk) const {
> assert(has_a(lk), "Layout not available");
> switch (lk) {
> case LayoutKind::BUFFERED:
> return _payload_alignment;
> case LayoutKind::NULLABLE_ATOMIC_FLAT:
> case LayoutKind::NULL_FREE_ATOMIC_FLAT:
> return size_in_bytes_of(lk);
> case LayoutKind::NULL_FREE_NON_ATOMIC_FLAT:
> case LayoutKind::NULLABLE_NON_ATOMIC_FLAT:
> return _non_atomic_alignment;
> case LayoutKind::REFERENCE:
> case LayoutKind::UNKNOWN:
> break;
> }
> ShouldNotReachHere();
> return 0;
> }
>
>
> To something like:
>
> int alignment_of(LayoutKind lk) const {
> assert(has_a(lk), "Layout not available");
> return _alignment[lk];
> }
>
> That would get rid of questions, why are we reading `_payload_alignment` for
> the Buffered, `size_in_bytes_of` for atomics, and `_non_atomic_alignment` for
> the non-atomics.
>
> The drawback would be a couple of more ints, but I think it would make the
> code more readable.
I've made this change in my suggestion branch.
> src/hotspot/share/classfile/fieldLayoutBuilder.hpp line 308:
>
>> 306: FieldGroup* get_or_create_contended_group(int g);
>> 307:
>> 308: LayoutDescriptions& layouts() { return _available_layouts; }
>
> The rest of the code use `layouts()` but the field is named
> `_available_layouts`. Why not name the field as `_layouts`?
Renamed in my suggestion.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/32276#discussion_r4561165056
PR Review Comment: https://git.openjdk.org/jdk/pull/32276#discussion_r4561158808