src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp

Print this page
rev 4810 : 8016697: PPC64 (part 5): Use stubs to implement safefetch
Summary: Implement Safefetch as stub routines. This reduces compiler and os dependencies.
Reviewed-by: twisti, kvn


 335 bool os::is_allocatable(size_t bytes) {
 336 #ifdef AMD64
 337   return true;
 338 #else
 339 
 340   if (bytes < 2 * G) {
 341     return true;
 342   }
 343 
 344   char* addr = reserve_memory(bytes, NULL);
 345 
 346   if (addr != NULL) {
 347     release_memory(addr, bytes);
 348   }
 349 
 350   return addr != NULL;
 351 #endif // AMD64
 352 
 353 }
 354 
 355 extern "C" void Fetch32PFI () ;
 356 extern "C" void Fetch32Resume () ;
 357 #ifdef AMD64
 358 extern "C" void FetchNPFI () ;
 359 extern "C" void FetchNResume () ;
 360 #endif // AMD64
 361 
 362 extern "C" JNIEXPORT int
 363 JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid,
 364                           int abort_if_unrecognized) {
 365   ucontext_t* uc = (ucontext_t*) ucVoid;
 366 
 367 #ifndef AMD64
 368   if (sig == SIGILL && info->si_addr == (caddr_t)sse_check) {
 369     // the SSE instruction faulted. supports_sse() need return false.
 370     uc->uc_mcontext.gregs[EIP] = (greg_t)sse_unavailable;
 371     return true;
 372   }
 373 #endif // !AMD64
 374 
 375   Thread* t = ThreadLocalStorage::get_thread_slow();  // slow & steady
 376 
 377   SignalHandlerMark shm(t);
 378 
 379   if(sig == SIGPIPE || sig == SIGXFSZ) {
 380     if (os::Solaris::chained_handler(sig, info, ucVoid)) {
 381       return true;


 419     }
 420   }
 421 
 422   if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
 423     // can't decode this kind of signal
 424     info = NULL;
 425   } else {
 426     assert(sig == info->si_signo, "bad siginfo");
 427   }
 428 
 429   // decide if this trap can be handled by a stub
 430   address stub = NULL;
 431 
 432   address pc          = NULL;
 433 
 434   //%note os_trap_1
 435   if (info != NULL && uc != NULL && thread != NULL) {
 436     // factor me: getPCfromContext
 437     pc = (address) uc->uc_mcontext.gregs[REG_PC];
 438 
 439     // SafeFetch32() support
 440     if (pc == (address) Fetch32PFI) {
 441       uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ;
 442       return true ;
 443     }
 444 #ifdef AMD64
 445     if (pc == (address) FetchNPFI) {
 446        uc->uc_mcontext.gregs [REG_PC] = intptr_t(FetchNResume) ;
 447        return true ;
 448     }
 449 #endif // AMD64
 450 
 451     // Handle ALL stack overflow variations here
 452     if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) {
 453       address addr = (address) info->si_addr;
 454       if (thread->in_stack_yellow_zone(addr)) {
 455         thread->disable_stack_yellow_zone();
 456         if (thread->thread_state() == _thread_in_Java) {
 457           // Throw a stack overflow exception.  Guard pages will be reenabled
 458           // while unwinding the stack.
 459           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
 460         } else {
 461           // Thread was in the vm or native code.  Return and try to finish.
 462           return true;
 463         }
 464       } else if (thread->in_stack_red_zone(addr)) {
 465         // Fatal red zone violation.  Disable the guard pages and fall through
 466         // to handle_unexpected_exception way down below.
 467         thread->disable_stack_red_zone();
 468         tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 469       }




 335 bool os::is_allocatable(size_t bytes) {
 336 #ifdef AMD64
 337   return true;
 338 #else
 339 
 340   if (bytes < 2 * G) {
 341     return true;
 342   }
 343 
 344   char* addr = reserve_memory(bytes, NULL);
 345 
 346   if (addr != NULL) {
 347     release_memory(addr, bytes);
 348   }
 349 
 350   return addr != NULL;
 351 #endif // AMD64
 352 
 353 }
 354 







 355 extern "C" JNIEXPORT int
 356 JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid,
 357                           int abort_if_unrecognized) {
 358   ucontext_t* uc = (ucontext_t*) ucVoid;
 359 
 360 #ifndef AMD64
 361   if (sig == SIGILL && info->si_addr == (caddr_t)sse_check) {
 362     // the SSE instruction faulted. supports_sse() need return false.
 363     uc->uc_mcontext.gregs[EIP] = (greg_t)sse_unavailable;
 364     return true;
 365   }
 366 #endif // !AMD64
 367 
 368   Thread* t = ThreadLocalStorage::get_thread_slow();  // slow & steady
 369 
 370   SignalHandlerMark shm(t);
 371 
 372   if(sig == SIGPIPE || sig == SIGXFSZ) {
 373     if (os::Solaris::chained_handler(sig, info, ucVoid)) {
 374       return true;


 412     }
 413   }
 414 
 415   if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
 416     // can't decode this kind of signal
 417     info = NULL;
 418   } else {
 419     assert(sig == info->si_signo, "bad siginfo");
 420   }
 421 
 422   // decide if this trap can be handled by a stub
 423   address stub = NULL;
 424 
 425   address pc          = NULL;
 426 
 427   //%note os_trap_1
 428   if (info != NULL && uc != NULL && thread != NULL) {
 429     // factor me: getPCfromContext
 430     pc = (address) uc->uc_mcontext.gregs[REG_PC];
 431 
 432     if (StubRoutines::is_safefetch_fault(pc)) {
 433       uc->uc_mcontext.gregs[REG_PC] = intptr_t(StubRoutines::continuation_for_safefetch_fault(pc));
 434       return true;






 435     }

 436 
 437     // Handle ALL stack overflow variations here
 438     if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) {
 439       address addr = (address) info->si_addr;
 440       if (thread->in_stack_yellow_zone(addr)) {
 441         thread->disable_stack_yellow_zone();
 442         if (thread->thread_state() == _thread_in_Java) {
 443           // Throw a stack overflow exception.  Guard pages will be reenabled
 444           // while unwinding the stack.
 445           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
 446         } else {
 447           // Thread was in the vm or native code.  Return and try to finish.
 448           return true;
 449         }
 450       } else if (thread->in_stack_red_zone(addr)) {
 451         // Fatal red zone violation.  Disable the guard pages and fall through
 452         // to handle_unexpected_exception way down below.
 453         thread->disable_stack_red_zone();
 454         tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 455       }