169 PcDesc* pc_desc = nm->pc_desc_near(fr->pc() + 1); |
169 PcDesc* pc_desc = nm->pc_desc_near(fr->pc() + 1); |
170 |
170 |
171 // Now do we have a useful PcDesc? |
171 // Now do we have a useful PcDesc? |
172 if (pc_desc == NULL || |
172 if (pc_desc == NULL || |
173 pc_desc->scope_decode_offset() == DebugInformationRecorder::serialized_null) { |
173 pc_desc->scope_decode_offset() == DebugInformationRecorder::serialized_null) { |
174 // No debug information available for this pc |
174 // No debug information is available for this PC. |
175 // vframeStream would explode if we try and walk the frames. |
175 // |
|
176 // vframeStreamCommon::fill_from_frame() will decode the frame depending |
|
177 // on the state of the thread. |
|
178 // |
|
179 // Case #1: If the thread is in Java (state == _thread_in_Java), then |
|
180 // the vframeStreamCommon object will be filled as if the frame were a native |
|
181 // compiled frame. Therefore, no debug information is needed. |
|
182 // |
|
183 // Case #2: If the thread is in any other state, then two steps will be performed: |
|
184 // - if asserts are enabled, found_bad_method_frame() will be called and |
|
185 // the assert in found_bad_method_frame() will be triggered; |
|
186 // - if asserts are disabled, the vframeStreamCommon object will be filled |
|
187 // as if it were a native compiled frame. |
|
188 // |
|
189 // Case (2) is similar to the way interpreter frames are processed in |
|
190 // vframeStreamCommon::fill_from_interpreter_frame in case no valid BCI |
|
191 // was found for an interpreted frame. If asserts are enabled, the assert |
|
192 // in found_bad_method_frame() will be triggered. If asserts are disabled, |
|
193 // the vframeStreamCommon object will be filled afterwards as if the |
|
194 // interpreter were at the point of entering into the method. |
176 return false; |
195 return false; |
177 } |
196 } |
178 |
197 |
179 // This PcDesc is useful however we must adjust the frame's pc |
198 // This PcDesc is useful however we must adjust the frame's pc |
180 // so that the vframeStream lookups will use this same pc |
199 // so that the vframeStream lookups will use this same pc |
227 // NOTE: there is something to be said for the approach that |
246 // NOTE: there is something to be said for the approach that |
228 // if we don't find a valid bci then the method is not likely |
247 // if we don't find a valid bci then the method is not likely |
229 // a valid method. Then again we may have caught an interpreter |
248 // a valid method. Then again we may have caught an interpreter |
230 // frame in the middle of construction and the bci field is |
249 // frame in the middle of construction and the bci field is |
231 // not yet valid. |
250 // not yet valid. |
232 |
|
233 *method_p = method; |
|
234 if (!method->is_valid_method()) return false; |
251 if (!method->is_valid_method()) return false; |
|
252 *method_p = method; // If the Method* found is invalid, it is |
|
253 // ignored by forte_fill_call_trace_given_top(). |
|
254 // So set method_p only if the Method is valid. |
235 |
255 |
236 address bcp = fr->interpreter_frame_bcp(); |
256 address bcp = fr->interpreter_frame_bcp(); |
237 int bci = method->validate_bci_from_bcp(bcp); |
257 int bci = method->validate_bci_from_bcp(bcp); |
238 |
258 |
239 // note: bci is set to -1 if not a valid bci |
259 // note: bci is set to -1 if not a valid bci |
243 |
263 |
244 return false; |
264 return false; |
245 } |
265 } |
246 |
266 |
247 |
267 |
248 // Determine if 'fr' can be used to find an initial Java frame. |
268 // Determine if a Java frame can be found starting with the frame 'fr'. |
249 // Return false if it can not find a fully decipherable Java frame |
269 // |
250 // (in other words a frame that isn't safe to use in a vframe stream). |
270 // Check the return value of find_initial_Java_frame and the value of |
251 // Obviously if it can't even find a Java frame false will also be returned. |
271 // 'method_p' to decide on how use the results returned by this method. |
252 // |
272 // |
253 // If we find a Java frame decipherable or not then by definition we have |
273 // If 'method_p' is not NULL, an initial Java frame has been found and |
254 // identified a method and that will be returned to the caller via method_p. |
274 // the stack can be walked starting from that initial frame. In this case, |
255 // If we can determine a bci that is returned also. (Hmm is it possible |
275 // 'method_p' points to the Method that the initial frame belongs to and |
256 // to return a method and bci and still return false? ) |
276 // the initial Java frame is returned in initial_frame_p. |
257 // |
277 // |
258 // The initial Java frame we find (if any) is return via initial_frame_p. |
278 // find_initial_Java_frame() returns true if a Method has been found (i.e., |
259 // |
279 // 'method_p' is not NULL) and the initial frame that belongs to that Method |
|
280 // is decipherable. |
|
281 // |
|
282 // A frame is considered to be decipherable: |
|
283 // |
|
284 // - if the frame is a compiled frame and a PCDesc is available; |
|
285 // |
|
286 // - if the frame is an interpreter frame that is valid or the thread is |
|
287 // state (_thread_in_native || state == _thread_in_vm || state == _thread_blocked). |
|
288 // |
|
289 // Note that find_initial_Java_frame() can return false even if an initial |
|
290 // Java method was found (e.g., there is no PCDesc available for the method). |
|
291 // |
|
292 // If 'method_p' is NULL, it was not possible to find a Java frame when |
|
293 // walking the stack starting from 'fr'. In this case find_initial_Java_frame |
|
294 // returns false. |
260 |
295 |
261 static bool find_initial_Java_frame(JavaThread* thread, |
296 static bool find_initial_Java_frame(JavaThread* thread, |
262 frame* fr, |
297 frame* fr, |
263 frame* initial_frame_p, |
298 frame* initial_frame_p, |
264 Method** method_p, |
299 Method** method_p, |
273 *method_p = NULL; |
308 *method_p = NULL; |
274 |
309 |
275 // On the initial call to this method the frame we get may not be |
310 // On the initial call to this method the frame we get may not be |
276 // recognizable to us. This should only happen if we are in a JRT_LEAF |
311 // recognizable to us. This should only happen if we are in a JRT_LEAF |
277 // or something called by a JRT_LEAF method. |
312 // or something called by a JRT_LEAF method. |
278 |
|
279 |
|
280 |
313 |
281 frame candidate = *fr; |
314 frame candidate = *fr; |
282 |
315 |
283 // If the starting frame we were given has no codeBlob associated with |
316 // If the starting frame we were given has no codeBlob associated with |
284 // it see if we can find such a frame because only frames with codeBlobs |
317 // it see if we can find such a frame because only frames with codeBlobs |
330 if (candidate.cb()->is_nmethod()) { |
363 if (candidate.cb()->is_nmethod()) { |
331 |
364 |
332 nmethod* nm = (nmethod*) candidate.cb(); |
365 nmethod* nm = (nmethod*) candidate.cb(); |
333 *method_p = nm->method(); |
366 *method_p = nm->method(); |
334 |
367 |
335 // If the frame isn't fully decipherable then the default |
368 // If the frame is not decipherable, then the value of -1 |
336 // value for the bci is a signal that we don't have a bci. |
369 // for the BCI is used to signal that no BCI is available. |
337 // If we have a decipherable frame this bci value will |
370 // Furthermore, the method returns false in this case. |
|
371 // |
|
372 // If a decipherable frame is available, the BCI value will |
338 // not be used. |
373 // not be used. |
339 |
374 |
340 *bci_p = -1; |
375 *bci_p = -1; |
341 |
376 |
342 *initial_frame_p = candidate; |
377 *initial_frame_p = candidate; |
343 |
378 |
344 // Native wrapper code is trivial to decode by vframeStream |
379 // Native wrapper code is trivial to decode by vframeStream |
345 |
380 |
346 if (nm->is_native_method()) return true; |
381 if (nm->is_native_method()) return true; |
347 |
382 |
348 // If it isn't decipherable then we have found a pc that doesn't |
383 // If the frame is not decipherable, then a PC was found |
349 // have a PCDesc that can get us a bci however we did find |
384 // that does not have a PCDesc from which a BCI can be obtained. |
350 // a method |
385 // Nevertheless, a Method was found. |
351 |
386 |
352 if (!is_decipherable_compiled_frame(thread, &candidate, nm)) { |
387 if (!is_decipherable_compiled_frame(thread, &candidate, nm)) { |
353 return false; |
388 return false; |
354 } |
389 } |
355 |
390 |
356 // is_decipherable_compiled_frame may modify candidate's pc |
391 // is_decipherable_compiled_frame may modify candidate's pc |
357 *initial_frame_p = candidate; |
392 *initial_frame_p = candidate; |
358 |
393 |
359 assert(nm->pc_desc_at(candidate.pc()) != NULL, "if it's decipherable then pc must be valid"); |
394 assert(nm->pc_desc_at(candidate.pc()) != NULL, "debug information must be available if the frame is decipherable"); |
360 |
395 |
361 return true; |
396 return true; |
362 } |
397 } |
363 |
398 |
364 // Must be some stub frame that we don't care about |
399 // Must be some stub frame that we don't care about |
384 frame top_frame) { |
419 frame top_frame) { |
385 NoHandleMark nhm; |
420 NoHandleMark nhm; |
386 |
421 |
387 frame initial_Java_frame; |
422 frame initial_Java_frame; |
388 Method* method; |
423 Method* method; |
389 int bci; |
424 int bci = -1; // assume BCI is not available for method |
|
425 // update with correct information if available |
390 int count; |
426 int count; |
391 |
427 |
392 count = 0; |
428 count = 0; |
393 assert(trace->frames != NULL, "trace->frames must be non-NULL"); |
429 assert(trace->frames != NULL, "trace->frames must be non-NULL"); |
394 |
430 |
395 bool fully_decipherable = find_initial_Java_frame(thd, &top_frame, &initial_Java_frame, &method, &bci); |
431 // Walk the stack starting from 'top_frame' and search for an initial Java frame. |
396 |
432 find_initial_Java_frame(thd, &top_frame, &initial_Java_frame, &method, &bci); |
397 // The frame might not be walkable but still recovered a method |
433 |
398 // (e.g. an nmethod with no scope info for the pc) |
434 // Check if a Java Method has been found. |
399 |
|
400 if (method == NULL) return; |
435 if (method == NULL) return; |
401 |
436 |
402 if (!method->is_valid_method()) { |
437 if (!method->is_valid_method()) { |
403 trace->num_frames = ticks_GC_active; // -2 |
438 trace->num_frames = ticks_GC_active; // -2 |
404 return; |
439 return; |
405 } |
|
406 |
|
407 // We got a Java frame however it isn't fully decipherable |
|
408 // so it won't necessarily be safe to use it for the |
|
409 // initial frame in the vframe stream. |
|
410 |
|
411 if (!fully_decipherable) { |
|
412 // Take whatever method the top-frame decoder managed to scrape up. |
|
413 // We look further at the top frame only if non-safepoint |
|
414 // debugging information is available. |
|
415 count++; |
|
416 trace->num_frames = count; |
|
417 trace->frames[0].method_id = method->find_jmethod_id_or_null(); |
|
418 if (!method->is_native()) { |
|
419 trace->frames[0].lineno = bci; |
|
420 } else { |
|
421 trace->frames[0].lineno = -3; |
|
422 } |
|
423 |
|
424 if (!initial_Java_frame.safe_for_sender(thd)) return; |
|
425 |
|
426 RegisterMap map(thd, false); |
|
427 initial_Java_frame = initial_Java_frame.sender(&map); |
|
428 } |
440 } |
429 |
441 |
430 vframeStreamForte st(thd, initial_Java_frame, false); |
442 vframeStreamForte st(thd, initial_Java_frame, false); |
431 |
443 |
432 for (; !st.at_end() && count < depth; st.forte_next(), count++) { |
444 for (; !st.at_end() && count < depth; st.forte_next(), count++) { |