Skip to content

Commit cf2c4cc

Browse files
committed
Add inlining cutoffs
1 parent a98da58 commit cf2c4cc

File tree

1 file changed

+66
-40
lines changed

1 file changed

+66
-40
lines changed

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

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,11 +1224,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
12241224

12251225
try {
12261226
if (instrumentation != null) {
1227-
int line = bciToLine(bci);
1228-
int pastLine = mutableData.getPastLine();
1229-
instrumentation.notifyStatement(virtualFrame, pastLine, line);
1230-
mutableData.setPastLine(line);
1231-
mutableData.setPastBci(bci);
1227+
notifyStatement(virtualFrame, instrumentation, mutableData, bci);
12321228
}
12331229

12341230
switch (bc) {
@@ -1681,8 +1677,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
16811677

16821678
if (instrumentation != null && instrumentationRoot instanceof WrapperNode) {
16831679
returnCalled = true;
1684-
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
1685-
wrapper.getProbeNode().onReturnValue(virtualFrame, value);
1680+
notifyRootReturn(virtualFrame, value);
16861681
}
16871682
if (isGeneratorOrCoroutine) {
16881683
throw new GeneratorReturnException(value);
@@ -2101,8 +2096,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
21012096
traceOrProfileYield(virtualFrame, mutableData, value, tracingEnabled, profilingEnabled);
21022097
if (instrumentation != null && instrumentationRoot instanceof WrapperNode) {
21032098
returnCalled = true;
2104-
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
2105-
wrapper.getProbeNode().onReturnValue(virtualFrame, value);
2099+
notifyRootReturn(virtualFrame, value);
21062100
}
21072101
return new GeneratorYieldResult(bci + 1, stackTop, value);
21082102
}
@@ -2192,19 +2186,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
21922186
traceException(virtualFrame, mutableData, bci, pe);
21932187
}
21942188
if (instrumentation != null) {
2195-
instrumentation.notifyException(virtualFrame, bciToLine(beginBci), e);
2196-
if (instrumentationRoot instanceof WrapperNode) {
2197-
returnCalled = true;
2198-
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
2199-
Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, e, false);
2200-
if (result == ProbeNode.UNWIND_ACTION_REENTER) {
2201-
throw CompilerDirectives.shouldNotReachHere("Reenter shouldn't occur at this point");
2202-
} else if (result != null) {
2203-
if (isGeneratorOrCoroutine) {
2204-
throw CompilerDirectives.shouldNotReachHere("Cannot replace return value of generators");
2205-
}
2206-
return result;
2207-
}
2189+
Object result = notifyException(virtualFrame, instrumentation, returnCalled, beginBci, e);
2190+
if (result != null) {
2191+
return result;
22082192
}
22092193
}
22102194

@@ -2226,30 +2210,72 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
22262210
bci = exceptionHandlerRanges[targetIndex];
22272211
oparg = 0;
22282212
}
2229-
} catch (ThreadDeath e) {
2213+
} catch (ThreadDeath t) {
22302214
// Need to handle instrumentation frame unwind
2231-
if (instrumentationRoot instanceof WrapperNode) {
2232-
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
2233-
Object ret = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, e, returnCalled);
2234-
if (ret == ProbeNode.UNWIND_ACTION_REENTER) {
2235-
if (isGeneratorOrCoroutine) {
2236-
CompilerDirectives.transferToInterpreterAndInvalidate();
2237-
throw new UnsupportedOperationException("Frame restarting is not possible in generators");
2238-
}
2239-
copyArgs(virtualFrame.getArguments(), localFrame);
2240-
bci = 0;
2241-
stackTop = getInitialStackTop();
2242-
oparg = 0;
2243-
continue;
2244-
} else if (ret != null) {
2245-
return ret;
2246-
}
2215+
Object result = handlePossibleReenter(virtualFrame, t, returnCalled);
2216+
if (result == ProbeNode.UNWIND_ACTION_REENTER) {
2217+
bci = 0;
2218+
stackTop = getInitialStackTop();
2219+
oparg = 0;
2220+
continue;
2221+
} else if (result != null) {
2222+
return result;
22472223
}
2248-
throw e;
2224+
throw t;
22492225
}
22502226
}
22512227
}
22522228

2229+
@InliningCutoff
2230+
private Object notifyException(VirtualFrame virtualFrame, InstrumentationSupport instrumentation, boolean returnCalled, int bci, Throwable e) {
2231+
instrumentation.notifyException(virtualFrame, bciToLine(bci), e);
2232+
if (instrumentationRoot instanceof WrapperNode) {
2233+
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
2234+
Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, e, returnCalled);
2235+
if (result == ProbeNode.UNWIND_ACTION_REENTER) {
2236+
throw CompilerDirectives.shouldNotReachHere("Reenter shouldn't occur at this point");
2237+
} else if (result != null) {
2238+
if (co.isGeneratorOrCoroutine()) {
2239+
throw CompilerDirectives.shouldNotReachHere("Cannot replace return value of generators");
2240+
}
2241+
}
2242+
return result;
2243+
}
2244+
return null;
2245+
}
2246+
2247+
@InliningCutoff
2248+
private void notifyRootReturn(VirtualFrame virtualFrame, Object value) {
2249+
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
2250+
wrapper.getProbeNode().onReturnValue(virtualFrame, value);
2251+
}
2252+
2253+
@InliningCutoff
2254+
private void notifyStatement(VirtualFrame virtualFrame, InstrumentationSupport instrumentation, MutableLoopData mutableData, int bci) {
2255+
int line = bciToLine(bci);
2256+
int pastLine = mutableData.getPastLine();
2257+
instrumentation.notifyStatement(virtualFrame, pastLine, line);
2258+
mutableData.setPastLine(line);
2259+
mutableData.setPastBci(bci);
2260+
}
2261+
2262+
@InliningCutoff
2263+
private Object handlePossibleReenter(VirtualFrame virtualFrame, ThreadDeath t, boolean returnCalled) {
2264+
if (instrumentationRoot instanceof WrapperNode) {
2265+
WrapperNode wrapper = (WrapperNode) instrumentationRoot;
2266+
Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, t, returnCalled);
2267+
if (result == ProbeNode.UNWIND_ACTION_REENTER) {
2268+
if (co.isGeneratorOrCoroutine()) {
2269+
CompilerDirectives.transferToInterpreterAndInvalidate();
2270+
throw new UnsupportedOperationException("Frame restarting is not possible in generators");
2271+
}
2272+
copyArgs(virtualFrame.getArguments(), virtualFrame);
2273+
}
2274+
return result;
2275+
}
2276+
return null;
2277+
}
2278+
22532279
@InliningCutoff
22542280
private Object enterRoot(VirtualFrame virtualFrame) {
22552281
if (instrumentationRoot instanceof WrapperNode) {

0 commit comments

Comments
 (0)