use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class SubstrateReplacements method getSnippet.
@Override
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
Integer startOffset = snippetStartOffsets.get(method);
if (startOffset == null) {
throw VMError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)"));
}
ParameterPlugin parameterPlugin = null;
if (args != null) {
parameterPlugin = new ConstantBindingParameterPlugin(args, providers.getMetaAccess(), snippetReflection);
}
EncodedGraph encodedGraph = new EncodedGraph(snippetEncoding, startOffset, snippetObjects, snippetNodeClasses, null, null, null, false, trackNodeSourcePosition);
try (DebugContext debug = openDebugContext("SVMSnippet_", method)) {
StructuredGraph result = new StructuredGraph.Builder(options, debug).method(method).trackNodeSourcePosition(trackNodeSourcePosition).build();
PEGraphDecoder graphDecoder = new PEGraphDecoder(ConfigurationValues.getTarget().arch, result, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), null, snippetInvocationPlugins, new InlineInvokePlugin[0], parameterPlugin, null, null, null) {
@Override
protected EncodedGraph lookupEncodedGraph(ResolvedJavaMethod lookupMethod, ResolvedJavaMethod originalMethod, BytecodeProvider intrinsicBytecodeProvider, boolean track) {
if (lookupMethod.equals(method)) {
assert !track || encodedGraph.trackNodeSourcePosition();
return encodedGraph;
} else {
throw VMError.shouldNotReachHere(method.format("%H.%n(%p)"));
}
}
};
graphDecoder.decode(method, trackNodeSourcePosition);
assert result.verify();
return result;
}
}
use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class SubstrateReplacements method registerSnippet.
/**
* Compiles the snippet and stores the graph.
*/
@Platforms(Platform.HOSTED_ONLY.class)
@Override
public void registerSnippet(ResolvedJavaMethod method, boolean trackNodeSourcePosition) {
assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
assert method.hasBytecodes() : "Snippet must not be abstract or native";
assert builder.graphs.get(method) == null : "snippet registered twice: " + method.getName();
try (DebugContext debug = openDebugContext("Snippet_", method)) {
StructuredGraph graph = makeGraph(debug, defaultBytecodeProvider, method, null, null, trackNodeSourcePosition, null);
// Check if all methods which should be inlined are really inlined.
for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod callee = callTarget.targetMethod();
if (!builder.delayedInvocationPluginMethods.contains(callee)) {
throw shouldNotReachHere("method " + callee.getName() + " not inlined in snippet " + method.getName() + " (maybe not final?)");
}
}
builder.graphs.put(method, graph);
}
}
use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class SubstrateReplacements method encodeSnippets.
@Platforms(Platform.HOSTED_ONLY.class)
public void encodeSnippets() {
GraphEncoder encoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
for (StructuredGraph graph : builder.graphs.values()) {
encoder.prepare(graph);
}
encoder.finishPrepare();
snippetStartOffsets = new HashMap<>();
for (Map.Entry<ResolvedJavaMethod, StructuredGraph> entry : builder.graphs.entrySet()) {
snippetStartOffsets.put(entry.getKey(), encoder.encode(entry.getValue()));
}
snippetEncoding = encoder.getEncoding();
snippetObjects = encoder.getObjects();
snippetNodeClasses = encoder.getNodeClasses();
snippetInvocationPlugins = makeInvocationPlugins(getGraphBuilderPlugins(), builder, Function.identity());
}
use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class PolymorphicInliningTest method testPolymorphicInlining.
public void testPolymorphicInlining() {
for (int i = 0; i < 10000; i++) {
if (i % 2 == 0) {
polymorphicCallsite(Receivers.subClassA);
} else {
polymorphicCallsite(Receivers.subClassB);
}
}
StructuredGraph graph = getGraph("polymorphicCallsite", false);
// This callsite should be inlined with a TypeCheckedInliningViolated deoptimization.
assertTrue(getNodeCount(graph, InvokeNode.class) == 0);
assertTrue(getNodeCount(graph, TypeSwitchNode.class) == 1);
assertTrue(getNodeCount(graph, DeoptimizeNode.class) >= 1);
}
use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.
the class PolymorphicInliningTest method testMegamorphicNotInlining.
public void testMegamorphicNotInlining() {
for (int i = 0; i < 10000; i++) {
switch(i % 10) {
case 0:
case 1:
polymorphicCallsite3(Receivers.subClassA);
break;
case 2:
polymorphicCallsite3(Receivers.subClassB);
break;
case 3:
polymorphicCallsite3(Receivers.subClassC);
break;
case 4:
polymorphicCallsite3(Receivers.subClassD);
break;
case 5:
polymorphicCallsite3(Receivers.subClassE);
break;
case 6:
polymorphicCallsite3(Receivers.subClassF);
break;
case 7:
polymorphicCallsite3(Receivers.subClassG);
break;
case 8:
polymorphicCallsite3(Receivers.subClassH);
break;
default:
polymorphicCallsite3(Receivers.notInlinableSubClass);
break;
}
}
StructuredGraph graph = getGraph("polymorphicCallsite3", false);
// This callsite should not be inlined due to non of the potential callee method exceeds the
// probability specified by GraalOptions.MegamorphicInliningMinMethodProbability.
assertTrue(getNodeCount(graph, InvokeNode.class) == 1);
assertTrue(getNodeCount(graph, TypeSwitchNode.class) == 0);
}
Aggregations