< prev index next >

src/os_cpu/linux_s390/vm/os_linux_s390.cpp

Print this page
rev 12487 : 8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
Reviewed-by: mdoerr


 127     epc = ExtendedPC(os::Linux::ucontext_get_pc(uc));
 128     if (ret_sp) { *ret_sp = os::Linux::ucontext_get_sp(uc); }
 129     if (ret_fp) { *ret_fp = os::Linux::ucontext_get_fp(uc); }
 130   } else {
 131     // Construct empty ExtendedPC for return value checking.
 132     epc = ExtendedPC(NULL);
 133     if (ret_sp) { *ret_sp = (intptr_t *)NULL; }
 134     if (ret_fp) { *ret_fp = (intptr_t *)NULL; }
 135   }
 136 
 137   return epc;
 138 }
 139 
 140 frame os::fetch_frame_from_context(const void* ucVoid) {
 141   intptr_t* sp;
 142   intptr_t* fp;
 143   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
 144   return frame(sp, epc.pc());
 145 }
 146 




































 147 frame os::get_sender_for_C_frame(frame* fr) {
 148   if (*fr->sp() == 0) {
 149     // fr is the last C frame.
 150     return frame();
 151   }
 152 
 153   // If its not one of our frames, the return pc is saved at gpr14
 154   // stack slot. The call_stub stores the return_pc to the stack slot
 155   // of gpr10.
 156   if ((Interpreter::code() != NULL && Interpreter::contains(fr->pc())) ||
 157       (CodeCache::contains(fr->pc()) && !StubRoutines::contains(fr->pc()))) {
 158     return frame(fr->sender_sp(), fr->sender_pc());
 159   } else {
 160     if (StubRoutines::contains(fr->pc())) {
 161       StubCodeDesc* desc = StubCodeDesc::desc_for(fr->pc());
 162       if (desc && !strcmp(desc->name(),"call_stub")) {
 163         return frame(fr->sender_sp(), fr->callstub_sender_pc());
 164       } else {
 165         return frame(fr->sender_sp(), fr->sender_pc());
 166       }


 262   if (info != NULL && uc != NULL && thread != NULL) {
 263     pc = os::Linux::ucontext_get_pc(uc);
 264     if (TraceTraps) {
 265       tty->print_cr("     pc at " INTPTR_FORMAT, p2i(pc));
 266     }
 267     if ((unsigned long)(pc - (address)info->si_addr) <= (unsigned long)Assembler::instr_maxlen() ) {
 268       trap_pc = (address)info->si_addr;
 269       if (TraceTraps) {
 270         tty->print_cr("trap_pc at " INTPTR_FORMAT, p2i(trap_pc));
 271       }
 272     }
 273 
 274     // Handle ALL stack overflow variations here
 275     if (sig == SIGSEGV) {
 276       address addr = (address)info->si_addr; // Address causing SIGSEGV, usually mem ref target.
 277 
 278       // Check if fault address is within thread stack.
 279       if (thread->on_local_stack(addr)) {
 280         // stack overflow
 281         if (thread->in_stack_yellow_reserved_zone(addr)) {
 282           thread->disable_stack_yellow_reserved_zone();
 283           if (thread->thread_state() == _thread_in_Java) {

















 284             // Throw a stack overflow exception.
 285             // Guard pages will be reenabled while unwinding the stack.

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

 289             return 1;
 290           }
 291         } else if (thread->in_stack_red_zone(addr)) {
 292           // Fatal red zone violation.  Disable the guard pages and fall through
 293           // to handle_unexpected_exception way down below.
 294           thread->disable_stack_red_zone();
 295           tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 296 
 297           // This is a likely cause, but hard to verify. Let's just print
 298           // it as a hint.
 299           tty->print_raw_cr("Please check if any of your loaded .so files has "
 300                             "enabled executable stack (see man page execstack(8))");
 301         } else {
 302           // Accessing stack address below sp may cause SEGV if current
 303           // thread has MAP_GROWSDOWN stack. This should only happen when
 304           // current thread was created by user code with MAP_GROWSDOWN flag
 305           // and then attached to VM. See notes in os_linux.cpp.
 306           if (thread->osthread()->expanding_stack() == 0) {
 307              thread->osthread()->set_expanding_stack();
 308              if (os::Linux::manually_expand_stack(thread, addr)) {




 127     epc = ExtendedPC(os::Linux::ucontext_get_pc(uc));
 128     if (ret_sp) { *ret_sp = os::Linux::ucontext_get_sp(uc); }
 129     if (ret_fp) { *ret_fp = os::Linux::ucontext_get_fp(uc); }
 130   } else {
 131     // Construct empty ExtendedPC for return value checking.
 132     epc = ExtendedPC(NULL);
 133     if (ret_sp) { *ret_sp = (intptr_t *)NULL; }
 134     if (ret_fp) { *ret_fp = (intptr_t *)NULL; }
 135   }
 136 
 137   return epc;
 138 }
 139 
 140 frame os::fetch_frame_from_context(const void* ucVoid) {
 141   intptr_t* sp;
 142   intptr_t* fp;
 143   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
 144   return frame(sp, epc.pc());
 145 }
 146 
 147 bool os::Linux::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
 148   address pc = (address) os::Linux::ucontext_get_pc(uc);
 149   if (Interpreter::contains(pc)) {
 150     // Interpreter performs stack banging after the fixed frame header has
 151     // been generated while the compilers perform it before. To maintain
 152     // semantic consistency between interpreted and compiled frames, the
 153     // method returns the Java sender of the current frame.
 154     *fr = os::fetch_frame_from_context(uc);
 155     if (!fr->is_first_java_frame()) {
 156       assert(fr->safe_for_sender(thread), "Safety check");
 157       *fr = fr->java_sender();
 158     }
 159   } else {
 160     // More complex code with compiled code.
 161     assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
 162     CodeBlob* cb = CodeCache::find_blob(pc);
 163     if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
 164       // Not sure where the pc points to, fallback to default
 165       // stack overflow handling. In compiled code, we bang before
 166       // the frame is complete.
 167       return false;
 168     } else {
 169       intptr_t* fp = os::Linux::ucontext_get_fp(uc);
 170       intptr_t* sp = os::Linux::ucontext_get_sp(uc);
 171       *fr = frame(sp, (address)*sp);
 172       if (!fr->is_java_frame()) {
 173         assert(fr->safe_for_sender(thread), "Safety check");
 174         assert(!fr->is_first_frame(), "Safety check");
 175         *fr = fr->java_sender();
 176       }
 177     }
 178   }
 179   assert(fr->is_java_frame(), "Safety check");
 180   return true;
 181 }
 182 
 183 frame os::get_sender_for_C_frame(frame* fr) {
 184   if (*fr->sp() == 0) {
 185     // fr is the last C frame.
 186     return frame();
 187   }
 188 
 189   // If its not one of our frames, the return pc is saved at gpr14
 190   // stack slot. The call_stub stores the return_pc to the stack slot
 191   // of gpr10.
 192   if ((Interpreter::code() != NULL && Interpreter::contains(fr->pc())) ||
 193       (CodeCache::contains(fr->pc()) && !StubRoutines::contains(fr->pc()))) {
 194     return frame(fr->sender_sp(), fr->sender_pc());
 195   } else {
 196     if (StubRoutines::contains(fr->pc())) {
 197       StubCodeDesc* desc = StubCodeDesc::desc_for(fr->pc());
 198       if (desc && !strcmp(desc->name(),"call_stub")) {
 199         return frame(fr->sender_sp(), fr->callstub_sender_pc());
 200       } else {
 201         return frame(fr->sender_sp(), fr->sender_pc());
 202       }


 298   if (info != NULL && uc != NULL && thread != NULL) {
 299     pc = os::Linux::ucontext_get_pc(uc);
 300     if (TraceTraps) {
 301       tty->print_cr("     pc at " INTPTR_FORMAT, p2i(pc));
 302     }
 303     if ((unsigned long)(pc - (address)info->si_addr) <= (unsigned long)Assembler::instr_maxlen() ) {
 304       trap_pc = (address)info->si_addr;
 305       if (TraceTraps) {
 306         tty->print_cr("trap_pc at " INTPTR_FORMAT, p2i(trap_pc));
 307       }
 308     }
 309 
 310     // Handle ALL stack overflow variations here
 311     if (sig == SIGSEGV) {
 312       address addr = (address)info->si_addr; // Address causing SIGSEGV, usually mem ref target.
 313 
 314       // Check if fault address is within thread stack.
 315       if (thread->on_local_stack(addr)) {
 316         // stack overflow
 317         if (thread->in_stack_yellow_reserved_zone(addr)) {

 318           if (thread->thread_state() == _thread_in_Java) {
 319             if (thread->in_stack_reserved_zone(addr)) {
 320               frame fr;
 321               if (os::Linux::get_frame_at_stack_banging_point(thread, uc, &fr)) {
 322                 assert(fr.is_java_frame(), "Must be a Javac frame");
 323                 frame activation =
 324                   SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
 325                 if (activation.sp() != NULL) {
 326                   thread->disable_stack_reserved_zone();
 327                   if (activation.is_interpreted_frame()) {
 328                     thread->set_reserved_stack_activation((address)activation.fp());
 329                   } else {
 330                     thread->set_reserved_stack_activation((address)activation.unextended_sp());
 331                   }
 332                   return 1;
 333                 }
 334               }
 335             }
 336             // Throw a stack overflow exception.
 337             // Guard pages will be reenabled while unwinding the stack.
 338             thread->disable_stack_yellow_reserved_zone();
 339             stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
 340           } else {
 341             // Thread was in the vm or native code. Return and try to finish.
 342             thread->disable_stack_yellow_reserved_zone();
 343             return 1;
 344           }
 345         } else if (thread->in_stack_red_zone(addr)) {
 346           // Fatal red zone violation.  Disable the guard pages and fall through
 347           // to handle_unexpected_exception way down below.
 348           thread->disable_stack_red_zone();
 349           tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 350 
 351           // This is a likely cause, but hard to verify. Let's just print
 352           // it as a hint.
 353           tty->print_raw_cr("Please check if any of your loaded .so files has "
 354                             "enabled executable stack (see man page execstack(8))");
 355         } else {
 356           // Accessing stack address below sp may cause SEGV if current
 357           // thread has MAP_GROWSDOWN stack. This should only happen when
 358           // current thread was created by user code with MAP_GROWSDOWN flag
 359           // and then attached to VM. See notes in os_linux.cpp.
 360           if (thread->osthread()->expanding_stack() == 0) {
 361              thread->osthread()->set_expanding_stack();
 362              if (os::Linux::manually_expand_stack(thread, addr)) {


< prev index next >