Skip to content

Commit ba06f63

Browse files
committed
Fix: BytecodeNode#setLocalValues should unwrap the frame from a continuation frame
1 parent 1006af4 commit ba06f63

File tree

2 files changed

+20
-14
lines changed
  • truffle/src

2 files changed

+20
-14
lines changed

truffle/src/com.oracle.truffle.api.bytecode.test/src/com/oracle/truffle/api/bytecode/test/LocalHelpersTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,9 @@ public void testGetLocalsContinuationStacktrace() {
10021002
CallTarget collectFrames = new RootNode(null) {
10031003
@Override
10041004
public Object execute(VirtualFrame frame) {
1005-
List<Object[]> frames = new ArrayList<>();
1005+
List<FrameInstance> frames = new ArrayList<>();
10061006
Truffle.getRuntime().iterateFrames(f -> {
1007-
frames.add(BytecodeNode.getLocalValues(f));
1007+
frames.add(f);
10081008
return null;
10091009
});
10101010
return frames;
@@ -1058,19 +1058,27 @@ public Object execute(VirtualFrame frame) {
10581058
assertTrue(result instanceof List<?>);
10591059

10601060
@SuppressWarnings("unchecked")
1061-
List<Object[]> frames = (List<Object[]>) result;
1061+
List<FrameInstance> frames = (List<FrameInstance>) result;
10621062
assertEquals(3, frames.size());
10631063

10641064
// <anon>
1065-
assertNull(frames.get(0));
1065+
assertNull(BytecodeNode.getLocalValues(frames.get(0)));
10661066

10671067
// bar
1068-
Object[] barLocals = frames.get(1);
1068+
Object[] barLocals = BytecodeNode.getLocalValues(frames.get(1));
10691069
assertArrayEquals(new Object[]{42}, barLocals);
1070+
Object[] barLocalNames = BytecodeNode.getLocalNames(frames.get(1));
1071+
assertArrayEquals(new Object[]{"y"}, barLocalNames);
1072+
BytecodeNode.setLocalValues(frames.get(1), new Object[]{-42});
1073+
assertArrayEquals(new Object[]{-42}, BytecodeNode.getLocalValues(frames.get(1)));
10701074

10711075
// foo
1072-
Object[] fooLocals = frames.get(2);
1076+
Object[] fooLocals = BytecodeNode.getLocalValues(frames.get(2));
10731077
assertArrayEquals(new Object[]{123}, fooLocals);
1078+
Object[] fooLocalNames = BytecodeNode.getLocalNames(frames.get(2));
1079+
assertArrayEquals(new Object[]{"x"}, fooLocalNames);
1080+
BytecodeNode.setLocalValues(frames.get(2), new Object[]{456});
1081+
assertArrayEquals(new Object[]{456}, BytecodeNode.getLocalValues(frames.get(2)));
10741082
}
10751083

10761084
@Test

truffle/src/com.oracle.truffle.api.bytecode/src/com/oracle/truffle/api/bytecode/BytecodeNode.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ public static Object[] getLocalValues(FrameInstance frameInstance) {
12261226
if (bytecode == null) {
12271227
return null;
12281228
}
1229-
Frame frame = resolveFrame(frameInstance);
1229+
Frame frame = resolveFrame(frameInstance, FrameAccess.READ_ONLY);
12301230
int bci = bytecode.findBytecodeIndexImpl(frame, frameInstance.getCallNode());
12311231
return bytecode.getLocalValues(bci, frame);
12321232
}
@@ -1265,16 +1265,14 @@ public static boolean setLocalValues(FrameInstance frameInstance, Object[] value
12651265
return false;
12661266
}
12671267
int bci = bytecode.findBytecodeIndex(frameInstance);
1268-
bytecode.setLocalValues(bci, frameInstance.getFrame(FrameAccess.READ_WRITE), values);
1268+
bytecode.setLocalValues(bci, resolveFrame(frameInstance, FrameAccess.READ_WRITE), values);
12691269
return true;
12701270
}
12711271

1272-
private static Frame resolveFrame(FrameInstance frameInstance) {
1273-
Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY);
1274-
if (frameInstance.getCallTarget() instanceof RootCallTarget root) {
1275-
if (root.getRootNode() instanceof ContinuationRootNode continuation) {
1276-
frame = continuation.findFrame(frame);
1277-
}
1272+
private static Frame resolveFrame(FrameInstance frameInstance, FrameAccess access) {
1273+
Frame frame = frameInstance.getFrame(access);
1274+
if (frameInstance.getCallTarget() instanceof RootCallTarget root && root.getRootNode() instanceof ContinuationRootNode continuation) {
1275+
frame = continuation.findFrame(frame);
12781276
}
12791277
return frame;
12801278
}

0 commit comments

Comments
 (0)