Skip to content

Commit 5c3dbe4

Browse files
committed
Use long OSR target, encoding both bytecode offset and stack pointer.
1 parent 3d4eb2a commit 5c3dbe4

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/nodes/WasmFunctionNode.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,26 @@ private Vector128Ops<V128> vector128Ops() {
196196
}
197197

198198
// region OSR support
199-
private record WasmOSRInterpreterState(int stackPointer, int line) {
199+
/**
200+
* Prepare for OSR. An interpreter that uses {@code long} targets must override this method.
201+
*/
202+
@Override
203+
public void prepareOSR(long target) {
204+
// do nothing
205+
}
206+
207+
@Override
208+
public void copyIntoOSRFrame(VirtualFrame osrFrame, VirtualFrame parentFrame, long target, Object targetMetadata) {
209+
BytecodeOSRNode.super.copyIntoOSRFrame(osrFrame, parentFrame, (int) target, targetMetadata);
200210
}
201211

202212
@Override
203-
public Object executeOSR(VirtualFrame osrFrame, int target, Object interpreterState) {
204-
WasmOSRInterpreterState state = (WasmOSRInterpreterState) interpreterState;
213+
public Object executeOSR(VirtualFrame osrFrame, long target, Object interpreterState) {
205214
WasmInstance instance = ((WasmRootNode) getRootNode()).instance(osrFrame);
206-
return executeBodyFromOffset(instance, osrFrame, target, state.stackPointer, state.line);
215+
int offset = (int) target;
216+
int stackPointer = (int) (target >>> 32);
217+
int line = (int) interpreterState;
218+
return executeBodyFromOffset(instance, osrFrame, offset, stackPointer, line);
207219
}
208220

209221
@Override
@@ -294,8 +306,11 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
294306
// A return statement causes the termination of the current function, i.e.
295307
// causes the execution to resume after the instruction that invoked
296308
// the current frame.
297-
if (backEdgeCounter.count > 0) {
298-
LoopNode.reportLoopCount(this, backEdgeCounter.count);
309+
if (CompilerDirectives.hasNextTier()) {
310+
int backEdgeCount = backEdgeCounter.count;
311+
if (backEdgeCount > 0) {
312+
LoopNode.reportLoopCount(this, backEdgeCount);
313+
}
299314
}
300315
final int resultCount = codeEntry.resultCount();
301316
unwindStack(frame, stackPointer, localCount, resultCount);
@@ -373,7 +388,7 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
373388
if (CompilerDirectives.hasNextTier() && ++backEdgeCounter.count >= REPORT_LOOP_STRIDE) {
374389
LoopNode.reportLoopCount(this, REPORT_LOOP_STRIDE);
375390
if (CompilerDirectives.inInterpreter() && BytecodeOSRNode.pollOSRBackEdge(this, REPORT_LOOP_STRIDE)) {
376-
Object result = BytecodeOSRNode.tryOSR(this, offset, new WasmOSRInterpreterState(stackPointer, lineIndex), null, frame);
391+
Object result = BytecodeOSRNode.tryOSR(this, offset | ((long) stackPointer << 32), lineIndex, null, frame);
377392
if (result != null) {
378393
return result;
379394
}
@@ -1669,9 +1684,9 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
16691684

16701685
/*
16711686
* The exception table is encoded in the following format:
1672-
*
1687+
*
16731688
* from | to | type | tag index (optional) | target
1674-
*
1689+
*
16751690
* The values from (exclusive) and to (inclusive) define a range. If source is
16761691
* inside this range, the entry defines a possible exception handler for the
16771692
* exception. If the type of the exception handler is catch or catch_ref, we check
@@ -1683,7 +1698,7 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
16831698
* only pushes the reference, and catch_all doesn't push anything onto the stack.
16841699
*
16851700
* If we find a matching entry, execution continues at the label defined by target.
1686-
*
1701+
*
16871702
* If the current entry doesn't match, we continue to the next, until we reach a
16881703
* match or the end of the table. If we reach the end of the table, we rethrow the
16891704
* exception to the next function on the call stack.

0 commit comments

Comments
 (0)