On Mon, 27 Apr 2026 14:28:27 GMT, Joel Sikström <[email protected]> wrote:
> Hello, > > Embdedded flat contended fields might not be included in the class' OopMap if > there are no other oop fields in the holder class. > > Flat fields are handled separately in fieldLayoutBuilder.cpp, resulting in > the current `_oop_count` not being updated if a flat field contains oops. > This is OK, since the oop fields are handled at a later point in time. > However, for contended fields, which are part of the contended group, > embedded oop fields are only tracked if: `cg->oop_count() > 0`, which is not > guaranteed to be true. > > I've written a test to see if the oop field is included in the class' OopMap > and also changed the `_oop_count` field `_has_embedded_oops`, and changed > that to a boolean property, which is how we've used it so far. > > Since embedded fields in flat paylods are not tracked in `cg->oop_fields()`, > we can't do the assert that is currently there, so I just removed that. > > Testing: > * New test fails without the fixes in fieldLayoutBuilder and passes with fixes > * Running Oracle's tier1-3 > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). I think the implementation looks good, but I wonder if we can simplify even more. src/hotspot/share/classfile/fieldLayoutBuilder.cpp line 178: > 176: _oop_fields(nullptr), > 177: _contended_group(contended_group), // -1 means no contended group, 0 > means default contended group > 178: _has_embedded_oops(false) {} I wonder if we should just remove the `_has_embedded_oops` completely. And just unconditionally call `register_embedded_oops`. It already handles an empty (no embedded oops) list of sub-blocks. It makes the code less complex, but we miss an optimisation in the case where we have flattened a lot of values where no fields contains oops. But seems like the better optimization if this was a problem would be to create a list of each raw block with oops, so we only walk those, rather than all if one happens to contain an oop. ------------- PR Review: https://git.openjdk.org/valhalla/pull/2371#pullrequestreview-4182800401 PR Review Comment: https://git.openjdk.org/valhalla/pull/2371#discussion_r3148963612
