[lworld] RFR: 8373858: [lworld] Segmented clearing for flatArrays with no oops in ZGC [v3]
Joel Sikström
jsikstro at openjdk.org
Thu Dec 18 15:53:47 UTC 2025
On Wed, 17 Dec 2025 16:22:05 GMT, Joel Sikström <jsikstro at openjdk.org> wrote:
>> Hello,
>>
>> ZGC optimizes initialization by performing segmented clearing for objArrays, which reduces time-to-safepoint. In the lworld branch, we currently opt out of segmented clearing if the objArray being initialized is a flatArray. This prevents us from taking advantage of shorter time-to-safepoints when the flatArray could be cleared in segments.
>>
>> The main question is: which types of flatArrays should support segmented clearing? Since ZGC only supports 64-bit atomic operations, flatArrays containing oops are not possible without relying on internal-only features like loose-consistency and null-restriction. A value object containing an oop and the added null-marker will always exceed 64 bits with ZGC, and therefore such objects will not be flattened in practice due to the 64-bit atomicity constraint.
>>
>> Given this, we are currently missing the opportunity to use segmented clearing for flatArrays that contain only primitive types, which we should add support for. Support for flatArrays containing oops can be considered in the future, once features like loose-consistency and null-restriction are available to the user.
>>
>> Testing:
>> * hotspot_valhalla, jdk_valhalla, tier1-4, with `-XX:+UseZGC`
>>
>> * Some sanity testing in lldb to see if I get segmented clearing for any flatArrays, and I can see several flatArrays containing java/lang/Integer or java/lang/Character being cleared in segmentes.
>
> Joel Sikström has updated the pull request incrementally with two additional commits since the last revision:
>
> - Add test for large primitive only flat arrays
> - Assert fixes
I tried filling flatArrays with colored nulls and added asserts to the test but I couldn't hit them at all. Not sure, but looks like there's something else going on.
assertEquals(array[0], null);
assertEquals(looseArray[0], new LooseIntegers());
I'd like to get this in before EOD tomorrow, so I'm integrating now. I'd be happy to follow up the test if we want to make it more complete.
Thank you for the reviews @xmas92 @stefank @Arraying. I reran hotspot_valhalla and jdk_valhalla on the tip of lworld, which looks good. I also double-checked that the test fails without some of the changes in this patch.
-------------
PR Comment: https://git.openjdk.org/valhalla/pull/1811#issuecomment-3670938301
More information about the valhalla-dev
mailing list