diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java index e0340ff637..b4cd78c9d0 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java @@ -71,9 +71,9 @@ import com.oracle.graal.python.runtime.object.PythonObjectFactory; import com.oracle.graal.python.util.PythonUtils; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.bytecode.introspection.BytecodeIntrospection; -import com.oracle.truffle.api.bytecode.introspection.Instruction; -import com.oracle.truffle.api.bytecode.introspection.SourceInformation; +import com.oracle.truffle.api.bytecode.BytecodeIntrospection; +import com.oracle.truffle.api.bytecode.Instruction; +import com.oracle.truffle.api.bytecode.SourceInformation; import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; @@ -354,7 +354,12 @@ Object positions(PCode self) { List lines = new ArrayList<>(); if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) self.getRootNodeForExtraction(); - for (Instruction instruction : rootNode.getIntrospectionData().getInstructions()) { + for (Instruction instruction : rootNode.getBytecodeNode().getInstructions()) { + if (instruction.isInstrumentation()) { + // Skip instrumented instructions. The co_positions array should agree + // with the logical instruction index. + continue; + } SourceSection section = rootNode.getSourceSectionForLocation(instruction.getLocation()); lines.add(factory.createTuple(new int[]{ section.getStartLine(), diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java index 3b869f5a78..cdf3af4229 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java @@ -486,8 +486,8 @@ public int lastiToLine(int lasti) { if (funcRootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) { BytecodeNode bytecodeNode = bytecodeDSLRootNode.getBytecodeNode(); // Emulate CPython's fixed 2-word instructions. - BytecodeLocation location = BytecodeLocation.fromInstructionIndex((lasti + 1) / 2, bytecodeNode); - return location.findSourceLocation().getStartLine(); + BytecodeLocation location = bytecodeNode.getBytecodeLocationFromInstructionIndex(lasti / 2); + return location.getSourceLocation().getStartLine(); } } else if (funcRootNode instanceof PBytecodeRootNode bytecodeRootNode) { return bytecodeRootNode.bciToLine(bytecodeRootNode.lastiToBci(lasti)); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java index 187876f7b1..f7c224372e 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java @@ -311,7 +311,7 @@ public static int bciToLasti(int bci, Node location) { if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { if (bci >= 0 && location instanceof BytecodeNode bytecodeNode) { // Emulate CPython's fixed 2-word instructions. - return bytecodeNode.findInstructionIndex(bci) * 2; + return bytecodeNode.getBytecodeLocation(bci).getInstructionIndex() * 2; } } else { if (location instanceof PBytecodeRootNode bytecodeRootNode) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java index 8c53c3c59c..b25ec24a46 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java @@ -424,7 +424,7 @@ public SourceSection getSourceSectionForLocation(int bci, BytecodeNode bytecodeN if (bytecodeNode != null) { BytecodeLocation bytecodeLocation = bytecodeNode.getBytecodeLocation(bci); if (bytecodeLocation != null) { - sourceSection = bytecodeLocation.findSourceLocation(); + sourceSection = bytecodeLocation.getSourceLocation(); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java index 7759928001..a75c091a5d 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java @@ -56,8 +56,6 @@ import com.oracle.graal.python.nodes.BuiltinNames; import com.oracle.graal.python.nodes.bytecode.BytecodeFrameInfo; import com.oracle.graal.python.nodes.bytecode.FrameInfo; -import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; -import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.exception.TopLevelExceptionHandler; import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode; @@ -116,7 +114,7 @@ private static int getLineno(Frame frame, Node location, FrameInstance frameInst } if (bytecodeNode != null) { - return bytecodeNode.getBytecodeLocation(frame, location).findSourceLocation().getStartLine(); + return bytecodeNode.getBytecodeLocation(frame, location).getSourceLocation().getStartLine(); } } else { return ((BytecodeFrameInfo) frameInfo).getLine(frame);