changeset 18927:8da21b779982

Initialize FrameState with less copying.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 22 Jan 2015 21:53:06 +0100
parents b4633ae1b31b
children c8fc6e2d128b
files graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java
diffstat 4 files changed, 46 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java	Thu Jan 22 21:14:53 2015 +0100
+++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java	Thu Jan 22 21:53:06 2015 +0100
@@ -1153,7 +1153,8 @@
             locks[i] = lirValueToHirNode.apply(lockValue);
             monitorIds[i] = getMonitorIdForHotSpotMonitorValueFromFrame(lockValue, hsailFrame, hostGraph);
         }
-        FrameState frameState = hostGraph.add(new FrameState(null, lowLevelFrame.getMethod(), lowLevelFrame.getBCI(), locals, stack, locks, monitorIds, lowLevelFrame.rethrowException, false));
+        FrameState frameState = hostGraph.add(new FrameState(null, lowLevelFrame.getMethod(), lowLevelFrame.getBCI(), locals, stack.toArray(new ValueNode[0]), stack.size(), locks, monitorIds,
+                        lowLevelFrame.rethrowException, false));
         if (outterFrameState != null) {
             frameState.setOuterFrameState(outterFrameState);
         }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java	Thu Jan 22 21:14:53 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java	Thu Jan 22 21:53:06 2015 +0100
@@ -511,8 +511,8 @@
                         ConstantNode errMsg = ConstantNode.forConstant(tool.getConstantReflection().forString(msg), providers.getMetaAccess(), graph);
                         callTarget = graph.add(new MethodCallTargetNode(InvokeKind.Static, checkCounter.getMethod(), new ValueNode[]{errMsg}, returnType));
                         invoke = graph.add(new InvokeNode(callTarget, 0));
-                        List<ValueNode> stack = Collections.emptyList();
-                        FrameState stateAfter = new FrameState(null, graph.method(), BytecodeFrame.AFTER_BCI, new ValueNode[0], stack, new ValueNode[0], new MonitorIdNode[0], false, false);
+                        FrameState stateAfter = new FrameState(null, graph.method(), BytecodeFrame.AFTER_BCI, new ValueNode[0], new ValueNode[0], 0, new ValueNode[0], new MonitorIdNode[0], false,
+                                        false);
                         invoke.setStateAfter(graph.add(stateAfter));
                         graph.addBeforeFixed(ret, invoke);
 
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java	Thu Jan 22 21:14:53 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java	Thu Jan 22 21:53:06 2015 +0100
@@ -155,8 +155,11 @@
     }
 
     public FrameState create(int bci) {
-        return graph.add(new FrameState(this.outerFrameStateSupplier == null ? null : outerFrameStateSupplier.get(), method, bci, locals, Arrays.asList(stack).subList(0, stackSize), lockedObjects,
-                        monitorIds, rethrowException, false));
+        FrameState outerFrameState = null;
+        if (outerFrameStateSupplier != null) {
+            outerFrameState = outerFrameStateSupplier.get();
+        }
+        return graph.add(new FrameState(outerFrameState, method, bci, locals, stack, stackSize, lockedObjects, monitorIds, rethrowException, false));
     }
 
     @Override
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java	Thu Jan 22 21:14:53 2015 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java	Thu Jan 22 21:53:06 2015 +0100
@@ -74,7 +74,7 @@
 
     protected final ResolvedJavaMethod method;
 
-    public FrameState(FrameState outerFrameState, ResolvedJavaMethod method, int bci, List<ValueNode> values, int localsSize, int stackSize, boolean rethrowException, boolean duringCall,
+    public FrameState(FrameState outerFrameState, ResolvedJavaMethod method, int bci, int localsSize, int stackSize, int lockSize, boolean rethrowException, boolean duringCall,
                     MonitorIdNode[] monitorIds, List<EscapeObjectState> virtualObjectMappings) {
         assert stackSize >= 0;
         this.outerFrameState = outerFrameState;
@@ -82,46 +82,54 @@
         this.bci = bci;
         this.localsSize = localsSize;
         this.stackSize = stackSize;
-        this.values = new NodeInputList<>(this, values);
+        this.values = new NodeInputList<>(this, localsSize + stackSize + lockSize);
+
         if (monitorIds != null && monitorIds.length > 0) {
             this.monitorIds = new NodeInputList<>(this, monitorIds);
         }
+
         if (virtualObjectMappings != null && virtualObjectMappings.size() > 0) {
             this.virtualObjectMappings = new NodeInputList<>(this, virtualObjectMappings);
         }
+
         this.rethrowException = rethrowException;
         this.duringCall = duringCall;
         assert !this.rethrowException || this.stackSize == 1 : "must have exception on top of the stack";
-        assert this.locksSize() == this.monitorIds.size();
+        assert this.locksSize() == this.monitorIdCount();
         METRIC_FRAMESTATE_COUNT.increment();
     }
 
+    public FrameState(FrameState outerFrameState, ResolvedJavaMethod method, int bci, List<ValueNode> values, int localsSize, int stackSize, boolean rethrowException, boolean duringCall,
+                    MonitorIdNode[] monitorIds, List<EscapeObjectState> virtualObjectMappings) {
+        this(outerFrameState, method, bci, localsSize, stackSize, values.size() - localsSize - stackSize, rethrowException, duringCall, monitorIds, virtualObjectMappings);
+        for (int i = 0; i < values.size(); ++i) {
+            this.values.initialize(i, values.get(i));
+        }
+    }
+
     public FrameState(int bci) {
-        this(null, null, bci, Collections.<ValueNode> emptyList(), 0, 0, false, false, null, Collections.<EscapeObjectState> emptyList());
+        this(null, null, bci, 0, 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,
+    public FrameState(FrameState outerFrameState, ResolvedJavaMethod method, int bci, ValueNode[] locals, ValueNode[] stack, int stackSize, ValueNode[] locks, MonitorIdNode[] monitorIds,
                     boolean rethrowException, boolean duringCall) {
-        this(outerFrameState, method, bci, createValues(locals, stack, locks), locals.length, stack.size(), rethrowException, duringCall, monitorIds, Collections.<EscapeObjectState> emptyList());
+        this(outerFrameState, method, bci, locals.length, stackSize, locks.length, rethrowException, duringCall, monitorIds, Collections.<EscapeObjectState> emptyList());
+        createValues(locals, stack, locks);
     }
 
-    private static List<ValueNode> createValues(ValueNode[] locals, List<ValueNode> stack, ValueNode[] locks) {
-        List<ValueNode> newValues = new ArrayList<>(locals.length + stack.size() + locks.length);
-        for (ValueNode value : locals) {
-            newValues.add(value);
-            assert value == null || value.isAlive();
+    private void createValues(ValueNode[] locals, ValueNode[] stack, ValueNode[] locks) {
+        int index = 0;
+        for (int i = 0; i < locals.length; ++i) {
+            this.values.initialize(index++, locals[i]);
         }
-        for (ValueNode value : stack) {
-            newValues.add(value);
-            assert value == null || value.isAlive();
+        for (int i = 0; i < stackSize; ++i) {
+            this.values.initialize(index++, stack[i]);
         }
-        for (ValueNode value : locks) {
-            newValues.add(value);
-            assert value == null || value.isAlive();
+        for (int i = 0; i < locks.length; ++i) {
+            this.values.initialize(index++, locks[i]);
         }
-        return newValues;
     }
 
     public NodeInputList<ValueNode> values() {
@@ -213,8 +221,8 @@
      * stack and the values in pushedValues pushed on the stack. The pushedValues will be formatted
      * correctly in slot encoding: a long or double will be followed by a null slot.
      */
-    public FrameState duplicateModifiedDuringCall(int newBci, Kind popKind, ValueNode... pushedValues) {
-        return duplicateModified(newBci, rethrowException, true, popKind, pushedValues);
+    public FrameState duplicateModifiedDuringCall(int newBci, Kind popKind) {
+        return duplicateModified(newBci, rethrowException, true, popKind);
     }
 
     public FrameState duplicateModified(int newBci, boolean newRethrowException, Kind popKind, ValueNode... pushedValues) {
@@ -363,6 +371,14 @@
         return monitorIds.get(i);
     }
 
+    public int monitorIdCount() {
+        if (monitorIds == null) {
+            return 0;
+        } else {
+            return monitorIds.size();
+        }
+    }
+
     public NodeIterable<FrameState> innerFrameStates() {
         return usages().filter(FrameState.class);
     }
@@ -432,7 +448,7 @@
 
     @Override
     public boolean verify() {
-        assertTrue(locksSize() == monitorIds.size(), "mismatch in number of locks");
+        assertTrue(locksSize() == monitorIdCount(), "mismatch in number of locks");
         for (ValueNode value : values) {
             assertTrue(value == null || !value.isDeleted(), "frame state must not contain deleted nodes");
             assertTrue(value == null || value instanceof VirtualObjectNode || (value.getKind() != Kind.Void), "unexpected value: %s", value);