--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java Fri Mar 16 11:26:05 2018 +0000
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java Fri Mar 16 22:59:32 2018 -0700
@@ -55,6 +55,7 @@
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.debug.TimerKey;
import org.graalvm.compiler.graph.Node;
+import org.graalvm.compiler.graph.NodeSourcePosition;
import org.graalvm.compiler.graph.Node.NodeIntrinsic;
import org.graalvm.compiler.java.GraphBuilderPhase;
import org.graalvm.compiler.java.GraphBuilderPhase.Instance;
@@ -148,7 +149,7 @@
if (subst != null) {
if (b.parsingIntrinsic() || InlineDuringParsing.getValue(b.getOptions()) || InlineIntrinsicsDuringParsing.getValue(b.getOptions())) {
// Forced inlining of intrinsics
- return createIntrinsicInlineInfo(subst.getMethod(), subst.getOrigin());
+ return createIntrinsicInlineInfo(subst.getMethod(), method, subst.getOrigin());
}
return null;
}
@@ -156,7 +157,7 @@
assert b.getDepth() < MAX_GRAPH_INLINING_DEPTH : "inlining limit exceeded";
// Force inlining when parsing replacements
- return createIntrinsicInlineInfo(method, defaultBytecodeProvider);
+ return createIntrinsicInlineInfo(method, null, defaultBytecodeProvider);
} else {
assert method.getAnnotation(NodeIntrinsic.class) == null : String.format("@%s method %s must only be called from within a replacement%n%s", NodeIntrinsic.class.getSimpleName(),
method.format("%h.%n"), b);
@@ -202,8 +203,8 @@
private static final TimerKey SnippetPreparationTime = DebugContext.timer("SnippetPreparationTime");
@Override
- public StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args) {
- return getSnippet(method, null, args);
+ public StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
+ return getSnippet(method, null, args, trackNodeSourcePosition, replaceePosition);
}
private static final AtomicInteger nextDebugContextId = new AtomicInteger();
@@ -217,29 +218,34 @@
@Override
@SuppressWarnings("try")
- public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args) {
+ public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
assert method.hasBytecodes() : "Snippet must not be abstract or native";
StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(method) : null;
- if (graph == null) {
+ if (graph == null || (trackNodeSourcePosition && !graph.trackNodeSourcePosition())) {
try (DebugContext debug = openDebugContext("Snippet_", method);
DebugCloseable a = SnippetPreparationTime.start(debug)) {
- StructuredGraph newGraph = makeGraph(debug, defaultBytecodeProvider, method, args, recursiveEntry);
+ StructuredGraph newGraph = makeGraph(debug, defaultBytecodeProvider, method, args, recursiveEntry, trackNodeSourcePosition, replaceePosition);
DebugContext.counter("SnippetNodeCount[%#s]", method).add(newGraph.getDebug(), newGraph.getNodeCount());
if (!UseSnippetGraphCache.getValue(options) || args != null) {
return newGraph;
}
newGraph.freeze();
- graphs.putIfAbsent(method, newGraph);
+ if (graph != null) {
+ graphs.replace(method, graph, newGraph);
+ } else {
+ graphs.putIfAbsent(method, newGraph);
+ }
graph = graphs.get(method);
}
}
+ assert !trackNodeSourcePosition || graph.trackNodeSourcePosition();
return graph;
}
@Override
- public void registerSnippet(ResolvedJavaMethod method) {
+ public void registerSnippet(ResolvedJavaMethod method, boolean trackNodeSourcePosition) {
// No initialization needed as snippet graphs are created on demand in getSnippet
}
@@ -266,7 +272,7 @@
}
@Override
- public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci) {
+ public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
StructuredGraph result;
InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
if (plugin != null && (!plugin.inlineOnly() || invokeBci >= 0)) {
@@ -275,9 +281,9 @@
MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess);
StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(substitute) : null;
- if (graph == null) {
+ if (graph == null || graph.trackNodeSourcePosition() != trackNodeSourcePosition) {
try (DebugContext debug = openDebugContext("Substitution_", method)) {
- graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method);
+ graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method, trackNodeSourcePosition, replaceePosition);
if (!UseSnippetGraphCache.getValue(options)) {
return graph;
}
@@ -311,9 +317,11 @@
* @param args
* @param original the original method if {@code method} is a {@linkplain MethodSubstitution
* substitution} otherwise null
+ * @param trackNodeSourcePosition
*/
- public StructuredGraph makeGraph(DebugContext debug, BytecodeProvider bytecodeProvider, ResolvedJavaMethod method, Object[] args, ResolvedJavaMethod original) {
- return createGraphMaker(method, original).makeGraph(debug, bytecodeProvider, args);
+ public StructuredGraph makeGraph(DebugContext debug, BytecodeProvider bytecodeProvider, ResolvedJavaMethod method, Object[] args, ResolvedJavaMethod original, boolean trackNodeSourcePosition,
+ NodeSourcePosition replaceePosition) {
+ return createGraphMaker(method, original).makeGraph(debug, bytecodeProvider, args, trackNodeSourcePosition, replaceePosition);
}
/**
@@ -350,10 +358,10 @@
}
@SuppressWarnings("try")
- public StructuredGraph makeGraph(DebugContext debug, BytecodeProvider bytecodeProvider, Object[] args) {
+ public StructuredGraph makeGraph(DebugContext debug, BytecodeProvider bytecodeProvider, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
try (DebugContext.Scope s = debug.scope("BuildSnippetGraph", method)) {
assert method.hasBytecodes() : method;
- StructuredGraph graph = buildInitialGraph(debug, bytecodeProvider, method, args);
+ StructuredGraph graph = buildInitialGraph(debug, bytecodeProvider, method, args, trackNodeSourcePosition, replaceePosition);
finalizeGraph(graph);
@@ -417,10 +425,12 @@
* Builds the initial graph for a replacement.
*/
@SuppressWarnings("try")
- protected StructuredGraph buildInitialGraph(DebugContext debug, BytecodeProvider bytecodeProvider, final ResolvedJavaMethod methodToParse, Object[] args) {
+ protected StructuredGraph buildInitialGraph(DebugContext debug, BytecodeProvider bytecodeProvider, final ResolvedJavaMethod methodToParse, Object[] args, boolean trackNodeSourcePosition,
+ NodeSourcePosition replaceePosition) {
// Replacements cannot have optimistic assumptions since they have
// to be valid for the entire run of the VM.
- final StructuredGraph graph = new StructuredGraph.Builder(replacements.options, debug).method(methodToParse).build();
+ final StructuredGraph graph = new StructuredGraph.Builder(replacements.options, debug).method(methodToParse).trackNodeSourcePosition(trackNodeSourcePosition).callerContext(
+ replaceePosition).build();
// Replacements are not user code so they do not participate in unsafe access
// tracking