7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.replacements.test; 24 25 import static org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo; 26 27 import org.junit.Test; 28 import org.graalvm.compiler.core.common.type.StampFactory; 29 import org.graalvm.compiler.core.test.GraalCompilerTest; 30 import org.graalvm.compiler.debug.Debug; 31 import org.graalvm.compiler.nodes.AbstractBeginNode; 32 import org.graalvm.compiler.nodes.StructuredGraph; 33 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 34 import org.graalvm.compiler.nodes.ValueNode; 35 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; 36 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; 37 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin; 38 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; 39 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; 40 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; 41 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType; 42 import org.graalvm.compiler.nodes.memory.ReadNode; 43 import org.graalvm.compiler.nodes.memory.address.AddressNode; 44 import org.graalvm.compiler.nodes.memory.address.OffsetAddressNode; 45 import org.graalvm.compiler.phases.OptimisticOptimizations; 46 import org.graalvm.compiler.phases.common.CanonicalizerPhase; 47 import org.graalvm.compiler.phases.tiers.PhaseContext; 48 import org.graalvm.compiler.replacements.CachingPEGraphDecoder; 49 import org.graalvm.word.LocationIdentity; 50 51 import jdk.vm.ci.meta.JavaKind; 52 import jdk.vm.ci.meta.ResolvedJavaMethod; 53 54 public class PEGraphDecoderTest extends GraalCompilerTest { 55 56 /** 57 * This method is intrinsified to a node with a guard dependency on the block it is in. The 58 * various tests ensure that this guard is correctly updated when blocks are merged during 59 * inlining. 60 */ 61 private static native int readInt(Object obj, long offset); 62 63 private static boolean flag; 64 private static int value; 65 66 private static void invokeSimple() { 67 value = 111; 68 } 69 113 AddressNode address = b.add(new OffsetAddressNode(obj, offset)); 114 ReadNode read = b.addPush(JavaKind.Int, new ReadNode(address, LocationIdentity.any(), StampFactory.forKind(JavaKind.Int), BarrierType.NONE)); 115 read.setGuard(AbstractBeginNode.prevBegin(read)); 116 return true; 117 } 118 }); 119 } 120 121 class InlineAll implements InlineInvokePlugin { 122 @Override 123 public InlineInfo shouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) { 124 return createStandardInlineInfo(method); 125 } 126 } 127 128 @Test 129 @SuppressWarnings("try") 130 public void test() { 131 ResolvedJavaMethod testMethod = getResolvedJavaMethod(PEGraphDecoderTest.class, "doTest", Object.class); 132 StructuredGraph targetGraph = null; 133 try (Debug.Scope scope = Debug.scope("GraphPETest", testMethod)) { 134 GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true); 135 registerPlugins(graphBuilderConfig.getPlugins().getInvocationPlugins()); 136 targetGraph = new StructuredGraph.Builder(getInitialOptions(), AllowAssumptions.YES).method(testMethod).build(); 137 CachingPEGraphDecoder decoder = new CachingPEGraphDecoder(getTarget().arch, targetGraph, getProviders(), graphBuilderConfig, OptimisticOptimizations.NONE, AllowAssumptions.YES, 138 getInitialOptions(), null, null, new InlineInvokePlugin[]{new InlineAll()}, null, null); 139 140 decoder.decode(testMethod); 141 Debug.dump(Debug.BASIC_LEVEL, targetGraph, "Target Graph"); 142 targetGraph.verify(); 143 144 PhaseContext context = new PhaseContext(getProviders()); 145 new CanonicalizerPhase().apply(targetGraph, context); 146 targetGraph.verify(); 147 148 } catch (Throwable ex) { 149 if (targetGraph != null) { 150 Debug.dump(Debug.BASIC_LEVEL, targetGraph, ex.toString()); 151 } 152 Debug.handle(ex); 153 } 154 } 155 } | 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.replacements.test; 24 25 import static org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo; 26 27 import org.graalvm.compiler.core.common.type.StampFactory; 28 import org.graalvm.compiler.core.test.GraalCompilerTest; 29 import org.graalvm.compiler.debug.DebugContext; 30 import org.graalvm.compiler.nodes.AbstractBeginNode; 31 import org.graalvm.compiler.nodes.StructuredGraph; 32 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 33 import org.graalvm.compiler.nodes.ValueNode; 34 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; 35 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; 36 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin; 37 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; 38 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; 39 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; 40 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType; 41 import org.graalvm.compiler.nodes.memory.ReadNode; 42 import org.graalvm.compiler.nodes.memory.address.AddressNode; 43 import org.graalvm.compiler.nodes.memory.address.OffsetAddressNode; 44 import org.graalvm.compiler.phases.OptimisticOptimizations; 45 import org.graalvm.compiler.phases.common.CanonicalizerPhase; 46 import org.graalvm.compiler.phases.tiers.PhaseContext; 47 import org.graalvm.compiler.replacements.CachingPEGraphDecoder; 48 import org.graalvm.word.LocationIdentity; 49 import org.junit.Test; 50 51 import jdk.vm.ci.meta.JavaKind; 52 import jdk.vm.ci.meta.ResolvedJavaMethod; 53 54 public class PEGraphDecoderTest extends GraalCompilerTest { 55 56 /** 57 * This method is intrinsified to a node with a guard dependency on the block it is in. The 58 * various tests ensure that this guard is correctly updated when blocks are merged during 59 * inlining. 60 */ 61 private static native int readInt(Object obj, long offset); 62 63 private static boolean flag; 64 private static int value; 65 66 private static void invokeSimple() { 67 value = 111; 68 } 69 113 AddressNode address = b.add(new OffsetAddressNode(obj, offset)); 114 ReadNode read = b.addPush(JavaKind.Int, new ReadNode(address, LocationIdentity.any(), StampFactory.forKind(JavaKind.Int), BarrierType.NONE)); 115 read.setGuard(AbstractBeginNode.prevBegin(read)); 116 return true; 117 } 118 }); 119 } 120 121 class InlineAll implements InlineInvokePlugin { 122 @Override 123 public InlineInfo shouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) { 124 return createStandardInlineInfo(method); 125 } 126 } 127 128 @Test 129 @SuppressWarnings("try") 130 public void test() { 131 ResolvedJavaMethod testMethod = getResolvedJavaMethod(PEGraphDecoderTest.class, "doTest", Object.class); 132 StructuredGraph targetGraph = null; 133 DebugContext debug = getDebugContext(); 134 try (DebugContext.Scope scope = debug.scope("GraphPETest", testMethod)) { 135 GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true); 136 registerPlugins(graphBuilderConfig.getPlugins().getInvocationPlugins()); 137 targetGraph = new StructuredGraph.Builder(getInitialOptions(), debug, AllowAssumptions.YES).method(testMethod).build(); 138 CachingPEGraphDecoder decoder = new CachingPEGraphDecoder(getTarget().arch, targetGraph, getProviders(), graphBuilderConfig, OptimisticOptimizations.NONE, AllowAssumptions.YES, 139 null, null, new InlineInvokePlugin[]{new InlineAll()}, null, null); 140 141 decoder.decode(testMethod); 142 debug.dump(DebugContext.BASIC_LEVEL, targetGraph, "Target Graph"); 143 targetGraph.verify(); 144 145 PhaseContext context = new PhaseContext(getProviders()); 146 new CanonicalizerPhase().apply(targetGraph, context); 147 targetGraph.verify(); 148 149 } catch (Throwable ex) { 150 if (targetGraph != null) { 151 debug.dump(DebugContext.BASIC_LEVEL, targetGraph, ex.toString()); 152 } 153 debug.handle(ex); 154 } 155 } 156 } |