< prev index next >

test/hotspot/jtreg/compiler/gcbarriers/TestImplicitNullChecks.java

Print this page
@@ -22,23 +22,21 @@
   */
  
  package compiler.gcbarriers;
  
  import compiler.lib.ir_framework.*;
- import java.lang.invoke.VarHandle;
- import java.lang.invoke.MethodHandles;
- import java.lang.ref.Reference;
- import java.lang.ref.ReferenceQueue;
  import java.lang.ref.SoftReference;
  import java.lang.ref.WeakReference;
  import jdk.test.lib.Asserts;
+ import jdk.internal.misc.Unsafe;
  
  /**
   * @test
   * @summary Test that implicit null checks are generated as expected for
              different GC memory accesses.
   * @library /test/lib /
+  * @modules java.base/jdk.internal.misc
   * @run driver compiler.gcbarriers.TestImplicitNullChecks
   */
  
  
  public class TestImplicitNullChecks {

@@ -49,22 +47,23 @@
  
      static class OuterWithVolatileField {
          volatile Object f;
      }
  
-     static final VarHandle fVarHandle;
+     static final Unsafe UNSAFE = Unsafe.getUnsafe();
+     static final long F_OFFSET;
      static {
-         MethodHandles.Lookup l = MethodHandles.lookup();
          try {
-             fVarHandle = l.findVarHandle(Outer.class, "f", Object.class);
+             F_OFFSET = UNSAFE.objectFieldOffset(Outer.class.getDeclaredField("f"));
          } catch (Exception e) {
              throw new Error(e);
          }
      }
  
      public static void main(String[] args) {
-         TestFramework.runWithFlags("-XX:CompileCommand=inline,java.lang.ref.*::*",
+         TestFramework.runWithFlags("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED",
+                                    "-XX:CompileCommand=inline,java.lang.ref.*::*",
                                     "-XX:-TieredCompilation");
      }
  
      @Test
      // On AIX, implicit null checks are limited because the zero page is

@@ -152,27 +151,27 @@
      // testGetAndSet below.
      @IR(applyIfOr = {"UseZGC", "true", "UseG1GC", "true"},
          failOn = IRNode.NULL_CHECK,
          phase = CompilePhase.FINAL_CODE)
      static Object testCompareAndExchange(Outer o, Object oldVal, Object newVal) {
-         return fVarHandle.compareAndExchange(o, oldVal, newVal);
+         return UNSAFE.compareAndExchangeReference(o, F_OFFSET, oldVal, newVal);
      }
  
      @Test
      @IR(applyIfOr = {"UseZGC", "true", "UseG1GC", "true"},
          failOn = IRNode.NULL_CHECK,
          phase = CompilePhase.FINAL_CODE)
      static boolean testCompareAndSwap(Outer o, Object oldVal, Object newVal) {
-         return fVarHandle.compareAndSet(o, oldVal, newVal);
+         return UNSAFE.compareAndSetReference(o, F_OFFSET, oldVal, newVal);
      }
  
      @Test
      @IR(applyIfOr = {"UseZGC", "true", "UseG1GC", "true"},
          failOn = IRNode.NULL_CHECK,
          phase = CompilePhase.FINAL_CODE)
      static Object testGetAndSet(Outer o, Object newVal) {
-         return fVarHandle.getAndSet(o, newVal);
+         return UNSAFE.getAndSetReference(o, F_OFFSET, newVal);
      }
  
      @Run(test = {"testCompareAndExchange",
                   "testCompareAndSwap",
                   "testGetAndSet"})
< prev index next >