Skip to content

Commit aa46552

Browse files
committed
[GR-71256] Fix exception location assertion during async Python actions.
PullRequest: graalpython/4098
2 parents 8cc4b8d + 6cbc02b commit aa46552

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ public final PFrame executeOnStack(boolean markAsEscaped, boolean forceSync, Fra
152152
*/
153153
public final PFrame execute(Node location, boolean markAsEscaped, boolean forceSync, Frame frameToMaterialize) {
154154
assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || frameToMaterialize.getArguments().length != 2 : "caller forgot to unwrap continuation frame";
155-
assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || !(location instanceof PBytecodeDSLRootNode) : location.getClass().getSimpleName();
155+
assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || !(location instanceof PBytecodeDSLRootNode) : String.format("Materialized frame: location must not be PBytecodeDSLRootNode, was: %s",
156+
location);
156157
return executeImpl(location, markAsEscaped, forceSync, frameToMaterialize);
157158
}
158159

@@ -228,7 +229,7 @@ private static void processBytecodeFrame(Frame frameToMaterialize, PFrame pyFram
228229
pyFrame.setBci(bytecodeNode.getBytecodeIndex(frameToMaterialize));
229230
pyFrame.setLocation(bytecodeNode);
230231
} else {
231-
assert false : String.format("%s, root: %s", location, location != null ? location.getRootNode() : "null");
232+
assert location == PythonLanguage.get(null).unavailableSafepointLocation : String.format("%s, root: %s", location, location != null ? location.getRootNode() : "null");
232233
pyFrame.setBci(-1);
233234
pyFrame.setLocation(location);
234235
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/AsyncHandler.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import com.oracle.graal.python.builtins.objects.function.PArguments;
6262
import com.oracle.graal.python.builtins.objects.function.Signature;
6363
import com.oracle.graal.python.nodes.PRootNode;
64+
import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode;
6465
import com.oracle.graal.python.nodes.call.CallDispatchers;
6566
import com.oracle.graal.python.nodes.call.CallNode;
6667
import com.oracle.graal.python.nodes.frame.ReadCallerFrameNode;
@@ -164,19 +165,30 @@ public final void execute(PythonContext context, Access access) {
164165
Node prev = null;
165166
Node location = access.getLocation();
166167
boolean locationAdoptable = location.isAdoptable();
168+
EncapsulatingNodeReference encapsulatingNodeRef = EncapsulatingNodeReference.getCurrent();
167169
if (locationAdoptable) {
168170
// If the location is not adoptable, then we are in
169-
// IndirectCallContext and SimpleIndirectInvokeNode will do
171+
// IndirectCallContext and SimpleIndirectInvokeNode below will do
170172
// IndirectCalleeContext.enter and transfer the state from thread state to
171-
// the frame. If we were woken-up in middle of Python frame code, we will
172-
// have to do a stack walk, but we still need the location
173-
prev = EncapsulatingNodeReference.getCurrent().set(location);
173+
// the frame. Otherwise, we were woken-up in middle of Python frame code, we
174+
// will have to do a stack walk if caller frame is needed, but we still need
175+
// the "call" location
176+
if (location instanceof PBytecodeDSLRootNode) {
177+
// PBytecodeDSLRootNode is not usable as a location. To resolve the BCI
178+
// stored in the frame, we need the currently executing BytecodeNode,
179+
// using PBytecodeRootNode.getBytecodeNode() is not correct. We use the
180+
// dummy node to pass our assertions during stack walking that "call
181+
// node" is never PBytecodeDSLRootNode
182+
prev = encapsulatingNodeRef.set(language.unavailableSafepointLocation);
183+
} else {
184+
prev = encapsulatingNodeRef.set(location);
185+
}
174186
}
175187
try {
176188
CallDispatchers.SimpleIndirectInvokeNode.executeUncached(context.getAsyncHandler().callTarget, args);
177189
} catch (PException e) {
178190
if (locationAdoptable) {
179-
EncapsulatingNodeReference.getCurrent().set(prev);
191+
encapsulatingNodeRef.set(prev);
180192
}
181193
handleException(e);
182194
} finally {

0 commit comments

Comments
 (0)