--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/StructuredGraph.java Fri Mar 16 11:26:05 2018 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/StructuredGraph.java Fri Mar 16 22:59:32 2018 -0700
@@ -22,6 +22,8 @@
*/
package org.graalvm.compiler.nodes;
+import static org.graalvm.compiler.graph.Graph.SourcePositionTracking.Default;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -39,6 +41,7 @@
import org.graalvm.compiler.core.common.type.Stamp;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.JavaMethodContext;
+import org.graalvm.compiler.debug.TTY;
import org.graalvm.compiler.graph.Graph;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeMap;
@@ -167,6 +170,7 @@
private CompilationIdentifier compilationId = CompilationIdentifier.INVALID_COMPILATION_ID;
private int entryBCI = JVMCICompiler.INVOCATION_ENTRY_BCI;
private boolean useProfilingInfo = true;
+ private SourcePositionTracking trackNodeSourcePosition = Default;
private final OptionValues options;
private Cancellable cancellable = null;
private final DebugContext debug;
@@ -179,6 +183,7 @@
this.options = options;
this.debug = debug;
this.assumptions = allowAssumptions == AllowAssumptions.YES ? new Assumptions() : null;
+ this.trackNodeSourcePosition = Graph.trackNodeSourcePositionDefault(options, debug);
}
/**
@@ -187,7 +192,8 @@
public Builder(OptionValues options, DebugContext debug) {
this.options = options;
this.debug = debug;
- assumptions = null;
+ this.assumptions = null;
+ this.trackNodeSourcePosition = Graph.trackNodeSourcePositionDefault(options, debug);
}
public String getName() {
@@ -257,13 +263,25 @@
return this;
}
+ public Builder trackNodeSourcePosition(SourcePositionTracking tracking) {
+ this.trackNodeSourcePosition = tracking;
+ return this;
+ }
+
+ public Builder trackNodeSourcePosition(boolean flag) {
+ if (flag) {
+ this.trackNodeSourcePosition = SourcePositionTracking.Track;
+ }
+ return this;
+ }
+
public Builder callerContext(NodeSourcePosition context) {
this.callerContext = context;
return this;
}
public StructuredGraph build() {
- return new StructuredGraph(name, rootMethod, entryBCI, assumptions, speculationLog, useProfilingInfo, compilationId, options, debug, cancellable, callerContext);
+ return new StructuredGraph(name, rootMethod, entryBCI, assumptions, speculationLog, useProfilingInfo, trackNodeSourcePosition, compilationId, options, debug, cancellable, callerContext);
}
}
@@ -328,6 +346,7 @@
Assumptions assumptions,
SpeculationLog speculationLog,
boolean useProfilingInfo,
+ SourcePositionTracking trackNodeSourcePosition,
CompilationIdentifier compilationId,
OptionValues options,
DebugContext debug,
@@ -342,8 +361,10 @@
this.assumptions = assumptions;
this.speculationLog = speculationLog;
this.useProfilingInfo = useProfilingInfo;
+ this.trackNodeSourcePosition = trackNodeSourcePosition;
+ assert trackNodeSourcePosition != null;
this.cancellable = cancellable;
- this.inliningLog = new InliningLog();
+ this.inliningLog = new InliningLog(rootMethod, options);
this.callerContext = context;
}
@@ -457,6 +478,12 @@
return inliningLog;
}
+ public void logInliningTree() {
+ if (GraalOptions.TraceInlining.getValue(getOptions())) {
+ TTY.println(getInliningLog().formatAsTree());
+ }
+ }
+
/**
* Creates a copy of this graph.
*
@@ -471,6 +498,7 @@
return copy(newName, duplicationMapCallback, compilationId, debugForCopy);
}
+ @SuppressWarnings("try")
private StructuredGraph copy(String newName, Consumer<UnmodifiableEconomicMap<Node, Node>> duplicationMapCallback, CompilationIdentifier newCompilationId, DebugContext debugForCopy) {
AllowAssumptions allowAssumptions = AllowAssumptions.ifNonNull(assumptions);
StructuredGraph copy = new StructuredGraph(newName,
@@ -479,6 +507,7 @@
assumptions == null ? null : new Assumptions(),
speculationLog,
useProfilingInfo,
+ trackNodeSourcePosition,
newCompilationId,
getOptions(), debugForCopy, null, callerContext);
if (allowAssumptions == AllowAssumptions.YES && assumptions != null) {
@@ -491,7 +520,13 @@
copy.isAfterExpandLogic = isAfterExpandLogic;
EconomicMap<Node, Node> replacements = EconomicMap.create(Equivalence.IDENTITY);
replacements.put(start, copy.start);
- UnmodifiableEconomicMap<Node, Node> duplicates = copy.addDuplicates(getNodes(), this, this.getNodeCount(), replacements);
+ UnmodifiableEconomicMap<Node, Node> duplicates;
+ try (InliningLog.UpdateScope scope = copy.getInliningLog().openDefaultUpdateScope()) {
+ duplicates = copy.addDuplicates(getNodes(), this, this.getNodeCount(), replacements);
+ if (scope != null) {
+ copy.getInliningLog().replaceLog(duplicates, this.getInliningLog());
+ }
+ }
if (duplicationMapCallback != null) {
duplicationMapCallback.accept(duplicates);
}
@@ -951,6 +986,11 @@
@Override
protected void afterRegister(Node node) {
assert hasValueProxies() || !(node instanceof ValueProxyNode);
+ if (GraalOptions.TraceInlining.getValue(getOptions())) {
+ if (node instanceof Invokable) {
+ ((Invokable) node).updateInliningLogAfterRegister(this);
+ }
+ }
}
public NodeSourcePosition getCallerContext() {