--- old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/StructuredGraph.java 2017-07-07 09:31:24.000000000 -0700 +++ new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/StructuredGraph.java 2017-07-07 09:31:24.000000000 -0700 @@ -33,6 +33,7 @@ import org.graalvm.compiler.core.common.GraalOptions; import org.graalvm.compiler.core.common.cfg.BlockMap; import org.graalvm.compiler.core.common.type.Stamp; +import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.JavaMethodContext; import org.graalvm.compiler.graph.Graph; import org.graalvm.compiler.graph.Node; @@ -167,60 +168,95 @@ private boolean useProfilingInfo = true; private final OptionValues options; private Cancellable cancellable = null; + private final DebugContext debug; /** * Creates a builder for a graph. */ - public Builder(OptionValues options, AllowAssumptions allowAssumptions) { + public Builder(OptionValues options, DebugContext debug, AllowAssumptions allowAssumptions) { this.options = options; + this.debug = debug; this.assumptions = allowAssumptions == AllowAssumptions.YES ? new Assumptions() : null; } /** * Creates a builder for a graph that does not support {@link Assumptions}. */ - public Builder(OptionValues options) { + public Builder(OptionValues options, DebugContext debug) { this.options = options; + this.debug = debug; assumptions = null; } + public String getName() { + return name; + } + public Builder name(String s) { this.name = s; return this; } + public ResolvedJavaMethod getMethod() { + return rootMethod; + } + public Builder method(ResolvedJavaMethod method) { this.rootMethod = method; return this; } + public DebugContext getDebug() { + return debug; + } + + public SpeculationLog getSpeculationLog() { + return speculationLog; + } + public Builder speculationLog(SpeculationLog log) { this.speculationLog = log; return this; } + public CompilationIdentifier getCompilationId() { + return compilationId; + } + public Builder compilationId(CompilationIdentifier id) { this.compilationId = id; return this; } + public Cancellable getCancellable() { + return cancellable; + } + public Builder cancellable(Cancellable cancel) { this.cancellable = cancel; return this; } + public int getEntryBCI() { + return entryBCI; + } + public Builder entryBCI(int bci) { this.entryBCI = bci; return this; } + public boolean getUseProfilingInfo() { + return useProfilingInfo; + } + public Builder useProfilingInfo(boolean flag) { this.useProfilingInfo = flag; return this; } public StructuredGraph build() { - return new StructuredGraph(name, rootMethod, entryBCI, assumptions, speculationLog, useProfilingInfo, compilationId, options, cancellable); + return new StructuredGraph(name, rootMethod, entryBCI, assumptions, speculationLog, useProfilingInfo, compilationId, options, debug, cancellable); } } @@ -280,8 +316,9 @@ boolean useProfilingInfo, CompilationIdentifier compilationId, OptionValues options, + DebugContext debug, Cancellable cancellable) { - super(name, options); + super(name, options, debug); this.setStart(add(new StartNode())); this.rootMethod = method; this.graphId = uniqueGraphIds.incrementAndGet(); @@ -404,13 +441,16 @@ * * @param newName the name of the copy, used for debugging purposes (can be null) * @param duplicationMapCallback consumer of the duplication map created during the copying + * @param debugForCopy the debug context for the graph copy. This must not be the debug for this + * graph if this graph can be accessed from multiple threads (e.g., it's in a cache + * accessed by multiple threads). */ @Override - protected Graph copy(String newName, Consumer> duplicationMapCallback) { - return copy(newName, duplicationMapCallback, compilationId); + protected Graph copy(String newName, Consumer> duplicationMapCallback, DebugContext debugForCopy) { + return copy(newName, duplicationMapCallback, compilationId, debugForCopy); } - private StructuredGraph copy(String newName, Consumer> duplicationMapCallback, CompilationIdentifier newCompilationId) { + private StructuredGraph copy(String newName, Consumer> duplicationMapCallback, CompilationIdentifier newCompilationId, DebugContext debugForCopy) { AllowAssumptions allowAssumptions = AllowAssumptions.ifNonNull(assumptions); StructuredGraph copy = new StructuredGraph(newName, method(), @@ -419,7 +459,7 @@ speculationLog, useProfilingInfo, newCompilationId, - getOptions(), null); + getOptions(), debugForCopy, null); if (allowAssumptions == AllowAssumptions.YES && assumptions != null) { copy.assumptions.record(assumptions); } @@ -437,8 +477,13 @@ return copy; } - public StructuredGraph copyWithIdentifier(CompilationIdentifier newCompilationId) { - return copy(name, null, newCompilationId); + /** + * @param debugForCopy the debug context for the graph copy. This must not be the debug for this + * graph if this graph can be accessed from multiple threads (e.g., it's in a cache + * accessed by multiple threads). + */ + public StructuredGraph copyWithIdentifier(CompilationIdentifier newCompilationId, DebugContext debugForCopy) { + return copy(name, null, newCompilationId, debugForCopy); } public ParameterNode getParameter(int index) {