# HG changeset patch # User Thomas Wuerthinger # Date 1422399125 -3600 # Node ID 5ff49be5a02c14219db42794e074285727747a96 # Parent 48b79b8e18f1fcd9174cfdca8e49ac1fc3b4ff3b Add a corner case test case with a mixture of unsafe writes and normal reads. diff -r 48b79b8e18f1 -r 5ff49be5a02c graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAccess01.java --- 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