Building a graph manually
Gilles Duboscq
gilles.m.duboscq at oracle.com
Mon Jun 20 09:49:58 UTC 2016
Hi,
Any bytecode instrumentation framework should work with Graal.
Maybe you could have a look at DiSL [1] for example.
Gilles
[1] https://disl.ow2.org/bin/view/Main/
On 18/06/16 10:14, Bahram Yarahmadi wrote:
> Hi guys
> Does anyone here know any proper bytecode instrumentation which I can use it with graal !?
>
> On Fri, Jun 17, 2016 at 1:11 PM, Bahram Yarahmadi <bahram.yarahmadi at gmail.com <mailto:bahram.yarahmadi at gmail.com>> wrote:
>
> Thanks Gilles
> I cannot even build the state on the fly,I think it must be a non trivial task
> I made some progress and now for "just some" methods , I can redirect an invoke with InliningUtil.replaceInvokeCallTarget ,
> for instance :I can invoke method X() instead of method Y() at runtime
> but my target is Lambdas with stream APIs ,
> for example:
> Intstream.rang(0,10).parallel.foreach(....)
> I modify the graph and I delete invoke#range,invoke#parallel ,invoke#foreach from cfg
> I made a pure control flow which only contains 285377351.linkToTargetMethod as an invoke node which is static but when I want to redirect this method I get this Error
> testGraphKitTool(com.oracle.graal.compiler.test.tutorial.GraalTutorial)
> java.lang.NullPointerException
> at com.oracle.graal.nodes.Invoke.getContextMethod(Invoke.java:75)
> at com.oracle.graal.compiler.test.tutorial.GraalTutorial.testGraphKitTool(GraalTutorial.java:449)
> 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)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
> at com.oracle.mxtool.junit.MxJUnitWrapper.main(MxJUnitWrapper.java:167)
>
> Time: 0.249
> There was 1 failure:
> 1) testGraphKitTool(com.oracle.graal.compiler.test.tutorial.GraalTutorial)
> java.lang.NullPointerException
> at com.oracle.graal.nodes.Invoke.getContextMethod(Invoke.java:75)
> at com.oracle.graal.compiler.test.tutorial.GraalTutorial.testGraphKitTool(GraalTutorial.java:449)
> 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)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
> at com.oracle.mxtool.junit.MxJUnitWrapper.main(MxJUnitWrapper.java:167)
>
>
> What is the difference between these two scenarios??
> Can I Interpret my graph instead of compile in graal in this case ??
>
> Thanks
>
> Bahram
>
> On Wed, Jun 15, 2016 at 8:21 PM, Gilles Duboscq <gilles.m.duboscq at oracle.com <mailto:gilles.m.duboscq at oracle.com>> wrote:
>
> 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 <mailto: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 <mailto: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