@@ -865,7 +865,7 @@ public Object execute(VirtualFrame virtualFrame) {
865
865
copyArgsAndCells (virtualFrame , virtualFrame .getArguments ());
866
866
}
867
867
868
- return executeFromBci (virtualFrame , virtualFrame , this , 0 , getInitialStackTop (), Integer . MAX_VALUE );
868
+ return executeFromBci (virtualFrame , virtualFrame , this , 0 , getInitialStackTop ());
869
869
} finally {
870
870
calleeContext .exit (virtualFrame , this );
871
871
}
@@ -886,14 +886,14 @@ public Frame restoreParentFrameFromArguments(Object[] arguments) {
886
886
@ Override
887
887
public Object executeOSR (VirtualFrame osrFrame , int target , Object interpreterStateObject ) {
888
888
OSRInterpreterState interpreterState = (OSRInterpreterState ) interpreterStateObject ;
889
- return executeFromBci (osrFrame , osrFrame , this , target , interpreterState .stackTop , interpreterState . loopEndBci );
889
+ return executeFromBci (osrFrame , osrFrame , this , target , interpreterState .stackTop );
890
890
}
891
891
892
- private static final class OSRContinuation {
892
+ private static final class InterpreterContinuation {
893
893
public final int bci ;
894
894
public final int stackTop ;
895
895
896
- private OSRContinuation (int bci , int stackTop ) {
896
+ private InterpreterContinuation (int bci , int stackTop ) {
897
897
this .bci = bci ;
898
898
this .stackTop = stackTop ;
899
899
}
@@ -913,42 +913,41 @@ private static final class MutableLoopData {
913
913
PException localException ;
914
914
}
915
915
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 ) {
917
917
/*
918
918
* A lot of python code is executed just a single time, such as top level module code. We
919
919
* want to save some time and memory by trying to first use uncached nodes. We use two
920
920
* separate entry points so that they get each get compiled with monomorphic calls to either
921
921
* cached or uncached nodes.
922
922
*/
923
923
if (usingCachedNodes ) {
924
- return executeCached (virtualFrame , localFrame , osrNode , initialBci , initialStackTop , loopEndBci );
924
+ return executeCached (virtualFrame , localFrame , osrNode , initialBci , initialStackTop );
925
925
} else {
926
926
CompilerDirectives .transferToInterpreterAndInvalidate ();
927
927
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 );
932
932
}
933
933
return result ;
934
934
}
935
935
}
936
936
937
937
@ 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 );
940
940
}
941
941
942
942
@ 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 );
945
945
}
946
946
947
947
@ ExplodeLoop (kind = ExplodeLoop .LoopExplosionKind .MERGE_EXPLODE )
948
948
@ SuppressWarnings ("fallthrough" )
949
949
@ 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 ) {
952
951
Object [] arguments = virtualFrame .getArguments ();
953
952
Object globals = PArguments .getGlobals (arguments );
954
953
Object locals = PArguments .getSpecialArgument (arguments );
@@ -985,22 +984,6 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
985
984
CompilerAsserts .partialEvaluationConstant (bci );
986
985
CompilerAsserts .partialEvaluationConstant (stackTop );
987
986
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
-
1004
987
try {
1005
988
switch (bc ) {
1006
989
case OpCodesConstants .LOAD_NONE :
@@ -1568,7 +1551,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1568
1551
}
1569
1552
if (CompilerDirectives .inInterpreter ()) {
1570
1553
if (!useCachedNodes ) {
1571
- return new OSRContinuation (bci , stackTop );
1554
+ return new InterpreterContinuation (bci , stackTop );
1572
1555
}
1573
1556
if (BytecodeOSRNode .pollOSRBackEdge (osrNode )) {
1574
1557
/*
@@ -1581,23 +1564,12 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1581
1564
* variables) or it will get mixed up. To retain such state, put it
1582
1565
* into the frame instead.
1583
1566
*/
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 );
1585
1568
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 );
1600
1571
}
1572
+ return osrResult ;
1601
1573
}
1602
1574
}
1603
1575
}
0 commit comments