[lworld] RFR: 8367338: [lworld] compiler/gcbarriers/TestImplicitNullChecks.java fails

Damon Fenacci dfenacci at openjdk.org
Fri Sep 26 15:06:54 UTC 2025


# Issue
IR checks of `testCompareAndExchange`, `testCompareAndSwap` and `testGetAndSet` of  `compiler/gcbarriers/TestImplicitNullChecks.java` fail because they expect no  `NULL_CHECK` in the final code graph but it encounters a few in each test instead.

# Cause
The tests in question simply call 3 different `VarHandle` functions (one each) but these don't get inlined as intrinsics directly. They instead rely on inline methods (with some conditional statements) that eventually call a method that gets intrinsified. Unfortunately the compilation of some of the inlined code can result in null-checks after being compiled.
For instance `testCompareAndExchange` inlines `Unsafe::compareAndExchangeReference`
https://github.com/openjdk/valhalla/blob/1ecd2e95a158c80186d4334ca3f0673f660d5042/src/java.base/share/classes/jdk/internal/misc/Unsafe.java#L1723-L1742
which calls `compareAndSetReference` or `compareAndExchangeReference` but `if (valueType.isValue() || isValueObject(expected))` adds a null-check for `valueType`.
This happens only in Valhalla because of a Valhalla-specific value-type checks (see [JDK-8351569](https://bugs.openjdk.org/browse/JDK-8351569)).

# Fix
The goal of the tests is to make sure that there are no null-checks with compare-and-exchange operations with ZGC and G1. Instead of relying on `VarHandle` compare-and-exchange-related methods we can use the equivalent `Unsafe` methods that are intrinsified directly.

# Testing
Tier 1-3+

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

Commit messages:
 - Merge branch 'lworld' into JDK-8367338
 - JDK-8367338: add exports to run command
 - JDK-8367338: use Unsafe
 - JDK-8367338: update comment
 - JDK-8367338: [lworld] compiler/gcbarriers/TestImplicitNullChecks.java fails

Changes: https://git.openjdk.org/valhalla/pull/1626/files
  Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=1626&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8367338
  Stats: 18 lines in 2 files changed: 13 ins; 1 del; 4 mod
  Patch: https://git.openjdk.org/valhalla/pull/1626.diff
  Fetch: git fetch https://git.openjdk.org/valhalla.git pull/1626/head:pull/1626

PR: https://git.openjdk.org/valhalla/pull/1626


More information about the valhalla-dev mailing list