@@ -1184,8 +1184,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1184
1184
final PythonLanguage language = PythonLanguage .get (this );
1185
1185
final Assumption noTraceOrProfile = language .noTracingOrProfilingAssumption ;
1186
1186
final InstrumentationSupport instrumentation = instrumentationRoot .getInstrumentation ();
1187
- if (instrumentation != null ) {
1188
- Object result = enterRoot (virtualFrame );
1187
+ if (instrumentation != null && ! fromOSR ) {
1188
+ Object result = notifyEnter (virtualFrame , instrumentation , initialBci );
1189
1189
if (result != null ) {
1190
1190
return result ;
1191
1191
}
@@ -1237,10 +1237,6 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1237
1237
CompilerAsserts .partialEvaluationConstant (stackTop );
1238
1238
1239
1239
try {
1240
- if (instrumentation != null ) {
1241
- notifyStatement (virtualFrame , instrumentation , mutableData , bci );
1242
- }
1243
-
1244
1240
switch (bc ) {
1245
1241
case OpCodesConstants .LOAD_NONE :
1246
1242
virtualFrame .setObject (++stackTop , PNone .NONE );
@@ -1689,8 +1685,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1689
1685
Object value = virtualFrame .getObject (stackTop );
1690
1686
traceOrProfileReturn (virtualFrame , mutableData , value , tracingEnabled , profilingEnabled );
1691
1687
1692
- if (instrumentation != null && instrumentationRoot instanceof WrapperNode ) {
1693
- notifyRootReturn (virtualFrame , mutableData , value );
1688
+ if (instrumentation != null ) {
1689
+ notifyReturn (virtualFrame , mutableData , instrumentation , beginBci , value );
1694
1690
}
1695
1691
if (isGeneratorOrCoroutine ) {
1696
1692
throw new GeneratorReturnException (value );
@@ -1790,6 +1786,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1790
1786
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1791
1787
bci += oparg ;
1792
1788
oparg = 0 ;
1789
+ if (instrumentation != null ) {
1790
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
1791
+ }
1793
1792
continue ;
1794
1793
case OpCodesConstants .POP_AND_JUMP_IF_FALSE : {
1795
1794
bytecodePopAndJumpIfFalse (virtualFrame , bci , stackTop );
@@ -1805,6 +1804,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1805
1804
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1806
1805
bci += oparg ;
1807
1806
oparg = 0 ;
1807
+ if (instrumentation != null ) {
1808
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
1809
+ }
1808
1810
continue ;
1809
1811
} else {
1810
1812
bci += 3 ;
@@ -1817,6 +1819,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1817
1819
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1818
1820
bci += oparg ;
1819
1821
oparg = 0 ;
1822
+ if (instrumentation != null ) {
1823
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
1824
+ }
1820
1825
continue ;
1821
1826
} else {
1822
1827
bci += 3 ;
@@ -1832,6 +1837,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1832
1837
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1833
1838
bci += oparg ;
1834
1839
oparg = 0 ;
1840
+ if (instrumentation != null ) {
1841
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
1842
+ }
1835
1843
continue ;
1836
1844
} else {
1837
1845
bci += 3 ;
@@ -1847,6 +1855,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1847
1855
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1848
1856
bci += oparg ;
1849
1857
oparg = 0 ;
1858
+ if (instrumentation != null ) {
1859
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
1860
+ }
1850
1861
continue ;
1851
1862
} else {
1852
1863
bci += 3 ;
@@ -1861,6 +1872,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1861
1872
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1862
1873
bci += oparg ;
1863
1874
oparg = 0 ;
1875
+ if (instrumentation != null ) {
1876
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
1877
+ }
1864
1878
continue ;
1865
1879
} else {
1866
1880
virtualFrame .setObject (stackTop --, null );
@@ -1876,6 +1890,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1876
1890
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1877
1891
bci += oparg ;
1878
1892
oparg = 0 ;
1893
+ if (instrumentation != null ) {
1894
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
1895
+ }
1879
1896
continue ;
1880
1897
} else {
1881
1898
virtualFrame .setObject (stackTop --, null );
@@ -1886,6 +1903,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1886
1903
case OpCodesConstants .JUMP_BACKWARD : {
1887
1904
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1888
1905
bci -= oparg ;
1906
+ if (instrumentation != null ) {
1907
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
1908
+ }
1889
1909
if (CompilerDirectives .hasNextTier ()) {
1890
1910
mutableData .loopCount ++;
1891
1911
}
@@ -1951,6 +1971,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1951
1971
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1952
1972
bci += oparg ;
1953
1973
oparg = 0 ;
1974
+ if (instrumentation != null ) {
1975
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
1976
+ }
1954
1977
continue ;
1955
1978
}
1956
1979
break ;
@@ -1972,6 +1995,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
1972
1995
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
1973
1996
bci += oparg ;
1974
1997
oparg = 0 ;
1998
+ if (instrumentation != null ) {
1999
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
2000
+ }
1975
2001
continue ;
1976
2002
}
1977
2003
break ;
@@ -2042,6 +2068,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2042
2068
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
2043
2069
bci += oparg ;
2044
2070
oparg = 0 ;
2071
+ if (instrumentation != null ) {
2072
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
2073
+ }
2045
2074
continue ;
2046
2075
} else {
2047
2076
bci += 3 ;
@@ -2108,7 +2137,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2108
2137
}
2109
2138
traceOrProfileYield (virtualFrame , mutableData , value , tracingEnabled , profilingEnabled );
2110
2139
if (instrumentation != null && instrumentationRoot instanceof WrapperNode ) {
2111
- notifyRootReturn (virtualFrame , mutableData , value );
2140
+ notifyReturn (virtualFrame , mutableData , instrumentation , beginBci , value );
2112
2141
}
2113
2142
return new GeneratorYieldResult (bci + 1 , stackTop , value );
2114
2143
}
@@ -2135,6 +2164,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2135
2164
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
2136
2165
bci += oparg ;
2137
2166
oparg = 0 ;
2167
+ if (instrumentation != null ) {
2168
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
2169
+ }
2138
2170
continue ;
2139
2171
}
2140
2172
}
@@ -2155,6 +2187,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2155
2187
oparg |= Byte .toUnsignedInt (localBC [bci + 1 ]);
2156
2188
bci += oparg ;
2157
2189
oparg = 0 ;
2190
+ if (instrumentation != null ) {
2191
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
2192
+ }
2158
2193
continue ;
2159
2194
}
2160
2195
}
@@ -2174,6 +2209,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2174
2209
// prepare next loop
2175
2210
oparg = 0 ;
2176
2211
bci ++;
2212
+ if (instrumentation != null ) {
2213
+ notifyStatement (virtualFrame , instrumentation , beginBci , bci );
2214
+ }
2177
2215
} catch (PythonExitException | PythonThreadKillException e ) {
2178
2216
throw e ;
2179
2217
} catch (OSRException e ) {
@@ -2182,13 +2220,14 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2182
2220
} catch (Throwable e ) {
2183
2221
if (instrumentation != null ) {
2184
2222
// Need to handle instrumentation frame unwind
2185
- Object result = notifyException (virtualFrame , instrumentation , mutableData , bci , e );
2223
+ Object result = notifyException (virtualFrame , instrumentation , mutableData , beginBci , e );
2186
2224
if (result == ProbeNode .UNWIND_ACTION_REENTER ) {
2187
2225
CompilerDirectives .transferToInterpreter ();
2188
2226
copyArgs (virtualFrame .getArguments (), virtualFrame );
2189
2227
bci = 0 ;
2190
2228
stackTop = getInitialStackTop ();
2191
2229
oparg = 0 ;
2230
+ notifyStatementAfterException (virtualFrame , instrumentation , beginBci );
2192
2231
continue ;
2193
2232
} else if (result != null ) {
2194
2233
return result ;
@@ -2197,7 +2236,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2197
2236
if (e instanceof ThreadDeath ) {
2198
2237
throw e ;
2199
2238
}
2200
- int targetIndex = handleException (virtualFrame , localFrame , isGeneratorOrCoroutine , noTraceOrProfile , mutableData , bciSlot , initialStackTop , beginBci , stackTop , e );
2239
+ int targetIndex = handleException (virtualFrame , localFrame , isGeneratorOrCoroutine , noTraceOrProfile , instrumentation , mutableData , bciSlot , initialStackTop , beginBci , stackTop , e );
2201
2240
if (targetIndex == -1 ) {
2202
2241
throw e ;
2203
2242
}
@@ -2209,7 +2248,8 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
2209
2248
}
2210
2249
2211
2250
@ InliningCutoff
2212
- private int handleException (VirtualFrame virtualFrame , Frame localFrame , boolean isGeneratorOrCoroutine , Assumption noTraceOrProfile , MutableLoopData mutableData , int bciSlot , int initialStackTop ,
2251
+ private int handleException (VirtualFrame virtualFrame , Frame localFrame , boolean isGeneratorOrCoroutine , Assumption noTraceOrProfile , InstrumentationSupport instrumentation ,
2252
+ MutableLoopData mutableData , int bciSlot , int initialStackTop ,
2213
2253
int beginBci , int stackTop , Throwable e ) {
2214
2254
PException pe = null ;
2215
2255
boolean isInteropException = false ;
@@ -2278,9 +2318,19 @@ private int handleException(VirtualFrame virtualFrame, Frame localFrame, boolean
2278
2318
* replaced with the exception
2279
2319
*/
2280
2320
virtualFrame .setObject (targetStackTop , isInteropException ? e : pe );
2321
+
2322
+ if (instrumentation != null ) {
2323
+ int bci = exceptionHandlerRanges [targetIndex ];
2324
+ notifyStatementAfterException (virtualFrame , instrumentation , bci );
2325
+ }
2281
2326
return targetIndex ;
2282
2327
}
2283
2328
2329
+ @ InliningCutoff
2330
+ private void notifyStatementAfterException (VirtualFrame virtualFrame , InstrumentationSupport instrumentation , int bci ) {
2331
+ instrumentation .notifyStatementEnter (virtualFrame , bciToLine (bci ));
2332
+ }
2333
+
2284
2334
@ InliningCutoff
2285
2335
private Object notifyException (VirtualFrame virtualFrame , InstrumentationSupport instrumentation , MutableLoopData mutableData , int bci , Throwable e ) {
2286
2336
try {
@@ -2307,23 +2357,22 @@ private void checkOnReturnExceptionalOrUnwindResult(Object result) {
2307
2357
}
2308
2358
2309
2359
@ InliningCutoff
2310
- private void notifyRootReturn (VirtualFrame virtualFrame , MutableLoopData mutableData , Object value ) {
2360
+ private void notifyReturn (VirtualFrame virtualFrame , MutableLoopData mutableData , InstrumentationSupport instrumentation , int bci , Object value ) {
2361
+ instrumentation .notifyStatementExit (virtualFrame , bciToLine (bci ));
2311
2362
mutableData .setReturnCalled (true );
2312
- WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2313
- wrapper .getProbeNode ().onReturnValue (virtualFrame , value );
2363
+ if (instrumentationRoot instanceof WrapperNode ) {
2364
+ WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2365
+ wrapper .getProbeNode ().onReturnValue (virtualFrame , value );
2366
+ }
2314
2367
}
2315
2368
2316
2369
@ InliningCutoff
2317
- private void notifyStatement (VirtualFrame virtualFrame , InstrumentationSupport instrumentation , MutableLoopData mutableData , int bci ) {
2318
- int line = bciToLine (bci );
2319
- int pastLine = mutableData .getPastLine ();
2320
- instrumentation .notifyStatement (virtualFrame , pastLine , line );
2321
- mutableData .setPastLine (line );
2322
- mutableData .setPastBci (bci );
2370
+ private void notifyStatement (VirtualFrame virtualFrame , InstrumentationSupport instrumentation , int prevBci , int nextBci ) {
2371
+ instrumentation .notifyStatement (virtualFrame , bciToLine (prevBci ), bciToLine (nextBci ));
2323
2372
}
2324
2373
2325
2374
@ InliningCutoff
2326
- private Object enterRoot (VirtualFrame virtualFrame ) {
2375
+ private Object notifyEnter (VirtualFrame virtualFrame , InstrumentationSupport instrumentation , int initialBci ) {
2327
2376
if (instrumentationRoot instanceof WrapperNode ) {
2328
2377
WrapperNode wrapper = (WrapperNode ) instrumentationRoot ;
2329
2378
try {
@@ -2340,6 +2389,13 @@ private Object enterRoot(VirtualFrame virtualFrame) {
2340
2389
}
2341
2390
}
2342
2391
}
2392
+ int line = bciToLine (initialBci );
2393
+ try {
2394
+ instrumentation .notifyStatementEnter (virtualFrame , line );
2395
+ } catch (Throwable t ) {
2396
+ instrumentation .notifyException (virtualFrame , line , t );
2397
+ throw t ;
2398
+ }
2343
2399
return null ;
2344
2400
}
2345
2401
@@ -4921,12 +4977,10 @@ public Object readSelf(VirtualFrame virtualFrame) {
4921
4977
}
4922
4978
}
4923
4979
4924
- @ TruffleBoundary
4925
4980
public int bciToLine (int bci ) {
4926
4981
return co .bciToLine (bci );
4927
4982
}
4928
4983
4929
- @ TruffleBoundary
4930
4984
public int getFirstLineno () {
4931
4985
return co .startLine ;
4932
4986
}
0 commit comments