Skip to content

Commit 2ddfc59

Browse files
[GR-59440] Fix getScopeSlowPath
We cannot assume that we are entered in the context here
1 parent 33bbd8b commit 2ddfc59

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
package com.oracle.truffle.espresso.nodes;
2424

25+
import java.util.ArrayList;
26+
import java.util.HashMap;
27+
2528
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2629
import com.oracle.truffle.api.frame.Frame;
2730
import com.oracle.truffle.api.frame.MaterializedFrame;
@@ -35,18 +38,15 @@
3538
import com.oracle.truffle.api.library.ExportMessage;
3639
import com.oracle.truffle.api.source.SourceSection;
3740
import com.oracle.truffle.espresso.EspressoScope;
41+
import com.oracle.truffle.espresso.classfile.attributes.Local;
3842
import com.oracle.truffle.espresso.classfile.descriptors.ByteSequence;
3943
import com.oracle.truffle.espresso.classfile.descriptors.Signatures;
4044
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
4145
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
4246
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Type;
4347
import com.oracle.truffle.espresso.impl.Method;
44-
import com.oracle.truffle.espresso.classfile.attributes.Local;
4548
import com.oracle.truffle.espresso.vm.continuation.UnwindContinuationException;
4649

47-
import java.util.ArrayList;
48-
import java.util.HashMap;
49-
5050
@GenerateWrapper(yieldExceptions = UnwindContinuationException.class, resumeMethodPrefix = "resumeContinuation")
5151
@ExportLibrary(NodeLibrary.class)
5252
abstract class AbstractInstrumentableBytecodeNode extends EspressoInstrumentableNode {
@@ -83,14 +83,15 @@ public final boolean hasScope(@SuppressWarnings("unused") Frame frame) {
8383

8484
@ExportMessage
8585
public final Object getScope(Frame frame, @SuppressWarnings("unused") boolean nodeEnter) {
86-
return getScopeSlowPath(frame != null ? frame.materialize() : null);
86+
return getScopeSlowPath(frame != null ? frame.materialize() : null, getMethod(), getBci(frame));
8787
}
8888

8989
@TruffleBoundary
90-
private Object getScopeSlowPath(MaterializedFrame frame) {
91-
// construct the current scope with valid local variables information
92-
Method method = getMethodVersion().getMethod();
93-
Local[] liveLocals = method.getLocalVariableTable().getLocalsAt(getBci(frame));
90+
private static Object getScopeSlowPath(MaterializedFrame frame, Method method, int bci) {
91+
// NOTE: this might be called while the thread is not entered into the context so
92+
// don't use things like a LanguageReference
93+
// Construct the current scope with valid local variables information
94+
Local[] liveLocals = method.getLocalVariableTable().getLocalsAt(bci);
9495
boolean allParamsIncluded = checkLocals(liveLocals, method);
9596
if (!allParamsIncluded) {
9697
ArrayList<Local> constructedLiveLocals = new ArrayList<>();
@@ -120,7 +121,7 @@ private Object getScopeSlowPath(MaterializedFrame frame) {
120121
for (int i = startslot; i < localCount; i++) {
121122
Symbol<Type> paramType = hasReceiver ? Signatures.parameterType(parsedSignature, i - 1) : Signatures.parameterType(parsedSignature, i);
122123
if (!slotToLocal.containsKey(i)) {
123-
Symbol<Name> localName = getLanguage().getNames().getOrCreate(ByteSequence.create("arg_" + i));
124+
Symbol<Name> localName = method.getLanguage().getNames().getOrCreate(ByteSequence.create("arg_" + i));
124125
constructedLiveLocals.add(new Local(localName, paramType, null, 0, 0xffff, i));
125126
slotToLocal.remove(i);
126127
}

0 commit comments

Comments
 (0)