Skip to content

Commit 9887cb6

Browse files
committed
Remove OSR return-to-interpreter mechanism for now
1 parent aa15d7f commit 9887cb6

File tree

3 files changed

+23
-53
lines changed

3 files changed

+23
-53
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/OSRInterpreterState.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@
4242

4343
final class OSRInterpreterState {
4444
public final int stackTop;
45-
public final int loopEndBci;
4645

47-
public OSRInterpreterState(int stackTop, int loopEndBci) {
46+
public OSRInterpreterState(int stackTop) {
4847
this.stackTop = stackTop;
49-
this.loopEndBci = loopEndBci;
5048
}
5149
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorRootNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private void copyStackSlotsIntoVirtualFrame(MaterializedFrame generatorFrame, Vi
139139
public Object executeOSR(VirtualFrame osrFrame, int target, Object interpreterStateObject) {
140140
OSRInterpreterState interpreterState = (OSRInterpreterState) interpreterStateObject;
141141
MaterializedFrame generatorFrame = PArguments.getGeneratorFrame(osrFrame);
142-
return rootNode.executeFromBci(osrFrame, generatorFrame, this, target, interpreterState.stackTop, interpreterState.loopEndBci);
142+
return rootNode.executeFromBci(osrFrame, generatorFrame, this, target, interpreterState.stackTop);
143143
}
144144

145145
@Override
@@ -157,7 +157,7 @@ public Object execute(VirtualFrame frame) {
157157
*/
158158
copyStackSlotsIntoVirtualFrame(generatorFrame, frame);
159159
try {
160-
return rootNode.executeFromBci(frame, generatorFrame, this, resumeBci, resumeStackTop, Integer.MAX_VALUE);
160+
return rootNode.executeFromBci(frame, generatorFrame, this, resumeBci, resumeStackTop);
161161
} finally {
162162
calleeContext.exit(frame, this);
163163
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ public Object execute(VirtualFrame virtualFrame) {
865865
copyArgsAndCells(virtualFrame, virtualFrame.getArguments());
866866
}
867867

868-
return executeFromBci(virtualFrame, virtualFrame, this, 0, getInitialStackTop(), Integer.MAX_VALUE);
868+
return executeFromBci(virtualFrame, virtualFrame, this, 0, getInitialStackTop());
869869
} finally {
870870
calleeContext.exit(virtualFrame, this);
871871
}
@@ -886,14 +886,14 @@ public Frame restoreParentFrameFromArguments(Object[] arguments) {
886886
@Override
887887
public Object executeOSR(VirtualFrame osrFrame, int target, Object interpreterStateObject) {
888888
OSRInterpreterState interpreterState = (OSRInterpreterState) interpreterStateObject;
889-
return executeFromBci(osrFrame, osrFrame, this, target, interpreterState.stackTop, interpreterState.loopEndBci);
889+
return executeFromBci(osrFrame, osrFrame, this, target, interpreterState.stackTop);
890890
}
891891

892-
private static final class OSRContinuation {
892+
private static final class InterpreterContinuation {
893893
public final int bci;
894894
public final int stackTop;
895895

896-
private OSRContinuation(int bci, int stackTop) {
896+
private InterpreterContinuation(int bci, int stackTop) {
897897
this.bci = bci;
898898
this.stackTop = stackTop;
899899
}
@@ -913,42 +913,41 @@ private static final class MutableLoopData {
913913
PException localException;
914914
}
915915

916-
Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, int loopEndBci) {
916+
Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop) {
917917
/*
918918
* A lot of python code is executed just a single time, such as top level module code. We
919919
* want to save some time and memory by trying to first use uncached nodes. We use two
920920
* separate entry points so that they get each get compiled with monomorphic calls to either
921921
* cached or uncached nodes.
922922
*/
923923
if (usingCachedNodes) {
924-
return executeCached(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, loopEndBci);
924+
return executeCached(virtualFrame, localFrame, osrNode, initialBci, initialStackTop);
925925
} else {
926926
CompilerDirectives.transferToInterpreterAndInvalidate();
927927
usingCachedNodes = true;
928-
Object result = executeUncached(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, loopEndBci);
929-
if (result instanceof OSRContinuation) {
930-
OSRContinuation continuation = (OSRContinuation) result;
931-
return executeCached(virtualFrame, localFrame, osrNode, continuation.bci, continuation.stackTop, loopEndBci);
928+
Object result = executeUncached(virtualFrame, localFrame, osrNode, initialBci, initialStackTop);
929+
if (result instanceof InterpreterContinuation) {
930+
InterpreterContinuation continuation = (InterpreterContinuation) result;
931+
return executeCached(virtualFrame, localFrame, osrNode, continuation.bci, continuation.stackTop);
932932
}
933933
return result;
934934
}
935935
}
936936

937937
@BytecodeInterpreterSwitch
938-
private Object executeCached(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, int loopEndBci) {
939-
return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, loopEndBci, true);
938+
private Object executeCached(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop) {
939+
return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, true);
940940
}
941941

942942
@BytecodeInterpreterSwitch
943-
private Object executeUncached(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, int loopEndBci) {
944-
return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, loopEndBci, false);
943+
private Object executeUncached(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop) {
944+
return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, false);
945945
}
946946

947947
@ExplodeLoop(kind = ExplodeLoop.LoopExplosionKind.MERGE_EXPLODE)
948948
@SuppressWarnings("fallthrough")
949949
@BytecodeInterpreterSwitch
950-
private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, int loopEndBci, boolean useCachedNodes) {
951-
boolean wasCompiled = CompilerDirectives.inCompiledCode();
950+
private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, boolean useCachedNodes) {
952951
Object[] arguments = virtualFrame.getArguments();
953952
Object globals = PArguments.getGlobals(arguments);
954953
Object locals = PArguments.getSpecialArgument(arguments);
@@ -985,22 +984,6 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
985984
CompilerAsserts.partialEvaluationConstant(bci);
986985
CompilerAsserts.partialEvaluationConstant(stackTop);
987986

988-
if (wasCompiled && bci > loopEndBci) {
989-
/*
990-
* This means we're in OSR and we just jumped out of the OSR compiled loop. We want
991-
* to return to the caller to continue in interpreter again otherwise we would most
992-
* likely deopt on the next instruction. The caller handles the special return value
993-
* in JUMP_BACKWARD. In generators, we need to additionally copy the stack items
994-
* back to the generator frame.
995-
*/
996-
if (localFrame != virtualFrame) {
997-
copyStackSlotsToGeneratorFrame(virtualFrame, localFrame, stackTop);
998-
// Clear slots that were popped (if any)
999-
clearFrameSlots(localFrame, stackTop + 1, initialStackTop);
1000-
}
1001-
return new OSRContinuation(bci, stackTop);
1002-
}
1003-
1004987
try {
1005988
switch (bc) {
1006989
case OpCodesConstants.LOAD_NONE:
@@ -1568,7 +1551,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
15681551
}
15691552
if (CompilerDirectives.inInterpreter()) {
15701553
if (!useCachedNodes) {
1571-
return new OSRContinuation(bci, stackTop);
1554+
return new InterpreterContinuation(bci, stackTop);
15721555
}
15731556
if (BytecodeOSRNode.pollOSRBackEdge(osrNode)) {
15741557
/*
@@ -1581,23 +1564,12 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
15811564
* variables) or it will get mixed up. To retain such state, put it
15821565
* into the frame instead.
15831566
*/
1584-
Object osrResult = BytecodeOSRNode.tryOSR(osrNode, bci, new OSRInterpreterState(stackTop, beginBci), null, virtualFrame);
1567+
Object osrResult = BytecodeOSRNode.tryOSR(osrNode, bci, new OSRInterpreterState(stackTop), null, virtualFrame);
15851568
if (osrResult != null) {
1586-
if (osrResult instanceof OSRContinuation) {
1587-
// We should continue executing in interpreter after the
1588-
// loop
1589-
OSRContinuation continuation = (OSRContinuation) osrResult;
1590-
bci = continuation.bci;
1591-
stackTop = continuation.stackTop;
1592-
oparg = 0;
1593-
continue;
1594-
} else {
1595-
// We reached a return/yield
1596-
if (CompilerDirectives.hasNextTier() && mutableData.loopCount > 0) {
1597-
LoopNode.reportLoopCount(this, mutableData.loopCount);
1598-
}
1599-
return osrResult;
1569+
if (CompilerDirectives.hasNextTier() && mutableData.loopCount > 0) {
1570+
LoopNode.reportLoopCount(this, mutableData.loopCount);
16001571
}
1572+
return osrResult;
16011573
}
16021574
}
16031575
}

0 commit comments

Comments
 (0)