Building a graph manually
Gilles Duboscq
gilles.m.duboscq at oracle.com
Wed Jun 15 15:51:06 UTC 2016
Hi,
Your InvokeNode does not seem to have a valid FrameState node.
The reason why it's hard to create an InvokeNode out of the blue is that in order to install code, it has to make sense for the VM.
For example, there needs to be a corresponding invoke bytecode somewhere and there needs to be a state where the VM can deoptimize to.
Gilles
On 15/06/16 17:35, Bahram Yarahmadi wrote:
> And this is the error that I always get
> [thread:1] scope:
> main.GraalCompilerRoot.GraalCompiler.FrontEnd.HighTier.CanonicalizerPhase.InterceptException
> Exception occurred in scope:
> main.GraalCompilerRoot.GraalCompiler.FrontEnd.HighTier.CanonicalizerPhase.InterceptException
> Context obj java.lang.NullPointerException
> Context obj
> com.oracle.graal.phases.common.CanonicalizerPhase at 77556fd
> Context obj com.oracle.graal.compiler.phases.HighTier at 368239c8
> Context obj StructuredGraph:1
> Context obj jdk.vm.ci.hotspot.HotSpotCodeCacheProvider at 3b192d32
> E
> testPrintBytecodes(com.oracle.graal.compiler.test.tutorial.GraalTutorial)
> java.lang.NullPointerException
> at com.oracle.graal.nodes.Invoke.getContextMethod(Invoke.java:75)
> at
> com.oracle.graal.nodes.java.MethodCallTargetNode.simplify(MethodCallTargetNode.java:165)
> at
> com.oracle.graal.phases.common.CanonicalizerPhase$Instance.tryCanonicalize(CanonicalizerPhase.java:308)
> at
> com.oracle.graal.phases.common.CanonicalizerPhase$Instance.processNode(CanonicalizerPhase.java:225)
> at
> com.oracle.graal.phases.common.CanonicalizerPhase$Instance.processWorkSet(CanonicalizerPhase.java:210)
> at
> com.oracle.graal.phases.common.CanonicalizerPhase$Instance.run(CanonicalizerPhase.java:180)
> at
> com.oracle.graal.phases.common.CanonicalizerPhase.run(CanonicalizerPhase.java:104)
> at
> com.oracle.graal.phases.common.CanonicalizerPhase.run(CanonicalizerPhase.java:1)
> at com.oracle.graal.phases.BasePhase.apply(BasePhase.java:143)
> at com.oracle.graal.phases.BasePhase.apply(BasePhase.java:133)
> at com.oracle.graal.phases.PhaseSuite.run(PhaseSuite.java:116)
> at com.oracle.graal.phases.BasePhase.apply(BasePhase.java:143)
> at com.oracle.graal.phases.BasePhase.apply(BasePhase.java:133)
> at
> com.oracle.graal.compiler.GraalCompiler.emitFrontEnd(GraalCompiler.java:200)
>
>
> On Wed, Jun 15, 2016 at 8:03 PM, Bahram Yarahmadi <
> bahram.yarahmadi at gmail.com> wrote:
>
>> 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());where and there needs to be a state where the VM can deoptimize to.
>> 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