use of org.graalvm.compiler.nodes.EncodedGraph in project graal by oracle.
the class GraalSupport method decodeGraph.
public static StructuredGraph decodeGraph(DebugContext debug, String name, CompilationIdentifier compilationId, SharedRuntimeMethod method) {
// XXX
EncodedGraph encodedGraph = encodedGraph(method, false);
if (encodedGraph == null) {
return null;
}
StructuredGraph graph = new StructuredGraph.Builder(debug.getOptions(), debug).name(name).method(method).compilationId(compilationId).build();
GraphDecoder decoder = new GraphDecoder(ConfigurationValues.getTarget().arch, graph);
decoder.decode(encodedGraph);
return graph;
}
use of org.graalvm.compiler.nodes.EncodedGraph 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.EncodedGraph in project graal by oracle.
the class CachingPEGraphDecoder method createGraph.
@SuppressWarnings("try")
private EncodedGraph createGraph(ResolvedJavaMethod method, ResolvedJavaMethod originalMethod, BytecodeProvider intrinsicBytecodeProvider) {
StructuredGraph graphToEncode = new StructuredGraph.Builder(options, debug, allowAssumptions).useProfilingInfo(false).trackNodeSourcePosition(graphBuilderConfig.trackNodeSourcePosition()).method(method).build();
try (DebugContext.Scope scope = debug.scope("createGraph", graphToEncode)) {
IntrinsicContext initialIntrinsicContext = intrinsicBytecodeProvider != null ? new IntrinsicContext(originalMethod, method, intrinsicBytecodeProvider, INLINE_AFTER_PARSING) : null;
GraphBuilderPhase.Instance graphBuilderPhaseInstance = createGraphBuilderPhaseInstance(initialIntrinsicContext);
graphBuilderPhaseInstance.apply(graphToEncode);
PhaseContext context = new PhaseContext(providers);
new CanonicalizerPhase().apply(graphToEncode, context);
/*
* ConvertDeoptimizeToGuardPhase reduces the number of merges in the graph, so that
* fewer frame states will be created. This significantly reduces the number of nodes in
* the initial graph.
*/
new ConvertDeoptimizeToGuardPhase().apply(graphToEncode, context);
EncodedGraph encodedGraph = GraphEncoder.encodeSingleGraph(graphToEncode, architecture);
graphCache.put(method, encodedGraph);
return encodedGraph;
} catch (Throwable ex) {
throw debug.handle(ex);
}
}
use of org.graalvm.compiler.nodes.EncodedGraph in project graal by oracle.
the class SubstratePEGraphDecoder method createGraph.
private EncodedGraph createGraph(ResolvedJavaMethod method, boolean trackNodeSourcePosition) {
EncodedGraph result = GraalSupport.encodedGraph((SharedRuntimeMethod) method, trackNodeSourcePosition);
if (result == null) {
throw shouldNotReachHere("Graph not available for runtime compilation: " + method.format("%H.%n(%p)"));
}
graphCache.put(method, result);
return result;
}
use of org.graalvm.compiler.nodes.EncodedGraph in project graal by oracle.
the class GraphEncoderTest method testStringMethods.
public void testStringMethods(boolean canonicalize) {
/* Encode and decode all methods of java.lang.String. */
List<StructuredGraph> originalGraphs = new ArrayList<>();
for (Method method : String.class.getDeclaredMethods()) {
ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method);
if (javaMethod.hasBytecodes()) {
StructuredGraph originalGraph = parseEager(javaMethod, AllowAssumptions.YES);
if (canonicalize) {
PhaseContext context = new PhaseContext(getProviders());
new CanonicalizerPhase().apply(originalGraph, context);
}
originalGraphs.add(originalGraph);
}
}
GraphEncoder encoder = new GraphEncoder(getTarget().arch);
for (StructuredGraph originalGraph : originalGraphs) {
encoder.prepare(originalGraph);
}
encoder.finishPrepare();
Map<StructuredGraph, Integer> startOffsets = new HashMap<>();
for (StructuredGraph originalGraph : originalGraphs) {
startOffsets.put(originalGraph, encoder.encode(originalGraph));
}
for (StructuredGraph originalGraph : originalGraphs) {
EncodedGraph encodedGraph = new EncodedGraph(encoder.getEncoding(), startOffsets.get(originalGraph), encoder.getObjects(), encoder.getNodeClasses(), originalGraph);
GraphEncoder.verifyEncoding(originalGraph, encodedGraph, getTarget().arch);
}
}
Aggregations