changeset 22836:3f2a5706a696

allow re-entrance of InstrumentationNode.virtualize and inspecting non-intrisified invocations
author zhengy <yudi.zheng@usi.ch>
date Thu, 15 Oct 2015 15:24:01 +0200
parents 1b06a64e784f
children 77ef4d74a6b2
files graal/com.oracle.graal.api.directives/src/com/oracle/graal/api/directives/GraalDirectives.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/instrumentation/ExtractInstrumentationPhase.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/instrumentation/nodes/InstrumentationBeginNode.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/instrumentation/nodes/InstrumentationNode.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java
diffstat 5 files changed, 38 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.directives/src/com/oracle/graal/api/directives/GraalDirectives.java	Tue Oct 13 13:56:13 2015 +0200
+++ b/graal/com.oracle.graal.api.directives/src/com/oracle/graal/api/directives/GraalDirectives.java	Thu Oct 15 15:24:01 2015 +0200
@@ -328,6 +328,14 @@
     }
 
     /**
+     * Ensures that the instrumentation is valid only if it is associated with an Invoke node.
+     *
+     * See {@link #instrumentationBegin(int)}.
+     */
+    public static void instrumentationToInvokeBegin(@SuppressWarnings("unused") int offset) {
+    }
+
+    /**
      * Marks the end of the instrumentation boundary. See {@link #instrumentationBegin(int)}.
      */
     public static void instrumentationEnd() {
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/instrumentation/ExtractInstrumentationPhase.java	Tue Oct 13 13:56:13 2015 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/instrumentation/ExtractInstrumentationPhase.java	Thu Oct 15 15:24:01 2015 +0200
@@ -37,6 +37,7 @@
 import com.oracle.graal.nodes.FixedNode;
 import com.oracle.graal.nodes.FixedWithNextNode;
 import com.oracle.graal.nodes.FrameState;
+import com.oracle.graal.nodes.Invoke;
 import com.oracle.graal.nodes.LoopEndNode;
 import com.oracle.graal.nodes.ParameterNode;
 import com.oracle.graal.nodes.ReturnNode;
@@ -63,11 +64,11 @@
     protected void run(StructuredGraph graph, HighTierContext context) {
         for (InstrumentationBeginNode begin : graph.getNodes().filter(InstrumentationBeginNode.class)) {
             Instrumentation instrumentation = new Instrumentation(begin);
-            InstrumentationNode instrumentationNode = instrumentation.createInstrumentationNode();
-
-            graph.addBeforeFixed(begin, instrumentationNode);
-            Debug.dump(instrumentationNode.instrumentationGraph(), "After extracted instrumentation at " + instrumentation);
-
+            if (!instrumentation.inspectingIntrinsic()) {
+                InstrumentationNode instrumentationNode = instrumentation.createInstrumentationNode();
+                graph.addBeforeFixed(begin, instrumentationNode);
+                Debug.dump(instrumentationNode.instrumentationGraph(), "After extracted instrumentation at " + instrumentation);
+            }
             instrumentation.unlink();
         }
 
@@ -175,6 +176,10 @@
             }
         }
 
+        public boolean inspectingIntrinsic() {
+            return begin.inspectInvocation() && !(target instanceof Invoke);
+        }
+
         public InstrumentationNode createInstrumentationNode() {
             ValueNode newTarget = target;
             // MonitorEnterNode may be deleted during PEA
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/instrumentation/nodes/InstrumentationBeginNode.java	Tue Oct 13 13:56:13 2015 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/instrumentation/nodes/InstrumentationBeginNode.java	Thu Oct 15 15:24:01 2015 +0200
@@ -38,21 +38,25 @@
     public static final NodeClass<InstrumentationBeginNode> TYPE = NodeClass.create(InstrumentationBeginNode.class);
 
     private final int offset;
+    private final boolean inspectInvocation;
 
-    public InstrumentationBeginNode(ValueNode offset) {
+    public InstrumentationBeginNode(ValueNode offset, boolean inspectInvocation) {
         super(TYPE, StampFactory.forVoid());
 
         if (!(offset instanceof ConstantNode)) {
             throw JVMCIError.shouldNotReachHere("should pass constant integer to instrumentationBegin(int)");
         }
-
-        ConstantNode constantNode = (ConstantNode) offset;
-        JavaConstant constant = (JavaConstant) constantNode.asConstant();
-        this.offset = constant.asInt();
+        JavaConstant constant = ((ConstantNode) offset).asJavaConstant();
+        this.offset = constant == null ? 0 : constant.asInt();
+        this.inspectInvocation = inspectInvocation;
     }
 
     public int getOffset() {
         return offset;
     }
 
+    public boolean inspectInvocation() {
+        return inspectInvocation;
+    }
+
 }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/instrumentation/nodes/InstrumentationNode.java	Tue Oct 13 13:56:13 2015 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/instrumentation/nodes/InstrumentationNode.java	Thu Oct 15 15:24:01 2015 +0200
@@ -102,13 +102,16 @@
     public void virtualize(VirtualizerTool tool) {
         // InstrumentationNode allows non-materialized inputs. During the inlining of the
         // InstrumentationNode, non-materialized inputs will be replaced by null.
-        if (target != null) {
+        if (!(target == null || (target instanceof VirtualObjectNode))) {
             ValueNode alias = tool.getAlias(target);
             if (alias instanceof VirtualObjectNode) {
                 tool.replaceFirstInput(target, alias);
             }
         }
         for (ValueNode input : weakDependencies) {
+            if (input instanceof VirtualObjectNode) {
+                continue;
+            }
             ValueNode alias = tool.getAlias(input);
             if (alias instanceof VirtualObjectNode) {
                 tool.replaceFirstInput(input, alias);
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java	Tue Oct 13 13:56:13 2015 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java	Thu Oct 15 15:24:01 2015 +0200
@@ -719,7 +719,13 @@
         if (UseGraalInstrumentation.getValue()) {
             r.register1("instrumentationBegin", int.class, new InvocationPlugin() {
                 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode offset) {
-                    b.add(new InstrumentationBeginNode(offset));
+                    b.add(new InstrumentationBeginNode(offset, false));
+                    return true;
+                }
+            });
+            r.register1("instrumentationToInvokeBegin", int.class, new InvocationPlugin() {
+                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode offset) {
+                    b.add(new InstrumentationBeginNode(offset, true));
                     return true;
                 }
             });