[lworld] RFR: 8367785: [lworld] Compiler adherence to new memory model rules for strict instance fields

Tobias Hartmann thartmann at openjdk.org
Mon Oct 6 08:14:31 UTC 2025


On Mon, 6 Oct 2025 08:01:04 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:

>> The new memory model rules for strict instance fields (see [JDK-8366372](https://bugs.openjdk.org/browse/JDK-8366372)) require a memory barrier at the beginning of `java.lang.Object::<init>`. The JITs will try to omit it if the receiver type is statically known (potentially via CHA + a dependency) and the class does not contain any strict fields.
>> 
>> Potentially, there's some more tricks that we can play. Most importantly, I think we can omit barriers for final fields at the end of the constructors if the field is also strict. I filed [JDK-8369166](https://bugs.openjdk.org/browse/JDK-8369166) for this.
>> 
>> I added a test that already caught [JDK-8369044](https://bugs.openjdk.org/browse/JDK-8369044) and will fail immediately without the JIT changes (on AArch64).
>> 
>> Thanks,
>> Tobias
>
> test/hotspot/jtreg/compiler/valhalla/inlinetypes/TestStrictFieldBarriers.java line 204:
> 
>> 202:                 if (res != 1) {
>> 203:                     System.err.println("Incorrect field value observed!");
>> 204:                     System.exit(1);
> 
> Is there any particular reason why you don't throw a `RuntimeException` here instead?

Yes, it's the best way (I think) to make sure all threads immediately exit if one thread observes an error. Throwing an exception will not stop the other threads.

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

PR Review Comment: https://git.openjdk.org/valhalla/pull/1656#discussion_r2405280126


More information about the valhalla-dev mailing list