changeset 18925:14599c77560a

Do not always allocate monitorId NodeInputList. Allow null NodeInputList.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 22 Jan 2015 21:01:46 +0100
parents 6338dfaf6a44
children b4633ae1b31b
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nfi/NativeCallStubGraphBuilder.java graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java
diffstat 5 files changed, 58 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java	Thu Jan 22 18:46:04 2015 +0100
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java	Thu Jan 22 21:01:46 2015 +0100
@@ -124,11 +124,13 @@
         }
         while (index < getCount()) {
             NodeList<Node> list = getNodeList(node, index);
-            int size = list.initialSize;
-            NodeList<Node> newList = type == Edges.Type.Inputs ? new NodeInputList<>(node, size) : new NodeSuccessorList<>(node, size);
+            if (list != null) {
+                int size = list.initialSize;
+                NodeList<Node> newList = type == Edges.Type.Inputs ? new NodeInputList<>(node, size) : new NodeSuccessorList<>(node, size);
 
-            // replacing with a new list object is the expected behavior!
-            initializeList(node, index, newList);
+                // replacing with a new list object is the expected behavior!
+                initializeList(node, index, newList);
+            }
             index++;
         }
     }
@@ -144,9 +146,11 @@
         int index = getDirectCount();
         while (index < getCount()) {
             NodeList<Node> list = getNodeList(prototype, index);
-            int size = list.initialSize;
-            NodeList<Node> newList = type == Edges.Type.Inputs ? new NodeInputList<>(node, size) : new NodeSuccessorList<>(node, size);
-            initializeList(node, index, newList);
+            if (list != null) {
+                int size = list.initialSize;
+                NodeList<Node> newList = type == Edges.Type.Inputs ? new NodeInputList<>(node, size) : new NodeSuccessorList<>(node, size);
+                initializeList(node, index, newList);
+            }
             index++;
         }
     }
@@ -201,9 +205,10 @@
         }
         while (index < getCount()) {
             NodeList<Node> list = getNodeList(node, index);
-            assert list != null : this;
-            if (list.replaceFirst(key, replacement)) {
-                return true;
+            if (list != null) {
+                if (list.replaceFirst(key, replacement)) {
+                    return true;
+                }
             }
             index++;
         }
@@ -256,7 +261,8 @@
             }
         }
         for (int i = directCount; i < getCount(); i++) {
-            if (getNodeList(node, i).contains(value)) {
+            NodeList<?> curList = getNodeList(node, i);
+            if (curList != null && curList.contains(value)) {
                 return true;
             }
         }
@@ -277,7 +283,7 @@
         }
         while (index < getCount()) {
             NodeList<Node> list = getNodeList(other, index);
-            if (!list.equals(getNodeList(node, index))) {
+            if (!Objects.equals(list, getNodeList(node, index))) {
                 return false;
             }
             index++;
@@ -329,12 +335,14 @@
                 if (subIndex == 0) {
                     list = edges.getNodeList(node, index);
                 }
-                while (subIndex < list.size()) {
-                    nextElement = list.get(subIndex);
-                    if (nextElement != null) {
-                        return;
+                if (list != null) {
+                    while (subIndex < list.size()) {
+                        nextElement = list.get(subIndex);
+                        if (nextElement != null) {
+                            return;
+                        }
+                        subIndex++;
                     }
-                    subIndex++;
                 }
                 subIndex = 0;
                 index++;
@@ -404,9 +412,11 @@
                 if (subIndex == 0) {
                     list = edges.getNodeList(node, index);
                 }
-                if (subIndex < list.size()) {
-                    nextElement = list.get(subIndex);
-                    return;
+                if (list != null) {
+                    if (subIndex < list.size()) {
+                        nextElement = list.get(subIndex);
+                        return;
+                    }
                 }
                 subIndex = 0;
                 index++;
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Thu Jan 22 18:46:04 2015 +0100
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Thu Jan 22 21:01:46 2015 +0100
@@ -597,8 +597,9 @@
 
         while (index < edges.getCount()) {
             NodeList<Node> list = edges.getNodeList(node, index);
-            assert list != null : edges;
-            edges.initializeList(node, index, updateEdgeListCopy(node, list, duplicationReplacement, edges.type()));
+            if (list != null) {
+                edges.initializeList(node, index, updateEdgeListCopy(node, list, duplicationReplacement, edges.type()));
+            }
             index++;
         }
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nfi/NativeCallStubGraphBuilder.java	Thu Jan 22 18:46:04 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nfi/NativeCallStubGraphBuilder.java	Thu Jan 22 21:01:46 2015 +0100
@@ -56,8 +56,7 @@
             ParameterNode arg0 = g.unique(new ParameterNode(0, StampFactory.forKind(Kind.Object)));
             ParameterNode arg1 = g.unique(new ParameterNode(1, StampFactory.forKind(Kind.Object)));
             ParameterNode arg2 = g.unique(new ParameterNode(2, StampFactory.forKind(Kind.Object)));
-            FrameState frameState = g.add(new FrameState(null, method, 0, Arrays.asList(new ValueNode[]{arg0, arg1, arg2}), 3, 0, false, false, new ArrayList<MonitorIdNode>(),
-                            new ArrayList<EscapeObjectState>()));
+            FrameState frameState = g.add(new FrameState(null, method, 0, Arrays.asList(new ValueNode[]{arg0, arg1, arg2}), 3, 0, false, false, null, new ArrayList<EscapeObjectState>()));
             g.start().setStateAfter(frameState);
             List<ValueNode> parameters = new ArrayList<>();
             FixedWithNextNode fixedWithNext = getParameters(g, arg0, argumentTypes.length, argumentTypes, parameters, providers);
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Thu Jan 22 18:46:04 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Thu Jan 22 21:01:46 2015 +0100
@@ -157,6 +157,7 @@
             private ValueNode methodSynchronizedObject;
             private ExceptionDispatchBlock unwindBlock;
             private BciBlock returnBlock;
+
             private ValueNode returnValue;
             private FixedWithNextNode beforeReturnNode;
             private ValueNode unwindValue;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java	Thu Jan 22 18:46:04 2015 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java	Thu Jan 22 21:01:46 2015 +0100
@@ -75,7 +75,7 @@
     protected final ResolvedJavaMethod method;
 
     public FrameState(FrameState outerFrameState, ResolvedJavaMethod method, int bci, List<ValueNode> values, int localsSize, int stackSize, boolean rethrowException, boolean duringCall,
-                    List<MonitorIdNode> monitorIds, List<EscapeObjectState> virtualObjectMappings) {
+                    MonitorIdNode[] monitorIds, List<EscapeObjectState> virtualObjectMappings) {
         assert stackSize >= 0;
         this.outerFrameState = outerFrameState;
         this.method = method;
@@ -83,7 +83,9 @@
         this.localsSize = localsSize;
         this.stackSize = stackSize;
         this.values = new NodeInputList<>(this, values);
-        this.monitorIds = new NodeInputList<>(this, monitorIds);
+        if (monitorIds != null && monitorIds.length > 0) {
+            this.monitorIds = new NodeInputList<>(this, monitorIds);
+        }
         this.virtualObjectMappings = new NodeInputList<>(this, virtualObjectMappings);
         this.rethrowException = rethrowException;
         this.duringCall = duringCall;
@@ -93,15 +95,14 @@
     }
 
     public FrameState(int bci) {
-        this(null, null, bci, Collections.<ValueNode> emptyList(), 0, 0, false, false, Collections.<MonitorIdNode> emptyList(), Collections.<EscapeObjectState> emptyList());
+        this(null, null, bci, Collections.<ValueNode> emptyList(), 0, 0, false, false, null, Collections.<EscapeObjectState> emptyList());
         assert bci == BytecodeFrame.BEFORE_BCI || bci == BytecodeFrame.AFTER_BCI || bci == BytecodeFrame.AFTER_EXCEPTION_BCI || bci == BytecodeFrame.UNKNOWN_BCI ||
                         bci == BytecodeFrame.INVALID_FRAMESTATE_BCI;
     }
 
     public FrameState(FrameState outerFrameState, ResolvedJavaMethod method, int bci, ValueNode[] locals, List<ValueNode> stack, ValueNode[] locks, MonitorIdNode[] monitorIds,
                     boolean rethrowException, boolean duringCall) {
-        this(outerFrameState, method, bci, createValues(locals, stack, locks), locals.length, stack.size(), rethrowException, duringCall, Arrays.asList(monitorIds),
-                        Collections.<EscapeObjectState> emptyList());
+        this(outerFrameState, method, bci, createValues(locals, stack, locks), locals.length, stack.size(), rethrowException, duringCall, monitorIds, Collections.<EscapeObjectState> emptyList());
     }
 
     private static List<ValueNode> createValues(ValueNode[] locals, List<ValueNode> stack, ValueNode[] locks) {
@@ -125,10 +126,6 @@
         return values;
     }
 
-    public NodeInputList<MonitorIdNode> monitorIds() {
-        return monitorIds;
-    }
-
     public FrameState outerFrameState() {
         return outerFrameState;
     }
@@ -173,7 +170,7 @@
      * Gets a copy of this frame state.
      */
     public FrameState duplicate(int newBci) {
-        return graph().add(new FrameState(outerFrameState(), method, newBci, values, localsSize, stackSize, rethrowException, duringCall, monitorIds, virtualObjectMappings));
+        return graph().add(new FrameState(outerFrameState(), method, newBci, values, localsSize, stackSize, rethrowException, duringCall, duplicateMonitorIds(), virtualObjectMappings));
     }
 
     /**
@@ -197,7 +194,7 @@
         for (EscapeObjectState state : virtualObjectMappings) {
             newVirtualMappings.add(state.duplicateWithVirtualState());
         }
-        return graph().add(new FrameState(newOuterFrameState, method, bci, values, localsSize, stackSize, rethrowException, duringCall, monitorIds, newVirtualMappings));
+        return graph().add(new FrameState(newOuterFrameState, method, bci, values, localsSize, stackSize, rethrowException, duringCall, duplicateMonitorIds(), newVirtualMappings));
     }
 
     /**
@@ -248,7 +245,15 @@
         copy.addAll(values.subList(localsSize + stackSize, values.size()));
 
         assert checkStackDepth(bci, stackSize, duringCall, newBci, newStackSize, newDuringCall);
-        return graph().add(new FrameState(outerFrameState(), method, newBci, copy, localsSize, newStackSize, newRethrowException, newDuringCall, monitorIds, virtualObjectMappings));
+        return graph().add(new FrameState(outerFrameState(), method, newBci, copy, localsSize, newStackSize, newRethrowException, newDuringCall, duplicateMonitorIds(), virtualObjectMappings));
+    }
+
+    private MonitorIdNode[] duplicateMonitorIds() {
+        if (monitorIds == null) {
+            return null;
+        } else {
+            return monitorIds.toArray(new MonitorIdNode[monitorIds.size()]);
+        }
     }
 
     /**
@@ -343,7 +348,7 @@
      * Get the MonitorIdNode that corresponds to the locked object at the specified index.
      */
     public MonitorIdNode monitorIdAt(int i) {
-        assert i >= 0 && i < locksSize();
+        assert monitorIds != null && i >= 0 && i < locksSize();
         return monitorIds.get(i);
     }
 
@@ -429,9 +434,11 @@
         for (ValueNode value : values.nonNull()) {
             closure.apply(this, value);
         }
-        for (MonitorIdNode monitorId : monitorIds) {
-            if (monitorId != null) {
-                closure.apply(this, monitorId);
+        if (monitorIds != null) {
+            for (MonitorIdNode monitorId : monitorIds) {
+                if (monitorId != null) {
+                    closure.apply(this, monitorId);
+                }
             }
         }
         for (EscapeObjectState state : virtualObjectMappings) {