src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp
changeset 57565 01bca26734bb
parent 55653 3243c42d737d
child 58679 9c3209ff7550
equal deleted inserted replaced
57564:0a8436eda2fa 57565:01bca26734bb
    51 #include "runtime/thread.inline.hpp"
    51 #include "runtime/thread.inline.hpp"
    52 #include "runtime/timer.hpp"
    52 #include "runtime/timer.hpp"
    53 #include "utilities/debug.hpp"
    53 #include "utilities/debug.hpp"
    54 #include "utilities/events.hpp"
    54 #include "utilities/events.hpp"
    55 #include "utilities/vmError.hpp"
    55 #include "utilities/vmError.hpp"
    56 #ifdef BUILTIN_SIM
       
    57 #include "../../../../../../simulator/simulator.hpp"
       
    58 #endif
       
    59 
    56 
    60 // put OS-includes here
    57 // put OS-includes here
    61 # include <sys/types.h>
    58 # include <sys/types.h>
    62 # include <sys/mman.h>
    59 # include <sys/mman.h>
    63 # include <pthread.h>
    60 # include <pthread.h>
    77 # include <pwd.h>
    74 # include <pwd.h>
    78 # include <poll.h>
    75 # include <poll.h>
    79 # include <ucontext.h>
    76 # include <ucontext.h>
    80 # include <fpu_control.h>
    77 # include <fpu_control.h>
    81 
    78 
    82 #ifdef BUILTIN_SIM
       
    83 #define REG_SP REG_RSP
       
    84 #define REG_PC REG_RIP
       
    85 #define REG_FP REG_RBP
       
    86 #else
       
    87 #define REG_FP 29
    79 #define REG_FP 29
    88 #define REG_LR 30
    80 #define REG_LR 30
    89 #endif
       
    90 
    81 
    91 NOINLINE address os::current_stack_pointer() {
    82 NOINLINE address os::current_stack_pointer() {
    92   return (address)__builtin_frame_address(0);
    83   return (address)__builtin_frame_address(0);
    93 }
    84 }
    94 
    85 
    99 
    90 
   100   return (char*) 0xffffffffffff;
    91   return (char*) 0xffffffffffff;
   101 }
    92 }
   102 
    93 
   103 address os::Linux::ucontext_get_pc(const ucontext_t * uc) {
    94 address os::Linux::ucontext_get_pc(const ucontext_t * uc) {
   104 #ifdef BUILTIN_SIM
       
   105   return (address)uc->uc_mcontext.gregs[REG_PC];
       
   106 #else
       
   107   return (address)uc->uc_mcontext.pc;
    95   return (address)uc->uc_mcontext.pc;
   108 #endif
       
   109 }
    96 }
   110 
    97 
   111 void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) {
    98 void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) {
   112 #ifdef BUILTIN_SIM
       
   113   uc->uc_mcontext.gregs[REG_PC] = (intptr_t)pc;
       
   114 #else
       
   115   uc->uc_mcontext.pc = (intptr_t)pc;
    99   uc->uc_mcontext.pc = (intptr_t)pc;
   116 #endif
       
   117 }
   100 }
   118 
   101 
   119 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {
   102 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {
   120 #ifdef BUILTIN_SIM
       
   121   return (intptr_t*)uc->uc_mcontext.gregs[REG_SP];
       
   122 #else
       
   123   return (intptr_t*)uc->uc_mcontext.sp;
   103   return (intptr_t*)uc->uc_mcontext.sp;
   124 #endif
       
   125 }
   104 }
   126 
   105 
   127 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {
   106 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {
   128 #ifdef BUILTIN_SIM
       
   129   return (intptr_t*)uc->uc_mcontext.gregs[REG_FP];
       
   130 #else
       
   131   return (intptr_t*)uc->uc_mcontext.regs[REG_FP];
   107   return (intptr_t*)uc->uc_mcontext.regs[REG_FP];
   132 #endif
       
   133 }
   108 }
   134 
   109 
   135 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
   110 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
   136 // is currently interrupted by SIGPROF.
   111 // is currently interrupted by SIGPROF.
   137 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal
   112 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal
   215 }
   190 }
   216 
   191 
   217 // By default, gcc always saves frame pointer rfp on this stack. This
   192 // By default, gcc always saves frame pointer rfp on this stack. This
   218 // may get turned off by -fomit-frame-pointer.
   193 // may get turned off by -fomit-frame-pointer.
   219 frame os::get_sender_for_C_frame(frame* fr) {
   194 frame os::get_sender_for_C_frame(frame* fr) {
   220 #ifdef BUILTIN_SIM
       
   221   return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
       
   222 #else
       
   223   return frame(fr->link(), fr->link(), fr->sender_pc());
   195   return frame(fr->link(), fr->link(), fr->sender_pc());
   224 #endif
       
   225 }
   196 }
   226 
   197 
   227 NOINLINE frame os::current_frame() {
   198 NOINLINE frame os::current_frame() {
   228   intptr_t *fp = *(intptr_t **)__builtin_frame_address(0);
   199   intptr_t *fp = *(intptr_t **)__builtin_frame_address(0);
   229   frame myframe((intptr_t*)os::current_stack_pointer(),
   200   frame myframe((intptr_t*)os::current_stack_pointer(),
   235   } else {
   206   } else {
   236     return os::get_sender_for_C_frame(&myframe);
   207     return os::get_sender_for_C_frame(&myframe);
   237   }
   208   }
   238 }
   209 }
   239 
   210 
   240 // Utility functions
       
   241 #ifdef BUILTIN_SIM
       
   242 extern "C" void Fetch32PFI () ;
       
   243 extern "C" void Fetch32Resume () ;
       
   244 extern "C" void FetchNPFI () ;
       
   245 extern "C" void FetchNResume () ;
       
   246 #endif
       
   247 
       
   248 extern "C" JNIEXPORT int
   211 extern "C" JNIEXPORT int
   249 JVM_handle_linux_signal(int sig,
   212 JVM_handle_linux_signal(int sig,
   250                         siginfo_t* info,
   213                         siginfo_t* info,
   251                         void* ucVoid,
   214                         void* ucVoid,
   252                         int abort_if_unrecognized) {
   215                         int abort_if_unrecognized) {
   313 
   276 
   314   //%note os_trap_1
   277   //%note os_trap_1
   315   if (info != NULL && uc != NULL && thread != NULL) {
   278   if (info != NULL && uc != NULL && thread != NULL) {
   316     pc = (address) os::Linux::ucontext_get_pc(uc);
   279     pc = (address) os::Linux::ucontext_get_pc(uc);
   317 
   280 
   318 #ifdef BUILTIN_SIM
       
   319     if (pc == (address) Fetch32PFI) {
       
   320        uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ;
       
   321        return 1 ;
       
   322     }
       
   323     if (pc == (address) FetchNPFI) {
       
   324        uc->uc_mcontext.gregs[REG_PC] = intptr_t (FetchNResume) ;
       
   325        return 1 ;
       
   326     }
       
   327 #else
       
   328     if (StubRoutines::is_safefetch_fault(pc)) {
   281     if (StubRoutines::is_safefetch_fault(pc)) {
   329       os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
   282       os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
   330       return 1;
   283       return 1;
   331     }
   284     }
   332 #endif
       
   333 
   285 
   334     address addr = (address) info->si_addr;
   286     address addr = (address) info->si_addr;
   335 
   287 
   336     // Make sure the high order byte is sign extended, as it may be masked away by the hardware.
   288     // Make sure the high order byte is sign extended, as it may be masked away by the hardware.
   337     if ((uintptr_t(addr) & (uintptr_t(1) << 55)) != 0) {
   289     if ((uintptr_t(addr) & (uintptr_t(1) << 55)) != 0) {
   541 void os::print_context(outputStream *st, const void *context) {
   493 void os::print_context(outputStream *st, const void *context) {
   542   if (context == NULL) return;
   494   if (context == NULL) return;
   543 
   495 
   544   const ucontext_t *uc = (const ucontext_t*)context;
   496   const ucontext_t *uc = (const ucontext_t*)context;
   545   st->print_cr("Registers:");
   497   st->print_cr("Registers:");
   546 #ifdef BUILTIN_SIM
       
   547   st->print(  "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]);
       
   548   st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]);
       
   549   st->print(", RCX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RCX]);
       
   550   st->print(", RDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDX]);
       
   551   st->cr();
       
   552   st->print(  "RSP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSP]);
       
   553   st->print(", RBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBP]);
       
   554   st->print(", RSI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSI]);
       
   555   st->print(", RDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDI]);
       
   556   st->cr();
       
   557   st->print(  "R8 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R8]);
       
   558   st->print(", R9 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R9]);
       
   559   st->print(", R10=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R10]);
       
   560   st->print(", R11=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R11]);
       
   561   st->cr();
       
   562   st->print(  "R12=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R12]);
       
   563   st->print(", R13=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R13]);
       
   564   st->print(", R14=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R14]);
       
   565   st->print(", R15=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R15]);
       
   566   st->cr();
       
   567   st->print(  "RIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RIP]);
       
   568   st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]);
       
   569   st->print(", CSGSFS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_CSGSFS]);
       
   570   st->print(", ERR=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ERR]);
       
   571   st->cr();
       
   572   st->print("  TRAPNO=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_TRAPNO]);
       
   573   st->cr();
       
   574 #else
       
   575   for (int r = 0; r < 31; r++) {
   498   for (int r = 0; r < 31; r++) {
   576     st->print("R%-2d=", r);
   499     st->print("R%-2d=", r);
   577     print_location(st, uc->uc_mcontext.regs[r]);
   500     print_location(st, uc->uc_mcontext.regs[r]);
   578   }
   501   }
   579 #endif
       
   580   st->cr();
   502   st->cr();
   581 
   503 
   582   intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
   504   intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
   583   st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
   505   st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
   584   print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
   506   print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
   604   // context does not match how we defined our abstract Register set, so
   526   // context does not match how we defined our abstract Register set, so
   605   // we can't just iterate through the gregs area
   527   // we can't just iterate through the gregs area
   606 
   528 
   607   // this is only for the "general purpose" registers
   529   // this is only for the "general purpose" registers
   608 
   530 
   609 #ifdef BUILTIN_SIM
       
   610   st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]);
       
   611   st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]);
       
   612   st->print("RCX="); print_location(st, uc->uc_mcontext.gregs[REG_RCX]);
       
   613   st->print("RDX="); print_location(st, uc->uc_mcontext.gregs[REG_RDX]);
       
   614   st->print("RSP="); print_location(st, uc->uc_mcontext.gregs[REG_RSP]);
       
   615   st->print("RBP="); print_location(st, uc->uc_mcontext.gregs[REG_RBP]);
       
   616   st->print("RSI="); print_location(st, uc->uc_mcontext.gregs[REG_RSI]);
       
   617   st->print("RDI="); print_location(st, uc->uc_mcontext.gregs[REG_RDI]);
       
   618   st->print("R8 ="); print_location(st, uc->uc_mcontext.gregs[REG_R8]);
       
   619   st->print("R9 ="); print_location(st, uc->uc_mcontext.gregs[REG_R9]);
       
   620   st->print("R10="); print_location(st, uc->uc_mcontext.gregs[REG_R10]);
       
   621   st->print("R11="); print_location(st, uc->uc_mcontext.gregs[REG_R11]);
       
   622   st->print("R12="); print_location(st, uc->uc_mcontext.gregs[REG_R12]);
       
   623   st->print("R13="); print_location(st, uc->uc_mcontext.gregs[REG_R13]);
       
   624   st->print("R14="); print_location(st, uc->uc_mcontext.gregs[REG_R14]);
       
   625   st->print("R15="); print_location(st, uc->uc_mcontext.gregs[REG_R15]);
       
   626 #else
       
   627   for (int r = 0; r < 31; r++)
   531   for (int r = 0; r < 31; r++)
   628     st->print_cr(  "R%d=" INTPTR_FORMAT, r, (uintptr_t)uc->uc_mcontext.regs[r]);
   532     st->print_cr(  "R%d=" INTPTR_FORMAT, r, (uintptr_t)uc->uc_mcontext.regs[r]);
   629 #endif
       
   630   st->cr();
   533   st->cr();
   631 }
   534 }
   632 
   535 
   633 void os::setup_fpu() {
   536 void os::setup_fpu() {
   634 }
   537 }