src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/UnsafeEATest.java
changeset 59095 03fbcd06b4c0
parent 58877 aec7bf35d6f5
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/UnsafeEATest.java	Thu Nov 14 11:16:14 2019 -0800
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/UnsafeEATest.java	Thu Nov 14 12:21:00 2019 -0800
@@ -48,27 +48,6 @@
 
     public static int zero = 0;
 
-    private static final long fieldOffset1;
-    private static final long fieldOffset2;
-
-    static {
-        try {
-            long localFieldOffset1 = UNSAFE.objectFieldOffset(TestClassInt.class.getField("x"));
-            // Make the fields 8 byte aligned (Required for testing setLong on Architectures which
-            // does not support unaligned memory access
-            if (localFieldOffset1 % 8 == 0) {
-                fieldOffset1 = localFieldOffset1;
-                fieldOffset2 = UNSAFE.objectFieldOffset(TestClassInt.class.getField("y"));
-            } else {
-                fieldOffset1 = UNSAFE.objectFieldOffset(TestClassInt.class.getField("y"));
-                fieldOffset2 = UNSAFE.objectFieldOffset(TestClassInt.class.getField("z"));
-            }
-            assert fieldOffset2 == fieldOffset1 + 4;
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     @Override
     protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis) {
         // Exercise both a graph containing UnsafeAccessNodes and one which has been possibly been
@@ -134,8 +113,8 @@
 
     public static int testSimpleIntSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putInt(x, fieldOffset1, 101);
-        return UNSAFE.getInt(x, fieldOffset1);
+        UNSAFE.putInt(x, TestClassInt.fieldOffset1, 101);
+        return UNSAFE.getInt(x, TestClassInt.fieldOffset1);
     }
 
     @Test
@@ -145,7 +124,7 @@
 
     public static TestClassInt testMaterializedIntSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putInt(x, fieldOffset1, 101);
+        UNSAFE.putInt(x, TestClassInt.fieldOffset1, 101);
         return x;
     }
 
@@ -156,8 +135,8 @@
 
     public static double testSimpleDoubleSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putDouble(x, fieldOffset1, 10.1);
-        return UNSAFE.getDouble(x, fieldOffset1);
+        UNSAFE.putDouble(x, TestClassInt.fieldOffset1, 10.1);
+        return UNSAFE.getDouble(x, TestClassInt.fieldOffset1);
     }
 
     @Test
@@ -167,9 +146,9 @@
 
     public static int testSimpleDoubleOverwriteWithIntSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putDouble(x, fieldOffset1, 10.1);
-        UNSAFE.putInt(x, fieldOffset1, 10);
-        return UNSAFE.getInt(x, fieldOffset1);
+        UNSAFE.putDouble(x, TestClassInt.fieldOffset1, 10.1);
+        UNSAFE.putInt(x, TestClassInt.fieldOffset1, 10);
+        return UNSAFE.getInt(x, TestClassInt.fieldOffset1);
     }
 
     @Test
@@ -183,9 +162,9 @@
 
     public static int testSimpleDoubleOverwriteWithSecondIntSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putDouble(x, fieldOffset1, 10.1);
-        UNSAFE.putInt(x, fieldOffset1, 10);
-        return UNSAFE.getInt(x, fieldOffset2);
+        UNSAFE.putDouble(x, TestClassInt.fieldOffset1, 10.1);
+        UNSAFE.putInt(x, TestClassInt.fieldOffset1, 10);
+        return UNSAFE.getInt(x, TestClassInt.fieldOffset2);
     }
 
     @Test
@@ -199,9 +178,9 @@
 
     public static int testSimpleDoubleOverwriteWithFirstIntSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putDouble(x, fieldOffset1, 10.1);
-        UNSAFE.putInt(x, fieldOffset2, 10);
-        return UNSAFE.getInt(x, fieldOffset1);
+        UNSAFE.putDouble(x, TestClassInt.fieldOffset1, 10.1);
+        UNSAFE.putInt(x, TestClassInt.fieldOffset2, 10);
+        return UNSAFE.getInt(x, TestClassInt.fieldOffset1);
     }
 
     @Test
@@ -215,9 +194,9 @@
 
     public static int testSimpleLongOverwriteWithSecondIntSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putLong(x, fieldOffset1, 0x1122334455667788L);
-        UNSAFE.putInt(x, fieldOffset1, 10);
-        return UNSAFE.getInt(x, fieldOffset2);
+        UNSAFE.putLong(x, TestClassInt.fieldOffset1, 0x1122334455667788L);
+        UNSAFE.putInt(x, TestClassInt.fieldOffset1, 10);
+        return UNSAFE.getInt(x, TestClassInt.fieldOffset2);
     }
 
     @Test
@@ -231,9 +210,9 @@
 
     public static int testSimpleLongOverwriteWithFirstIntSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putLong(x, fieldOffset1, 0x1122334455667788L);
-        UNSAFE.putInt(x, fieldOffset2, 10);
-        return UNSAFE.getInt(x, fieldOffset1);
+        UNSAFE.putLong(x, TestClassInt.fieldOffset1, 0x1122334455667788L);
+        UNSAFE.putInt(x, TestClassInt.fieldOffset2, 10);
+        return UNSAFE.getInt(x, TestClassInt.fieldOffset1);
     }
 
     @Test
@@ -250,12 +229,12 @@
         TestClassInt x;
         if (a) {
             x = new TestClassInt(0, 0);
-            UNSAFE.putDouble(x, fieldOffset1, doubleField);
+            UNSAFE.putDouble(x, TestClassInt.fieldOffset1, doubleField);
         } else {
             x = new TestClassInt();
-            UNSAFE.putDouble(x, fieldOffset1, doubleField2);
+            UNSAFE.putDouble(x, TestClassInt.fieldOffset1, doubleField2);
         }
-        return UNSAFE.getDouble(x, fieldOffset1);
+        return UNSAFE.getDouble(x, TestClassInt.fieldOffset1);
     }
 
     static class ExtendedTestClassInt extends TestClassInt {
@@ -271,14 +250,14 @@
         TestClassInt x;
         if (value == 1) {
             x = new TestClassInt();
-            UNSAFE.putDouble(x, fieldOffset1, 10);
+            UNSAFE.putDouble(x, TestClassInt.fieldOffset1, 10);
         } else {
             x = new TestClassInt();
-            UNSAFE.putInt(x, fieldOffset1, 0);
+            UNSAFE.putInt(x, TestClassInt.fieldOffset1, 0);
         }
-        UNSAFE.putInt(x, fieldOffset1, 0);
+        UNSAFE.putInt(x, TestClassInt.fieldOffset1, 0);
         if (value == 2) {
-            UNSAFE.putInt(x, fieldOffset2, 0);
+            UNSAFE.putInt(x, TestClassInt.fieldOffset2, 0);
         }
         GraalDirectives.deoptimizeAndInvalidate();
         return x;
@@ -291,7 +270,7 @@
 
     public static TestClassInt testMaterializedDoubleSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putDouble(x, fieldOffset1, 10.1);
+        UNSAFE.putDouble(x, TestClassInt.fieldOffset1, 10.1);
         return x;
     }
 
@@ -305,10 +284,10 @@
 
     public static TestClassInt testDeoptDoubleVarSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putDouble(x, fieldOffset1, doubleField);
+        UNSAFE.putDouble(x, TestClassInt.fieldOffset1, doubleField);
         doubleField2 = 123;
         try {
-            doubleField = ((int) UNSAFE.getDouble(x, fieldOffset1)) / zero;
+            doubleField = ((int) UNSAFE.getDouble(x, TestClassInt.fieldOffset1)) / zero;
         } catch (RuntimeException e) {
             return x;
         }
@@ -322,10 +301,10 @@
 
     public static TestClassInt testDeoptDoubleConstantSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putDouble(x, fieldOffset1, 10.123);
+        UNSAFE.putDouble(x, TestClassInt.fieldOffset1, 10.123);
         doubleField2 = 123;
         try {
-            doubleField = ((int) UNSAFE.getDouble(x, fieldOffset1)) / zero;
+            doubleField = ((int) UNSAFE.getDouble(x, TestClassInt.fieldOffset1)) / zero;
         } catch (RuntimeException e) {
             return x;
         }
@@ -342,10 +321,10 @@
 
     public static TestClassInt testDeoptLongVarSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putLong(x, fieldOffset1, longField);
+        UNSAFE.putLong(x, TestClassInt.fieldOffset1, longField);
         longField2 = 123;
         try {
-            longField = UNSAFE.getLong(x, fieldOffset1) / zero;
+            longField = UNSAFE.getLong(x, TestClassInt.fieldOffset1) / zero;
         } catch (RuntimeException e) {
             return x;
         }
@@ -359,10 +338,10 @@
 
     public static TestClassInt testDeoptLongConstantSnippet() {
         TestClassInt x = new TestClassInt();
-        UNSAFE.putLong(x, fieldOffset1, 0x2222222210123L);
+        UNSAFE.putLong(x, TestClassInt.fieldOffset1, 0x2222222210123L);
         longField2 = 123;
         try {
-            longField = UNSAFE.getLong(x, fieldOffset1) / zero;
+            longField = UNSAFE.getLong(x, TestClassInt.fieldOffset1) / zero;
         } catch (RuntimeException e) {
             return x;
         }