RFR: 8330153: C2: dump barrier information for all Mach nodes

Roberto Castañeda Lozano rcastanedalo at openjdk.org
Fri Apr 12 13:18:01 UTC 2024


This debug-only changeset ensures that GC-specific barrier information is dumped (via [`BarrierSetC2::dump_barrier_data()`](https://github.com/openjdk/jdk/blob/aebfd53e9d19f5939c81fa1a2fc75716c3355900/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp#L311-L313)) for all C2 Mach nodes, not just `MachType` ones. This makes it possible to e.g. write IR tests that verify barrier properties of `CompareAndSwap`/`WeakCompareAndSwap` Mach implementations, which do not inherit from `MachTypeNode`. An example of such a test can be found [here](https://github.com/robcasloz/jdk/blob/e9b3c2a4cb5dd80d85af8320e559acea5920b2ff/test/hotspot/jtreg/compiler/gcbarriers/TestG1BarrierGeneration.java#L283-L292).

The [following program](https://bugs.openjdk.org/secure/attachment/108921/Example.java) illustrates the effect of the change:


import java.lang.invoke.VarHandle;
import java.lang.invoke.MethodHandles;

public class Example {
    static class Outer {
        Object f;
    }

    static final VarHandle fVarHandle;
    static {
        MethodHandles.Lookup l = MethodHandles.lookup();
        try {
            fVarHandle = l.findVarHandle(Outer.class, "f", Object.class);
        } catch (Exception e) {
            throw new Error(e);
        }
    }

    static boolean testCompareAndSwap(Outer o, Object oldVal, Object newVal) {
        return fVarHandle.compareAndSet(o, oldVal, newVal);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10_000; i++) {
            Outer o = new Outer();
            Object oldVal = new Object();
            o.f = oldVal;
            Object newVal = new Object();
            testCompareAndSwap(o, oldVal, newVal);
        }
    }
}


Before this changeset, issuing this command:


$ java -Xbatch -XX:+UseZGC -XX:+ZGenerational -XX:CompileOnly=Example::testCompareAndSwap -XX:CompileCommand=PrintIdealPhase,Example::testCompareAndSwap,FINAL_CODE Example.java | grep zCompareAndSwapP


gives the following dump:


 R10     37  zCompareAndSwapP  === 28 35 38 54 22 41  [[ 40 42 36 27 56 25 ]]  !jvms: VarHandleReferences$FieldInstanceReadWrite::compareAndSet @ bci:44 (line 180) VarHandleGuards::guard_LLL_Z @ bci:50 (line 68) Example::testCompareAndSwap @ bci:6 (line 20)


After this changeset, we get:


 R10     37  zCompareAndSwapP  === 28 35 38 54 22 41  [[ 40 42 36 27 56 25 ]]  barrier(strong )  !jvms: VarHandleReferences$FieldInstanceReadWrite::compareAndSet @ bci:44 (line 180) VarHandleGuards::guard_LLL_Z @ bci:50 (line 68) Example::testCompareAndSwap @ bci:6 (line 20)


Note the additional `barrier(strong )` field in the second dump.

**Testing:** tier1-3 (windows-x64, linux-x64, linux-aarch64, and macosx-x64; release and debug mode).

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

Commit messages:
 - Dump barrier information for all Mach nodes, not just MachType ones, to include CompareAndSwap/WeakCompareAndSwap matches

Changes: https://git.openjdk.org/jdk/pull/18754/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18754&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8330153
  Stats: 11 lines in 1 file changed: 6 ins; 5 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/18754.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18754/head:pull/18754

PR: https://git.openjdk.org/jdk/pull/18754


More information about the hotspot-compiler-dev mailing list