changeset 17060:cc8bd79d8d57

fixed race involving NodeRefIterator.Empty
author Doug Simon <doug.simon@oracle.com>
date Mon, 08 Sep 2014 13:24:50 +0200
parents a5dc5513ce85
children 75dd27a1d79f
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterable.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterator.java
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterable.java	Mon Sep 08 09:46:07 2014 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterable.java	Mon Sep 08 13:24:50 2014 +0200
@@ -30,7 +30,7 @@
  * An iterator over the references to a given {@link Node}'s {@linkplain Input inputs} or
  * {@linkplain Successor successors}.
  */
-public class NodeRefIterable implements NodeClassIterable {
+public final class NodeRefIterable implements NodeClassIterable {
 
     protected final Node node;
 
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterator.java	Mon Sep 08 09:46:07 2014 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeRefIterator.java	Mon Sep 08 13:24:50 2014 +0200
@@ -36,7 +36,7 @@
  */
 public class NodeRefIterator implements NodePosIterator {
 
-    public static final NodeRefIterator Empty = new NodeRefIterator(null, 0, 0, false);
+    public static final NodeRefIterator Empty = new NodeRefIterator();
 
     protected final Node node;
 
@@ -93,6 +93,18 @@
     }
 
     /**
+     * Constructor for {@link #Empty}.
+     */
+    private NodeRefIterator() {
+        this(null, 0, 0, false);
+        // This constructor must only be used to construct Empty
+        assert Empty == null;
+        // This must be set here to prevent multiple threads racing to
+        // call forward() which never needs to be done for Empty.
+        this.needsForward = false;
+    }
+
+    /**
      * Gets the value of a {@link Node} field in the node.
      *
      * @param at the index of the Node field whose value is being requested. This is guaranteed to