< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/PEAReadEliminationTest.java

Print this page

        

*** 20,29 **** --- 20,30 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.core.test.ea; + import org.graalvm.compiler.core.test.GraalCompilerTest; import org.junit.Test; import sun.misc.Unsafe; import org.graalvm.compiler.nodes.StructuredGraph;
*** 34,44 **** import org.graalvm.compiler.phases.common.CanonicalizerPhase; import org.graalvm.compiler.phases.common.inlining.InliningPhase; import org.graalvm.compiler.phases.tiers.HighTierContext; import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase; ! public class PEAReadEliminationTest extends EarlyReadEliminationTest { public static int testIndexed1Snippet(int[] array) { array[1] = 1; array[2] = 2; array[3] = 3; --- 35,45 ---- import org.graalvm.compiler.phases.common.CanonicalizerPhase; import org.graalvm.compiler.phases.common.inlining.InliningPhase; import org.graalvm.compiler.phases.tiers.HighTierContext; import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase; ! public class PEAReadEliminationTest extends GraalCompilerTest { public static int testIndexed1Snippet(int[] array) { array[1] = 1; array[2] = 2; array[3] = 3;
*** 48,58 **** return array[1] + array[2] + array[3] + array[4] + array[5] + array[6]; } @Test public void testIndexed1() { ! StructuredGraph graph = processMethod("testIndexed1Snippet", false); assertDeepEquals(0, graph.getNodes().filter(LoadIndexedNode.class).count()); } public static int testIndexed2Snippet(int v, int[] array) { array[1] = 1; --- 49,59 ---- return array[1] + array[2] + array[3] + array[4] + array[5] + array[6]; } @Test public void testIndexed1() { ! StructuredGraph graph = processMethod("testIndexed1Snippet"); assertDeepEquals(0, graph.getNodes().filter(LoadIndexedNode.class).count()); } public static int testIndexed2Snippet(int v, int[] array) { array[1] = 1;
*** 68,78 **** return array[1] + array[2] + array[3] + array[4] + array[5] + array[6]; } @Test public void testIndexed2() { ! StructuredGraph graph = processMethod("testIndexed2Snippet", false); assertDeepEquals(3, graph.getNodes().filter(LoadIndexedNode.class).count()); assertDeepEquals(7, graph.getNodes().filter(StoreIndexedNode.class).count()); } public static int testIndexed3Snippet(int v, int[] array, short[] array2) { --- 69,79 ---- return array[1] + array[2] + array[3] + array[4] + array[5] + array[6]; } @Test public void testIndexed2() { ! StructuredGraph graph = processMethod("testIndexed2Snippet"); assertDeepEquals(3, graph.getNodes().filter(LoadIndexedNode.class).count()); assertDeepEquals(7, graph.getNodes().filter(StoreIndexedNode.class).count()); } public static int testIndexed3Snippet(int v, int[] array, short[] array2) {
*** 92,102 **** return array[1] + array[2] + array[3] + array[4] + array[5] + array[6] + array2[1] + array2[2] + array2[3] + array2[4] + array2[5] + array2[6]; } @Test public void testIndexed3() { ! StructuredGraph graph = processMethod("testIndexed3Snippet", false); assertDeepEquals(3, graph.getNodes().filter(LoadIndexedNode.class).count()); } private static native void nonInlineable(); --- 93,103 ---- return array[1] + array[2] + array[3] + array[4] + array[5] + array[6] + array2[1] + array2[2] + array2[3] + array2[4] + array2[5] + array2[6]; } @Test public void testIndexed3() { ! StructuredGraph graph = processMethod("testIndexed3Snippet"); assertDeepEquals(3, graph.getNodes().filter(LoadIndexedNode.class).count()); } private static native void nonInlineable();
*** 111,121 **** return array[1] + array[2] + array[3] + array[4] + array[5] + array[6]; } @Test public void testIndexed4() { ! StructuredGraph graph = processMethod("testIndexed4Snippet", false); assertDeepEquals(3, graph.getNodes().filter(LoadIndexedNode.class).count()); } private static final long offsetInt1 = Unsafe.ARRAY_INT_BASE_OFFSET + Unsafe.ARRAY_INT_INDEX_SCALE * 1; private static final long offsetInt2 = Unsafe.ARRAY_INT_BASE_OFFSET + Unsafe.ARRAY_INT_INDEX_SCALE * 2; --- 112,122 ---- return array[1] + array[2] + array[3] + array[4] + array[5] + array[6]; } @Test public void testIndexed4() { ! StructuredGraph graph = processMethod("testIndexed4Snippet"); assertDeepEquals(3, graph.getNodes().filter(LoadIndexedNode.class).count()); } private static final long offsetInt1 = Unsafe.ARRAY_INT_BASE_OFFSET + Unsafe.ARRAY_INT_INDEX_SCALE * 1; private static final long offsetInt2 = Unsafe.ARRAY_INT_BASE_OFFSET + Unsafe.ARRAY_INT_INDEX_SCALE * 2;
*** 127,137 **** return s + UNSAFE.getInt(array, offsetInt1) + UNSAFE.getInt(array, offsetInt2); } @Test public void testUnsafe1() { ! StructuredGraph graph = processMethod("testUnsafe1Snippet", false); assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count()); } public static int testUnsafe2Snippet(int v, Object array) { int s = UNSAFE.getInt(array, offsetInt1); --- 128,138 ---- return s + UNSAFE.getInt(array, offsetInt1) + UNSAFE.getInt(array, offsetInt2); } @Test public void testUnsafe1() { ! StructuredGraph graph = processMethod("testUnsafe1Snippet"); assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count()); } public static int testUnsafe2Snippet(int v, Object array) { int s = UNSAFE.getInt(array, offsetInt1);
*** 140,150 **** return s + UNSAFE.getInt(array, offsetInt1) + UNSAFE.getInt(array, offsetInt2); } @Test public void testUnsafe2() { ! StructuredGraph graph = processMethod("testUnsafe2Snippet", false); assertDeepEquals(3, graph.getNodes().filter(RawLoadNode.class).count()); } private static final long offsetObject1 = Unsafe.ARRAY_OBJECT_BASE_OFFSET + Unsafe.ARRAY_OBJECT_INDEX_SCALE * 1; private static final long offsetObject2 = Unsafe.ARRAY_OBJECT_BASE_OFFSET + Unsafe.ARRAY_OBJECT_INDEX_SCALE * 2; --- 141,151 ---- return s + UNSAFE.getInt(array, offsetInt1) + UNSAFE.getInt(array, offsetInt2); } @Test public void testUnsafe2() { ! StructuredGraph graph = processMethod("testUnsafe2Snippet"); assertDeepEquals(3, graph.getNodes().filter(RawLoadNode.class).count()); } private static final long offsetObject1 = Unsafe.ARRAY_OBJECT_BASE_OFFSET + Unsafe.ARRAY_OBJECT_INDEX_SCALE * 1; private static final long offsetObject2 = Unsafe.ARRAY_OBJECT_BASE_OFFSET + Unsafe.ARRAY_OBJECT_INDEX_SCALE * 2;
*** 156,166 **** return s + (Integer) UNSAFE.getObject(array, offsetObject1) + (Integer) UNSAFE.getObject(array, offsetObject2); } @Test public void testUnsafe3() { ! StructuredGraph graph = processMethod("testUnsafe3Snippet", false); assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count()); } public static int testUnsafe4Snippet(int v, Object[] array) { int s = (Integer) UNSAFE.getObject(array, offsetObject1); --- 157,167 ---- return s + (Integer) UNSAFE.getObject(array, offsetObject1) + (Integer) UNSAFE.getObject(array, offsetObject2); } @Test public void testUnsafe3() { ! StructuredGraph graph = processMethod("testUnsafe3Snippet"); assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count()); } public static int testUnsafe4Snippet(int v, Object[] array) { int s = (Integer) UNSAFE.getObject(array, offsetObject1);
*** 170,201 **** return s + (Integer) UNSAFE.getObject(array, offsetObject1) + (Integer) UNSAFE.getObject(array, offsetObject2); } @Test public void testUnsafe4() { ! StructuredGraph graph = processMethod("testUnsafe4Snippet", false); assertDeepEquals(3, graph.getNodes().filter(RawLoadNode.class).count()); } ! private static final long offsetLong1 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 1; ! private static final long offsetLong2 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 2; ! ! public static int testUnsafe5Snippet(int v, long[] array) { ! int s = UNSAFE.getInt(array, offsetLong1); ! UNSAFE.putInt(array, offsetLong1, v); ! UNSAFE.putInt(array, offsetLong2, v); ! return s + UNSAFE.getInt(array, offsetLong1) + UNSAFE.getInt(array, offsetLong2); ! } ! ! @Test ! public void testUnsafe5() { ! StructuredGraph graph = processMethod("testUnsafe5Snippet", false); ! assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count()); ! } ! ! @Override ! protected StructuredGraph processMethod(final String snippet, boolean doLowering) { StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO); HighTierContext context = getDefaultHighTierContext(); new InliningPhase(new CanonicalizerPhase()).apply(graph, context); new PartialEscapePhase(false, true, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context); return graph; --- 171,185 ---- return s + (Integer) UNSAFE.getObject(array, offsetObject1) + (Integer) UNSAFE.getObject(array, offsetObject2); } @Test public void testUnsafe4() { ! StructuredGraph graph = processMethod("testUnsafe4Snippet"); assertDeepEquals(3, graph.getNodes().filter(RawLoadNode.class).count()); } ! protected StructuredGraph processMethod(final String snippet) { StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO); HighTierContext context = getDefaultHighTierContext(); new InliningPhase(new CanonicalizerPhase()).apply(graph, context); new PartialEscapePhase(false, true, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context); return graph;
< prev index next >