src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.jdk9.test/src/org/graalvm/compiler/replacements/jdk9/UnsafeReplacementsTest.java
changeset 52220 9c260a6b6471
parent 50858 2d3e99a72541
equal deleted inserted replaced
52219:151b990e3764 52220:9c260a6b6471
   119     public static boolean unsafeCompareAndSetDouble() {
   119     public static boolean unsafeCompareAndSetDouble() {
   120         Container container = new Container();
   120         Container container = new Container();
   121         return unsafe.compareAndSetDouble(container, doubleOffset, 0.125, 0.25);
   121         return unsafe.compareAndSetDouble(container, doubleOffset, 0.125, 0.25);
   122     }
   122     }
   123 
   123 
   124     public static boolean unsafeCompareAndSetObject() {
   124     public static boolean unsafeCompareAndSetReference() {
   125         Container container = new Container();
   125         Container container = new Container();
   126         return unsafe.compareAndSetObject(container, objectOffset, dummyValue, newDummyValue);
   126         return unsafe.compareAndSetReference(container, objectOffset, dummyValue, newDummyValue);
   127     }
   127     }
   128 
   128 
   129     public static boolean unsafeCompareAndExchangeBoolean() {
   129     public static boolean unsafeCompareAndExchangeBoolean() {
   130         Container container = new Container();
   130         Container container = new Container();
   131         return unsafe.compareAndExchangeBoolean(container, booleanOffset, false, true);
   131         return unsafe.compareAndExchangeBoolean(container, booleanOffset, false, true);
   164     public static double unsafeCompareAndExchangeDouble() {
   164     public static double unsafeCompareAndExchangeDouble() {
   165         Container container = new Container();
   165         Container container = new Container();
   166         return unsafe.compareAndExchangeDouble(container, doubleOffset, 0.125, 0.25);
   166         return unsafe.compareAndExchangeDouble(container, doubleOffset, 0.125, 0.25);
   167     }
   167     }
   168 
   168 
   169     public static Object unsafeCompareAndExchangeObject() {
   169     public static Object unsafeCompareAndExchangeReference() {
   170         Container container = new Container();
   170         Container container = new Container();
   171         return unsafe.compareAndExchangeObject(container, objectOffset, dummyValue, newDummyValue);
   171         return unsafe.compareAndExchangeReference(container, objectOffset, dummyValue, newDummyValue);
   172     }
   172     }
   173 
   173 
   174     @Test
   174     @Test
   175     public void testCompareAndSet() {
   175     public void testCompareAndSet() {
   176         TargetDescription target = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getTarget();
   176         TargetDescription target = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getTarget();
   181             testGraph("unsafeCompareAndSetShort");
   181             testGraph("unsafeCompareAndSetShort");
   182             testGraph("unsafeCompareAndSetInt");
   182             testGraph("unsafeCompareAndSetInt");
   183             testGraph("unsafeCompareAndSetLong");
   183             testGraph("unsafeCompareAndSetLong");
   184             testGraph("unsafeCompareAndSetFloat");
   184             testGraph("unsafeCompareAndSetFloat");
   185             testGraph("unsafeCompareAndSetDouble");
   185             testGraph("unsafeCompareAndSetDouble");
   186             testGraph("unsafeCompareAndSetObject");
   186             testGraph("unsafeCompareAndSetReference");
   187             testGraph("unsafeCompareAndExchangeBoolean");
   187             testGraph("unsafeCompareAndExchangeBoolean");
   188             testGraph("unsafeCompareAndExchangeByte");
   188             testGraph("unsafeCompareAndExchangeByte");
   189             testGraph("unsafeCompareAndExchangeChar");
   189             testGraph("unsafeCompareAndExchangeChar");
   190             testGraph("unsafeCompareAndExchangeShort");
   190             testGraph("unsafeCompareAndExchangeShort");
   191             testGraph("unsafeCompareAndExchangeInt");
   191             testGraph("unsafeCompareAndExchangeInt");
   192             testGraph("unsafeCompareAndExchangeLong");
   192             testGraph("unsafeCompareAndExchangeLong");
   193             testGraph("unsafeCompareAndExchangeFloat");
   193             testGraph("unsafeCompareAndExchangeFloat");
   194             testGraph("unsafeCompareAndExchangeDouble");
   194             testGraph("unsafeCompareAndExchangeDouble");
   195             testGraph("unsafeCompareAndExchangeObject");
   195             testGraph("unsafeCompareAndExchangeReference");
   196         }
   196         }
   197         test("unsafeCompareAndSetBoolean");
   197         test("unsafeCompareAndSetBoolean");
   198         test("unsafeCompareAndSetByte");
   198         test("unsafeCompareAndSetByte");
   199         test("unsafeCompareAndSetChar");
   199         test("unsafeCompareAndSetChar");
   200         test("unsafeCompareAndSetShort");
   200         test("unsafeCompareAndSetShort");
   201         test("unsafeCompareAndSetInt");
   201         test("unsafeCompareAndSetInt");
   202         test("unsafeCompareAndSetLong");
   202         test("unsafeCompareAndSetLong");
   203         test("unsafeCompareAndSetFloat");
   203         test("unsafeCompareAndSetFloat");
   204         test("unsafeCompareAndSetDouble");
   204         test("unsafeCompareAndSetDouble");
   205         test("unsafeCompareAndSetObject");
   205         test("unsafeCompareAndSetReference");
   206         test("unsafeCompareAndExchangeBoolean");
   206         test("unsafeCompareAndExchangeBoolean");
   207         test("unsafeCompareAndExchangeByte");
   207         test("unsafeCompareAndExchangeByte");
   208         test("unsafeCompareAndExchangeChar");
   208         test("unsafeCompareAndExchangeChar");
   209         test("unsafeCompareAndExchangeShort");
   209         test("unsafeCompareAndExchangeShort");
   210         test("unsafeCompareAndExchangeInt");
   210         test("unsafeCompareAndExchangeInt");
   211         test("unsafeCompareAndExchangeLong");
   211         test("unsafeCompareAndExchangeLong");
   212         test("unsafeCompareAndExchangeFloat");
   212         test("unsafeCompareAndExchangeFloat");
   213         test("unsafeCompareAndExchangeDouble");
   213         test("unsafeCompareAndExchangeDouble");
   214         test("unsafeCompareAndExchangeObject");
   214         test("unsafeCompareAndExchangeReference");
   215     }
   215     }
   216 
   216 
   217     public static int unsafeGetAndAddByte() {
   217     public static int unsafeGetAndAddByte() {
   218         Container container = new Container();
   218         Container container = new Container();
   219         return unsafe.getAndAddByte(container, byteOffset, (byte) 2);
   219         return unsafe.getAndAddByte(container, byteOffset, (byte) 2);
   286     public static long unsafeGetAndSetLong() {
   286     public static long unsafeGetAndSetLong() {
   287         Container container = new Container();
   287         Container container = new Container();
   288         return unsafe.getAndSetLong(container, longOffset, 0x12345678abL);
   288         return unsafe.getAndSetLong(container, longOffset, 0x12345678abL);
   289     }
   289     }
   290 
   290 
   291     public static Object unsafeGetAndSetObject() {
   291     public static Object unsafeGetAndSetReference() {
   292         Container container = new Container();
   292         Container container = new Container();
   293         container.objectField = null;
   293         container.objectField = null;
   294         Container other = new Container();
   294         Container other = new Container();
   295         return unsafe.getAndSetObject(container, objectOffset, other);
   295         return unsafe.getAndSetReference(container, objectOffset, other);
   296     }
   296     }
   297 
   297 
   298     @Test
   298     @Test
   299     public void testGetAndSet() {
   299     public void testGetAndSet() {
   300         TargetDescription target = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getTarget();
   300         TargetDescription target = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getTarget();
   305             testGraph("unsafeGetAndSetShort");
   305             testGraph("unsafeGetAndSetShort");
   306         }
   306         }
   307         if (target.arch instanceof AMD64 || target.arch instanceof AArch64) {
   307         if (target.arch instanceof AMD64 || target.arch instanceof AArch64) {
   308             testGraph("unsafeGetAndSetInt");
   308             testGraph("unsafeGetAndSetInt");
   309             testGraph("unsafeGetAndSetLong");
   309             testGraph("unsafeGetAndSetLong");
   310             testGraph("unsafeGetAndSetObject");
   310             testGraph("unsafeGetAndSetReference");
   311         }
   311         }
   312         test("unsafeGetAndSetBoolean");
   312         test("unsafeGetAndSetBoolean");
   313         test("unsafeGetAndSetByte");
   313         test("unsafeGetAndSetByte");
   314         test("unsafeGetAndSetChar");
   314         test("unsafeGetAndSetChar");
   315         test("unsafeGetAndSetShort");
   315         test("unsafeGetAndSetShort");
   316         test("unsafeGetAndSetInt");
   316         test("unsafeGetAndSetInt");
   317         test("unsafeGetAndSetLong");
   317         test("unsafeGetAndSetLong");
   318         test("unsafeGetAndSetObject");
   318         test("unsafeGetAndSetReference");
   319     }
   319     }
   320 
   320 
   321     public static void fieldInstance() {
   321     public static void fieldInstance() {
   322         JdkInternalMiscUnsafeAccessTestBoolean.testFieldInstance();
   322         JdkInternalMiscUnsafeAccessTestBoolean.testFieldInstance();
   323     }
   323     }
   560         Container container = new Container();
   560         Container container = new Container();
   561         unsafe.putDouble(container, doubleOffset, 1.23456789);
   561         unsafe.putDouble(container, doubleOffset, 1.23456789);
   562         return unsafe.getDouble(container, doubleOffset);
   562         return unsafe.getDouble(container, doubleOffset);
   563     }
   563     }
   564 
   564 
   565     public static Object unsafeGetPutObject() {
   565     public static Object unsafeGetPutReference() {
   566         Container container = new Container();
   566         Container container = new Container();
   567         unsafe.putObject(container, objectOffset, "Hello there");
   567         unsafe.putReference(container, objectOffset, "Hello there");
   568         return unsafe.getObject(container, objectOffset);
   568         return unsafe.getReference(container, objectOffset);
   569     }
   569     }
   570 
   570 
   571     public static boolean unsafeGetPutBooleanOpaque() {
   571     public static boolean unsafeGetPutBooleanOpaque() {
   572         Container container = new Container();
   572         Container container = new Container();
   573         unsafe.putBooleanOpaque(container, booleanOffset, true);
   573         unsafe.putBooleanOpaque(container, booleanOffset, true);
   614         Container container = new Container();
   614         Container container = new Container();
   615         unsafe.putDoubleOpaque(container, doubleOffset, 1.23456789);
   615         unsafe.putDoubleOpaque(container, doubleOffset, 1.23456789);
   616         return unsafe.getDoubleOpaque(container, doubleOffset);
   616         return unsafe.getDoubleOpaque(container, doubleOffset);
   617     }
   617     }
   618 
   618 
   619     public static Object unsafeGetPutObjectOpaque() {
   619     public static Object unsafeGetPutReferenceOpaque() {
   620         Container container = new Container();
   620         Container container = new Container();
   621         unsafe.putObjectOpaque(container, objectOffset, "Hello there");
   621         unsafe.putReferenceOpaque(container, objectOffset, "Hello there");
   622         return unsafe.getObjectOpaque(container, objectOffset);
   622         return unsafe.getReferenceOpaque(container, objectOffset);
   623     }
   623     }
   624 
   624 
   625     public static boolean unsafeGetPutBooleanRA() {
   625     public static boolean unsafeGetPutBooleanRA() {
   626         Container container = new Container();
   626         Container container = new Container();
   627         unsafe.putBooleanRelease(container, booleanOffset, true);
   627         unsafe.putBooleanRelease(container, booleanOffset, true);
   668         Container container = new Container();
   668         Container container = new Container();
   669         unsafe.putDoubleRelease(container, doubleOffset, 1.23456789);
   669         unsafe.putDoubleRelease(container, doubleOffset, 1.23456789);
   670         return unsafe.getDoubleAcquire(container, doubleOffset);
   670         return unsafe.getDoubleAcquire(container, doubleOffset);
   671     }
   671     }
   672 
   672 
   673     public static Object unsafeGetPutObjectRA() {
   673     public static Object unsafeGetPutReferenceRA() {
   674         Container container = new Container();
   674         Container container = new Container();
   675         unsafe.putObjectRelease(container, objectOffset, "Hello there");
   675         unsafe.putReferenceRelease(container, objectOffset, "Hello there");
   676         return unsafe.getObjectAcquire(container, objectOffset);
   676         return unsafe.getReferenceAcquire(container, objectOffset);
   677     }
   677     }
   678 
   678 
   679     public static boolean unsafeGetPutBooleanVolatile() {
   679     public static boolean unsafeGetPutBooleanVolatile() {
   680         Container container = new Container();
   680         Container container = new Container();
   681         unsafe.putBooleanVolatile(container, booleanOffset, true);
   681         unsafe.putBooleanVolatile(container, booleanOffset, true);
   722         Container container = new Container();
   722         Container container = new Container();
   723         unsafe.putDoubleVolatile(container, doubleOffset, 1.23456789);
   723         unsafe.putDoubleVolatile(container, doubleOffset, 1.23456789);
   724         return unsafe.getDoubleVolatile(container, doubleOffset);
   724         return unsafe.getDoubleVolatile(container, doubleOffset);
   725     }
   725     }
   726 
   726 
   727     public static Object unsafeGetPutObjectVolatile() {
   727     public static Object unsafeGetPutReferenceVolatile() {
   728         Container container = new Container();
   728         Container container = new Container();
   729         unsafe.putObjectVolatile(container, objectOffset, "Hello there");
   729         unsafe.putReferenceVolatile(container, objectOffset, "Hello there");
   730         return unsafe.getObjectVolatile(container, objectOffset);
   730         return unsafe.getReferenceVolatile(container, objectOffset);
   731     }
   731     }
   732 
   732 
   733     @Test
   733     @Test
   734     public void testUnsafeGetPutPlain() {
   734     public void testUnsafeGetPutPlain() {
   735         testGraph("unsafeGetPutBoolean");
   735         testGraph("unsafeGetPutBoolean");
   784         testGraph("unsafeGetPutCharRA");
   784         testGraph("unsafeGetPutCharRA");
   785         testGraph("unsafeGetPutIntRA");
   785         testGraph("unsafeGetPutIntRA");
   786         testGraph("unsafeGetPutLongRA");
   786         testGraph("unsafeGetPutLongRA");
   787         testGraph("unsafeGetPutFloatRA");
   787         testGraph("unsafeGetPutFloatRA");
   788         testGraph("unsafeGetPutDoubleRA");
   788         testGraph("unsafeGetPutDoubleRA");
   789         testGraph("unsafeGetPutObjectRA");
   789         testGraph("unsafeGetPutReferenceRA");
   790 
   790 
   791         test("unsafeGetPutBooleanRA");
   791         test("unsafeGetPutBooleanRA");
   792         test("unsafeGetPutByteRA");
   792         test("unsafeGetPutByteRA");
   793         test("unsafeGetPutShortRA");
   793         test("unsafeGetPutShortRA");
   794         test("unsafeGetPutCharRA");
   794         test("unsafeGetPutCharRA");
   795         test("unsafeGetPutIntRA");
   795         test("unsafeGetPutIntRA");
   796         test("unsafeGetPutLongRA");
   796         test("unsafeGetPutLongRA");
   797         test("unsafeGetPutFloatRA");
   797         test("unsafeGetPutFloatRA");
   798         test("unsafeGetPutDoubleRA");
   798         test("unsafeGetPutDoubleRA");
   799         test("unsafeGetPutObjectRA");
   799         test("unsafeGetPutReferenceRA");
   800     }
   800     }
   801 
   801 
   802     @Test
   802     @Test
   803     public void testUnsafeGetPutVolatile() {
   803     public void testUnsafeGetPutVolatile() {
   804         testGraph("unsafeGetPutBooleanVolatile");
   804         testGraph("unsafeGetPutBooleanVolatile");
   807         testGraph("unsafeGetPutCharVolatile");
   807         testGraph("unsafeGetPutCharVolatile");
   808         testGraph("unsafeGetPutIntVolatile");
   808         testGraph("unsafeGetPutIntVolatile");
   809         testGraph("unsafeGetPutLongVolatile");
   809         testGraph("unsafeGetPutLongVolatile");
   810         testGraph("unsafeGetPutFloatVolatile");
   810         testGraph("unsafeGetPutFloatVolatile");
   811         testGraph("unsafeGetPutDoubleVolatile");
   811         testGraph("unsafeGetPutDoubleVolatile");
   812         testGraph("unsafeGetPutObjectVolatile");
   812         testGraph("unsafeGetPutReferenceVolatile");
   813 
   813 
   814         test("unsafeGetPutBooleanVolatile");
   814         test("unsafeGetPutBooleanVolatile");
   815         test("unsafeGetPutByteVolatile");
   815         test("unsafeGetPutByteVolatile");
   816         test("unsafeGetPutShortVolatile");
   816         test("unsafeGetPutShortVolatile");
   817         test("unsafeGetPutCharVolatile");
   817         test("unsafeGetPutCharVolatile");
   818         test("unsafeGetPutIntVolatile");
   818         test("unsafeGetPutIntVolatile");
   819         test("unsafeGetPutLongVolatile");
   819         test("unsafeGetPutLongVolatile");
   820         test("unsafeGetPutFloatVolatile");
   820         test("unsafeGetPutFloatVolatile");
   821         test("unsafeGetPutDoubleVolatile");
   821         test("unsafeGetPutDoubleVolatile");
   822         test("unsafeGetPutObjectVolatile");
   822         test("unsafeGetPutReferenceVolatile");
   823     }
   823     }
   824 }
   824 }