Bug in Truffle: parent is accessed racily

Andrew Haley aph at redhat.com
Thu Jan 19 17:44:34 UTC 2017


I've been seeing some odd failures in InstrumentationMultiThreadingTest.
I occasionally get NullPointerExceptions on Node.getRootNode().

I think the real problem is in class Node, where Node.parent is accessed
racily by multiple threads.  parent really needs to be volatile:

diff --git a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java
index e153bc6..52a2c95 100644
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java
@@ -55,7 +55,7 @@ import com.oracle.truffle.api.utilities.JSONHelper;
 public abstract class Node implements NodeInterface, Cloneable {

     private final NodeClass nodeClass;
-    @CompilationFinal private Node parent;
+    @CompilationFinal private volatile Node parent;

     /**
      * Marks array fields that are children of this node.

Andrew.


More information about the graal-dev mailing list