Skip to content

Commit 6cbc02b

Browse files
committed
Fix exception location assertion during Python async actions
1 parent dda8714 commit 6cbc02b

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private static void processBytecodeFrame(Frame frameToMaterialize, PFrame pyFram
229229
pyFrame.setBci(bytecodeNode.getBytecodeIndex(frameToMaterialize));
230230
pyFrame.setLocation(bytecodeNode);
231231
} else {
232-
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");
233233
pyFrame.setBci(-1);
234234
pyFrame.setLocation(location);
235235
}

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,30 @@ public final void execute(PythonContext context, Access access) {
165165
Node prev = null;
166166
Node location = access.getLocation();
167167
boolean locationAdoptable = location.isAdoptable();
168+
EncapsulatingNodeReference encapsulatingNodeRef = EncapsulatingNodeReference.getCurrent();
168169
if (locationAdoptable) {
169170
// If the location is not adoptable, then we are in
170-
// IndirectCallContext and SimpleIndirectInvokeNode will do
171+
// IndirectCallContext and SimpleIndirectInvokeNode below will do
171172
// IndirectCalleeContext.enter and transfer the state from thread state to
172-
// the frame. If we were woken-up in middle of Python frame code, we will
173-
// have to do a stack walk, but we still need the location
174-
assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER ||
175-
!(location instanceof PBytecodeDSLRootNode) : String.format("Async action: location must not be PBytecodeDSLRootNode, was: %s", location);
176-
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+
}
177186
}
178187
try {
179188
CallDispatchers.SimpleIndirectInvokeNode.executeUncached(context.getAsyncHandler().callTarget, args);
180189
} catch (PException e) {
181190
if (locationAdoptable) {
182-
EncapsulatingNodeReference.getCurrent().set(prev);
191+
encapsulatingNodeRef.set(prev);
183192
}
184193
handleException(e);
185194
} finally {

0 commit comments

Comments
 (0)