|
94 | 94 | import com.oracle.truffle.api.dsl.TypeSystemReference; |
95 | 95 | import com.oracle.truffle.api.frame.VirtualFrame; |
96 | 96 | import com.oracle.truffle.api.nodes.LanguageInfo; |
| 97 | +import com.oracle.truffle.api.profiles.ConditionProfile; |
97 | 98 | import com.oracle.truffle.llvm.api.Toolchain; |
98 | 99 |
|
99 | 100 | @CoreFunctions(defineModule = "sys") |
@@ -350,42 +351,54 @@ public abstract static class GetFrameNode extends PythonBuiltinNode { |
350 | 351 | @Specialization |
351 | 352 | PFrame first(VirtualFrame frame, @SuppressWarnings("unused") PNone arg, |
352 | 353 | @Shared("caller") @Cached ReadCallerFrameNode readCallerNode) { |
353 | | - return escapeFrame(frame, 0, readCallerNode); |
| 354 | + PFrame requested = escapeFrame(frame, 0, readCallerNode); |
| 355 | + // there must always be *the current frame* |
| 356 | + assert requested != null : "frame must not be null"; |
| 357 | + return requested; |
354 | 358 | } |
355 | 359 |
|
356 | 360 | @Specialization |
357 | 361 | PFrame counted(VirtualFrame frame, int num, |
358 | | - @Shared("caller") @Cached ReadCallerFrameNode readCallerNode) { |
359 | | - return escapeFrame(frame, num, readCallerNode); |
| 362 | + @Shared("caller") @Cached ReadCallerFrameNode readCallerNode, |
| 363 | + @Shared("callStackDepthProfile") @Cached("createBinaryProfile()") ConditionProfile callStackDepthProfile) { |
| 364 | + PFrame requested = escapeFrame(frame, num, readCallerNode); |
| 365 | + if (callStackDepthProfile.profile(requested == null)) { |
| 366 | + throw raiseCallStackDepth(); |
| 367 | + } |
| 368 | + return requested; |
360 | 369 | } |
361 | 370 |
|
362 | 371 | @Specialization(rewriteOn = ArithmeticException.class) |
363 | 372 | PFrame countedLong(VirtualFrame frame, long num, |
364 | | - @Shared("caller") @Cached ReadCallerFrameNode readCallerNode) { |
365 | | - return counted(frame, PInt.intValueExact(num), readCallerNode); |
| 373 | + @Shared("caller") @Cached ReadCallerFrameNode readCallerNode, |
| 374 | + @Shared("callStackDepthProfile") @Cached("createBinaryProfile()") ConditionProfile callStackDepthProfile) { |
| 375 | + return counted(frame, PInt.intValueExact(num), readCallerNode, callStackDepthProfile); |
366 | 376 | } |
367 | 377 |
|
368 | 378 | @Specialization |
369 | 379 | PFrame countedLongOvf(VirtualFrame frame, long num, |
370 | | - @Shared("caller") @Cached ReadCallerFrameNode readCallerNode) { |
| 380 | + @Shared("caller") @Cached ReadCallerFrameNode readCallerNode, |
| 381 | + @Shared("callStackDepthProfile") @Cached("createBinaryProfile()") ConditionProfile callStackDepthProfile) { |
371 | 382 | try { |
372 | | - return counted(frame, PInt.intValueExact(num), readCallerNode); |
| 383 | + return counted(frame, PInt.intValueExact(num), readCallerNode, callStackDepthProfile); |
373 | 384 | } catch (ArithmeticException e) { |
374 | 385 | throw raiseCallStackDepth(); |
375 | 386 | } |
376 | 387 | } |
377 | 388 |
|
378 | 389 | @Specialization(rewriteOn = ArithmeticException.class) |
379 | 390 | PFrame countedPInt(VirtualFrame frame, PInt num, |
380 | | - @Shared("caller") @Cached ReadCallerFrameNode readCallerNode) { |
381 | | - return counted(frame, num.intValueExact(), readCallerNode); |
| 391 | + @Shared("caller") @Cached ReadCallerFrameNode readCallerNode, |
| 392 | + @Shared("callStackDepthProfile") @Cached("createBinaryProfile()") ConditionProfile callStackDepthProfile) { |
| 393 | + return counted(frame, num.intValueExact(), readCallerNode, callStackDepthProfile); |
382 | 394 | } |
383 | 395 |
|
384 | 396 | @Specialization |
385 | 397 | PFrame countedPIntOvf(VirtualFrame frame, PInt num, |
386 | | - @Shared("caller") @Cached ReadCallerFrameNode readCallerNode) { |
| 398 | + @Shared("caller") @Cached ReadCallerFrameNode readCallerNode, |
| 399 | + @Shared("callStackDepthProfile") @Cached("createBinaryProfile()") ConditionProfile callStackDepthProfile) { |
387 | 400 | try { |
388 | | - return counted(frame, num.intValueExact(), readCallerNode); |
| 401 | + return counted(frame, num.intValueExact(), readCallerNode, callStackDepthProfile); |
389 | 402 | } catch (ArithmeticException e) { |
390 | 403 | throw raiseCallStackDepth(); |
391 | 404 | } |
|
0 commit comments