290
290
import com .oracle .truffle .api .frame .FrameDescriptor ;
291
291
import com .oracle .truffle .api .frame .VirtualFrame ;
292
292
import com .oracle .truffle .api .instrumentation .GenerateWrapper .YieldException ;
293
- import com .oracle .truffle .api .instrumentation .InstrumentableNode ;
294
293
import com .oracle .truffle .api .instrumentation .ProbeNode ;
295
294
import com .oracle .truffle .api .instrumentation .StandardTags .StatementTag ;
296
- import com .oracle .truffle .api .instrumentation .Tag ;
297
295
import com .oracle .truffle .api .interop .InteropLibrary ;
298
296
import com .oracle .truffle .api .nodes .BytecodeOSRNode ;
299
297
import com .oracle .truffle .api .nodes .ControlFlowException ;
@@ -1816,17 +1814,17 @@ public int getBci(Frame frame) {
1816
1814
}
1817
1815
1818
1816
@ Override
1819
- public InstrumentableNode materializeInstrumentableNodes (Set <Class <? extends Tag >> materializedTags ) {
1817
+ public void prepareForInstrumentation (Set <Class <?>> tags ) {
1820
1818
InstrumentationSupport info = this .instrumentation ;
1821
- if (info == null && materializedTags .contains (StatementTag .class )) {
1819
+ if (info == null && tags .contains (StatementTag .class )) {
1822
1820
Lock lock = getLock ();
1823
1821
lock .lock ();
1824
1822
try {
1825
1823
info = this .instrumentation ;
1826
1824
// double checked locking
1827
1825
if (info == null ) {
1828
1826
generifyBytecodeLevelInlining ();
1829
- this .instrumentation = info = insert (new InstrumentationSupport (getMethodVersion (), frameDescriptor ));
1827
+ this .instrumentation = info = insert (new InstrumentationSupport (getMethodVersion ()));
1830
1828
// the debug info contains instrumentable nodes so we need to notify for
1831
1829
// instrumentation updates.
1832
1830
notifyInserted (info );
@@ -1835,7 +1833,6 @@ public InstrumentableNode materializeInstrumentableNodes(Set<Class<? extends Tag
1835
1833
lock .unlock ();
1836
1834
}
1837
1835
}
1838
- return this ;
1839
1836
}
1840
1837
1841
1838
private static boolean takeBranchRef1 (StaticObject operand , int opcode ) {
@@ -2018,15 +2015,11 @@ private int beforeJumpChecks(VirtualFrame frame, int curBCI, int targetBCI, int
2018
2015
if (CompilerDirectives .inInterpreter () && BytecodeOSRNode .pollOSRBackEdge (this , REPORT_LOOP_STRIDE )) {
2019
2016
livenessAnalysis .catchUpOSR (frame , targetBCI , skipLivenessActions );
2020
2017
Object osrResult ;
2021
- StoredWrapperNode storedWrapperNode = null ;
2022
2018
try {
2023
- storedWrapperNode = storeWrapperNodeIfSet (frame , instrument );
2024
2019
osrResult = BytecodeOSRNode .tryOSR (this , targetBCI , new EspressoOSRInterpreterState (top , nextStatementIndex ), null , frame );
2025
2020
} catch (Throwable any ) {
2026
2021
// Has already been guest-handled in OSR. Shortcut out of the method.
2027
2022
throw new EspressoOSRReturnException (any );
2028
- } finally {
2029
- restoreWrapperNode (frame , storedWrapperNode , instrument );
2030
2023
}
2031
2024
if (osrResult != null ) {
2032
2025
throw new EspressoOSRReturnException (osrResult );
@@ -2039,32 +2032,6 @@ private int beforeJumpChecks(VirtualFrame frame, int curBCI, int targetBCI, int
2039
2032
return nextStatementIndex ;
2040
2033
}
2041
2034
2042
- private static void restoreWrapperNode (VirtualFrame frame , StoredWrapperNode storedWrapperNode , InstrumentationSupport instrument ) {
2043
- // restore wrapper nodes after OSR
2044
- if (storedWrapperNode != null ) {
2045
- frame .setAuxiliarySlot (instrument .wrapperSlotIndex , storedWrapperNode .storedWrapperNode ());
2046
- if (InstrumentationSupport .assertionsEnabled ()) {
2047
- frame .setAuxiliarySlot (instrument .indexSlotIndex , storedWrapperNode .storedIndex ());
2048
- }
2049
- }
2050
- }
2051
-
2052
- private static StoredWrapperNode storeWrapperNodeIfSet (VirtualFrame frame , InstrumentationSupport instrument ) {
2053
- // check if we have stores wrapper nodes and index in the frame and store if so
2054
- if (instrument != null ) {
2055
- Object storedWrapperNode = frame .getAuxiliarySlot (instrument .wrapperSlotIndex );
2056
- int storedIndex = 0 ;
2057
- if (InstrumentationSupport .assertionsEnabled ()) {
2058
- storedIndex = (int ) frame .getAuxiliarySlot (instrument .indexSlotIndex );
2059
- }
2060
- return new StoredWrapperNode (storedWrapperNode , storedIndex );
2061
- }
2062
- return null ;
2063
- }
2064
-
2065
- private record StoredWrapperNode (Object storedWrapperNode , int storedIndex ) {
2066
- }
2067
-
2068
2035
@ ExplodeLoop
2069
2036
@ SuppressWarnings ("unused" )
2070
2037
private ExceptionHandler resolveExceptionHandlers (int bci , StaticObject ex ) {
@@ -2938,8 +2905,6 @@ private boolean lockIsHeld() {
2938
2905
2939
2906
static final class InstrumentationSupport extends EspressoNode {
2940
2907
static final int NO_STATEMENT = -1 ;
2941
- private static final Object WRAPPER_SLOT_KEY = new Object ();
2942
- private static final Object WRAPPER_INDEX_SLOT_KEY = new Object ();
2943
2908
2944
2909
@ SuppressWarnings ("all" )
2945
2910
private static boolean assertionsEnabled () {
@@ -2948,22 +2913,16 @@ private static boolean assertionsEnabled() {
2948
2913
return areAssertionsEnabled ;
2949
2914
}
2950
2915
2951
- @ Children private final EspressoBaseStatementNode [] statementNodes ;
2916
+ @ Children private final EspressoStatementNode [] statementNodes ;
2952
2917
@ Child private MapperBCI hookBCIToNodeIndex ;
2953
2918
2954
2919
private final EspressoContext context ;
2955
2920
private final MethodVersion method ;
2956
2921
2957
- private final int wrapperSlotIndex ;
2958
- private final int indexSlotIndex ;
2959
-
2960
- InstrumentationSupport (MethodVersion method , FrameDescriptor frameDescriptor ) {
2922
+ InstrumentationSupport (MethodVersion method ) {
2961
2923
this .method = method ;
2962
2924
this .context = method .getMethod ().getContext ();
2963
2925
2964
- this .wrapperSlotIndex = frameDescriptor .findOrAddAuxiliarySlot (WRAPPER_SLOT_KEY );
2965
- this .indexSlotIndex = frameDescriptor .findOrAddAuxiliarySlot (WRAPPER_INDEX_SLOT_KEY );
2966
-
2967
2926
LineNumberTableAttribute table = method .getLineNumberTableAttribute ();
2968
2927
2969
2928
if (table != LineNumberTableAttribute .EMPTY ) {
@@ -2974,9 +2933,8 @@ private static boolean assertionsEnabled() {
2974
2933
Arrays .fill (seenLines , -1 );
2975
2934
int maxSeenLine = -1 ;
2976
2935
2977
- this .statementNodes = new EspressoBaseStatementNode [entries .size ()];
2978
- this .hookBCIToNodeIndex = new MapperBCI (table );
2979
-
2936
+ EspressoStatementNode [] statements = new EspressoStatementNode [entries .size ()];
2937
+ MapperBCI mapper = new MapperBCI (table );
2980
2938
for (int i = 0 ; i < entries .size (); i ++) {
2981
2939
LineNumberTableAttribute .Entry entry = entries .get (i );
2982
2940
int lineNumber = entry .getLineNumber ();
@@ -2991,11 +2949,13 @@ private static boolean assertionsEnabled() {
2991
2949
}
2992
2950
}
2993
2951
if (!seen ) {
2994
- statementNodes [ hookBCIToNodeIndex .initIndex (i , entry .getBCI ())] = new EspressoStatementNode (entry .getBCI (), lineNumber );
2952
+ statements [ mapper .initIndex (i , entry .getBCI ())] = new EspressoStatementNode (entry .getBCI (), method . getMethod (). getSource (). createSection ( lineNumber ) );
2995
2953
seenLines [i ] = lineNumber ;
2996
2954
maxSeenLine = Math .max (maxSeenLine , lineNumber );
2997
2955
}
2998
2956
}
2957
+ this .hookBCIToNodeIndex = mapper ;
2958
+ this .statementNodes = statements ;
2999
2959
} else {
3000
2960
this .statementNodes = null ;
3001
2961
this .hookBCIToNodeIndex = null ;
@@ -3040,22 +3000,18 @@ public void notifyResume(VirtualFrame frame, AbstractInstrumentableBytecodeNode
3040
3000
}
3041
3001
3042
3002
void notifyExceptionAt (VirtualFrame frame , Throwable t , int statementIndex ) {
3043
- assert (int ) frame .getAuxiliarySlot (indexSlotIndex ) == statementIndex ;
3044
- WrapperNode wrapperNode = (WrapperNode ) frame .getAuxiliarySlot (wrapperSlotIndex );
3045
- if (wrapperNode == null ) {
3003
+ ProbeNode probeNode = getProbeAt (statementIndex );
3004
+ if (probeNode == null ) {
3046
3005
return ;
3047
3006
}
3048
- ProbeNode probeNode = wrapperNode .getProbeNode ();
3049
3007
probeNode .onReturnExceptionalOrUnwind (frame , t , false );
3050
3008
}
3051
3009
3052
3010
void notifyYieldAt (VirtualFrame frame , Object o , int statementIndex ) {
3053
- assert (int ) frame .getAuxiliarySlot (indexSlotIndex ) == statementIndex ;
3054
- WrapperNode wrapperNode = (WrapperNode ) frame .getAuxiliarySlot (wrapperSlotIndex );
3055
- if (wrapperNode == null ) {
3011
+ ProbeNode probeNode = getProbeAt (statementIndex );
3012
+ if (probeNode == null ) {
3056
3013
return ;
3057
3014
}
3058
- ProbeNode probeNode = wrapperNode .getProbeNode ();
3059
3015
probeNode .onYield (frame , o );
3060
3016
}
3061
3017
@@ -3076,21 +3032,10 @@ public void notifyFieldAccess(VirtualFrame frame, int index, Field field, Static
3076
3032
}
3077
3033
3078
3034
private void enterAt (VirtualFrame frame , int index ) {
3079
- WrapperNode wrapperNode = getWrapperAt (index );
3080
- /*
3081
- * We need to store this wrapper node in the frame to make sure we exit on the same
3082
- * wrapper. Wrapper nodes can be replaced at arbitrary time for example when the
3083
- * debugger is disposed and the session is ended.
3084
- */
3085
- frame .setAuxiliarySlot (wrapperSlotIndex , wrapperNode );
3086
- // only add wrapper index in frame when assertions enabled
3087
- if (assertionsEnabled ()) {
3088
- frame .setAuxiliarySlot (indexSlotIndex , index );
3089
- }
3090
- if (wrapperNode == null ) {
3035
+ ProbeNode probeNode = getProbeAt (index );
3036
+ if (probeNode == null ) {
3091
3037
return ;
3092
3038
}
3093
- ProbeNode probeNode = wrapperNode .getProbeNode ();
3094
3039
try {
3095
3040
probeNode .onEnter (frame );
3096
3041
} catch (Throwable t ) {
@@ -3109,21 +3054,10 @@ private void enterAt(VirtualFrame frame, int index) {
3109
3054
}
3110
3055
3111
3056
private void resumeAt (VirtualFrame frame , int index ) {
3112
- WrapperNode wrapperNode = getWrapperAt (index );
3113
- /*
3114
- * We need to store this wrapper node in the frame to make sure we exit on the same
3115
- * wrapper. Wrapper nodes can be replaced at arbitrary time for example when the
3116
- * debugger is disposed and the session is ended.
3117
- */
3118
- frame .setAuxiliarySlot (wrapperSlotIndex , wrapperNode );
3119
- // only add wrapper index in frame when assertions enabled
3120
- if (assertionsEnabled ()) {
3121
- frame .setAuxiliarySlot (indexSlotIndex , index );
3122
- }
3123
- if (wrapperNode == null ) {
3057
+ ProbeNode probeNode = getProbeAt (index );
3058
+ if (probeNode == null ) {
3124
3059
return ;
3125
3060
}
3126
- ProbeNode probeNode = wrapperNode .getProbeNode ();
3127
3061
try {
3128
3062
probeNode .onResume (frame );
3129
3063
} catch (Throwable t ) {
@@ -3142,12 +3076,10 @@ private void resumeAt(VirtualFrame frame, int index) {
3142
3076
}
3143
3077
3144
3078
private void exitAt (VirtualFrame frame , int index , Object returnValue ) {
3145
- assert (int ) frame .getAuxiliarySlot (indexSlotIndex ) == index ;
3146
- WrapperNode wrapperNode = (WrapperNode ) frame .getAuxiliarySlot (wrapperSlotIndex );
3147
- if (wrapperNode == null ) {
3079
+ ProbeNode probeNode = getProbeAt (index );
3080
+ if (probeNode == null ) {
3148
3081
return ;
3149
3082
}
3150
- ProbeNode probeNode = wrapperNode .getProbeNode ();
3151
3083
try {
3152
3084
probeNode .onReturnValue (frame , returnValue );
3153
3085
} catch (Throwable t ) {
@@ -3190,21 +3122,16 @@ int getStartStatementIndex(int startBci) {
3190
3122
return hookBCIToNodeIndex .lookupBucket (startBci );
3191
3123
}
3192
3124
3193
- /*
3194
- * This method must only be called when entering a node. The returned node should be stored
3195
- * in the frame in the WRAPPER_SLOT along with the index. This is needed to make sure that
3196
- * we always exit on the same wrapper.
3197
- */
3198
- private WrapperNode getWrapperAt (int index ) {
3125
+ private ProbeNode getProbeAt (int index ) {
3199
3126
if (statementNodes == null || index < 0 ) {
3200
3127
return null ;
3201
3128
}
3202
- EspressoBaseStatementNode node = statementNodes [index ];
3203
- if (!( node instanceof WrapperNode ) ) {
3129
+ EspressoStatementNode node = statementNodes [index ];
3130
+ if (node == null ) {
3204
3131
return null ;
3205
3132
}
3206
3133
CompilerAsserts .partialEvaluationConstant (node );
3207
- return (( WrapperNode ) node );
3134
+ return node . findProbe ( );
3208
3135
}
3209
3136
}
3210
3137
0 commit comments