changeset 18991:5ff49be5a02c

Add a corner case test case with a mixture of unsafe writes and normal reads.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 27 Jan 2015 23:52:05 +0100
parents 48b79b8e18f1
children b1c03c2bfa40
files graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAccess01.java
diffstat 1 files changed, 37 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAccess01.java	Tue Jan 27 23:19:40 2015 +0100
+++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAccess01.java	Tue Jan 27 23:52:05 2015 +0100
@@ -34,16 +34,28 @@
  */
 public class UnsafeAccess01 extends JTTTest {
 
-    private static class TestClass {
-        @SuppressWarnings("unused") private int field = 42;
+    private static int randomValue = 100;
+    private static final Unsafe unsafe;
+    private static final long offset;
+    private static Object staticObject = new TestClass();
+
+    static {
+        unsafe = getUnsafe();
+        Field field = null;
+        try {
+            field = TestClass.class.getDeclaredField("field");
+        } catch (NoSuchFieldException e) {
+        } catch (SecurityException e) {
+        }
+        offset = unsafe.objectFieldOffset(field);
     }
 
-    public static int test() throws SecurityException, NoSuchFieldException {
-        final Unsafe unsafe = getUnsafe();
+    private static class TestClass {
+        private int field = 42;
+    }
 
+    public static int test() {
         final TestClass object = new TestClass();
-        final Field field = TestClass.class.getDeclaredField("field");
-        final long offset = unsafe.objectFieldOffset(field);
         final int value = unsafe.getInt(object, offset);
         return value;
     }
@@ -63,4 +75,22 @@
         runTest("test");
     }
 
-}
+    @Test
+    public void runDiamond() throws Throwable {
+        runTest("testDiamond");
+    }
+
+    public static int testDiamond() {
+
+        final Object object = staticObject;
+        final int oldValue = ((TestClass) object).field;
+
+        if (randomValue == 100) {
+            unsafe.putInt(object, offset, 41);
+        } else {
+            unsafe.putInt(object, offset, 40);
+        }
+        unsafe.putInt(object, offset, 42);
+        return oldValue;
+    }
+}
\ No newline at end of file