changeset 21301:31dcb86ad3a6

Merge with 21993236a2198d6bde4d8be6672df8083e0d2d32
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Mon, 11 May 2015 19:58:25 -0700
parents 07c22c0ab91e (current diff) 21993236a219 (diff)
children e93c6e5c6c35
files
diffstat 17 files changed, 211 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodePosition.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodePosition.java	Mon May 11 19:58:25 2015 -0700
@@ -109,4 +109,15 @@
     public BytecodePosition getCaller() {
         return caller;
     }
+
+    /*
+     * Adds a caller to the current position returning the new position.
+     */
+    public BytecodePosition addCaller(BytecodePosition link) {
+        if (getCaller() == null) {
+            return new BytecodePosition(link, getMethod(), getBCI());
+        } else {
+            return new BytecodePosition(getCaller().addCaller(link), getMethod(), getBCI());
+        }
+    }
 }
--- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/GraphBuilderConfiguration.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/GraphBuilderConfiguration.java	Mon May 11 19:58:25 2015 -0700
@@ -229,6 +229,10 @@
         return debugInfoMode.ordinal() >= DebugInfoMode.Full.ordinal();
     }
 
+    public boolean insertSimpleDebugInfo() {
+        return debugInfoMode == DebugInfoMode.Simple;
+    }
+
     public boolean doLivenessAnalysis() {
         return doLivenessAnalysis;
     }
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractBytecodeParser.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractBytecodeParser.java	Mon May 11 19:58:25 2015 -0700
@@ -73,6 +73,9 @@
         @Option(help = "Do not bail out but throw an exception on failed loop explosion.", type = OptionType.Debug)
         public static final OptionValue<Boolean> FailedLoopExplosionIsFatal = new OptionValue<>(false);
 
+        @Option(help = "When creating info points hide the methods of the substitutions.", type = OptionType.Debug)
+        public static final OptionValue<Boolean> HideSubstitutionStates = new OptionValue<>(false);
+
         // @formatter:on
     }
 
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Mon May 11 19:58:25 2015 -0700
@@ -2245,9 +2245,14 @@
                 int bci = block.startBci;
                 BytecodesParsed.add(block.endBci - bci);
 
+                /* Reset line number for new block */
+                if (graphBuilderConfig.insertSimpleDebugInfo()) {
+                    previousLineNumber = -1;
+                }
+
                 while (bci < endBCI) {
-                    if (graphBuilderConfig.insertNonSafepointDebugInfo() && lnt != null) {
-                        currentLineNumber = lnt.getLineNumber(bci);
+                    if (graphBuilderConfig.insertNonSafepointDebugInfo()) {
+                        currentLineNumber = lnt != null ? lnt.getLineNumber(bci) : (graphBuilderConfig.insertFullDebugInfo() ? -1 : bci);
                         if (currentLineNumber != previousLineNumber) {
                             append(createInfoPointNode(InfopointReason.LINE_NUMBER));
                             previousLineNumber = currentLineNumber;
@@ -2331,7 +2336,16 @@
                 if (graphBuilderConfig.insertFullDebugInfo()) {
                     return new FullInfopointNode(reason, createFrameState(bci(), null));
                 } else {
-                    return new SimpleInfopointNode(reason, new BytecodePosition(null, method, bci()));
+                    BytecodePosition position = createBytecodePosition();
+                    // Update the previous infopoint position if no new fixed nodes were inserted
+                    if (lastInstr instanceof SimpleInfopointNode) {
+                        SimpleInfopointNode lastInfopoint = (SimpleInfopointNode) lastInstr;
+                        if (lastInfopoint.getReason() == reason) {
+                            lastInfopoint.setPosition(position);
+                            return lastInfopoint;
+                        }
+                    }
+                    return new SimpleInfopointNode(reason, position);
                 }
             }
 
@@ -2600,6 +2614,10 @@
                 FrameState stateAfter = createFrameState(stream.nextBCI(), sideEffect);
                 sideEffect.setStateAfter(stateAfter);
             }
+
+            private BytecodePosition createBytecodePosition() {
+                return frameState.createBytecodePosition(bci());
+            }
         }
     }
 
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java	Mon May 11 19:58:25 2015 -0700
@@ -228,6 +228,39 @@
         return graph.add(new FrameState(outerFrameState, method, bci, locals, stack, stackSize, lockedObjects, Arrays.asList(monitorIds), rethrowException, duringCall));
     }
 
+    public BytecodePosition createBytecodePosition(int bci) {
+        BytecodeParser parent = parser.getParent();
+        if (AbstractBytecodeParser.Options.HideSubstitutionStates.getValue()) {
+            if (parser.parsingReplacement()) {
+                IntrinsicContext intrinsic = parser.replacementContext.asIntrinsic();
+                if (intrinsic != null) {
+                    // Attribute to the method being replaced
+                    return new BytecodePosition(parent.getFrameState().createBytecodePosition(parent.bci()), intrinsic.method, -1);
+                }
+            }
+            // If this is the recursive call in a partial intrinsification
+            // the frame(s) of the intrinsic method are omitted
+            while (parent != null && parent.parsingReplacement() && parent.replacementContext.asIntrinsic() != null) {
+                parent = parent.getParent();
+            }
+        }
+        return create(null, bci, parent);
+    }
+
+    private BytecodePosition create(BytecodePosition o, int bci, BytecodeParser parent) {
+        BytecodePosition outer = o;
+        if (outer == null && parent != null) {
+            outer = parent.getFrameState().createBytecodePosition(parent.bci());
+        }
+        if (bci == BytecodeFrame.AFTER_EXCEPTION_BCI && parent != null) {
+            return FrameState.toBytecodePosition(outerFrameState);
+        }
+        if (bci == BytecodeFrame.INVALID_FRAMESTATE_BCI) {
+            throw GraalInternalError.shouldNotReachHere();
+        }
+        return new BytecodePosition(outer, method, bci);
+    }
+
     public HIRFrameStateBuilder copy() {
         return new HIRFrameStateBuilder(this);
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java	Mon May 11 19:58:25 2015 -0700
@@ -166,6 +166,17 @@
         this.outerFrameState = x;
     }
 
+    public BytecodePosition toBytecodePosition() {
+        return toBytecodePosition(this);
+    }
+
+    public static BytecodePosition toBytecodePosition(FrameState fs) {
+        if (fs == null) {
+            return null;
+        }
+        return new BytecodePosition(toBytecodePosition(fs.outerFrameState()), fs.method(), fs.bci);
+    }
+
     /**
      * @see BytecodeFrame#rethrowException
      */
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GraphDecoder.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GraphDecoder.java	Mon May 11 19:58:25 2015 -0700
@@ -409,7 +409,7 @@
             methodScope.unwindNode = (UnwindNode) node;
 
         } else {
-            simplifyFixedNode(methodScope, loopScope, nodeOrderId, node);
+            handleFixedNode(methodScope, loopScope, nodeOrderId, node);
         }
 
         return resultScope;
@@ -527,7 +527,7 @@
      * @param nodeOrderId The orderId of the node.
      * @param node The node to be simplified.
      */
-    protected void simplifyFixedNode(MethodScope methodScope, LoopScope loopScope, int nodeOrderId, FixedNode node) {
+    protected void handleFixedNode(MethodScope methodScope, LoopScope loopScope, int nodeOrderId, FixedNode node) {
     }
 
     protected void handleProxyNodes(MethodScope methodScope, LoopScope loopScope, LoopExitNode loopExit) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/SimpleInfopointNode.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/SimpleInfopointNode.java	Mon May 11 19:58:25 2015 -0700
@@ -48,15 +48,7 @@
     }
 
     public void addCaller(BytecodePosition caller) {
-        this.position = relink(this.position, caller);
-    }
-
-    private static BytecodePosition relink(BytecodePosition position, BytecodePosition link) {
-        if (position.getCaller() == null) {
-            return new BytecodePosition(link, position.getMethod(), position.getBCI());
-        } else {
-            return new BytecodePosition(relink(position.getCaller(), link), position.getMethod(), position.getBCI());
-        }
+        this.position = position.addCaller(caller);
     }
 
     @Override
@@ -65,4 +57,21 @@
             graph().removeFixed(this);
         }
     }
+
+    public void setPosition(BytecodePosition position) {
+        this.position = position;
+    }
+
+    @Override
+    public boolean verify() {
+        BytecodePosition pos = position;
+        if (pos != null) {
+            // Verify that the outermost position belongs to this graph.
+            while (pos.getCaller() != null) {
+                pos = pos.getCaller();
+            }
+            assert pos.getMethod().equals(graph().method());
+        }
+        return super.verify();
+    }
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/SimplifyingGraphDecoder.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/SimplifyingGraphDecoder.java	Mon May 11 19:58:25 2015 -0700
@@ -91,7 +91,7 @@
     }
 
     @Override
-    protected void simplifyFixedNode(MethodScope methodScope, LoopScope loopScope, int nodeOrderId, FixedNode node) {
+    protected void handleFixedNode(MethodScope methodScope, LoopScope loopScope, int nodeOrderId, FixedNode node) {
         if (node instanceof IfNode) {
             IfNode ifNode = (IfNode) node;
             if (ifNode.condition() instanceof LogicNegationNode) {
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java	Mon May 11 19:58:25 2015 -0700
@@ -427,11 +427,18 @@
     }
 
     public static BytecodePosition processSimpleInfopoint(Invoke invoke, SimpleInfopointNode infopointNode, BytecodePosition incomingPos) {
-        BytecodePosition pos = incomingPos != null ? incomingPos : new BytecodePosition(toBytecodePosition(invoke.stateAfter().outerFrameState()), invoke.asNode().graph().method(), invoke.bci());
+        BytecodePosition pos = processBytecodePosition(invoke, incomingPos);
         infopointNode.addCaller(pos);
+        assert infopointNode.verify();
         return pos;
     }
 
+    public static BytecodePosition processBytecodePosition(Invoke invoke, BytecodePosition incomingPos) {
+        assert invoke.stateAfter() != null;
+        assert incomingPos == null || incomingPos.equals(InliningUtil.processBytecodePosition(invoke, null)) : incomingPos + " " + InliningUtil.processBytecodePosition(invoke, null);
+        return incomingPos != null ? incomingPos : new BytecodePosition(FrameState.toBytecodePosition(invoke.stateAfter().outerFrameState()), invoke.stateAfter().method(), invoke.bci());
+    }
+
     public static void processMonitorId(FrameState stateAfter, MonitorIdNode monitorIdNode) {
         if (stateAfter != null) {
             int callerLockDepth = stateAfter.nestedLockDepth();
@@ -439,13 +446,6 @@
         }
     }
 
-    private static BytecodePosition toBytecodePosition(FrameState fs) {
-        if (fs == null) {
-            return null;
-        }
-        return new BytecodePosition(toBytecodePosition(fs.outerFrameState()), fs.method(), fs.bci);
-    }
-
     protected static void processFrameStates(Invoke invoke, StructuredGraph inlineGraph, Map<Node, Node> duplicates, FrameState stateAtExceptionEdge, boolean alwaysDuplicateStateAfter) {
         FrameState stateAtReturn = invoke.stateAfter();
         FrameState outerFrameState = null;
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/PEGraphDecoder.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/PEGraphDecoder.java	Mon May 11 19:58:25 2015 -0700
@@ -97,6 +97,15 @@
         public boolean isInlinedMethod() {
             return caller != null;
         }
+
+        public BytecodePosition getBytecodePosition() {
+            if (bytecodePosition == null) {
+                ensureOuterStateDecoded(this);
+                ensureExceptionStateDecoded(this);
+                bytecodePosition = InliningUtil.processBytecodePosition(invokeData.invoke, null);
+            }
+            return bytecodePosition;
+        }
     }
 
     protected class PENonAppendGraphBuilderContext implements GraphBuilderContext {
@@ -520,6 +529,15 @@
     protected abstract EncodedGraph lookupEncodedGraph(ResolvedJavaMethod method);
 
     @Override
+    protected void handleFixedNode(MethodScope s, LoopScope loopScope, int nodeOrderId, FixedNode node) {
+        PEMethodScope methodScope = (PEMethodScope) s;
+        if (node instanceof SimpleInfopointNode && methodScope.isInlinedMethod()) {
+            InliningUtil.processSimpleInfopoint(methodScope.invokeData.invoke, (SimpleInfopointNode) node, methodScope.getBytecodePosition());
+        }
+        super.handleFixedNode(s, loopScope, nodeOrderId, node);
+    }
+
+    @Override
     protected Node handleFloatingNodeBeforeAdd(MethodScope s, LoopScope loopScope, Node node) {
         PEMethodScope methodScope = (PEMethodScope) s;
 
@@ -592,11 +610,7 @@
         PEMethodScope methodScope = (PEMethodScope) s;
 
         if (methodScope.isInlinedMethod()) {
-            if (node instanceof SimpleInfopointNode) {
-                methodScope.bytecodePosition = InliningUtil.processSimpleInfopoint(methodScope.invokeData.invoke, (SimpleInfopointNode) node, methodScope.bytecodePosition);
-                return node;
-
-            } else if (node instanceof FrameState) {
+            if (node instanceof FrameState) {
                 FrameState frameState = (FrameState) node;
 
                 ensureOuterStateDecoded(methodScope);
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java	Mon May 11 19:58:25 2015 -0700
@@ -84,6 +84,7 @@
         if (Options.UseBlackholeSubstitution.getValue()) {
             registerJMHBlackholePlugins(plugins);
         }
+        registerJFRThrowablePlugins(plugins);
     }
 
     private static final Field STRING_VALUE_FIELD;
@@ -651,4 +652,18 @@
             }
         }
     }
+
+    private static void registerJFRThrowablePlugins(InvocationPlugins plugins) {
+        String name = "oracle.jrockit.jfr.jdkevents.ThrowableTracer";
+        Class<?> tracerClass = MethodSubstitutionPlugin.resolveClass(name, true);
+        if (tracerClass != null) {
+            Registration r = new Registration(plugins, tracerClass);
+            r.register2("traceThrowable", Throwable.class, String.class, new InvocationPlugin() {
+                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) {
+                    b.add(new VirtualizableInvokeMacroNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnType(), throwable, message));
+                    return true;
+                }
+            });
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/VirtualizableInvokeMacroNode.java	Mon May 11 19:58:25 2015 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.replacements.nodes;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.graph.*;
+import com.oracle.graal.nodeinfo.*;
+import com.oracle.graal.nodes.CallTargetNode.InvokeKind;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.spi.*;
+
+/**
+ * A helper class to allow elimination of byte code instrumentation that could interfere with escape
+ * analysis.
+ */
+@NodeInfo
+public class VirtualizableInvokeMacroNode extends MacroStateSplitNode implements Virtualizable {
+
+    public static final NodeClass<VirtualizableInvokeMacroNode> TYPE = NodeClass.create(VirtualizableInvokeMacroNode.class);
+
+    public VirtualizableInvokeMacroNode(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, int bci, JavaType returnType, ValueNode... arguments) {
+        super(TYPE, invokeKind, targetMethod, bci, returnType, arguments);
+    }
+
+    @Override
+    public void virtualize(VirtualizerTool tool) {
+        for (ValueNode arg : arguments) {
+            State state = tool.getObjectState(arg);
+            if (state != null && state.getState() == EscapeState.Virtual) {
+                tool.delete();
+            }
+        }
+    }
+}
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Mon May 11 19:58:25 2015 -0700
@@ -306,7 +306,7 @@
     }
 
     @Override
-    public boolean enableInfopoints() {
+    public boolean platformEnableInfopoints() {
         return HotSpotGraalRuntime.runtime().getCompilerToVM().shouldDebugNonSafepoints();
     }
 
--- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/BytecodeInterpreterPartialEvaluationTest.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/BytecodeInterpreterPartialEvaluationTest.java	Mon May 11 19:58:25 2015 -0700
@@ -269,7 +269,7 @@
         assertPartialEvalEqualsAndRunsCorrect(new Program("nestedLoopsProgram", bytecodes, 0, 6));
     }
 
-    @Test(timeout = 1000)
+    @Test(timeout = 2000)
     public void manyIfsProgram() {
         byte[] bytecodes = new byte[]{
         /* 0: */Bytecode.CONST,
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java	Mon May 11 19:58:25 2015 -0700
@@ -281,7 +281,12 @@
 
     public abstract void reinstallStubs();
 
-    public abstract boolean enableInfopoints();
+    public final boolean enableInfopoints() {
+        /* Currently infopoints can change code generation so don't enable them automatically */
+        return platformEnableInfopoints() && TruffleEnableInfopoints.getValue();
+    }
+
+    protected abstract boolean platformEnableInfopoints();
 
     private final class DispatchTruffleCompilationListener implements GraalTruffleCompilationListener {
 
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java	Mon May 11 18:43:12 2015 -0700
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java	Mon May 11 19:58:25 2015 -0700
@@ -170,5 +170,8 @@
 
     @Option(help = "Print additional more verbose Truffle compilation statistics at the end of a run.", type = OptionType.Debug)
     public static final OptionValue<Boolean> TruffleCompilationStatisticDetails = new OptionValue<>(false);
+
+    @Option(help = "Enable support for simple infopoints in truffle partial evaluations.", type = OptionType.Expert)
+    public static final OptionValue<Boolean> TruffleEnableInfopoints = new OptionValue<>(false);
     // @formatter:on
 }