5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 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.core.test.inlining; 24 25 import jdk.vm.ci.code.site.InfopointReason; 26 import jdk.vm.ci.meta.ResolvedJavaMethod; 27 28 import org.junit.Ignore; 29 import org.junit.Test; 30 31 import org.graalvm.compiler.core.test.GraalCompilerTest; 32 import org.graalvm.compiler.debug.Debug; 33 import org.graalvm.compiler.debug.Debug.Scope; 34 import org.graalvm.compiler.debug.DebugDumpScope; 35 import org.graalvm.compiler.graph.Node; 36 import org.graalvm.compiler.nodes.FullInfopointNode; 37 import org.graalvm.compiler.nodes.Invoke; 38 import org.graalvm.compiler.nodes.StructuredGraph; 39 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 40 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; 41 import org.graalvm.compiler.phases.OptimisticOptimizations; 42 import org.graalvm.compiler.phases.PhaseSuite; 43 import org.graalvm.compiler.phases.common.CanonicalizerPhase; 44 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase; 45 import org.graalvm.compiler.phases.common.inlining.InliningPhase; 46 import org.graalvm.compiler.phases.tiers.HighTierContext; 47 48 public class InliningTest extends GraalCompilerTest { 49 50 @Test 51 public void testInvokeStaticInlining() { 52 assertInlined(getGraph("invokeStaticSnippet", false)); 53 assertInlined(getGraph("invokeStaticOnInstanceSnippet", false)); 54 } 55 56 @SuppressWarnings("all") 57 public static Boolean invokeStaticSnippet(boolean value) { 58 return Boolean.valueOf(value); 59 } 60 61 @SuppressWarnings({"all", "static"}) 62 public static Boolean invokeStaticOnInstanceSnippet(Boolean obj, boolean value) { 63 return obj.valueOf(value); 64 } 65 66 @Test 219 return testInterface.publicNotOverriddenMethod(); 220 } 221 222 @SuppressWarnings("all") 223 public static int invokeOverriddenInterfaceMethodSnippet(MultipleImplementorsInterface testInterface) { 224 return testInterface.publicOverriddenMethod(); 225 } 226 227 @SuppressWarnings("all") 228 public static int invokeOverriddenPublicMethodSnippet(SuperClass superClass) { 229 return superClass.publicOverriddenMethod(); 230 } 231 232 @SuppressWarnings("all") 233 public static int invokeOverriddenProtectedMethodSnippet(SuperClass superClass) { 234 return superClass.protectedOverriddenMethod(); 235 } 236 237 @SuppressWarnings("try") 238 private StructuredGraph getGraph(final String snippet, final boolean eagerInfopointMode) { 239 try (Scope s = Debug.scope("InliningTest", new DebugDumpScope(snippet, true))) { 240 ResolvedJavaMethod method = getResolvedJavaMethod(snippet); 241 StructuredGraph graph = eagerInfopointMode ? parseDebug(method, AllowAssumptions.YES) : parseEager(method, AllowAssumptions.YES); 242 try (Scope s2 = Debug.scope("Inlining", graph)) { 243 PhaseSuite<HighTierContext> graphBuilderSuite = eagerInfopointMode 244 ? getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true)) 245 : getDefaultGraphBuilderSuite(); 246 HighTierContext context = new HighTierContext(getProviders(), graphBuilderSuite, OptimisticOptimizations.ALL); 247 Debug.dump(Debug.BASIC_LEVEL, graph, "Graph"); 248 new CanonicalizerPhase().apply(graph, context); 249 new InliningPhase(new CanonicalizerPhase()).apply(graph, context); 250 Debug.dump(Debug.BASIC_LEVEL, graph, "Graph"); 251 new CanonicalizerPhase().apply(graph, context); 252 new DeadCodeEliminationPhase().apply(graph); 253 return graph; 254 } 255 } catch (Throwable e) { 256 throw Debug.handle(e); 257 } 258 } 259 260 private static StructuredGraph assertInlined(StructuredGraph graph) { 261 return assertNotInGraph(graph, Invoke.class); 262 } 263 264 private static StructuredGraph assertNotInlined(StructuredGraph graph) { 265 return assertInGraph(graph, Invoke.class); 266 } 267 268 private static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) { 269 for (Node node : graph.getNodes()) { 270 if (clazz.isInstance(node)) { 271 fail(node.toString()); 272 } 273 } 274 return graph; 275 } 276 | 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 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.core.test.inlining; 24 25 import org.graalvm.compiler.core.test.GraalCompilerTest; 26 import org.graalvm.compiler.debug.DebugContext; 27 import org.graalvm.compiler.debug.DebugDumpScope; 28 import org.graalvm.compiler.graph.Node; 29 import org.graalvm.compiler.nodes.FullInfopointNode; 30 import org.graalvm.compiler.nodes.Invoke; 31 import org.graalvm.compiler.nodes.StructuredGraph; 32 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 33 import org.graalvm.compiler.nodes.StructuredGraph.Builder; 34 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; 35 import org.graalvm.compiler.phases.OptimisticOptimizations; 36 import org.graalvm.compiler.phases.PhaseSuite; 37 import org.graalvm.compiler.phases.common.CanonicalizerPhase; 38 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase; 39 import org.graalvm.compiler.phases.common.inlining.InliningPhase; 40 import org.graalvm.compiler.phases.tiers.HighTierContext; 41 import org.junit.Ignore; 42 import org.junit.Test; 43 44 import jdk.vm.ci.code.site.InfopointReason; 45 import jdk.vm.ci.meta.ResolvedJavaMethod; 46 47 public class InliningTest extends GraalCompilerTest { 48 49 @Test 50 public void testInvokeStaticInlining() { 51 assertInlined(getGraph("invokeStaticSnippet", false)); 52 assertInlined(getGraph("invokeStaticOnInstanceSnippet", false)); 53 } 54 55 @SuppressWarnings("all") 56 public static Boolean invokeStaticSnippet(boolean value) { 57 return Boolean.valueOf(value); 58 } 59 60 @SuppressWarnings({"all", "static"}) 61 public static Boolean invokeStaticOnInstanceSnippet(Boolean obj, boolean value) { 62 return obj.valueOf(value); 63 } 64 65 @Test 218 return testInterface.publicNotOverriddenMethod(); 219 } 220 221 @SuppressWarnings("all") 222 public static int invokeOverriddenInterfaceMethodSnippet(MultipleImplementorsInterface testInterface) { 223 return testInterface.publicOverriddenMethod(); 224 } 225 226 @SuppressWarnings("all") 227 public static int invokeOverriddenPublicMethodSnippet(SuperClass superClass) { 228 return superClass.publicOverriddenMethod(); 229 } 230 231 @SuppressWarnings("all") 232 public static int invokeOverriddenProtectedMethodSnippet(SuperClass superClass) { 233 return superClass.protectedOverriddenMethod(); 234 } 235 236 @SuppressWarnings("try") 237 private StructuredGraph getGraph(final String snippet, final boolean eagerInfopointMode) { 238 DebugContext debug = getDebugContext(); 239 try (DebugContext.Scope s = debug.scope("InliningTest", new DebugDumpScope(snippet, true))) { 240 ResolvedJavaMethod method = getResolvedJavaMethod(snippet); 241 Builder builder = builder(method, AllowAssumptions.YES, debug); 242 StructuredGraph graph = eagerInfopointMode ? parse(builder, getDebugGraphBuilderSuite()) : parse(builder, getEagerGraphBuilderSuite()); 243 try (DebugContext.Scope s2 = debug.scope("Inlining", graph)) { 244 PhaseSuite<HighTierContext> graphBuilderSuite = eagerInfopointMode 245 ? getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true)) 246 : getDefaultGraphBuilderSuite(); 247 HighTierContext context = new HighTierContext(getProviders(), graphBuilderSuite, OptimisticOptimizations.ALL); 248 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); 249 new CanonicalizerPhase().apply(graph, context); 250 new InliningPhase(new CanonicalizerPhase()).apply(graph, context); 251 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); 252 new CanonicalizerPhase().apply(graph, context); 253 new DeadCodeEliminationPhase().apply(graph); 254 return graph; 255 } 256 } catch (Throwable e) { 257 throw debug.handle(e); 258 } 259 } 260 261 private static StructuredGraph assertInlined(StructuredGraph graph) { 262 return assertNotInGraph(graph, Invoke.class); 263 } 264 265 private static StructuredGraph assertNotInlined(StructuredGraph graph) { 266 return assertInGraph(graph, Invoke.class); 267 } 268 269 private static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) { 270 for (Node node : graph.getNodes()) { 271 if (clazz.isInstance(node)) { 272 fail(node.toString()); 273 } 274 } 275 return graph; 276 } 277 |