Skip to content

Commit c905785

Browse files
Improve how we retrieve the context in BytecodeNode
1 parent 1ec3a06 commit c905785

File tree

1 file changed

+29
-17
lines changed
  • espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes

1 file changed

+29
-17
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/BytecodeNode.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,12 @@ public SourceSection getSourceSectionAtBCI(int bci) {
493493
return getMethodVersion().getSourceSectionAtBCI(bci);
494494
}
495495

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+
496502
@ExplodeLoop
497503
private void initArguments(VirtualFrame frame) {
498504
Object[] arguments = frame.getArguments();
@@ -1540,14 +1546,15 @@ private Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop
15401546
} catch (AbstractTruffleException | StackOverflowError | OutOfMemoryError e) {
15411547
CompilerAsserts.partialEvaluationConstant(curBCI);
15421548
// 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) {
15441551
// Always deopt on SOE.
15451552
CompilerDirectives.transferToInterpreter();
15461553
EspressoException wrappedStackOverflowError = null;
1547-
if (e == getContext().getStackOverflow()) {
1554+
if (e == context.getStackOverflow()) {
15481555
wrappedStackOverflowError = (EspressoException) e;
15491556
} else {
1550-
wrappedStackOverflowError = getContext().getStackOverflow();
1557+
wrappedStackOverflowError = context.getStackOverflow();
15511558
}
15521559
/*
15531560
* Stack Overflow management. All calls to stack manipulation are manually
@@ -1591,15 +1598,15 @@ private Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop
15911598
// this branch is not compiled, it can be a loop exit
15921599
throw e;
15931600
}
1594-
assert getContext().getEspressoEnv().Polyglot;
1601+
assert context.getEspressoEnv().Polyglot;
15951602
Meta meta = getMethod().getMeta();
15961603
meta.polyglot.ForeignException.safeInitialize(); // should fold
15971604
wrappedException = EspressoException.wrap(
1598-
getAllocator().createForeignException(getContext(), e, InteropLibrary.getUncached(e)), meta);
1605+
getAllocator().createForeignException(context, e, InteropLibrary.getUncached(e)), meta);
15991606
} else {
16001607
assert e instanceof OutOfMemoryError;
16011608
CompilerDirectives.transferToInterpreter();
1602-
wrappedException = getContext().getOutOfMemory();
1609+
wrappedException = context.getOutOfMemory();
16031610
}
16041611

16051612
ExceptionHandler[] handlers = getMethodVersion().getExceptionHandlers();
@@ -1737,8 +1744,9 @@ private StaticObject newReferenceArray(Klass componentType, int length) {
17371744
}
17381745

17391746
private BaseQuickNode getBaseQuickNode(int curBCI, int top, int statementIndex, BaseQuickNode quickNode) {
1747+
EspressoContext context = getMethodContext();
17401748
// block while class redefinition is ongoing
1741-
getMethod().getContext().getClassRedefinition().check();
1749+
context.getClassRedefinition().check();
17421750
// re-check if node was already replaced by another thread
17431751
if (quickNode != nodes[readCPI(curBCI)]) {
17441752
// another thread beat us
@@ -1754,7 +1762,7 @@ private BaseQuickNode getBaseQuickNode(int curBCI, int top, int statementIndex,
17541762
// another thread beat us
17551763
return nodes[cpi];
17561764
} 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));
17581766
nodes[cpi] = newNode;
17591767
return newNode;
17601768
}
@@ -2258,7 +2266,7 @@ private InvokeQuickNode quickenInvoke(int top, int curBCI, int opcode, int state
22582266
CompilerDirectives.transferToInterpreterAndInvalidate();
22592267
assert Bytecodes.isInvoke(opcode);
22602268
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));
22622270
return quick;
22632271
}
22642272

@@ -2488,11 +2496,12 @@ public Klass resolveType(int opcode, char cpi) {
24882496

24892497
private Field resolveField(int opcode, char cpi) {
24902498
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);
24922501
if (field.needsReResolution()) {
24932502
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);
24962505
}
24972506
return field;
24982507
}
@@ -2509,12 +2518,13 @@ private ResolvedInvoke getResolvedInvoke(int opcode, char cpi) {
25092518
assert !lockIsHeld();
25102519
// During resolution of the symbolic reference to the method, any of the exceptions
25112520
// 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);
25132523
Method resolutionSeed = (Method) resolvedConstant.value();
25142524

2515-
Klass symbolicRef = getConstantPool().getResolvedHolderKlass(cpi, getDeclaringKlass());
2525+
Klass symbolicRef = getConstantPool().getResolvedHolderKlass(cpi, declaringKlass);
25162526
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);
25182528
MethodHandleInvoker invoker = null;
25192529
// There might be an invoker if it's an InvokeGeneric
25202530
if (resolvedConstant instanceof ResolvedWithInvokerClassMethodRefConstant withInvoker) {
@@ -2698,7 +2708,8 @@ private int putField(VirtualFrame frame, int top, Field field, int curBCI, int o
26982708
CompilerAsserts.partialEvaluationConstant(field);
26992709
CompilerAsserts.partialEvaluationConstant(mode);
27002710

2701-
EspressoLinkResolver.checkFieldAccessOrThrow(getContext(), field, mode, getDeclaringKlass(), getMethod());
2711+
Method method = getMethod();
2712+
EspressoLinkResolver.checkFieldAccessOrThrow(method.getContext(), field, mode, getDeclaringKlass(), method);
27022713

27032714
byte typeHeader = field.getType().byteAt(0);
27042715
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
28112822

28122823
CompilerAsserts.partialEvaluationConstant(field);
28132824

2814-
EspressoLinkResolver.checkFieldAccessOrThrow(getContext(), field, mode, getDeclaringKlass(), getMethod());
2825+
Method method = getMethod();
2826+
EspressoLinkResolver.checkFieldAccessOrThrow(method.getContext(), field, mode, getDeclaringKlass(), method);
28152827

28162828
int slot = top - 1;
28172829
StaticObject receiver;

0 commit comments

Comments
 (0)