@@ -493,6 +493,12 @@ public SourceSection getSourceSectionAtBCI(int bci) {
493
493
return getMethodVersion ().getSourceSectionAtBCI (bci );
494
494
}
495
495
496
+ private EspressoContext getMethodContext () {
497
+ // This should be used instead of getContext() because it leads to a constant while the
498
+ // generic EspressoNode.getContext() doesn't necessarily lead to a constant.
499
+ return getMethodVersion ().getMethod ().getContext ();
500
+ }
501
+
496
502
@ ExplodeLoop
497
503
private void initArguments (VirtualFrame frame ) {
498
504
Object [] arguments = frame .getArguments ();
@@ -1540,14 +1546,15 @@ private Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop
1540
1546
} catch (AbstractTruffleException | StackOverflowError | OutOfMemoryError e ) {
1541
1547
CompilerAsserts .partialEvaluationConstant (curBCI );
1542
1548
// Handle both guest and host StackOverflowError.
1543
- if (e == getContext ().getStackOverflow () || e instanceof StackOverflowError ) {
1549
+ EspressoContext context = getMethodContext ();
1550
+ if (e == context .getStackOverflow () || e instanceof StackOverflowError ) {
1544
1551
// Always deopt on SOE.
1545
1552
CompilerDirectives .transferToInterpreter ();
1546
1553
EspressoException wrappedStackOverflowError = null ;
1547
- if (e == getContext () .getStackOverflow ()) {
1554
+ if (e == context .getStackOverflow ()) {
1548
1555
wrappedStackOverflowError = (EspressoException ) e ;
1549
1556
} else {
1550
- wrappedStackOverflowError = getContext () .getStackOverflow ();
1557
+ wrappedStackOverflowError = context .getStackOverflow ();
1551
1558
}
1552
1559
/*
1553
1560
* Stack Overflow management. All calls to stack manipulation are manually
@@ -1591,15 +1598,15 @@ private Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop
1591
1598
// this branch is not compiled, it can be a loop exit
1592
1599
throw e ;
1593
1600
}
1594
- assert getContext () .getEspressoEnv ().Polyglot ;
1601
+ assert context .getEspressoEnv ().Polyglot ;
1595
1602
Meta meta = getMethod ().getMeta ();
1596
1603
meta .polyglot .ForeignException .safeInitialize (); // should fold
1597
1604
wrappedException = EspressoException .wrap (
1598
- getAllocator ().createForeignException (getContext () , e , InteropLibrary .getUncached (e )), meta );
1605
+ getAllocator ().createForeignException (context , e , InteropLibrary .getUncached (e )), meta );
1599
1606
} else {
1600
1607
assert e instanceof OutOfMemoryError ;
1601
1608
CompilerDirectives .transferToInterpreter ();
1602
- wrappedException = getContext () .getOutOfMemory ();
1609
+ wrappedException = context .getOutOfMemory ();
1603
1610
}
1604
1611
1605
1612
ExceptionHandler [] handlers = getMethodVersion ().getExceptionHandlers ();
@@ -1737,8 +1744,9 @@ private StaticObject newReferenceArray(Klass componentType, int length) {
1737
1744
}
1738
1745
1739
1746
private BaseQuickNode getBaseQuickNode (int curBCI , int top , int statementIndex , BaseQuickNode quickNode ) {
1747
+ EspressoContext context = getMethodContext ();
1740
1748
// block while class redefinition is ongoing
1741
- getMethod (). getContext () .getClassRedefinition ().check ();
1749
+ context .getClassRedefinition ().check ();
1742
1750
// re-check if node was already replaced by another thread
1743
1751
if (quickNode != nodes [readCPI (curBCI )]) {
1744
1752
// another thread beat us
@@ -1754,7 +1762,7 @@ private BaseQuickNode getBaseQuickNode(int curBCI, int top, int statementIndex,
1754
1762
// another thread beat us
1755
1763
return nodes [cpi ];
1756
1764
} else {
1757
- BaseQuickNode newNode = insert (dispatchQuickened (top , curBCI , originalOpcode , statementIndex , resolvedInvoke , getMethod (). getContext () .getEspressoEnv ().bytecodeLevelInlining ));
1765
+ BaseQuickNode newNode = insert (dispatchQuickened (top , curBCI , originalOpcode , statementIndex , resolvedInvoke , context .getEspressoEnv ().bytecodeLevelInlining ));
1758
1766
nodes [cpi ] = newNode ;
1759
1767
return newNode ;
1760
1768
}
@@ -2258,7 +2266,7 @@ private InvokeQuickNode quickenInvoke(int top, int curBCI, int opcode, int state
2258
2266
CompilerDirectives .transferToInterpreterAndInvalidate ();
2259
2267
assert Bytecodes .isInvoke (opcode );
2260
2268
InvokeQuickNode quick = (InvokeQuickNode ) tryPatchQuick (curBCI , cpi -> getResolvedInvoke (opcode , cpi ),
2261
- resolvedInvoke -> dispatchQuickened (top , curBCI , opcode , statementIndex , resolvedInvoke , getMethod (). getContext ().getEspressoEnv ().bytecodeLevelInlining ));
2269
+ resolvedInvoke -> dispatchQuickened (top , curBCI , opcode , statementIndex , resolvedInvoke , getMethodContext ().getEspressoEnv ().bytecodeLevelInlining ));
2262
2270
return quick ;
2263
2271
}
2264
2272
@@ -2488,11 +2496,12 @@ public Klass resolveType(int opcode, char cpi) {
2488
2496
2489
2497
private Field resolveField (int opcode , char cpi ) {
2490
2498
assert opcode == GETFIELD || opcode == GETSTATIC || opcode == PUTFIELD || opcode == PUTSTATIC ;
2491
- Field field = getConstantPool ().resolvedFieldAt (getMethod ().getDeclaringKlass (), cpi );
2499
+ ObjectKlass declaringKlass = getMethod ().getDeclaringKlass ();
2500
+ Field field = getConstantPool ().resolvedFieldAt (declaringKlass , cpi );
2492
2501
if (field .needsReResolution ()) {
2493
2502
CompilerDirectives .transferToInterpreterAndInvalidate ();
2494
- getMethod () .getContext ().getClassRedefinition ().check ();
2495
- field = getConstantPool ().resolveFieldAndUpdate (getMethod (). getDeclaringKlass () , cpi , field );
2503
+ declaringKlass .getContext ().getClassRedefinition ().check ();
2504
+ field = getConstantPool ().resolveFieldAndUpdate (declaringKlass , cpi , field );
2496
2505
}
2497
2506
return field ;
2498
2507
}
@@ -2509,12 +2518,13 @@ private ResolvedInvoke getResolvedInvoke(int opcode, char cpi) {
2509
2518
assert !lockIsHeld ();
2510
2519
// During resolution of the symbolic reference to the method, any of the exceptions
2511
2520
// pertaining to method resolution (§5.4.3.3) can be thrown.
2512
- ResolvedConstant resolvedConstant = getConstantPool ().resolvedAt (getDeclaringKlass (), cpi );
2521
+ ObjectKlass declaringKlass = getDeclaringKlass ();
2522
+ ResolvedConstant resolvedConstant = getConstantPool ().resolvedAt (declaringKlass , cpi );
2513
2523
Method resolutionSeed = (Method ) resolvedConstant .value ();
2514
2524
2515
- Klass symbolicRef = getConstantPool ().getResolvedHolderKlass (cpi , getDeclaringKlass () );
2525
+ Klass symbolicRef = getConstantPool ().getResolvedHolderKlass (cpi , declaringKlass );
2516
2526
CallSiteType callSiteType = SiteTypes .callSiteFromOpCode (opcode );
2517
- ResolvedCall <Klass , Method , Field > resolvedCall = EspressoLinkResolver .resolveCallSiteOrThrow (getContext (), getDeclaringKlass () , resolutionSeed , callSiteType , symbolicRef );
2527
+ ResolvedCall <Klass , Method , Field > resolvedCall = EspressoLinkResolver .resolveCallSiteOrThrow (declaringKlass . getContext (), declaringKlass , resolutionSeed , callSiteType , symbolicRef );
2518
2528
MethodHandleInvoker invoker = null ;
2519
2529
// There might be an invoker if it's an InvokeGeneric
2520
2530
if (resolvedConstant instanceof ResolvedWithInvokerClassMethodRefConstant withInvoker ) {
@@ -2698,7 +2708,8 @@ private int putField(VirtualFrame frame, int top, Field field, int curBCI, int o
2698
2708
CompilerAsserts .partialEvaluationConstant (field );
2699
2709
CompilerAsserts .partialEvaluationConstant (mode );
2700
2710
2701
- EspressoLinkResolver .checkFieldAccessOrThrow (getContext (), field , mode , getDeclaringKlass (), getMethod ());
2711
+ Method method = getMethod ();
2712
+ EspressoLinkResolver .checkFieldAccessOrThrow (method .getContext (), field , mode , getDeclaringKlass (), method );
2702
2713
2703
2714
byte typeHeader = field .getType ().byteAt (0 );
2704
2715
int slotCount = (typeHeader == 'J' || typeHeader == 'D' ) ? 2 : 1 ;
@@ -2811,7 +2822,8 @@ private int getField(VirtualFrame frame, int top, Field field, int curBCI, int o
2811
2822
2812
2823
CompilerAsserts .partialEvaluationConstant (field );
2813
2824
2814
- EspressoLinkResolver .checkFieldAccessOrThrow (getContext (), field , mode , getDeclaringKlass (), getMethod ());
2825
+ Method method = getMethod ();
2826
+ EspressoLinkResolver .checkFieldAccessOrThrow (method .getContext (), field , mode , getDeclaringKlass (), method );
2815
2827
2816
2828
int slot = top - 1 ;
2817
2829
StaticObject receiver ;
0 commit comments