Skip to content

Commit a02fcca

Browse files
committed
Don't handle exceptions twice in OSR
1 parent de37997 commit a02fcca

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.nodes.bytecode;
42+
43+
import com.oracle.graal.python.runtime.exception.PythonControlFlowException;
44+
import com.oracle.truffle.api.exception.AbstractTruffleException;
45+
46+
/*
47+
Container for for propagating exceptions from OSR without handling them twice.
48+
*/
49+
public class OSRException extends PythonControlFlowException {
50+
private static final long serialVersionUID = 425126860491305807L;
51+
public final AbstractTruffleException exception;
52+
53+
public OSRException(AbstractTruffleException exception) {
54+
this.exception = exception;
55+
}
56+
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,19 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
17691769
* variables) or it will get mixed up. To retain such state, put it
17701770
* into the frame instead.
17711771
*/
1772-
Object osrResult = BytecodeOSRNode.tryOSR(osrNode, bci, new OSRInterpreterState(stackTop), null, virtualFrame);
1772+
Object osrResult;
1773+
try {
1774+
osrResult = BytecodeOSRNode.tryOSR(osrNode, bci, new OSRInterpreterState(stackTop), null, virtualFrame);
1775+
} catch (AbstractTruffleException e) {
1776+
/*
1777+
* If the OSR execution throws a python exception, it means it
1778+
* has already been processed by the bytecode exception handler
1779+
* therein. We wrap it in order to make sure it doesn't get
1780+
* processed again, which would overwrite the traceback entry
1781+
* with the location of this jump instruction.
1782+
*/
1783+
throw new OSRException(e);
1784+
}
17731785
if (osrResult != null) {
17741786
if (CompilerDirectives.hasNextTier() && mutableData.loopCount > 0) {
17751787
LoopNode.reportLoopCount(this, mutableData.loopCount);
@@ -2039,6 +2051,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
20392051
bci++;
20402052
} catch (PythonExitException | PythonThreadKillException e) {
20412053
throw e;
2054+
} catch (OSRException e) {
2055+
// Exception from OSR was already handled in the OSR code
2056+
throw e.exception;
20422057
} catch (Exception | StackOverflowError | AssertionError e) {
20432058
PException pe = null;
20442059
boolean isInteropException = false;

0 commit comments

Comments
 (0)