hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Graph.java
changeset 46680 2894e4262fd6
parent 46640 70bdce04c59b
--- a/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Graph.java	Mon Jul 17 09:21:48 2017 -0700
+++ b/hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Graph.java	Mon Jul 17 16:31:51 2017 -0700
@@ -150,7 +150,7 @@
     /**
      * The {@link DebugContext} used while compiling this graph.
      */
-    private final DebugContext debug;
+    private DebugContext debug;
 
     private class NodeSourcePositionScope implements DebugCloseable {
         private final NodeSourcePosition previous;
@@ -373,6 +373,21 @@
         return debug;
     }
 
+    /**
+     * Resets the {@link DebugContext} for this graph to a new value. This is useful when a graph is
+     * "handed over" from its creating thread to another thread.
+     *
+     * This must only be done when the current thread is no longer using the graph. This is in
+     * general impossible to test due to races and since metrics can be updated at any time. As
+     * such, this method only performs a weak sanity check that at least the current debug context
+     * does not have a nested scope open (the top level scope will always be open if scopes are
+     * enabled).
+     */
+    public void resetDebug(DebugContext newDebug) {
+        assert newDebug == debug || !debug.inNestedScope() : String.format("Cannot reset the debug context for %s while it has the nested scope \"%s\" open", this, debug.getCurrentScopeName());
+        this.debug = newDebug;
+    }
+
     @Override
     public String toString() {
         return name == null ? super.toString() : "Graph " + name;