changeset 2737:99c84a06bb64

Added two new utilities to the Graph class: NodeBitMap and NodeMap.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Fri, 20 May 2011 10:40:39 +0200
parents 03b80fb10ae9
children 88123130ede6
files graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java graal/GraalGraph/.classpath graal/GraalGraph/src/com/oracle/graal/graph/Graph.java
diffstat 3 files changed, 67 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Fri May 20 10:16:39 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Fri May 20 10:40:39 2011 +0200
@@ -36,7 +36,7 @@
  * The {@code FrameState} class encapsulates the frame state (i.e. local variables and
  * operand stack) at a particular point in the abstract interpretation.
  */
-public class FrameState extends Value implements FrameStateAccess {
+public final class FrameState extends Value implements FrameStateAccess {
 
     protected final int localsSize;
 
--- a/graal/GraalGraph/.classpath	Fri May 20 10:16:39 2011 +0200
+++ b/graal/GraalGraph/.classpath	Fri May 20 10:40:39 2011 +0200
@@ -1,8 +1,9 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="src" path="test"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
-	<classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="test"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/com.oracle.max.cri"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
--- a/graal/GraalGraph/src/com/oracle/graal/graph/Graph.java	Fri May 20 10:16:39 2011 +0200
+++ b/graal/GraalGraph/src/com/oracle/graal/graph/Graph.java	Fri May 20 10:40:39 2011 +0200
@@ -26,6 +26,8 @@
 import java.util.Collection;
 import java.util.Collections;
 
+import com.sun.cri.ci.CiBitMap;
+
 public class Graph {
 
     private final ArrayList<Node> nodes;
@@ -54,4 +56,59 @@
     public Root root() {
         return root;
     }
+    
+    public NodeBitMap createNodeBitMap() {
+        return new NodeBitMap();
+    }
+    
+    public <T> NodeMap<T> createNodeMap() {
+        return new NodeMap<T>();
+    }
+
+    public final class NodeBitMap {
+
+        private final CiBitMap bitMap = new CiBitMap(nextId);
+
+        private NodeBitMap() {
+        }
+
+        public boolean isMarked(Node node) {
+            check(node);
+            return bitMap.get(node.id());
+        }
+
+        public void mark(Node node) {
+            check(node);
+            bitMap.set(node.id());
+        }
+
+        private void check(Node node) {
+            assert node.graph == Graph.this : "this node is not part of the graph";
+            assert node.id() < bitMap.length() : "this node was added to the graph after creating the node bitmap";
+        }
+    }
+
+    public final class NodeMap<T> {
+
+        private final Object[] values = new Object[nextId];
+
+        private NodeMap() {
+        }
+
+        @SuppressWarnings("unchecked")
+        public T get(Node node) {
+            check(node);
+            return (T) values[node.id()];
+        }
+
+        public void set(Node node, T value) {
+            check(node);
+            values[node.id()] = value;
+        }
+
+        private void check(Node node) {
+            assert node.graph == Graph.this : "this node is not part of the graph";
+            assert node.id() < values.length : "this node was added to the graph after creating the node map";
+        }
+    }
 }