< prev index next >

src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 572     if (thread->thread_state() == _thread_in_Java && stub == NULL) {
 573       // Java thread running in Java code => find exception handler if any
 574       // a fault inside compiled code, the interpreter, or a stub
 575 
 576       if ((sig == SIGSEGV || sig == SIGBUS) && os::is_poll_address((address)info->si_addr)) {
 577         stub = SharedRuntime::get_poll_stub(pc);
 578 #if defined(__APPLE__)
 579       // 32-bit Darwin reports a SIGBUS for nearly all memory access exceptions.
 580       // 64-bit Darwin may also use a SIGBUS (seen with compressed oops).
 581       // Catching SIGBUS here prevents the implicit SIGBUS NULL check below from
 582       // being called, so only do so if the implicit NULL check is not necessary.
 583       } else if (sig == SIGBUS && !MacroAssembler::uses_implicit_null_check(info->si_addr)) {
 584 #else
 585       } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
 586 #endif
 587         // BugId 4454115: A read from a MappedByteBuffer can fault
 588         // here if the underlying file has been truncated.
 589         // Do not crash the VM in such a case.
 590         CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 591         CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
 592         bool is_unsafe_arraycopy = thread->doing_unsafe_access() && UnsafeCopyMemory::contains_pc(pc);
 593         if ((nm != NULL && nm->has_unsafe_access()) || is_unsafe_arraycopy) {
 594           address next_pc = Assembler::locate_next_instruction(pc);
 595           if (is_unsafe_arraycopy) {
 596             next_pc = UnsafeCopyMemory::page_error_continue_pc(pc);
 597           }
 598           stub = SharedRuntime::handle_unsafe_access(thread, next_pc);
 599         }
 600       }
 601       else
 602 
 603 #ifdef AMD64
 604       if (sig == SIGFPE  &&
 605           (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) {
 606         stub =
 607           SharedRuntime::
 608           continuation_for_implicit_exception(thread,
 609                                               pc,
 610                                               SharedRuntime::
 611                                               IMPLICIT_DIVIDE_BY_ZERO);
 612 #ifdef __APPLE__
 613       } else if (sig == SIGFPE && info->si_code == FPE_NOOP) {
 614         int op = pc[0];
 615 
 616         // Skip REX
 617         if ((pc[0] & 0xf0) == 0x40) {


 646           // NOTE: that we take the exception at the NEXT floating point instruction.
 647           assert(pc[0] == 0xDB, "not a FIST opcode");
 648           assert(pc[1] == 0x14, "not a FIST opcode");
 649           assert(pc[2] == 0x24, "not a FIST opcode");
 650           return true;
 651         } else if (op == 0xF7) {
 652           // IDIV
 653           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
 654         } else {
 655           // TODO: handle more cases if we are using other x86 instructions
 656           //   that can generate SIGFPE signal on bsd.
 657           tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
 658           fatal("please update this code.");
 659         }
 660 #endif // AMD64
 661       } else if ((sig == SIGSEGV || sig == SIGBUS) &&
 662                  MacroAssembler::uses_implicit_null_check(info->si_addr)) {
 663           // Determination of interpreter/vtable stub/compiled code null exception
 664           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 665       }
 666     } else if ((thread->thread_state() == _thread_in_vm ||
 667                 thread->thread_state() == _thread_in_native) &&
 668                sig == SIGBUS && /* info->si_code == BUS_OBJERR && */
 669                thread->doing_unsafe_access()) {
 670         address next_pc = Assembler::locate_next_instruction(pc);
 671         if (UnsafeCopyMemory::contains_pc(pc)) {
 672           next_pc = UnsafeCopyMemory::page_error_continue_pc(pc);
 673         }
 674         stub = SharedRuntime::handle_unsafe_access(thread, next_pc);
 675     }
 676 
 677     // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
 678     // and the heap gets shrunk before the field access.
 679     if ((sig == SIGSEGV) || (sig == SIGBUS)) {
 680       address addr = JNI_FastGetField::find_slowcase_pc(pc);
 681       if (addr != (address)-1) {
 682         stub = addr;
 683       }
 684     }
 685   }
 686 
 687 #ifndef AMD64
 688   // Execution protection violation
 689   //
 690   // This should be kept as the last step in the triage.  We don't
 691   // have a dedicated trap number for a no-execute fault, so be
 692   // conservative and allow other handlers the first shot.
 693   //


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 572     if (thread->thread_state() == _thread_in_Java && stub == NULL) {
 573       // Java thread running in Java code => find exception handler if any
 574       // a fault inside compiled code, the interpreter, or a stub
 575 
 576       if ((sig == SIGSEGV || sig == SIGBUS) && os::is_poll_address((address)info->si_addr)) {
 577         stub = SharedRuntime::get_poll_stub(pc);
 578 #if defined(__APPLE__)
 579       // 32-bit Darwin reports a SIGBUS for nearly all memory access exceptions.
 580       // 64-bit Darwin may also use a SIGBUS (seen with compressed oops).
 581       // Catching SIGBUS here prevents the implicit SIGBUS NULL check below from
 582       // being called, so only do so if the implicit NULL check is not necessary.
 583       } else if (sig == SIGBUS && !MacroAssembler::uses_implicit_null_check(info->si_addr)) {
 584 #else
 585       } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
 586 #endif
 587         // BugId 4454115: A read from a MappedByteBuffer can fault
 588         // here if the underlying file has been truncated.
 589         // Do not crash the VM in such a case.
 590         CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 591         CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
 592         if (nm != NULL && nm->has_unsafe_access()) {

 593           address next_pc = Assembler::locate_next_instruction(pc);



 594           stub = SharedRuntime::handle_unsafe_access(thread, next_pc);
 595         }
 596       }
 597       else
 598 
 599 #ifdef AMD64
 600       if (sig == SIGFPE  &&
 601           (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) {
 602         stub =
 603           SharedRuntime::
 604           continuation_for_implicit_exception(thread,
 605                                               pc,
 606                                               SharedRuntime::
 607                                               IMPLICIT_DIVIDE_BY_ZERO);
 608 #ifdef __APPLE__
 609       } else if (sig == SIGFPE && info->si_code == FPE_NOOP) {
 610         int op = pc[0];
 611 
 612         // Skip REX
 613         if ((pc[0] & 0xf0) == 0x40) {


 642           // NOTE: that we take the exception at the NEXT floating point instruction.
 643           assert(pc[0] == 0xDB, "not a FIST opcode");
 644           assert(pc[1] == 0x14, "not a FIST opcode");
 645           assert(pc[2] == 0x24, "not a FIST opcode");
 646           return true;
 647         } else if (op == 0xF7) {
 648           // IDIV
 649           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
 650         } else {
 651           // TODO: handle more cases if we are using other x86 instructions
 652           //   that can generate SIGFPE signal on bsd.
 653           tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
 654           fatal("please update this code.");
 655         }
 656 #endif // AMD64
 657       } else if ((sig == SIGSEGV || sig == SIGBUS) &&
 658                  MacroAssembler::uses_implicit_null_check(info->si_addr)) {
 659           // Determination of interpreter/vtable stub/compiled code null exception
 660           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 661       }
 662     } else if (thread->thread_state() == _thread_in_vm &&

 663                sig == SIGBUS && /* info->si_code == BUS_OBJERR && */
 664                thread->doing_unsafe_access()) {
 665         address next_pc = Assembler::locate_next_instruction(pc);



 666         stub = SharedRuntime::handle_unsafe_access(thread, next_pc);
 667     }
 668 
 669     // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
 670     // and the heap gets shrunk before the field access.
 671     if ((sig == SIGSEGV) || (sig == SIGBUS)) {
 672       address addr = JNI_FastGetField::find_slowcase_pc(pc);
 673       if (addr != (address)-1) {
 674         stub = addr;
 675       }
 676     }
 677   }
 678 
 679 #ifndef AMD64
 680   // Execution protection violation
 681   //
 682   // This should be kept as the last step in the triage.  We don't
 683   // have a dedicated trap number for a no-execute fault, so be
 684   // conservative and allow other handlers the first shot.
 685   //


< prev index next >