Building a graph manually
Bahram Yarahmadi
bahram.yarahmadi at gmail.com
Wed Jun 15 15:33:58 UTC 2016
Thanks for your help christian ,It worked
I want to modify the graph an insert my own InvokeNode with
MethodCallTargetNode to graph but according to the post from this mailing
list (http://mail.openjdk.java.net/pipermail/graal-dev/2013-July/000650.html"
it was impossible.Is it possible after about three years ?!
This is my code,I get an error when I try to run it with unittest
StructuredGraph graph = new StructuredGraph(AllowAssumptions.YES);
ReturnNode returnNode = graph.add(new ReturnNode(null));
ValueNode valueNode1 = new ConstantNode(JavaConstant.forInt(154),
StampFactory.intValue());
ValueNode valueNode2 = new ConstantNode(JavaConstant.forInt(25),
StampFactory.intValue());
ValueNode[] valueNodes = new ValueNode[2];
valueNodes[0] = valueNode1;
valueNodes[1] = valueNode2;
graph.addWithoutUnique(valueNode1);
graph.addWithoutUnique(valueNode2);
ResolvedJavaMethod method = findMethod(Student.class, "SubInt");
MethodCallTargetNode callTarget = graph.add(new
MethodCallTargetNode(MethodCallTargetNode.InvokeKind.Static,
method, valueNodes, StampFactory.forDeclaredType(null,
method.getSignature().getReturnType(null), false), null));
InvokeNode ink = graph.add(new InvokeNode(callTarget,
BytecodeFrame.UNWIND_BCI));
graph.start().setNext(ink);
ink.setNext(returnNode);
OptimisticOptimizations optimisticOpts =
OptimisticOptimizations.ALL;
PhaseSuite<HighTierContext> graphBuilderSuite =
backend.getSuites().getDefaultGraphBuilderSuite();
Suites suites = backend.getSuites().getDefaultSuites();
LIRSuites lirSuites = backend.getSuites().getDefaultLIRSuites();
ProfilingInfo profilingInfo = graph.getProfilingInfo(method);
CompilationResult compilationResult = new CompilationResult();
CompilationResultBuilderFactory factory =
CompilationResultBuilderFactory.Default;
GraalCompiler.compileGraph(graph, method, providers, backend,
graphBuilderSuite,
optimisticOpts, profilingInfo, suites, lirSuites,
compilationResult, factory);
CompiledCode compiledCode = backend.createCompiledCode(method,
compilationResult);
InstalledCode installedCode = codeCache.addCode(method,
compiledCode, null, null);
try {
installedCode.executeVarargs();
} catch (InvalidInstalledCodeException e) {
e.printStackTrace();
}
and by the way,Is it a correct way to compile a graph ? or It is better to
write my own compilation phases
Thanks again
Regards
On Tue, Jun 14, 2016 at 10:54 PM, Christian Wimmer <
christian.wimmer at oracle.com> wrote:
> Seems like you are not adding the ConstantNode to the graph.
>
> ValueNode valueNode1 = new ConstantNode(JavaConstant.forInt(154),
> StampFactory.intValue());
>
> should be
>
> ValueNode valueNode1 = graph.unique(new
> ConstantNode(JavaConstant.forInt(154), StampFactory.intValue()));
>
> Since constants are floating nodes, you need to use unique() instead of
> add() - but they still need to be made part of the graph.
>
> -Christian
>
>
>
> On 06/14/2016 01:44 AM, Bahram Yarahmadi wrote:
>
>> Hello guys,
>>
>> I want to build a graph manually but when I want to add an invokeNode to
>> the graph I get an error
>> this is my code :
>> StructuredGraph graph = new
>> StructuredGraph(AllowAssumptions.YES);
>> ReturnNode returnNode = graph.add(new ReturnNode(null));
>> ValueNode valueNode1 = new ConstantNode(JavaConstant.forInt(154),
>> StampFactory.intValue());
>> ValueNode valueNode2 = new ConstantNode(JavaConstant.forInt(25),
>> StampFactory.intValue());
>> ValueNode[] valueNodes = new ValueNode[2];
>> valueNodes[0] = valueNode1;
>> valueNodes[1] = valueNode2;
>> ResolvedJavaMethod method = findMethod(AA.class, "SubInt");
>> MethodCallTargetNode callTarget = graph.add(new
>> MethodCallTargetNode(MethodCallTargetNode.InvokeKind.Static,
>> method, valueNodes,
>> StampFactory.forDeclaredType(null,
>> method.getSignature().getReturnType(null), false), null));
>> InvokeNode ink = graph.add(new InvokeNode(callTarget,
>> BytecodeFrame.UNWIND_BCI));
>> graph.start().setNext(ink);
>> ink.setNext(returnNode);
>> Debug.dump(Debug.BASIC_LOG_LEVEL, graph, "Graph");
>> and my SubInt method is
>>
>> public static void SubInt(int a, int b) {
>> System.out.println("///");
>> }
>> but when I try to test with inittest I get this error :
>> testPrintBytecodes(com.oracle.graal.compiler.test.tutorial.GraalTutorial)
>> java.lang.AssertionError: Input not alive
>> at
>>
>> com.oracle.graal.graph.NodeClass.registerAtInputsAsUsageHelper(NodeClass.java:1257)
>> at
>>
>> com.oracle.graal.graph.NodeClass.registerAtInputsAsUsage(NodeClass.java:1245)
>> at com.oracle.graal.graph.Node.initialize(Node.java:593)
>> at com.oracle.graal.graph.Graph.addHelper(Graph.java:446)
>> at com.oracle.graal.graph.Graph.add(Graph.java:398)
>> at
>>
>> com.oracle.graal.compiler.test.tutorial.GraalTutorial.testPrintBytecodes(GraalTutorial.java:278)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>>
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>> at
>>
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> at java.lang.reflect.Method.invoke(Method.java:498)
>>
>>
>>
>> Thanks again
>>
>> Bahram,
>>
>>
More information about the graal-dev
mailing list