506 // dumping last frame with frame::describe 507 508 JavaThread* p = JavaThread::active(); 509 510 ResourceMark rm; 511 PRESERVE_EXCEPTION_MARK; // may not be needed by safer and unexpensive here 512 FrameValues values; 513 514 // Note: We want to allow trace_method_handle from any call site. 515 // While trace_method_handle creates a frame, it may be entered 516 // without a PC on the stack top (e.g. not just after a call). 517 // Walking that frame could lead to failures due to that invalid PC. 518 // => carefully detect that frame when doing the stack walking 519 520 // Current C frame 521 frame cur_frame = os::current_frame(); 522 523 // Robust search of trace_calling_frame (independant of inlining). 524 // Assumes saved_regs comes from a pusha in the trace_calling_frame. 525 assert(cur_frame.sp() < saved_regs, "registers not saved on stack ?"); 526 frame trace_calling_frame = os::get_sender_for_C_frame(&cur_frame); 527 while (trace_calling_frame.fp() < saved_regs) { 528 trace_calling_frame = os::get_sender_for_C_frame(&trace_calling_frame); 529 } 530 531 // safely create a frame and call frame::describe 532 intptr_t *dump_sp = trace_calling_frame.sender_sp(); 533 intptr_t *dump_fp = trace_calling_frame.link(); 534 535 bool walkable = has_mh; // whether the traced frame shoud be walkable 536 537 if (walkable) { 538 // The previous definition of walkable may have to be refined 539 // if new call sites cause the next frame constructor to start 540 // failing. Alternatively, frame constructors could be 541 // modified to support the current or future non walkable 542 // frames (but this is more intrusive and is not considered as 543 // part of this RFE, which will instead use a simpler output). 544 frame dump_frame = frame(dump_sp, dump_fp); 545 dump_frame.describe(values, 1); 546 } else { 547 // Stack may not be walkable (invalid PC above FP): 548 // Add descriptions without building a Java frame to avoid issues 549 values.describe(-1, dump_fp, "fp for #1 <not parsed, cannot trust pc>"); 550 values.describe(-1, dump_sp, "sp for #1"); 551 } 552 values.describe(-1, entry_sp, "raw top of stack"); 553 554 tty->print_cr("Stack layout:"); 555 values.print(p); 556 } 557 if (has_mh && mh->is_oop()) { 558 mh->print(); 559 if (java_lang_invoke_MethodHandle::is_instance(mh)) { 560 if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0) 561 java_lang_invoke_MethodHandle::form(mh)->print(); 562 } 563 } 564 } | 506 // dumping last frame with frame::describe 507 508 JavaThread* p = JavaThread::active(); 509 510 ResourceMark rm; 511 PRESERVE_EXCEPTION_MARK; // may not be needed by safer and unexpensive here 512 FrameValues values; 513 514 // Note: We want to allow trace_method_handle from any call site. 515 // While trace_method_handle creates a frame, it may be entered 516 // without a PC on the stack top (e.g. not just after a call). 517 // Walking that frame could lead to failures due to that invalid PC. 518 // => carefully detect that frame when doing the stack walking 519 520 // Current C frame 521 frame cur_frame = os::current_frame(); 522 523 // Robust search of trace_calling_frame (independant of inlining). 524 // Assumes saved_regs comes from a pusha in the trace_calling_frame. 525 assert(cur_frame.sp() < saved_regs, "registers not saved on stack ?"); 526 frame trace_calling_frame = os::get_sender_for_C_frame(p, &cur_frame); 527 while (trace_calling_frame.fp() < saved_regs) { 528 trace_calling_frame = os::get_sender_for_C_frame(p, &trace_calling_frame); 529 } 530 531 // safely create a frame and call frame::describe 532 intptr_t *dump_sp = trace_calling_frame.sender_sp(); 533 intptr_t *dump_fp = trace_calling_frame.link(); 534 535 bool walkable = has_mh; // whether the traced frame shoud be walkable 536 537 if (walkable) { 538 // The previous definition of walkable may have to be refined 539 // if new call sites cause the next frame constructor to start 540 // failing. Alternatively, frame constructors could be 541 // modified to support the current or future non walkable 542 // frames (but this is more intrusive and is not considered as 543 // part of this RFE, which will instead use a simpler output). 544 frame dump_frame = frame(p, dump_sp, dump_fp); 545 dump_frame.describe(values, 1); 546 } else { 547 // Stack may not be walkable (invalid PC above FP): 548 // Add descriptions without building a Java frame to avoid issues 549 values.describe(-1, dump_fp, "fp for #1 <not parsed, cannot trust pc>"); 550 values.describe(-1, dump_sp, "sp for #1"); 551 } 552 values.describe(-1, entry_sp, "raw top of stack"); 553 554 tty->print_cr("Stack layout:"); 555 values.print(p); 556 } 557 if (has_mh && mh->is_oop()) { 558 mh->print(); 559 if (java_lang_invoke_MethodHandle::is_instance(mh)) { 560 if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0) 561 java_lang_invoke_MethodHandle::form(mh)->print(); 562 } 563 } 564 } |