src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp

Print this page




 344     epc = ExtendedPC(os::Bsd::ucontext_get_pc(uc));
 345     if (ret_sp) *ret_sp = os::Bsd::ucontext_get_sp(uc);
 346     if (ret_fp) *ret_fp = os::Bsd::ucontext_get_fp(uc);
 347   } else {
 348     // construct empty ExtendedPC for return value checking
 349     epc = ExtendedPC(NULL);
 350     if (ret_sp) *ret_sp = (intptr_t *)NULL;
 351     if (ret_fp) *ret_fp = (intptr_t *)NULL;
 352   }
 353 
 354   return epc;
 355 }
 356 
 357 frame os::fetch_frame_from_context(void* ucVoid) {
 358   intptr_t* sp;
 359   intptr_t* fp;
 360   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
 361   return frame(sp, fp, epc.pc());
 362 }
 363 










































 364 // By default, gcc always save frame pointer (%ebp/%rbp) on stack. It may get
 365 // turned off by -fomit-frame-pointer,
 366 frame os::get_sender_for_C_frame(frame* fr) {
 367   return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
 368 }
 369 
 370 intptr_t* _get_previous_fp() {
 371 #if defined(SPARC_WORKS) || defined(__clang__) || defined(__llvm__)
 372   register intptr_t **ebp;
 373   __asm__("mov %%"SPELL_REG_FP", %0":"=r"(ebp));
 374 #else
 375   register intptr_t **ebp __asm__ (SPELL_REG_FP);
 376 #endif
 377   return (intptr_t*) *ebp;   // we want what it points to.
 378 }
 379 
 380 
 381 frame os::current_frame() {
 382   intptr_t* fp = _get_previous_fp();
 383   frame myframe((intptr_t*)os::current_stack_pointer(),


 461   address pc          = NULL;
 462 
 463   //%note os_trap_1
 464   if (info != NULL && uc != NULL && thread != NULL) {
 465     pc = (address) os::Bsd::ucontext_get_pc(uc);
 466 
 467     if (StubRoutines::is_safefetch_fault(pc)) {
 468       os::Bsd::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
 469       return 1;
 470     }
 471 
 472     // Handle ALL stack overflow variations here
 473     if (sig == SIGSEGV || sig == SIGBUS) {
 474       address addr = (address) info->si_addr;
 475 
 476       // check if fault address is within thread stack
 477       if (addr < thread->stack_base() &&
 478           addr >= thread->stack_base() - thread->stack_size()) {
 479         // stack overflow
 480         if (thread->in_stack_yellow_zone(addr)) {
 481           thread->disable_stack_yellow_zone();
 482           if (thread->thread_state() == _thread_in_Java) {

















 483             // Throw a stack overflow exception.  Guard pages will be reenabled
 484             // while unwinding the stack.

 485             stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
 486           } else {
 487             // Thread was in the vm or native code.  Return and try to finish.

 488             return 1;
 489           }
 490         } else if (thread->in_stack_red_zone(addr)) {
 491           // Fatal red zone violation.  Disable the guard pages and fall through
 492           // to handle_unexpected_exception way down below.
 493           thread->disable_stack_red_zone();
 494           tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 495         }
 496       }
 497     }
 498 
 499     if ((sig == SIGSEGV || sig == SIGBUS) && VM_Version::is_cpuinfo_segv_addr(pc)) {
 500       // Verify that OS save/restore AVX registers.
 501       stub = VM_Version::cpuinfo_cont_addr();
 502     }
 503 
 504     // We test if stub is already set (by the stack overflow code
 505     // above) so it is not overwritten by the code that follows. This
 506     // check is not required on other platforms, because on other
 507     // platforms we check for SIGSEGV only or SIGBUS only, where here




 344     epc = ExtendedPC(os::Bsd::ucontext_get_pc(uc));
 345     if (ret_sp) *ret_sp = os::Bsd::ucontext_get_sp(uc);
 346     if (ret_fp) *ret_fp = os::Bsd::ucontext_get_fp(uc);
 347   } else {
 348     // construct empty ExtendedPC for return value checking
 349     epc = ExtendedPC(NULL);
 350     if (ret_sp) *ret_sp = (intptr_t *)NULL;
 351     if (ret_fp) *ret_fp = (intptr_t *)NULL;
 352   }
 353 
 354   return epc;
 355 }
 356 
 357 frame os::fetch_frame_from_context(void* ucVoid) {
 358   intptr_t* sp;
 359   intptr_t* fp;
 360   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
 361   return frame(sp, fp, epc.pc());
 362 }
 363 
 364 frame os::fetch_frame_from_ucontext(Thread* thread, void* ucVoid) {
 365   intptr_t* sp;
 366   intptr_t* fp;
 367   ExtendedPC epc = os::Bsd::fetch_frame_from_ucontext(thread, (ucontext_t*)ucVoid, &sp, &fp);
 368   return frame(sp, fp, epc.pc());
 369 }
 370 
 371 bool os::Bsd::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
 372   address pc = (address) os::Bsd::ucontext_get_pc(uc);
 373   if (Interpreter::contains(pc)) {
 374     // interpreter performs stack banging after the fixed frame header has
 375     // been generated while the compilers perform it before. To maintain
 376     // semantic consistency between interpreted and compiled frames, the
 377     // method returns the Java sender of the current frame.
 378     *fr = os::fetch_frame_from_ucontext(thread, uc);
 379     assert(fr->safe_for_sender(thread), "Safety check");
 380     if (!fr->is_first_java_frame()) {
 381       *fr = fr->java_sender();
 382     }
 383   } else {
 384     // more complex code with compiled code
 385     assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
 386     CodeBlob* cb = CodeCache::find_blob(pc);
 387     if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
 388       // Not sure where the pc points to, fallback to default 
 389       // stack overflow handling
 390       return false;
 391     } else {
 392       *fr = os::fetch_frame_from_ucontext(thread, uc);
 393       // in compiled code, the stack banging is performed just after the return pc
 394       // has been pushed on the stack
 395       *fr = frame(fr->sp() + 1, fr->fp(), (address)*(fr->sp()));
 396       if (!fr->is_java_frame()) {
 397         assert(fr->safe_for_sender(thread), "Safety check");
 398         *fr = fr->java_sender();
 399       }
 400     }
 401   }
 402   assert(fr->is_java_frame(), "Safety check");
 403   return true;
 404 }
 405 
 406 // By default, gcc always save frame pointer (%ebp/%rbp) on stack. It may get
 407 // turned off by -fomit-frame-pointer,
 408 frame os::get_sender_for_C_frame(frame* fr) {
 409   return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
 410 }
 411 
 412 intptr_t* _get_previous_fp() {
 413 #if defined(SPARC_WORKS) || defined(__clang__) || defined(__llvm__)
 414   register intptr_t **ebp;
 415   __asm__("mov %%"SPELL_REG_FP", %0":"=r"(ebp));
 416 #else
 417   register intptr_t **ebp __asm__ (SPELL_REG_FP);
 418 #endif
 419   return (intptr_t*) *ebp;   // we want what it points to.
 420 }
 421 
 422 
 423 frame os::current_frame() {
 424   intptr_t* fp = _get_previous_fp();
 425   frame myframe((intptr_t*)os::current_stack_pointer(),


 503   address pc          = NULL;
 504 
 505   //%note os_trap_1
 506   if (info != NULL && uc != NULL && thread != NULL) {
 507     pc = (address) os::Bsd::ucontext_get_pc(uc);
 508 
 509     if (StubRoutines::is_safefetch_fault(pc)) {
 510       os::Bsd::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
 511       return 1;
 512     }
 513 
 514     // Handle ALL stack overflow variations here
 515     if (sig == SIGSEGV || sig == SIGBUS) {
 516       address addr = (address) info->si_addr;
 517 
 518       // check if fault address is within thread stack
 519       if (addr < thread->stack_base() &&
 520           addr >= thread->stack_base() - thread->stack_size()) {
 521         // stack overflow
 522         if (thread->in_stack_yellow_zone(addr)) {

 523           if (thread->thread_state() == _thread_in_Java) {
 524             if (thread->in_stack_reserved_zone(addr)) {
 525               frame fr;
 526               if (os::Bsd::get_frame_at_stack_banging_point(thread, uc, &fr)) {
 527                 assert(fr.is_java_frame(), "Must be a Java frame");
 528                 frame activation = SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
 529                 if (activation.sp() != NULL) {
 530                   thread->disable_stack_reserved_zone();
 531                   if (activation.is_interpreted_frame()) {
 532                     thread->set_reserved_stack_activation(
 533                       activation.fp() + frame::interpreter_frame_initial_sp_offset);
 534                   } else {
 535                     thread->set_reserved_stack_activation(activation.unextended_sp());
 536                   }
 537                   return 1;
 538                 }
 539               }
 540             }
 541             // Throw a stack overflow exception.  Guard pages will be reenabled
 542             // while unwinding the stack.
 543             thread->disable_stack_yellow_zone();
 544             stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
 545           } else {
 546             // Thread was in the vm or native code.  Return and try to finish.
 547             thread->disable_stack_yellow_zone();
 548             return 1;
 549           }
 550         } else if (thread->in_stack_red_zone(addr)) {
 551           // Fatal red zone violation.  Disable the guard pages and fall through
 552           // to handle_unexpected_exception way down below.
 553           thread->disable_stack_red_zone();
 554           tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 555         }
 556       }
 557     }
 558 
 559     if ((sig == SIGSEGV || sig == SIGBUS) && VM_Version::is_cpuinfo_segv_addr(pc)) {
 560       // Verify that OS save/restore AVX registers.
 561       stub = VM_Version::cpuinfo_cont_addr();
 562     }
 563 
 564     // We test if stub is already set (by the stack overflow code
 565     // above) so it is not overwritten by the code that follows. This
 566     // check is not required on other platforms, because on other
 567     // platforms we check for SIGSEGV only or SIGBUS only, where here