@@ -95,178 +95,4 @@ public static void processFullBuffers() {
95
95
96
96
SubstrateJVM .getSamplerBufferPool ().adjustBufferCount ();
97
97
}
98
- <<<<<<< HEAD
99
- =======
100
-
101
- @ Uninterruptible (reason = "The callee explicitly does a safepoint check." , calleeMustBe = false )
102
- private static void safepointCheck () {
103
- safepointCheck0 ();
104
- }
105
-
106
- private static void safepointCheck0 () {
107
- }
108
-
109
- @ Uninterruptible (reason = "Prevent JFR recording and epoch change." )
110
- private static void serializeStackTraces (SamplerBuffer rawStackTraceBuffer ) {
111
- assert rawStackTraceBuffer .isNonNull ();
112
-
113
- Pointer end = rawStackTraceBuffer .getPos ();
114
- Pointer current = SamplerBufferAccess .getDataStart (rawStackTraceBuffer );
115
- while (current .belowThan (end )) {
116
- Pointer entryStart = current ;
117
- assert entryStart .unsignedRemainder (Long .BYTES ).equal (0 );
118
-
119
- /* Sample hash. */
120
- int sampleHash = current .readInt (0 );
121
- current = current .add (Integer .BYTES );
122
-
123
- /* Is truncated. */
124
- boolean isTruncated = current .readInt (0 ) == 1 ;
125
- current = current .add (Integer .BYTES );
126
-
127
- /* Sample size, excluding the header and the end marker. */
128
- int sampleSize = current .readInt (0 );
129
- current = current .add (Integer .BYTES );
130
-
131
- /* Padding. */
132
- current = current .add (Integer .BYTES );
133
-
134
- /* Tick. */
135
- long sampleTick = current .readLong (0 );
136
- current = current .add (Long .BYTES );
137
-
138
- /* Event thread. */
139
- long threadId = current .readLong (0 );
140
- current = current .add (Long .BYTES );
141
-
142
- /* Thread state. */
143
- long threadState = current .readLong (0 );
144
- current = current .add (Long .BYTES );
145
-
146
- assert current .subtract (entryStart ).equal (SamplerSampleWriter .getHeaderSize ());
147
-
148
- CIntPointer statusPtr = StackValue .get (CIntPointer .class );
149
- JfrStackTraceTableEntry entry = SubstrateJVM .getStackTraceRepo ().getOrPutStackTrace (current , WordFactory .unsigned (sampleSize ), sampleHash , statusPtr );
150
- long stackTraceId = entry .isNull () ? 0 : entry .getId ();
151
-
152
- int status = statusPtr .read ();
153
- if (status == JfrStackTraceTableEntryStatus .INSERTED || status == JfrStackTraceTableEntryStatus .EXISTING_RAW ) {
154
- /* Walk the IPs and serialize the stacktrace. */
155
- assert current .add (sampleSize ).belowThan (end );
156
- boolean serialized = serializeStackTrace (current , sampleSize , isTruncated , stackTraceId );
157
- if (serialized ) {
158
- SubstrateJVM .getStackTraceRepo ().commitSerializedStackTrace (entry );
159
- }
160
- } else {
161
- /* Processing is not needed: skip the rest of the data. */
162
- assert status == JfrStackTraceTableEntryStatus .EXISTING_SERIALIZED || status == JfrStackTraceTableEntryStatus .INSERT_FAILED ;
163
- }
164
- current = current .add (sampleSize );
165
-
166
- /*
167
- * Emit an event depending on the end marker of the raw stack trace. This needs to be
168
- * done here because the sampler can't emit the event directly.
169
- */
170
- long endMarker = current .readLong (0 );
171
- if (endMarker == SamplerSampleWriter .EXECUTION_SAMPLE_END ) {
172
- if (stackTraceId != 0 ) {
173
- ExecutionSampleEvent .writeExecutionSample (sampleTick , threadId , stackTraceId , threadState );
174
- } else {
175
- JfrThreadLocal .increaseMissedSamples ();
176
- }
177
- } else {
178
- assert endMarker == SamplerSampleWriter .JFR_STACK_TRACE_END ;
179
- }
180
- current = current .add (SamplerSampleWriter .END_MARKER_SIZE );
181
- }
182
-
183
- SamplerBufferAccess .reinitialize (rawStackTraceBuffer );
184
- }
185
-
186
- @ Uninterruptible (reason = "Prevent JFR recording and epoch change." )
187
- private static boolean serializeStackTrace (Pointer rawStackTrace , int sampleSize , boolean isTruncated , long stackTraceId ) {
188
- assert sampleSize % Long .BYTES == 0 ;
189
-
190
- JfrBuffer targetBuffer = SubstrateJVM .getStackTraceRepo ().getCurrentBuffer ();
191
- if (targetBuffer .isNull ()) {
192
- return false ;
193
- }
194
-
195
- /*
196
- * One IP may correspond to multiple Java-level stack frames. We need to precompute the
197
- * number of stack trace elements because the count can't be patched later on
198
- * (JfrNativeEventWriter.putInt() would not necessarily reserve enough bytes).
199
- */
200
- int numStackTraceElements = visitRawStackTrace (rawStackTrace , sampleSize , WordFactory .nullPointer ());
201
- if (numStackTraceElements == 0 ) {
202
- return false ;
203
- }
204
-
205
- JfrNativeEventWriterData data = StackValue .get (JfrNativeEventWriterData .class );
206
- JfrNativeEventWriterDataAccess .initialize (data , targetBuffer );
207
- JfrNativeEventWriter .putLong (data , stackTraceId );
208
- JfrNativeEventWriter .putBoolean (data , isTruncated );
209
- JfrNativeEventWriter .putInt (data , numStackTraceElements );
210
- visitRawStackTrace (rawStackTrace , sampleSize , data );
211
- boolean success = JfrNativeEventWriter .commit (data );
212
-
213
- /* Buffer can get replaced with a larger one. */
214
- SubstrateJVM .getStackTraceRepo ().setCurrentBuffer (data .getJfrBuffer ());
215
- return success ;
216
- }
217
-
218
- @ Uninterruptible (reason = "Prevent JFR recording and epoch change." )
219
- private static int visitRawStackTrace (Pointer rawStackTrace , int sampleSize , JfrNativeEventWriterData data ) {
220
- int numStackTraceElements = 0 ;
221
- Pointer rawStackTraceEnd = rawStackTrace .add (sampleSize );
222
- Pointer ipPtr = rawStackTrace ;
223
- while (ipPtr .belowThan (rawStackTraceEnd )) {
224
- long ip = ipPtr .readLong (0 );
225
- numStackTraceElements += visitFrame (data , ip );
226
- ipPtr = ipPtr .add (Long .BYTES );
227
- }
228
- return numStackTraceElements ;
229
- }
230
-
231
- @ Uninterruptible (reason = "Prevent JFR recording, epoch change, and that the GC frees the CodeInfo." )
232
- private static int visitFrame (JfrNativeEventWriterData data , long address ) {
233
- CodePointer ip = WordFactory .pointer (address );
234
- UntetheredCodeInfo untetheredInfo = CodeInfoTable .lookupCodeInfo (ip );
235
- if (untetheredInfo .isNull ()) {
236
- /* Unknown frame. Must not happen for AOT-compiled code. */
237
- VMError .shouldNotReachHere ("Stack walk must walk only frames of known code." );
238
- }
239
-
240
- Object tether = CodeInfoAccess .acquireTether (untetheredInfo );
241
- try {
242
- CodeInfo tetheredCodeInfo = CodeInfoAccess .convert (untetheredInfo , tether );
243
- return visitFrame (data , tetheredCodeInfo , ip );
244
- } finally {
245
- CodeInfoAccess .releaseTether (untetheredInfo , tether );
246
- }
247
- }
248
-
249
- @ Uninterruptible (reason = "Prevent JFR recording and epoch change." )
250
- private static int visitFrame (JfrNativeEventWriterData data , CodeInfo codeInfo , CodePointer ip ) {
251
- int numStackTraceElements = 0 ;
252
- FRAME_INFO_CURSOR .initialize (codeInfo , ip );
253
- while (FRAME_INFO_CURSOR .advance ()) {
254
- if (data .isNonNull ()) {
255
- FrameInfoQueryResult frame = FRAME_INFO_CURSOR .get ();
256
- serializeStackTraceElement (data , frame );
257
- }
258
- numStackTraceElements ++;
259
- }
260
- return numStackTraceElements ;
261
- }
262
-
263
- @ Uninterruptible (reason = "Prevent JFR recording and epoch change." )
264
- private static void serializeStackTraceElement (JfrNativeEventWriterData data , FrameInfoQueryResult stackTraceElement ) {
265
- long methodId = SubstrateJVM .getMethodRepo ().getMethodId (stackTraceElement .getSourceClass (), stackTraceElement .getSourceMethodName (), stackTraceElement .getMethodId ());
266
- JfrNativeEventWriter .putLong (data , methodId );
267
- JfrNativeEventWriter .putInt (data , stackTraceElement .getSourceLineNumber ());
268
- JfrNativeEventWriter .putInt (data , stackTraceElement .getBci ());
269
- JfrNativeEventWriter .putLong (data , JfrFrameType .FRAME_AOT_COMPILED .getId ());
270
- }
271
- >>>>>>> 36915 eee070d9433c26d7ec247b8cc08b98b89ae
272
98
}
0 commit comments