Skip to content

Commit 4273bc8

Browse files
committed
Bytecode DSL tracing fix: pop tracing data even if trace function raises
- Ensures that instrumentation data is always popped from the thread state, even if the trace or profile function raises an exception. - Improves assertion in popInstrumentationData for more informative errors.
1 parent c1989a7 commit 4273bc8

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,11 @@ public static void doExit(VirtualFrame frame, AbstractTruffleException ate,
487487
}
488488

489489
if (root.needsTraceAndProfileInstrumentation()) {
490-
root.traceOrProfileReturn(frame, location, null);
491-
root.getThreadState().popInstrumentationData(root);
490+
try {
491+
root.traceOrProfileReturn(frame, location, null);
492+
} finally {
493+
root.getThreadState().popInstrumentationData(root);
494+
}
492495
}
493496

494497
root.calleeContext.exit(frame, root, location);
@@ -1055,11 +1058,13 @@ public static Object doYield(
10551058
@Bind ContinuationRootNode continuationRootNode,
10561059
@Bind PBytecodeDSLRootNode innerRoot,
10571060
@Bind BytecodeNode bytecodeNode) {
1058-
Object result = createGenerator(continuationFrame, inliningTarget, continuationRootNode, innerRoot);
1059-
if (innerRoot.needsTraceAndProfileInstrumentation()) {
1060-
innerRoot.getThreadState().popInstrumentationData(innerRoot);
1061+
try {
1062+
return createGenerator(continuationFrame, inliningTarget, continuationRootNode, innerRoot);
1063+
} finally {
1064+
if (innerRoot.needsTraceAndProfileInstrumentation()) {
1065+
innerRoot.getThreadState().popInstrumentationData(innerRoot);
1066+
}
10611067
}
1062-
return result;
10631068
}
10641069

10651070
private static PythonAbstractObject createGenerator(MaterializedFrame continuationFrame, Node inliningTarget,
@@ -1115,8 +1120,11 @@ public static Object doObject(Object value,
11151120
@Bind PBytecodeDSLRootNode root,
11161121
@Bind BytecodeNode bytecode) {
11171122
if (root.needsTraceAndProfileInstrumentation()) {
1118-
root.traceOrProfileReturn(frame, bytecode, value);
1119-
root.getThreadState().popInstrumentationData(root);
1123+
try {
1124+
root.traceOrProfileReturn(frame, bytecode, value);
1125+
} finally {
1126+
root.getThreadState().popInstrumentationData(root);
1127+
}
11201128
}
11211129

11221130
// Suspended generators have no backref

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ public void pushInstrumentationData(PBytecodeDSLRootNode rootNode) {
613613

614614
public void popInstrumentationData(PBytecodeDSLRootNode rootNode) {
615615
assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER;
616-
assert instrumentationData != null;
617-
assert instrumentationData.getRootNode() == rootNode : instrumentationData.getRootNode();
616+
assert instrumentationData != null : rootNode;
617+
assert instrumentationData.getRootNode() == rootNode : String.format("%s != %s", instrumentationData.getRootNode(), rootNode);
618618
instrumentationData = instrumentationData.getPrevious();
619619
}
620620

0 commit comments

Comments
 (0)