# HG changeset patch # User Thomas Wuerthinger # Date 1421959986 -3600 # Node ID 8da21b77998256ecb563197fb5ab2fc9717555da # Parent b4633ae1b31b0f2e21e57a10d1401dec14d7a059 Initialize FrameState with less copying. diff -r b4633ae1b31b -r 8da21b779982 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java --- 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); } diff -r b4633ae1b31b -r 8da21b779982 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java --- 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 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); diff -r b4633ae1b31b -r 8da21b779982 graal/com.oracle.graal.java/src/com/oracle/graal/java/HIRFrameStateBuilder.java --- 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 diff -r b4633ae1b31b -r 8da21b779982 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FrameState.java --- 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 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 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 values, int localsSize, int stackSize, boolean rethrowException, boolean duringCall, + MonitorIdNode[] monitorIds, List 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. emptyList(), 0, 0, false, false, null, Collections. emptyList()); + this(null, null, bci, 0, 0, 0, false, false, null, Collections. 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 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. emptyList()); + this(outerFrameState, method, bci, locals.length, stackSize, locks.length, rethrowException, duringCall, monitorIds, Collections. emptyList()); + createValues(locals, stack, locks); } - private static List createValues(ValueNode[] locals, List stack, ValueNode[] locks) { - List 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 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 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);