# HG changeset patch # User Michael Van De Vanter # Date 1370908085 25200 # Node ID fb2c8034e9b96adc7c2dd49d4248ad0f47c79d97 # Parent b9b8af46c2b72d0a94d5390e4e26fb67ac06ce8c# Parent 13384d19fec0af8e42d8d97a0dd231365831802a Merge with 13384d19fec0af8e42d8d97a0dd231365831802a diff -r b9b8af46c2b7 -r fb2c8034e9b9 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Mon Jun 10 16:46:26 2013 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Mon Jun 10 16:48:05 2013 -0700 @@ -48,10 +48,10 @@ import com.oracle.graal.lir.amd64.AMD64ControlFlow.CondMoveOp; import com.oracle.graal.lir.amd64.AMD64Move.CompareAndSwapCompressedOp; import com.oracle.graal.lir.amd64.AMD64Move.CompareAndSwapOp; -import com.oracle.graal.lir.amd64.AMD64Move.LoadCompressedOop; +import com.oracle.graal.lir.amd64.AMD64Move.LoadCompressedPointer; import com.oracle.graal.lir.amd64.AMD64Move.LoadOp; import com.oracle.graal.lir.amd64.AMD64Move.MoveFromRegOp; -import com.oracle.graal.lir.amd64.AMD64Move.StoreCompressedOop; +import com.oracle.graal.lir.amd64.AMD64Move.StoreCompressedPointer; import com.oracle.graal.lir.amd64.AMD64Move.StoreConstantOp; import com.oracle.graal.lir.amd64.AMD64Move.StoreOp; import com.oracle.graal.nodes.*; @@ -410,9 +410,8 @@ Variable result = newVariable(kind); assert access == null || access instanceof HeapAccess; if (runtime().config.useCompressedOops && isCompressCandidate(access)) { - assert kind == Kind.Object; Variable scratch = newVariable(Kind.Long); - append(new LoadCompressedOop(kind, result, scratch, loadAddress, access != null ? state(access) : null, runtime().config.narrowOopBase, runtime().config.narrowOopShift, + append(new LoadCompressedPointer(kind, result, scratch, loadAddress, access != null ? state(access) : null, runtime().config.narrowOopBase, runtime().config.narrowOopShift, runtime().config.logMinObjAlignment)); } else { append(new LoadOp(kind, result, loadAddress, access != null ? state(access) : null)); @@ -433,9 +432,8 @@ } Variable input = load(inputVal); if (runtime().config.useCompressedOops && isCompressCandidate(access)) { - assert kind == Kind.Object; Variable scratch = newVariable(Kind.Long); - append(new StoreCompressedOop(kind, storeAddress, input, scratch, state, runtime().config.narrowOopBase, runtime().config.narrowOopShift, runtime().config.logMinObjAlignment)); + append(new StoreCompressedPointer(kind, storeAddress, input, scratch, state, runtime().config.narrowOopBase, runtime().config.narrowOopShift, runtime().config.logMinObjAlignment)); } else { append(new StoreOp(kind, storeAddress, input, state)); } @@ -463,7 +461,6 @@ RegisterValue raxRes = AMD64.rax.asValue(kind); emitMove(raxRes, expected); if (runtime().config.useCompressedOops && node.compress()) { - assert kind == Kind.Object; Variable scratch = newVariable(Kind.Long); append(new CompareAndSwapCompressedOp(raxRes, address, raxRes, newValue, scratch, runtime().config.narrowOopBase, runtime().config.narrowOopShift, runtime().config.logMinObjAlignment)); } else { diff -r b9b8af46c2b7 -r fb2c8034e9b9 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/CompressedOopTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/CompressedOopTest.java Mon Jun 10 16:46:26 2013 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/CompressedOopTest.java Mon Jun 10 16:48:05 2013 -0700 @@ -29,7 +29,6 @@ import org.junit.*; -import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.api.runtime.*; import com.oracle.graal.compiler.test.*; @@ -39,141 +38,172 @@ * The following tests perform object/array equality and assignments in various ways. The selected * cases have been the problematic ones while implementing the Compressed Oops support. */ - public class CompressedOopTest extends GraalCompilerTest { private final MetaAccessProvider metaAccessProvider; - Object[] argsToBind; public CompressedOopTest() { this.metaAccessProvider = Graal.getRequiredCapability(MetaAccessProvider.class); } + private HotSpotInstalledCode getInstalledCode(String name) throws Exception { + final Method method = CompressedOopTest.class.getMethod(name, Object.class, Object.class, Object.class); + final HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(method); + final HotSpotInstalledCode installedBenchmarkCode = (HotSpotInstalledCode) getCode(javaMethod, parse(method)); + return installedBenchmarkCode; + } + @Test - public void test() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("fieldTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; - final Method benchmarkMethod = CompressedOopTest.class.getMethod("benchmark", HotSpotInstalledCode.class, Object.class, Object.class, Object.class); - final ResolvedJavaMethod benchmarkJavaMethod = metaAccessProvider.lookupJavaMethod(benchmarkMethod); - final HotSpotInstalledCode installedBenchmarkCode = (HotSpotInstalledCode) getCode(benchmarkJavaMethod, parse(benchmarkMethod)); + public void test() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("fieldTest"); Container c1 = new Container(); - Assert.assertEquals(c1.b, installedBenchmarkCode.executeVarargs(argsToBind[0], c1, c1, c1)); + Assert.assertEquals(c1.b, installedBenchmarkCode.executeVarargs(c1, c1, c1)); + } + + public static Object fieldTest(Object c1, @SuppressWarnings("unused") Object c2, @SuppressWarnings("unused") Object c3) { + ((Container) c1).a = ((Container) c1).b; + return ((Container) c1).a; } @Test - public void test1() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("arrayTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; - final Method benchmarkMethod = CompressedOopTest.class.getMethod("benchmark", HotSpotInstalledCode.class, Object.class, Object.class, Object.class); - final ResolvedJavaMethod benchmarkJavaMethod = metaAccessProvider.lookupJavaMethod(benchmarkMethod); - final HotSpotInstalledCode installedBenchmarkCode = (HotSpotInstalledCode) getCode(benchmarkJavaMethod, parse(benchmarkMethod)); + public void test1() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("arrayTest"); ArrayContainer ac = new ArrayContainer(); - Assert.assertEquals(ac.a[9], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 0, 9)); - Assert.assertEquals(ac.a[8], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 1, 8)); - Assert.assertEquals(ac.a[7], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 2, 7)); - Assert.assertEquals(ac.a[6], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 3, 6)); - Assert.assertEquals(ac.a[5], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 4, 5)); - Assert.assertEquals(ac.a[4], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 5, 4)); - Assert.assertEquals(ac.a[3], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 6, 3)); - Assert.assertEquals(ac.a[2], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 7, 2)); - Assert.assertEquals(ac.a[1], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 8, 1)); - Assert.assertEquals(ac.a[0], installedBenchmarkCode.executeVarargs(argsToBind[0], ac.a, 9, 0)); + Assert.assertEquals(ac.a[9], installedBenchmarkCode.executeVarargs(ac.a, 0, 9)); + Assert.assertEquals(ac.a[8], installedBenchmarkCode.executeVarargs(ac.a, 1, 8)); + Assert.assertEquals(ac.a[7], installedBenchmarkCode.executeVarargs(ac.a, 2, 7)); + Assert.assertEquals(ac.a[6], installedBenchmarkCode.executeVarargs(ac.a, 3, 6)); + Assert.assertEquals(ac.a[5], installedBenchmarkCode.executeVarargs(ac.a, 4, 5)); + Assert.assertEquals(ac.a[4], installedBenchmarkCode.executeVarargs(ac.a, 5, 4)); + Assert.assertEquals(ac.a[3], installedBenchmarkCode.executeVarargs(ac.a, 6, 3)); + Assert.assertEquals(ac.a[2], installedBenchmarkCode.executeVarargs(ac.a, 7, 2)); + Assert.assertEquals(ac.a[1], installedBenchmarkCode.executeVarargs(ac.a, 8, 1)); + Assert.assertEquals(ac.a[0], installedBenchmarkCode.executeVarargs(ac.a, 9, 0)); + } + + public static Object arrayTest(Object c1, Object c2, Object c3) { + Object[] array = (Object[]) c1; + int initialIndex = ((Integer) c2).intValue(); + int replacingIndex = ((Integer) c3).intValue(); + array[initialIndex] = array[replacingIndex]; + return array[initialIndex]; } @Test - public void test2() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("arrayCopyTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; + public void test2() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("arrayCopyTest"); ArrayContainer source = new ArrayContainer(); ArrayContainer destination = new ArrayContainer(); Assert.assertEquals(source.a.length, destination.a.length); Assert.assertFalse(Arrays.equals(source.a, destination.a)); - fooCode.execute(source.a, destination.a, source.a); + installedBenchmarkCode.execute(source.a, destination.a, source.a); Assert.assertArrayEquals(source.a, destination.a); } + public static void arrayCopyTest(Object c1, Object c2, @SuppressWarnings("unused") Object c3) { + Object[] source = (Object[]) c1; + Object[] destination = (Object[]) c2; + System.arraycopy(source, 0, destination, 0, source.length); + } + @Test - public void test3() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("compareAndSwapTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; + public void test3() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("compareAndSwapTest"); Object initial = new Object(); Object replacement = new Object(); AtomicReference cas = new AtomicReference<>(); Assert.assertEquals(cas.get(), null); - fooCode.execute(cas, null, initial); + installedBenchmarkCode.execute(cas, null, initial); Assert.assertEquals(cas.get(), initial); - fooCode.execute(cas, initial, replacement); + installedBenchmarkCode.execute(cas, initial, replacement); Assert.assertEquals(cas.get(), replacement); } + @SuppressWarnings("unchecked") + public static void compareAndSwapTest(Object c1, Object c2, Object c3) throws ClassCastException { + AtomicReference cas = (AtomicReference) c1; + cas.compareAndSet(c2, c3); + } + @Test - public void test4() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("charArrayCopyTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; + public void test4() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("charArrayCopyTest"); StringContainer1 source1 = new StringContainer1(); StringContainer2 source2 = new StringContainer2(); char[] result = new char[source1.value.length + source2.value.length]; - fooCode.execute(source1.value, source2.value, result); + installedBenchmarkCode.execute(source1.value, source2.value, result); Assert.assertArrayEquals(new char[]{'T', 'e', 's', 't', ' ', 'S', 't', 'r', 'i', 'n', 'g'}, result); } + public static char[] charArrayCopyTest(Object c1, Object c2, Object c3) { + char[] source1 = (char[]) c1; + char[] source2 = (char[]) c2; + char[] result = (char[]) c3; + for (int i = 0; i < source1.length; i++) { + result[i] = source1[i]; + } + + for (int i = 0; i < source2.length; i++) { + result[source1.length + i] = source2[i]; + } + return result; + } + @Test - public void test5() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("charContainerArrayCopyTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; + public void test5() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("charContainerArrayCopyTest"); StringContainer1 source1 = new StringContainer1(); StringContainer2 source2 = new StringContainer2(); char[] result = new char[source1.value.length + source2.value.length]; - fooCode.execute(source1, source2, result); + installedBenchmarkCode.execute(source1, source2, result); Assert.assertArrayEquals(new char[]{'T', 'e', 's', 't', ' ', 'S', 't', 'r', 'i', 'n', 'g'}, result); } + public static char[] charContainerArrayCopyTest(Object c1, Object c2, Object c3) { + char[] source1 = ((StringContainer1) c1).value; + char[] source2 = ((StringContainer2) c2).value; + char[] result = (char[]) c3; + for (int i = 0; i < source1.length; i++) { + result[i] = source1[i]; + } + for (int i = 0; i < source2.length; i++) { + result[source1.length + i] = source2[i]; + } + return result; + } + @Test - public void test6() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("stringCopyTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; + public void test6() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("stringCopyTest"); String a = new String("Test "); String b = new String("String"); - String c = (String) fooCode.execute(a, b, null); + String c = (String) installedBenchmarkCode.execute(a, b, null); Assert.assertTrue(c.equals("Test String")); } + public static String stringCopyTest(Object c1, Object c2, @SuppressWarnings("unused") Object c3) { + String source = (String) c1; + String destination = (String) c2; + return source + destination; + } + @Test - public void test7() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("queueTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; + public void test7() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("queueTest"); ArrayDeque q = new ArrayDeque<>(); Object[] objects = new Object[512]; for (int i = 0; i < objects.length; i++) { objects[i] = new Object(); } - int j = 0; while (j < objects.length) { - fooCode.execute(q, objects[j], null); + installedBenchmarkCode.execute(q, objects[j], null); j++; } System.gc(); Assert.assertTrue(q.size() == objects.length); Assert.assertTrue(!q.isEmpty()); - j = 0; while (j < objects.length) { Assert.assertTrue(objects[j] == q.remove()); @@ -184,18 +214,20 @@ Assert.assertTrue(q.isEmpty()); } + @SuppressWarnings("unchecked") + public static void queueTest(Object c1, Object c2, @SuppressWarnings("unused") Object c3) { + ArrayDeque queue = (ArrayDeque) c1; + queue.add(c2); + } + @Test - public void test8() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("unmodListTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; + public void test8() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("unmodListTest"); List list = new ArrayList<>(); for (int i = 0; i < 512; i++) { list.add(new Object()); } - - Object[] array = (Object[]) fooCode.execute(list, null, null); + Object[] array = (Object[]) installedBenchmarkCode.execute(list, null, null); Assert.assertTrue(list.size() == array.length); int i = 0; for (Object obj : list) { @@ -204,134 +236,6 @@ } } - @Test - public void test9() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("unmodListTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; - List list = new ArrayList<>(); - Object[] array = (Object[]) fooCode.execute(list, null, null); - Assert.assertTrue(list.size() == array.length); - } - - public void test10() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("constantTest", Object.class, Object.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; - Container c = new Container(); - Assert.assertFalse((boolean) fooCode.execute(c, null, null)); - } - - @Test - public void test11() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("stringEqualsTest", String.class, String.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; - String s1 = new String("Test"); - String s2 = new String("Test"); - boolean result = ((Boolean) (fooCode.execute(s1, s2, null))).booleanValue(); - Assert.assertTrue(result); - } - - @Test - public void test12() throws NoSuchMethodException, SecurityException, InvalidInstalledCodeException { - final Method fooMethod = CompressedOopTest.class.getMethod("stringConstantEqualsTest", String.class, String.class, Object.class); - final HotSpotResolvedJavaMethod fooJavaMethod = (HotSpotResolvedJavaMethod) metaAccessProvider.lookupJavaMethod(fooMethod); - final HotSpotInstalledCode fooCode = (HotSpotInstalledCode) getCode(fooJavaMethod, parse(fooMethod)); - argsToBind = new Object[]{fooCode}; - String s1 = new String("Test"); - boolean result = ((Boolean) (fooCode.execute(s1, null, null))).booleanValue(); - Assert.assertTrue(result); - } - - public static Object benchmark(HotSpotInstalledCode code, Object o1, Object o2, Object o3) throws InvalidInstalledCodeException { - return code.execute(o1, o2, o3); - } - - public static Object fieldTest(Object c1, @SuppressWarnings("unused") Object c2, @SuppressWarnings("unused") Object c3) { - ((Container) c1).a = ((Container) c1).b; - return ((Container) c1).a; - } - - public static Object arrayTest(Object c1, Object c2, Object c3) { - Object[] array = (Object[]) c1; - int initialIndex = ((Integer) c2).intValue(); - int replacingIndex = ((Integer) c3).intValue(); - array[initialIndex] = array[replacingIndex]; - return array[initialIndex]; - } - - public static void arrayCopyTest(Object c1, Object c2, @SuppressWarnings("unused") Object c3) { - Object[] source = (Object[]) c1; - Object[] destination = (Object[]) c2; - System.arraycopy(source, 0, destination, 0, source.length); - } - - public static String stringCopyTest(Object c1, Object c2, @SuppressWarnings("unused") Object c3) { - String source = (String) c1; - String destination = (String) c2; - return source + destination; - } - - public static char[] charArrayCopyTest(Object c1, Object c2, Object c3) { - char[] source1 = (char[]) c1; - char[] source2 = (char[]) c2; - char[] result = (char[]) c3; - - for (int i = 0; i < source1.length; i++) { - result[i] = source1[i]; - } - - for (int i = 0; i < source2.length; i++) { - result[source1.length + i] = source2[i]; - } - return result; - } - - public static char[] charContainerArrayCopyTest(Object c1, Object c2, Object c3) { - char[] source1 = ((StringContainer1) c1).value; - char[] source2 = ((StringContainer2) c2).value; - char[] result = (char[]) c3; - - for (int i = 0; i < source1.length; i++) { - result[i] = source1[i]; - } - - for (int i = 0; i < source2.length; i++) { - result[source1.length + i] = source2[i]; - } - return result; - } - - @SuppressWarnings("unchecked") - public static void compareAndSwapTest(Object c1, Object c2, Object c3) throws ClassCastException { - AtomicReference cas = (AtomicReference) c1; - cas.compareAndSet(c2, c3); - } - - @SuppressWarnings("unchecked") - public static HashMap hashMapCloneTest(Object c1, @SuppressWarnings("unused") Object c2, @SuppressWarnings("unused") Object c3) { - HashMap map = (HashMap) c1; - return (HashMap) map.clone(); - } - - @SuppressWarnings("unchecked") - public static void hashMapCopyTest(Object c1, Object c2, @SuppressWarnings("unused") Object c3) { - HashMap map = (HashMap) c1; - HashMap map1 = (HashMap) c2; - map.clear(); - map.putAll(map1); - } - - @SuppressWarnings("unchecked") - public static void queueTest(Object c1, Object c2, @SuppressWarnings("unused") Object c3) { - ArrayDeque queue = (ArrayDeque) c1; - queue.add(c2); - } - @SuppressWarnings("unchecked") public static Object[] unmodListTest(Object c1, @SuppressWarnings("unused") Object c2, @SuppressWarnings("unused") Object c3) { List queue = (ArrayList) c1; @@ -339,83 +243,114 @@ return result; } + @Test + public void test9() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("unmodListTest"); + List list = new ArrayList<>(); + Object[] array = (Object[]) installedBenchmarkCode.execute(list, null, null); + Assert.assertTrue(list.size() == array.length); + } + + public void test10() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("constantTest"); + Container c = new Container(); + Assert.assertFalse((boolean) installedBenchmarkCode.execute(c, null, null)); + } + public static Boolean constantTest(Object c1, @SuppressWarnings("unused") Object c2, @SuppressWarnings("unused") Object c3) { ConstantContainer container = (ConstantContainer) c1; return container.a.equals(container.b); } - public static Boolean stringEqualsTest(String c1, String c2, @SuppressWarnings("unused") Object c3) { - return c1.equals(c2); + @Test + public void test11() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("stringEqualsTest"); + String s1 = new String("Test"); + String s2 = new String("Test"); + boolean result = ((Boolean) (installedBenchmarkCode.execute(s1, s2, null))).booleanValue(); + Assert.assertTrue(result); + } + + public static Boolean stringEqualsTest(Object c1, Object c2, @SuppressWarnings("unused") Object c3) { + return ((String) c1).equals(c2); + } + + @Test + public void test12() throws Exception { + HotSpotInstalledCode installedBenchmarkCode = getInstalledCode("stringConstantEqualsTest"); + String s1 = new String("Test"); + boolean result = ((Boolean) (installedBenchmarkCode.execute(s1, null, null))).booleanValue(); + Assert.assertTrue(result); + } + + public static Boolean stringConstantEqualsTest(Object c1, @SuppressWarnings("unused") Object c2, @SuppressWarnings("unused") Object c3) { + return "Test".equals(c1); + } + + static class Container { + + public Object a = new Object(); + public Object b = new Object(); + } + + static class ArrayContainer { + + public Object[] a = new Object[10]; + + public ArrayContainer() { + for (int i = 0; i < 10; i++) { + a[i] = new Object(); + } + } } - public static Boolean stringConstantEqualsTest(String c1, @SuppressWarnings("unused") String c2, @SuppressWarnings("unused") Object c3) { - return "Test".equals(c1); + static class HashMapContainer { + + public HashMap a = new HashMap<>(); + + public HashMapContainer() { + for (int i = 0; i < 10; i++) { + a.put(new Object(), new Object()); + } + } + } + + static class StringContainer1 { + + public char[] value = new char[5]; + + public StringContainer1() { + value[0] = 'T'; + value[1] = 'e'; + value[2] = 's'; + value[3] = 't'; + value[4] = ' '; + + } + } + + static class StringContainer2 { + + public char[] value = new char[6]; + + public StringContainer2() { + value[0] = 'S'; + value[1] = 't'; + value[2] = 'r'; + value[3] = 'i'; + value[4] = 'n'; + value[5] = 'g'; + } + } + + static class ConstantContainer { + + public final Object a = new Object(); + public final Object b = new Object(); + + public ConstantContainer() { + + } } } - -class Container { - - public Object a = new Object(); - public Object b = new Object(); -} - -class ArrayContainer { - - public Object[] a = new Object[10]; - - public ArrayContainer() { - for (int i = 0; i < 10; i++) { - a[i] = new Object(); - } - } -} - -class HashMapContainer { - - public HashMap a = new HashMap<>(); - - public HashMapContainer() { - for (int i = 0; i < 10; i++) { - a.put(new Object(), new Object()); - } - } -} - -class StringContainer1 { - - public char[] value = new char[5]; - - public StringContainer1() { - value[0] = 'T'; - value[1] = 'e'; - value[2] = 's'; - value[3] = 't'; - value[4] = ' '; - - } -} - -class StringContainer2 { - - public char[] value = new char[6]; - - public StringContainer2() { - value[0] = 'S'; - value[1] = 't'; - value[2] = 'r'; - value[3] = 'i'; - value[4] = 'n'; - value[5] = 'g'; - } -} - -class ConstantContainer { - - public final Object a = new Object(); - public final Object b = new Object(); - - public ConstantContainer() { - - } -} diff -r b9b8af46c2b7 -r fb2c8034e9b9 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Mon Jun 10 16:46:26 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Mon Jun 10 16:48:05 2013 -0700 @@ -533,8 +533,7 @@ HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) loadField.field(); ValueNode object = loadField.isStatic() ? ConstantNode.forObject(field.getDeclaringClass().mirror(), this, graph) : loadField.object(); assert loadField.kind() != Kind.Illegal; - ReadNode memoryRead = graph.add(new ReadNode(object, createFieldLocation(graph, field), loadField.stamp(), WriteBarrierType.NONE, - (loadField.kind() == Kind.Object && !field.getName().equals("classMirrorOffset")))); + ReadNode memoryRead = graph.add(new ReadNode(object, createFieldLocation(graph, field), loadField.stamp(), WriteBarrierType.NONE, (loadField.kind() == Kind.Object))); tool.createNullCheckGuard(memoryRead, object); graph.replaceFixedWithFixed(loadField, memoryRead); @@ -617,7 +616,10 @@ UnsafeLoadNode load = (UnsafeLoadNode) n; assert load.kind() != Kind.Illegal; IndexedLocationNode location = IndexedLocationNode.create(ANY_LOCATION, load.accessKind(), load.displacement(), load.offset(), graph, 1); - ReadNode memoryRead = graph.add(new ReadNode(load.object(), location, load.stamp(), WriteBarrierType.NONE, (!load.object().isNullConstant() && load.accessKind() == Kind.Object))); + // Unsafe Accesses to the metaspace or to any + // absolute address do not perform uncompression. + boolean compress = (!load.object().isNullConstant() && load.accessKind() == Kind.Object); + ReadNode memoryRead = graph.add(new ReadNode(load.object(), location, load.stamp(), WriteBarrierType.NONE, compress)); // An unsafe read must not floating outside its block as may float above an explicit // null check on its object. memoryRead.setGuard(AbstractBeginNode.prevBegin(load)); diff -r b9b8af46c2b7 -r fb2c8034e9b9 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java Mon Jun 10 16:46:26 2013 -0700 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java Mon Jun 10 16:48:05 2013 -0700 @@ -117,33 +117,28 @@ } } - public static class LoadCompressedOop extends LoadOp { + public static class LoadCompressedPointer extends LoadOp { private long narrowOopBase; private int narrowOopShift; private int logMinObjAlignment; @Temp({REG}) private AllocatableValue scratch; - public LoadCompressedOop(Kind kind, AllocatableValue result, AllocatableValue scratch, AMD64AddressValue address, LIRFrameState state, long narrowOopBase, int narrowOopShift, + public LoadCompressedPointer(Kind kind, AllocatableValue result, AllocatableValue scratch, AMD64AddressValue address, LIRFrameState state, long narrowOopBase, int narrowOopShift, int logMinObjAlignment) { super(kind, result, address, state); this.narrowOopBase = narrowOopBase; this.narrowOopShift = narrowOopShift; this.logMinObjAlignment = logMinObjAlignment; this.scratch = scratch; + assert kind == Kind.Object; } @Override public void emitMemAccess(AMD64MacroAssembler masm) { - switch (kind) { - case Object: - Register resRegister = asRegister(result); - masm.movl(resRegister, address.toAddress()); - decodeOop(masm, resRegister, narrowOopBase, narrowOopShift, logMinObjAlignment); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } + Register resRegister = asRegister(result); + masm.movl(resRegister, address.toAddress()); + decodePointer(masm, resRegister, narrowOopBase, narrowOopShift, logMinObjAlignment); } } @@ -190,7 +185,7 @@ } } - public static class StoreCompressedOop extends AMD64LIRInstruction { + public static class StoreCompressedPointer extends AMD64LIRInstruction { protected final Kind kind; private long narrowOopBase; @@ -201,7 +196,7 @@ @Alive({COMPOSITE}) protected AMD64AddressValue address; @State protected LIRFrameState state; - public StoreCompressedOop(Kind kind, AMD64AddressValue address, AllocatableValue input, AllocatableValue scratch, LIRFrameState state, long narrowOopBase, int narrowOopShift, + public StoreCompressedPointer(Kind kind, AMD64AddressValue address, AllocatableValue input, AllocatableValue scratch, LIRFrameState state, long narrowOopBase, int narrowOopShift, int logMinObjAlignment) { this.narrowOopBase = narrowOopBase; this.narrowOopShift = narrowOopShift; @@ -211,27 +206,17 @@ this.address = address; this.state = state; this.input = input; + assert kind == Kind.Object; } @Override public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) { - emitMemAccess(tasm, masm); - } - - public void emitMemAccess(TargetMethodAssembler tasm, AMD64MacroAssembler masm) { - switch (kind) { - case Object: - masm.movq(asRegister(scratch), asRegister(input)); - encodeOop(masm, asRegister(scratch), narrowOopBase, narrowOopShift, logMinObjAlignment); - if (state != null) { - tasm.recordImplicitException(masm.codeBuffer.position(), state); - } - masm.movl(address.toAddress(), asRegister(scratch)); - // masm.movq(asRegister(scratch), 0xDEADBEEF); - break; - default: - throw GraalInternalError.shouldNotReachHere(); + masm.movq(asRegister(scratch), asRegister(input)); + encodePointer(masm, asRegister(scratch), narrowOopBase, narrowOopShift, logMinObjAlignment); + if (state != null) { + tasm.recordImplicitException(masm.codeBuffer.position(), state); } + masm.movl(address.toAddress(), asRegister(scratch)); } } @@ -438,6 +423,7 @@ this.address = address; this.cmpValue = cmpValue; this.newValue = newValue; + assert cmpValue.getKind() == Kind.Object; } @Override @@ -658,44 +644,44 @@ protected static void compareAndSwapCompressed(TargetMethodAssembler tasm, AMD64MacroAssembler masm, AllocatableValue result, AMD64AddressValue address, AllocatableValue cmpValue, AllocatableValue newValue, AllocatableValue scratch, long narrowOopBase, int narrowOopShift, int logMinObjAlignment) { assert asRegister(cmpValue) == AMD64.rax && asRegister(result) == AMD64.rax; - - switch (cmpValue.getKind()) { - case Object: - final Register scratchRegister = asRegister(scratch); - final Register cmpRegister = asRegister(cmpValue); - final Register newRegister = asRegister(newValue); - encodeOop(masm, cmpRegister, narrowOopBase, narrowOopShift, logMinObjAlignment); - masm.movq(scratchRegister, newRegister); - encodeOop(masm, scratchRegister, narrowOopBase, narrowOopShift, logMinObjAlignment); - if (tasm.target.isMP) { - masm.lock(); - } - masm.cmpxchgl(scratchRegister, address.toAddress()); - break; - default: - throw GraalInternalError.shouldNotReachHere(); + final Register scratchRegister = asRegister(scratch); + final Register cmpRegister = asRegister(cmpValue); + final Register newRegister = asRegister(newValue); + encodePointer(masm, cmpRegister, narrowOopBase, narrowOopShift, logMinObjAlignment); + masm.movq(scratchRegister, newRegister); + encodePointer(masm, scratchRegister, narrowOopBase, narrowOopShift, logMinObjAlignment); + if (tasm.target.isMP) { + masm.lock(); } + masm.cmpxchgl(scratchRegister, address.toAddress()); } - private static void encodeOop(AMD64MacroAssembler masm, Register scratchRegister, long narrowOopBase, int narrowOopShift, int logMinObjAlignment) { + private static void encodePointer(AMD64MacroAssembler masm, Register scratchRegister, long narrowOopBase, int narrowOopShift, int logMinObjAlignment) { + // If the narrowOopBase is zero, the uncompressed address has to be shifted right + // in order to be compressed. if (narrowOopBase == 0) { if (narrowOopShift != 0) { assert logMinObjAlignment == narrowOopShift : "Encode algorithm is wrong"; masm.shrq(scratchRegister, logMinObjAlignment); } } else { + // Otherwise the narrow heap base, which resides always in register 12, is subtracted + // followed by right shift. masm.subq(scratchRegister, AMD64.r12); masm.shrq(scratchRegister, logMinObjAlignment); } } - private static void decodeOop(AMD64MacroAssembler masm, Register resRegister, long narrowOopBase, int narrowOopShift, int logMinObjAlignment) { + private static void decodePointer(AMD64MacroAssembler masm, Register resRegister, long narrowOopBase, int narrowOopShift, int logMinObjAlignment) { + // If the narrowOopBase is zero, the compressed address has to be shifted left + // in order to be uncompressed. if (narrowOopBase == 0) { if (narrowOopShift != 0) { assert logMinObjAlignment == narrowOopShift : "Decode algorithm is wrong"; masm.shlq(resRegister, logMinObjAlignment); } } else { + // Otherwise the narrow heap base is added to the shifted address. masm.shlq(resRegister, logMinObjAlignment); masm.addq(resRegister, AMD64.r12); } diff -r b9b8af46c2b7 -r fb2c8034e9b9 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/WriteNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/WriteNode.java Mon Jun 10 16:46:26 2013 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/WriteNode.java Mon Jun 10 16:48:05 2013 -0700 @@ -37,7 +37,6 @@ @Input private ValueNode value; @Input(notDataflow = true) private FrameState stateAfter; - private final WriteBarrierType barrierType; public FrameState stateAfter() { return stateAfter; @@ -60,7 +59,6 @@ public WriteNode(ValueNode object, ValueNode value, ValueNode location, WriteBarrierType barrierType, boolean compress) { super(object, location, StampFactory.forVoid(), barrierType, compress); this.value = value; - this.barrierType = barrierType; } @Override diff -r b9b8af46c2b7 -r fb2c8034e9b9 src/share/vm/graal/graalCodeInstaller.cpp --- a/src/share/vm/graal/graalCodeInstaller.cpp Mon Jun 10 16:46:26 2013 -0700 +++ b/src/share/vm/graal/graalCodeInstaller.cpp Mon Jun 10 16:48:05 2013 -0700 @@ -269,12 +269,7 @@ arrayOop values = (arrayOop) VirtualObject::values(value); for (jint i = 0; i < values->length(); i++) { ScopeValue* cur_second = NULL; - oop object; - if(UseCompressedOops) { - object=oopDesc::decode_heap_oop(((narrowOop*) values->base(T_OBJECT))[i]); - } else { - object=((oop*) (values->base(T_OBJECT)))[i]; - } + oop object = ((objArrayOop) (values))->obj_at(i); ScopeValue* value = get_hotspot_value(object, total_frame_size, objects, cur_second, oop_recorder); if (isLongArray && cur_second == NULL) { @@ -456,13 +451,8 @@ memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); _instructions->set_end(_instructions->start() + _code_size); - oop site; for (int i = 0; i < _sites->length(); i++) { - if(UseCompressedOops) { - site=oopDesc::decode_heap_oop(((narrowOop*) _sites->base(T_OBJECT))[i]); - } else { - site=((oop*) (_sites->base(T_OBJECT)))[i]; - } + oop site=((objArrayOop) (_sites))->obj_at(i); jint pc_offset = CompilationResult_Site::pcOffset(site); if (site->is_a(CompilationResult_Call::klass())) { @@ -492,13 +482,8 @@ #ifndef PRODUCT if (_comments != NULL) { - oop comment; for (int i = 0; i < _comments->length(); i++) { - if(UseCompressedOops) { - comment=oopDesc::decode_heap_oop(((narrowOop*) _comments->base(T_OBJECT))[i]); - } else { - comment=((oop*) (_comments->base(T_OBJECT)))[i]; - } + oop comment=((objArrayOop) (_comments))->obj_at(i); assert(comment->is_a(HotSpotCompiledCode_Comment::klass()), "cce"); jint offset = HotSpotCompiledCode_Comment::pcOffset(comment); char* text = java_lang_String::as_utf8_string(HotSpotCompiledCode_Comment::text(comment)); @@ -558,14 +543,8 @@ GrowableArray* pcos = new GrowableArray (num_handlers); if (_exception_handlers != NULL) { - oop* exception_handlers = (oop*) _exception_handlers->base(T_OBJECT); for (int i = 0; i < _exception_handlers->length(); i++) { - oop exc; - if(UseCompressedOops) { - exc=oopDesc::decode_heap_oop(((narrowOop*) _exception_handlers->base(T_OBJECT))[i]); - } else { - exc=((oop*) (_exception_handlers->base(T_OBJECT)))[i]; - } + oop exc=((objArrayOop) (_exception_handlers))->obj_at(i); jint pc_offset = CompilationResult_Site::pcOffset(exc); jint handler_offset = CompilationResult_ExceptionHandler::handlerPos(exc); @@ -637,12 +616,7 @@ for (jint i = 0; i < values->length(); i++) { ScopeValue* second = NULL; - oop value; - if(UseCompressedOops) { - value=oopDesc::decode_heap_oop(((narrowOop*) values->base(T_OBJECT))[i]); - } else { - value = ((oop*) values->base(T_OBJECT))[i]; - } + oop value=((objArrayOop) (values))->obj_at(i); if (i < local_count) { ScopeValue* first = get_hotspot_value(value, _total_frame_size, objects, second, _oop_recorder); if (second != NULL) { @@ -661,11 +635,7 @@ if (second != NULL) { i++; assert(i < values->length(), "double-slot value not followed by Value.ILLEGAL"); - if(UseCompressedOops) { - assert(oopDesc::decode_heap_oop(((narrowOop*) values->base(T_OBJECT))[i]) == Value::ILLEGAL(), "double-slot value not followed by Value.ILLEGAL"); - } else { - assert(((oop*) values->base(T_OBJECT))[i] == Value::ILLEGAL(), "double-slot value not followed by Value.ILLEGAL"); - } + assert(((objArrayOop) (values))->obj_at(i) == Value::ILLEGAL(), "double-slot value not followed by Value.ILLEGAL"); } } diff -r b9b8af46c2b7 -r fb2c8034e9b9 src/share/vm/graal/graalCompilerToVM.hpp --- a/src/share/vm/graal/graalCompilerToVM.hpp Mon Jun 10 16:46:26 2013 -0700 +++ b/src/share/vm/graal/graalCompilerToVM.hpp Mon Jun 10 16:48:05 2013 -0700 @@ -54,12 +54,7 @@ oop next_arg(BasicType expectedType) { assert(_index < _args->length(), "out of bounds"); - oop arg; - if(UseCompressedOops) { - arg = oopDesc::decode_heap_oop(((narrowOop*) _args->base(T_OBJECT))[_index++]); - } else { - arg = ((oop*) _args->base(T_OBJECT))[_index++]; - } + oop arg=((objArrayOop) (_args))->obj_at(_index++); assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch"); return arg; } diff -r b9b8af46c2b7 -r fb2c8034e9b9 src/share/vm/prims/unsafe.cpp --- a/src/share/vm/prims/unsafe.cpp Mon Jun 10 16:46:26 2013 -0700 +++ b/src/share/vm/prims/unsafe.cpp Mon Jun 10 16:48:05 2013 -0700 @@ -188,6 +188,8 @@ #define GET_OOP_FIELD(obj, offset, v) \ oop p = JNIHandles::resolve(obj); \ oop v; \ + /* Uncompression is not performed to unsafeAccess with null object. + * This concerns accesses to the metaspace such as the classMirrorOffset which is not compressed.*/ \ if (UseCompressedOops && p!=NULL && offset>=oopDesc::header_size()) { \ narrowOop n = *(narrowOop*)index_oop_from_field_offset_long(p, offset); \ v = oopDesc::decode_heap_oop(n); \