Skip to content

Commit e29d69a

Browse files
committed
Preserve frame arguments when doing OSR
1 parent fdb8b25 commit e29d69a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -33,6 +33,7 @@
3333
import com.oracle.graal.python.builtins.objects.object.PythonObject;
3434
import com.oracle.graal.python.runtime.exception.PException;
3535
import com.oracle.graal.python.util.PythonUtils;
36+
import com.oracle.truffle.api.CompilerAsserts;
3637
import com.oracle.truffle.api.CompilerDirectives.ValueType;
3738
import com.oracle.truffle.api.Truffle;
3839
import com.oracle.truffle.api.frame.Frame;
@@ -279,6 +280,19 @@ public static PCell[] getClosure(Object[] arguments) {
279280
return (PCell[]) arguments[INDEX_CLOSURE];
280281
}
281282

283+
/*
284+
* We repurpose the varargs slot for storing the OSR frame. In the bytecode interpreter, varargs
285+
* should only be read once at the beginning of execute which is before OSR.
286+
*/
287+
public static void setOSRFrame(Object[] arguments, VirtualFrame parentFrame) {
288+
CompilerAsserts.neverPartOfCompilation();
289+
arguments[INDEX_VARIABLE_ARGUMENTS] = parentFrame;
290+
}
291+
292+
public static Frame getOSRFrame(Object[] arguments) {
293+
return (Frame) arguments[INDEX_VARIABLE_ARGUMENTS];
294+
}
295+
282296
public static PCell[] getClosure(Frame frame) {
283297
return getClosure(frame.getArguments());
284298
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,18 @@ public Object execute(VirtualFrame virtualFrame) {
779779
}
780780
}
781781

782+
@Override
783+
public Object[] storeParentFrameInArguments(VirtualFrame parentFrame) {
784+
Object[] arguments = parentFrame.getArguments();
785+
PArguments.setOSRFrame(arguments, parentFrame);
786+
return arguments;
787+
}
788+
789+
@Override
790+
public Frame restoreParentFrameFromArguments(Object[] arguments) {
791+
return PArguments.getOSRFrame(arguments);
792+
}
793+
782794
@Override
783795
public Object executeOSR(VirtualFrame osrFrame, int target, Object interpreterState) {
784796
return executeInner(osrFrame, true, target, (Integer) interpreterState);

0 commit comments

Comments
 (0)