@@ -456,7 +456,11 @@ private void setVar(VirtualFrame virtualFrame, Object localsObject, PyObjectSetI
456
456
}
457
457
458
458
private static FrameDescriptor makeFrameDescriptor (CodeUnit co ) {
459
- FrameDescriptor .Builder newBuilder = FrameDescriptor .newBuilder (4 );
459
+ int capacity = co .varnames .length + co .cellvars .length + co .freevars .length + co .stacksize + 1 ;
460
+ if (co .isGeneratorOrCoroutine ()) {
461
+ capacity += 2 ;
462
+ }
463
+ FrameDescriptor .Builder newBuilder = FrameDescriptor .newBuilder (capacity );
460
464
newBuilder .info (new FrameInfo ());
461
465
// locals
462
466
newBuilder .addSlots (co .varnames .length , FrameSlotKind .Illegal );
@@ -472,7 +476,7 @@ private static FrameDescriptor makeFrameDescriptor(CodeUnit co) {
472
476
// stackTop saved when pausing a generator
473
477
newBuilder .addSlot (FrameSlotKind .Int , null , null );
474
478
// return value of a generator
475
- newBuilder .addSlot (FrameSlotKind .Int , null , null );
479
+ newBuilder .addSlot (FrameSlotKind .Illegal , null , null );
476
480
}
477
481
return newBuilder .build ();
478
482
}
@@ -630,17 +634,17 @@ private <A, T extends Node> T doInsertChildNode(Node[] nodes, int nodeIndex, Nod
630
634
}
631
635
632
636
@ SuppressWarnings ("unchecked" )
633
- private <T extends Node > T insertChildNode (Node [] nodes , int nodeIndex , IntNodeFunction <T > nodeSupplier , int argument ) {
637
+ private <T extends Node > T insertChildNodeInt (Node [] nodes , int nodeIndex , IntNodeFunction <T > nodeSupplier , int argument ) {
634
638
Node node = nodes [nodeIndex ];
635
639
if (node != null ) {
636
640
return (T ) node ;
637
641
}
638
- return doInsertChildNode (nodes , nodeIndex , nodeSupplier , argument );
642
+ return doInsertChildNodeInt (nodes , nodeIndex , nodeSupplier , argument );
639
643
}
640
644
641
645
@ BytecodeInterpreterSwitchBoundary
642
646
@ SuppressWarnings ("unchecked" )
643
- private <T extends Node > T doInsertChildNode (Node [] nodes , int nodeIndex , IntNodeFunction <T > nodeSupplier , int argument ) {
647
+ private <T extends Node > T doInsertChildNodeInt (Node [] nodes , int nodeIndex , IntNodeFunction <T > nodeSupplier , int argument ) {
644
648
CompilerDirectives .transferToInterpreterAndInvalidate ();
645
649
T newNode = nodeSupplier .apply (argument );
646
650
nodes [nodeIndex ] = insert (newNode );
@@ -717,8 +721,8 @@ private static int encodeStackTop(int stackTop) {
717
721
718
722
@ ExplodeLoop
719
723
private void copyArgs (Object [] args , Frame localFrame ) {
720
- for ( int i = 0 ; i < PArguments . getUserArgumentLength ( args ); i ++) {
721
- // we can set these as object, since they're already boxed
724
+ int argCount = co . argCount + co . positionalOnlyArgCount + co . kwOnlyArgCount ;
725
+ for ( int i = 0 ; i < argCount ; i ++) {
722
726
localFrame .setObject (i , args [i + PArguments .USER_ARGUMENTS_OFFSET ]);
723
727
}
724
728
}
@@ -774,8 +778,6 @@ public Object executeOSR(VirtualFrame osrFrame, int target, Object interpreterSt
774
778
@ ExplodeLoop (kind = ExplodeLoop .LoopExplosionKind .MERGE_EXPLODE )
775
779
@ SuppressWarnings ("fallthrough" )
776
780
private Object executeInner (VirtualFrame virtualFrame , boolean resumingAfterOSR , int initialBci , int initialStackTop ) {
777
- boolean inInterpreter = CompilerDirectives .inInterpreter ();
778
-
779
781
Object globals = PArguments .getGlobals (virtualFrame );
780
782
Object locals = PArguments .getSpecialArgument (virtualFrame );
781
783
@@ -800,14 +802,18 @@ private Object executeInner(VirtualFrame virtualFrame, boolean resumingAfterOSR,
800
802
String [] localNames = names ;
801
803
Node [] localNodes = adoptedNodes ;
802
804
803
- verifyBeforeLoop (stackTop , bci , localBC );
805
+ CompilerAsserts .partialEvaluationConstant (localBC );
806
+ CompilerAsserts .partialEvaluationConstant (bci );
807
+ CompilerAsserts .partialEvaluationConstant (stackTop );
804
808
805
809
int oparg = 0 ;
806
810
while (true ) {
807
811
final byte bc = localBC [bci ];
808
812
final int beginBci = bci ;
809
813
810
- verifyInLoop (stackTop , bci , bc );
814
+ CompilerAsserts .partialEvaluationConstant (bc );
815
+ CompilerAsserts .partialEvaluationConstant (bci );
816
+ CompilerAsserts .partialEvaluationConstant (stackTop );
811
817
812
818
try {
813
819
switch (bc ) {
@@ -1000,15 +1006,15 @@ private Object executeInner(VirtualFrame virtualFrame, boolean resumingAfterOSR,
1000
1006
break ;
1001
1007
case OpCodesConstants .UNARY_OP : {
1002
1008
int op = Byte .toUnsignedInt (localBC [++bci ]);
1003
- UnaryOpNode opNode = insertChildNode (localNodes , bci , UNARY_OP_FACTORY , op );
1009
+ UnaryOpNode opNode = insertChildNodeInt (localNodes , bci , UNARY_OP_FACTORY , op );
1004
1010
Object value = localFrame .getObject (stackTop );
1005
1011
Object result = opNode .execute (virtualFrame , value );
1006
1012
localFrame .setObject (stackTop , result );
1007
1013
break ;
1008
1014
}
1009
1015
case OpCodesConstants .BINARY_OP : {
1010
1016
int op = Byte .toUnsignedInt (localBC [++bci ]);
1011
- BinaryOp opNode = (BinaryOp ) insertChildNode (localNodes , bci , BINARY_OP_FACTORY , op );
1017
+ BinaryOp opNode = (BinaryOp ) insertChildNodeInt (localNodes , bci , BINARY_OP_FACTORY , op );
1012
1018
Object right = localFrame .getObject (stackTop );
1013
1019
localFrame .setObject (stackTop --, null );
1014
1020
Object left = localFrame .getObject (stackTop );
@@ -1037,7 +1043,7 @@ private Object executeInner(VirtualFrame virtualFrame, boolean resumingAfterOSR,
1037
1043
break ;
1038
1044
}
1039
1045
case OpCodesConstants .RETURN_VALUE : {
1040
- if (inInterpreter ) {
1046
+ if (CompilerDirectives . hasNextTier () && loopCount > 0 ) {
1041
1047
LoopNode .reportLoopCount (this , loopCount );
1042
1048
}
1043
1049
Object value = localFrame .getObject (stackTop );
@@ -1189,24 +1195,26 @@ private Object executeInner(VirtualFrame virtualFrame, boolean resumingAfterOSR,
1189
1195
case OpCodesConstants .JUMP_BACKWARD : {
1190
1196
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1191
1197
bci -= oparg ;
1192
- if (inInterpreter ) {
1198
+ if (CompilerDirectives . hasNextTier () ) {
1193
1199
loopCount ++;
1194
- if (BytecodeOSRNode .pollOSRBackEdge (this )) {
1195
- /*
1196
- * Beware of race conditions when adding more things to the
1197
- * interpreterState argument. It gets stored already at this point,
1198
- * but the compilation runs in parallel. The compiled code may get
1199
- * entered from a different invocation of this root, using the
1200
- * interpreterState that was saved here. Don't put any data specific
1201
- * to particular invocation in there (like python-level arguments or
1202
- * variables) or it will get mixed up. To retain such state, put it
1203
- * into the frame instead.
1204
- */
1205
- Object osrResult = BytecodeOSRNode .tryOSR (this , bci , stackTop , null , virtualFrame );
1206
- if (osrResult != null ) {
1200
+ }
1201
+ if (CompilerDirectives .inInterpreter () && BytecodeOSRNode .pollOSRBackEdge (this )) {
1202
+ /*
1203
+ * Beware of race conditions when adding more things to the
1204
+ * interpreterState argument. It gets stored already at this point, but
1205
+ * the compilation runs in parallel. The compiled code may get entered
1206
+ * from a different invocation of this root, using the interpreterState
1207
+ * that was saved here. Don't put any data specific to particular
1208
+ * invocation in there (like python-level arguments or variables) or it
1209
+ * will get mixed up. To retain such state, put it into the frame
1210
+ * instead.
1211
+ */
1212
+ Object osrResult = BytecodeOSRNode .tryOSR (this , bci , stackTop , null , virtualFrame );
1213
+ if (osrResult != null ) {
1214
+ if (CompilerDirectives .hasNextTier () && loopCount > 0 ) {
1207
1215
LoopNode .reportLoopCount (this , loopCount );
1208
- return osrResult ;
1209
1216
}
1217
+ return osrResult ;
1210
1218
}
1211
1219
}
1212
1220
oparg = 0 ;
@@ -1325,7 +1333,7 @@ private Object executeInner(VirtualFrame virtualFrame, boolean resumingAfterOSR,
1325
1333
throw bytecodeEndExcHandler (virtualFrame , localFrame , stackTop );
1326
1334
}
1327
1335
case OpCodesConstants .YIELD_VALUE : {
1328
- if (inInterpreter ) {
1336
+ if (CompilerDirectives . hasNextTier () && loopCount > 0 ) {
1329
1337
LoopNode .reportLoopCount (this , loopCount );
1330
1338
}
1331
1339
Object value = localFrame .getObject (stackTop );
@@ -1889,18 +1897,6 @@ private void initFreeVarsLoop(Frame localFrame, Object[] originalArgs) {
1889
1897
}
1890
1898
}
1891
1899
1892
- private void verifyInLoop (int stackTop , int bci , final byte bc ) {
1893
- CompilerAsserts .partialEvaluationConstant (bc );
1894
- CompilerAsserts .partialEvaluationConstant (bci );
1895
- CompilerAsserts .partialEvaluationConstant (stackTop );
1896
- }
1897
-
1898
- private void verifyBeforeLoop (int stackTop , int bci , byte [] localBC ) {
1899
- CompilerAsserts .partialEvaluationConstant (localBC );
1900
- CompilerAsserts .partialEvaluationConstant (bci );
1901
- CompilerAsserts .partialEvaluationConstant (stackTop );
1902
- }
1903
-
1904
1900
@ ExplodeLoop
1905
1901
@ SuppressWarnings ("unchecked" )
1906
1902
private static <T > void moveFromStack (Frame localFrame , int start , int stop , T [] target ) {
@@ -2109,9 +2105,6 @@ private int bytecodeUnpackEx(VirtualFrame virtualFrame, Frame localFrame, int st
2109
2105
return unpackNode .execute (virtualFrame , stackTop - 1 , localFrame , collection , countBefore , countAfter );
2110
2106
}
2111
2107
2112
- /**
2113
- * @see #saveExceptionBlockstack
2114
- */
2115
2108
@ ExplodeLoop
2116
2109
private long findHandler (int bci ) {
2117
2110
CompilerAsserts .partialEvaluationConstant (bci );
0 commit comments