# HG changeset patch # User Lukas Stadler # Date 1305190831 -7200 # Node ID 6ca76b891d31070de583780f48db5fe8cad5e934 # Parent b101099de4c8c2b7c756edbb2af3ed7ece9a4908 duplicateModified helper method diff -r b101099de4c8 -r 6ca76b891d31 graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java --- a/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Thu May 12 10:26:55 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Thu May 12 11:00:31 2011 +0200 @@ -448,38 +448,19 @@ } protected FrameState stateBeforeInvoke(Invoke invoke) { - FrameState stateAfter = invoke.stateAfter(); - FrameStateBuilder builder = new FrameStateBuilder(compilation.method, invoke.graph()); - builder.initializeFrom(stateAfter); - if (invoke.kind != CiKind.Void) { - builder.pop(invoke.kind); + Value[] args = new Value[invoke.argumentCount()]; + for (int i = 0; i < invoke.argumentCount(); i++) { + args[i] = invoke.argument(i); } - int argumentCount = invoke.argumentCount(); // invoke.arguments() iterable? - for (int i = 0; i < argumentCount; i++) { - Value arg = invoke.argument(i); - if (arg != null) { - //builder.push(arg.kind, arg); - } - } - return builder.create(invoke.bci()); + return invoke.stateAfter().duplicateModified(invoke.bci(), invoke.kind/*, args*/); } protected FrameState stateBeforeInvokeWithArguments(Invoke invoke) { - - FrameState stateAfter = invoke.stateAfter(); - FrameStateBuilder builder = new FrameStateBuilder(compilation.method, invoke.graph()); - builder.initializeFrom(stateAfter); - if (invoke.kind != CiKind.Void) { - builder.pop(invoke.kind); + Value[] args = new Value[invoke.argumentCount()]; + for (int i = 0; i < invoke.argumentCount(); i++) { + args[i] = invoke.argument(i); } - int argumentCount = invoke.argumentCount(); // invoke.arguments() iterable? - for (int i = 0; i < argumentCount; i++) { - Value arg = invoke.argument(i); - if (arg != null) { - builder.push(arg.kind, arg); - } - } - return builder.create(invoke.bci()); + return invoke.stateAfter().duplicateModified(invoke.bci(), invoke.kind, args); } @Override @@ -995,11 +976,7 @@ } private FrameState stateBeforeRegisterFinalizer(RegisterFinalizer rf) { - Value object = rf.object(); - FrameStateBuilder builder = new FrameStateBuilder(compilation.method, rf.graph()); - builder.initializeFrom(rf.stateAfter()); - builder.push(object.kind, object); - return builder.create(rf.bci()); + return rf.stateAfter().duplicateModified(rf.bci(), CiKind.Void, rf.object()); } @Override diff -r b101099de4c8 -r 6ca76b891d31 graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java --- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Thu May 12 10:26:55 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Thu May 12 11:00:31 2011 +0200 @@ -86,7 +86,7 @@ inputs().set(i, locals[i]); } for (int i = 0; i < stackSize; i++) { - inputs().set(i + localsSize, stack[i]); + inputs().set(localsSize + i, stack[i]); } for (int i = 0; i < locks.size(); i++) { inputs().set(locals.length + stackSize + i, locks.get(i)); @@ -116,6 +116,37 @@ return other; } + /** + * Creates a copy of this frame state with one stack element of type popKind popped from the stack and the + * values in pushedValues pushed on the stack. + */ + public FrameState duplicateModified(int bci, CiKind popKind, Value... pushedValues) { + int popSlots = popKind.sizeInSlots(); + int pushSlots = 0; + for (Value v : pushedValues) { + pushSlots += v.kind.sizeInSlots(); + } + FrameState other = new FrameState(bci, localsSize, stackSize - popSlots + pushSlots, locksSize(), graph()); + for (int i = 0; i < localsSize; i++) { + other.inputs().set(i, localAt(i)); + } + for (int i = 0; i < stackSize - popSlots; i++) { + other.inputs().set(localsSize + i, stackAt(i)); + } + int slot = stackSize - popSlots; + for (Value v : pushedValues) { + assert v.kind.sizeInSlots() > 0; + if (v.kind.sizeInSlots() == 2) { + other.inputs().set(localsSize + slot++, null); + } + other.inputs().set(localsSize + slot++, v); + } + for (int i = 0; i < locksSize; i++) { + other.inputs().set(localsSize + i, lockAt(i)); + } + return other; + } + public boolean isCompatibleWith(FrameStateAccess other) { if (stackSize() != other.stackSize() || localsSize() != other.localsSize() || locksSize() != other.locksSize()) { return false; diff -r b101099de4c8 -r 6ca76b891d31 graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java Thu May 12 10:26:55 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java Thu May 12 11:00:31 2011 +0200 @@ -187,6 +187,7 @@ * @return the instruction on the top of the stack */ public Value pop(CiKind kind) { + assert kind != CiKind.Void; if (kind.sizeInSlots() == 2) { xpop(); }