Skip to content

Commit 2c06433

Browse files
committed
Store OSR frame in a Pair with previous value
1 parent 5e622fa commit 2c06433

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.oracle.graal.python.runtime.PythonOptions;
3232
import com.oracle.graal.python.runtime.exception.PException;
3333
import com.oracle.graal.python.util.PythonUtils;
34-
import com.oracle.truffle.api.CompilerAsserts;
3534
import com.oracle.truffle.api.exception.AbstractTruffleException;
3635
import com.oracle.truffle.api.frame.Frame;
3736
import com.oracle.truffle.api.frame.MaterializedFrame;
@@ -42,7 +41,7 @@
4241
* The layout of an argument array for a Python frame.
4342
*
4443
* +-------------------+
45-
* INDEX_VARIABLE_ARGUMENTS -> | Object[] | This slot is also used to pass parent frame reference in bytecode OSR compilation.
44+
* INDEX_VARIABLE_ARGUMENTS -> | Object[] |
4645
* +-------------------+
4746
* INDEX_KEYWORD_ARGUMENTS -> | PKeyword[] |
4847
* +-------------------+
@@ -244,19 +243,6 @@ public static PCell[] getClosure(Object[] arguments) {
244243
return (PCell[]) arguments[INDEX_CLOSURE];
245244
}
246245

247-
/*
248-
* We repurpose the varargs slot for storing the OSR frame. In the bytecode interpreter, varargs
249-
* should only be read once at the beginning of execute which is before OSR.
250-
*/
251-
public static void setOSRFrame(Object[] arguments, VirtualFrame parentFrame) {
252-
CompilerAsserts.neverPartOfCompilation();
253-
arguments[INDEX_VARIABLE_ARGUMENTS] = parentFrame;
254-
}
255-
256-
public static Frame getOSRFrame(Object[] arguments) {
257-
return (Frame) arguments[INDEX_VARIABLE_ARGUMENTS];
258-
}
259-
260246
public static PCell[] getClosure(Frame frame) {
261247
return getClosure(frame.getArguments());
262248
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import java.util.Set;
5858
import java.util.concurrent.locks.Lock;
5959

60+
import org.graalvm.collections.Pair;
61+
6062
import com.oracle.graal.python.PythonLanguage;
6163
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
6264
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.FormatNode;
@@ -176,9 +178,9 @@
176178
import com.oracle.graal.python.nodes.builtins.ListNodesFactory;
177179
import com.oracle.graal.python.nodes.builtins.TupleNodes;
178180
import com.oracle.graal.python.nodes.builtins.TupleNodesFactory;
181+
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNodeFactory.ObjHashMapPutNodeGen;
179182
import com.oracle.graal.python.nodes.bytecode.SequenceFromStackNode.ListFromStackNode;
180183
import com.oracle.graal.python.nodes.bytecode.SequenceFromStackNode.TupleFromStackNode;
181-
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNodeFactory.ObjHashMapPutNodeGen;
182184
import com.oracle.graal.python.nodes.bytecode.SequenceFromStackNodeFactory.ListFromStackNodeGen;
183185
import com.oracle.graal.python.nodes.bytecode.SequenceFromStackNodeFactory.TupleFromStackNodeGen;
184186
import com.oracle.graal.python.nodes.bytecode.instrumentation.InstrumentationRoot;
@@ -1100,16 +1102,22 @@ public Object execute(VirtualFrame virtualFrame) {
11001102
}
11011103
}
11021104

1105+
// Doesn't matter which PArguments slot we use as long as it exists
1106+
private static final int OSR_FRAME_INDEX = 0;
1107+
11031108
@Override
11041109
public Object[] storeParentFrameInArguments(VirtualFrame parentFrame) {
11051110
Object[] arguments = parentFrame.getArguments();
1106-
PArguments.setOSRFrame(arguments, parentFrame);
1111+
arguments[0] = Pair.create(arguments[OSR_FRAME_INDEX], parentFrame);
11071112
return arguments;
11081113
}
11091114

11101115
@Override
1116+
@SuppressWarnings("unchecked")
11111117
public Frame restoreParentFrameFromArguments(Object[] arguments) {
1112-
return PArguments.getOSRFrame(arguments);
1118+
Pair<Object, Frame> pair = (Pair<Object, Frame>) arguments[OSR_FRAME_INDEX];
1119+
arguments[0] = pair.getLeft();
1120+
return pair.getRight();
11131121
}
11141122

11151123
@Override

0 commit comments

Comments
 (0)