rev 12273 : 8169317: [s390] Various minor bug fixes and adaptions.

   1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2016 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 // This file is organized as os_linux_x86.cpp.
  27 
  28 // no precompiled headers
  29 #include "asm/assembler.inline.hpp"
  30 #include "classfile/classLoader.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "classfile/vmSymbols.hpp"
  33 #include "code/icBuffer.hpp"
  34 #include "code/nativeInst.hpp"
  35 #include "code/vtableStubs.hpp"
  36 #include "compiler/disassembler.hpp"
  37 #include "interpreter/interpreter.hpp"
  38 #include "jvm_linux.h"
  39 #include "memory/allocation.inline.hpp"
  40 #include "nativeInst_s390.hpp"
  41 #include "os_share_linux.hpp"
  42 #include "prims/jniFastGetField.hpp"
  43 #include "prims/jvm.h"
  44 #include "prims/jvm_misc.hpp"
  45 #include "runtime/arguments.hpp"
  46 #include "runtime/extendedPC.hpp"
  47 #include "runtime/frame.inline.hpp"
  48 #include "runtime/interfaceSupport.hpp"
  49 #include "runtime/java.hpp"
  50 #include "runtime/javaCalls.hpp"
  51 #include "runtime/mutexLocker.hpp"
  52 #include "runtime/osThread.hpp"
  53 #include "runtime/sharedRuntime.hpp"
  54 #include "runtime/stubRoutines.hpp"
  55 #include "runtime/thread.inline.hpp"
  56 #include "runtime/timer.hpp"
  57 #include "utilities/events.hpp"
  58 #include "utilities/vmError.hpp"
  59 
  60 // put OS-includes here
  61 # include <sys/types.h>
  62 # include <sys/mman.h>
  63 # include <pthread.h>
  64 # include <signal.h>
  65 # include <errno.h>
  66 # include <dlfcn.h>
  67 # include <stdlib.h>
  68 # include <stdio.h>
  69 # include <unistd.h>
  70 # include <sys/resource.h>
  71 # include <pthread.h>
  72 # include <sys/stat.h>
  73 # include <sys/time.h>
  74 # include <sys/utsname.h>
  75 # include <sys/socket.h>
  76 # include <sys/wait.h>
  77 # include <pwd.h>
  78 # include <poll.h>
  79 # include <ucontext.h>
  80 
  81 address os::current_stack_pointer() {
  82   intptr_t* csp;
  83 
  84   // Inline assembly for `z_lgr regno(csp), Z_SP' (Z_SP = Z_R15):
  85   __asm__ __volatile__ ("lgr %0, 15":"=r"(csp):);
  86 
  87   assert(((uint64_t)csp & (frame::alignment_in_bytes-1)) == 0, "SP must be aligned");
  88   return (address) csp;
  89 }
  90 
  91 char* os::non_memory_address_word() {
  92   // Must never look like an address returned by reserve_memory,
  93   // even in its subfields (as defined by the CPU immediate fields,
  94   // if the CPU splits constants across multiple instructions).
  95   return (char*) -1;
  96 }
  97 
  98 // OS specific thread initialization.
  99 void os::initialize_thread(Thread* thread) { }
 100 
 101 // Frame information (pc, sp, fp) retrieved via ucontext
 102 // always looks like a C-frame according to the frame
 103 // conventions in frame_s390.hpp.
 104 address os::Linux::ucontext_get_pc(const ucontext_t * uc) {
 105   return (address)uc->uc_mcontext.psw.addr;
 106 }
 107 
 108 void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) {
 109   uc->uc_mcontext.psw.addr = (unsigned long)pc;
 110 }
 111 
 112 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {
 113   return (intptr_t*)uc->uc_mcontext.gregs[15/*REG_SP*/];
 114 }
 115 
 116 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {
 117   return NULL;
 118 }
 119 
 120 ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
 121                     intptr_t** ret_sp, intptr_t** ret_fp) {
 122 
 123   ExtendedPC  epc;
 124   const ucontext_t* uc = (const ucontext_t*)ucVoid;
 125 
 126   if (uc != NULL) {
 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       }
 167     } else {
 168       return frame(fr->sender_sp(), fr->native_sender_pc());
 169     }
 170   }
 171 }
 172 
 173 frame os::current_frame() {
 174   // Expected to return the stack pointer of this method.
 175   // But if inlined, returns the stack pointer of our caller!
 176   intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
 177   assert (csp != NULL, "sp should not be NULL");
 178   // Pass a dummy pc. This way we don't have to load it from the
 179   // stack, since we don't know in which slot we can find it.
 180   frame topframe(csp, (address)0x8);
 181   if (os::is_first_C_frame(&topframe)) {
 182     // Stack is not walkable.
 183     return frame();
 184   } else {
 185     frame senderFrame = os::get_sender_for_C_frame(&topframe);
 186     assert(senderFrame.pc() != NULL, "Sender pc should not be NULL");
 187     // Return sender of sender of current topframe which hopefully
 188     // both have pc != NULL.
 189 #ifdef _NMT_NOINLINE_   // Is set in slowdebug builds.
 190     // Current_stack_pointer is not inlined, we must pop one more frame.
 191     frame tmp = os::get_sender_for_C_frame(&topframe);
 192     return os::get_sender_for_C_frame(&tmp);
 193 #else
 194     return os::get_sender_for_C_frame(&topframe);
 195 #endif
 196   }
 197 }
 198 
 199 // Utility functions
 200 
 201 extern "C" JNIEXPORT int
 202 JVM_handle_linux_signal(int sig,
 203                         siginfo_t* info,
 204                         void* ucVoid,
 205                         int abort_if_unrecognized) {
 206   ucontext_t* uc = (ucontext_t*) ucVoid;
 207 
 208   Thread* t = Thread::current_or_null_safe();
 209 
 210   // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
 211   // (no destructors can be run).
 212   os::WatcherThreadCrashProtection::check_crash_protection(sig, t);
 213 
 214   SignalHandlerMark shm(t);
 215 
 216   // Note: it's not uncommon that JNI code uses signal/sigset to install
 217   // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
 218   // or have a SIGILL handler when detecting CPU type). When that happens,
 219   // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To
 220   // avoid unnecessary crash when libjsig is not preloaded, try handle signals
 221   // that do not require siginfo/ucontext first.
 222 
 223   if (sig == SIGPIPE) {
 224     if (os::Linux::chained_handler(sig, info, ucVoid)) {
 225       return true;
 226     } else {
 227       if (PrintMiscellaneous && (WizardMode || Verbose)) {
 228         warning("Ignoring SIGPIPE - see bug 4229104");
 229       }
 230       return true;
 231     }
 232   }
 233 
 234   JavaThread* thread = NULL;
 235   VMThread* vmthread = NULL;
 236   if (os::Linux::signal_handlers_are_installed) {
 237     if (t != NULL) {
 238       if(t->is_Java_thread()) {
 239         thread = (JavaThread*)t;
 240       } else if(t->is_VM_thread()) {
 241         vmthread = (VMThread *)t;
 242       }
 243     }
 244   }
 245 
 246   // Moved SafeFetch32 handling outside thread!=NULL conditional block to make
 247   // it work if no associated JavaThread object exists.
 248   if (uc) {
 249     address const pc = os::Linux::ucontext_get_pc(uc);
 250     if (pc && StubRoutines::is_safefetch_fault(pc)) {
 251       os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
 252       return true;
 253     }
 254   }
 255 
 256   // Decide if this trap can be handled by a stub.
 257   address stub    = NULL;
 258   address pc      = NULL;  // Pc as retrieved from PSW. Usually points past failing instruction.
 259   address trap_pc = NULL;  // Pc of the instruction causing the trap.
 260 
 261   //%note os_trap_1
 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)) {
 309                thread->osthread()->clear_expanding_stack();
 310                return 1;
 311              }
 312              thread->osthread()->clear_expanding_stack();
 313           } else {
 314              fatal("recursive segv. expanding stack.");
 315           }
 316         }
 317       }
 318     }
 319 
 320     if (thread->thread_state() == _thread_in_Java) {
 321       // Java thread running in Java code => find exception handler if any
 322       // a fault inside compiled code, the interpreter, or a stub
 323 
 324       // Handle signal from NativeJump::patch_verified_entry().
 325       if (sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) {
 326         if (TraceTraps) {
 327           tty->print_cr("trap: zombie_not_entrant (SIGILL)");
 328         }
 329         stub = SharedRuntime::get_handle_wrong_method_stub();
 330       }
 331 
 332       else if (sig == SIGSEGV &&
 333                os::is_poll_address((address)info->si_addr)) {
 334         if (TraceTraps) {
 335           tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
 336         }
 337         stub = SharedRuntime::get_poll_stub(pc);
 338 
 339         // Info->si_addr only points to the page base address, so we
 340         // must extract the real si_addr from the instruction and the
 341         // ucontext.
 342         assert(((NativeInstruction*)pc)->is_safepoint_poll(), "must be safepoint poll");
 343         const address real_si_addr = ((NativeInstruction*)pc)->get_poll_address(uc);
 344       }
 345 
 346       // SIGTRAP-based implicit null check in compiled code.
 347       else if ((sig == SIGFPE) &&
 348                TrapBasedNullChecks &&
 349                (trap_pc != NULL) &&
 350                Assembler::is_sigtrap_zero_check(trap_pc)) {
 351         if (TraceTraps) {
 352           tty->print_cr("trap: NULL_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
 353         }
 354         stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
 355       }
 356 
 357       else if (sig == SIGSEGV && ImplicitNullChecks &&
 358                CodeCache::contains((void*) pc) &&
 359                !MacroAssembler::needs_explicit_null_check((intptr_t) info->si_addr)) {
 360         if (TraceTraps) {
 361           tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
 362         }
 363         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 364       }
 365 
 366       // SIGTRAP-based implicit range check in compiled code.
 367       else if (sig == SIGFPE && TrapBasedRangeChecks &&
 368                (trap_pc != NULL) &&
 369                Assembler::is_sigtrap_range_check(trap_pc)) {
 370         if (TraceTraps) {
 371           tty->print_cr("trap: RANGE_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
 372         }
 373         stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
 374       }
 375 
 376       else if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
 377         stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
 378       }
 379 
 380       else if (sig == SIGBUS) {
 381         // BugId 4454115: A read from a MappedByteBuffer can fault here if the
 382         // underlying file has been truncated. Do not crash the VM in such a case.
 383         CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 384         CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
 385         if (nm != NULL && nm->has_unsafe_access()) {
 386           // We don't really need a stub here! Just set the pending exeption and
 387           // continue at the next instruction after the faulting read. Returning
 388           // garbage from this read is ok.
 389           thread->set_pending_unsafe_access_error();
 390           uc->uc_mcontext.psw.addr = ((unsigned long)pc) + Assembler::instr_len(pc);
 391           return true;
 392         }
 393       }
 394     }
 395 
 396     else { // thread->thread_state() != _thread_in_Java
 397       if (sig == SIGILL && VM_Version::is_determine_features_test_running()) {
 398         // SIGILL must be caused by VM_Version::determine_features().
 399         //*(int *) (pc-6)=0; // Patch instruction to 0 to indicate that it causes a SIGILL.
 400                              // Flushing of icache is not necessary.
 401         stub = pc; // Continue with next instruction.
 402       } else if (thread->thread_state() == _thread_in_vm &&
 403                  sig == SIGBUS && thread->doing_unsafe_access()) {
 404         // We don't really need a stub here! Just set the pending exeption and
 405         // continue at the next instruction after the faulting read. Returning
 406         // garbage from this read is ok.
 407         thread->set_pending_unsafe_access_error();
 408         os::Linux::ucontext_set_pc(uc, pc + Assembler::instr_len(pc));
 409         return true;
 410       }
 411     }
 412 
 413     // Check to see if we caught the safepoint code in the
 414     // process of write protecting the memory serialization page.
 415     // It write enables the page immediately after protecting it
 416     // so we can just return to retry the write.
 417     // Info->si_addr need not be the exact address, it is only
 418     // guaranteed to be on the same page as the address that caused
 419     // the SIGSEGV.
 420     if ((sig == SIGSEGV) &&
 421         (os::get_memory_serialize_page() ==
 422          (address)((uintptr_t)info->si_addr & ~(os::vm_page_size()-1)))) {
 423       return true;
 424     }
 425   }
 426 
 427   if (stub != NULL) {
 428     // Save all thread context in case we need to restore it.
 429     if (thread != NULL) thread->set_saved_exception_pc(pc);
 430     os::Linux::ucontext_set_pc(uc, stub);
 431     return true;
 432   }
 433 
 434   // signal-chaining
 435   if (os::Linux::chained_handler(sig, info, ucVoid)) {
 436     return true;
 437   }
 438 
 439   if (!abort_if_unrecognized) {
 440     // caller wants another chance, so give it to him
 441     return false;
 442   }
 443 
 444   if (pc == NULL && uc != NULL) {
 445     pc = os::Linux::ucontext_get_pc(uc);
 446   }
 447 
 448   // unmask current signal
 449   sigset_t newset;
 450   sigemptyset(&newset);
 451   sigaddset(&newset, sig);
 452   sigprocmask(SIG_UNBLOCK, &newset, NULL);
 453 
 454   VMError::report_and_die(t, sig, pc, info, ucVoid);
 455 
 456   ShouldNotReachHere();
 457   return false;
 458 }
 459 
 460 void os::Linux::init_thread_fpu_state(void) {
 461   // Nothing to do on z/Architecture.
 462 }
 463 
 464 int os::Linux::get_fpu_control_word(void) {
 465   // Nothing to do on z/Architecture.
 466   return 0;
 467 }
 468 
 469 void os::Linux::set_fpu_control_word(int fpu_control) {
 470   // Nothing to do on z/Architecture.
 471 }
 472 
 473 ////////////////////////////////////////////////////////////////////////////////
 474 // thread stack
 475 
 476 size_t os::Posix::_compiler_thread_min_stack_allowed = 128 * K;
 477 size_t os::Posix::_java_thread_min_stack_allowed = 128 * K;
 478 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
 479 
 480 // return default stack size for thr_type
 481 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
 482   // default stack size (compiler thread needs larger stack)
 483   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K);
 484   return s;
 485 }
 486 
 487 size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
 488   // z/Architecture: put 2 guard pages right in the middle of thread stack. This value
 489   // should be consistent with the value used by register stack handling code.
 490   return 2 * page_size();
 491 }
 492 
 493 // Java thread:
 494 //
 495 //   Low memory addresses
 496 //    +------------------------+
 497 //    |                        |\
 498 //    |    glibc guard page    | - Right in the middle of stack, 2 pages
 499 //    |                        |/
 500 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
 501 //    |                        |\
 502 //    |  HotSpot Guard Pages   | - red and yellow pages
 503 //    |                        |/
 504 //    +------------------------+ JavaThread::stack_yellow_zone_base()
 505 //    |                        |\
 506 //    |      Normal Stack      | -
 507 //    |                        |/
 508 // P2 +------------------------+ Thread::stack_base()
 509 //
 510 // Non-Java thread:
 511 //
 512 //   Low memory addresses
 513 //    +------------------------+
 514 //    |                        |\
 515 //    |    glibc guard page    | - Right in the middle of stack, 2 pages
 516 //    |                        |/
 517 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
 518 //    |                        |\
 519 //    |      Normal Stack      | -
 520 //    |                        |/
 521 // P2 +------------------------+ Thread::stack_base()
 522 //
 523 // ** P2 is the address returned from pthread_attr_getstackaddr(), P2 - P1
 524 //    is the stack size returned by pthread_attr_getstacksize().
 525 
 526 
 527 static void current_stack_region(address * bottom, size_t * size) {
 528   if (os::Linux::is_initial_thread()) {
 529     // Initial thread needs special handling because pthread_getattr_np()
 530     // may return bogus value.
 531     *bottom = os::Linux::initial_thread_stack_bottom();
 532     *size   = os::Linux::initial_thread_stack_size();
 533   } else {
 534     pthread_attr_t attr;
 535 
 536     int rslt = pthread_getattr_np(pthread_self(), &attr);
 537 
 538     // JVM needs to know exact stack location, abort if it fails
 539     if (rslt != 0) {
 540       if (rslt == ENOMEM) {
 541         vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
 542       } else {
 543         fatal("pthread_getattr_np failed with errno = %d", rslt);
 544       }
 545     }
 546 
 547     if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
 548       fatal("Can not locate current stack attributes!");
 549     }
 550 
 551     pthread_attr_destroy(&attr);
 552 
 553   }
 554   assert(os::current_stack_pointer() >= *bottom &&
 555          os::current_stack_pointer() < *bottom + *size, "just checking");
 556 }
 557 
 558 address os::current_stack_base() {
 559   address bottom;
 560   size_t size;
 561   current_stack_region(&bottom, &size);
 562   return (bottom + size);
 563 }
 564 
 565 size_t os::current_stack_size() {
 566   // stack size includes normal stack and HotSpot guard pages
 567   address bottom;
 568   size_t size;
 569   current_stack_region(&bottom, &size);
 570   return size;
 571 }
 572 
 573 /////////////////////////////////////////////////////////////////////////////
 574 // helper functions for fatal error handler
 575 
 576 void os::print_context(outputStream *st, const void *context) {
 577   if (context == NULL) return;
 578 
 579   const ucontext_t* uc = (const ucontext_t*)context;
 580 
 581   st->print_cr("Processor state:");
 582   st->print_cr("----------------");
 583   st->print_cr("        ip = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.addr);
 584   st->print_cr(" proc mask = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.mask);
 585   st->print_cr("   fpc reg = 0x%8.8x "          , uc->uc_mcontext.fpregs.fpc);
 586   st->cr();
 587 
 588   st->print_cr("General Purpose Registers:");
 589   st->print_cr("--------------------------");
 590   for( int i = 0; i < 16; i+=2 ) {
 591     st->print("  r%-2d = " INTPTR_FORMAT "  " ,  i,   uc->uc_mcontext.gregs[i]);
 592     st->print("  r%-2d = " INTPTR_FORMAT "  |",  i+1, uc->uc_mcontext.gregs[i+1]);
 593     st->print("  r%-2d = %23.1ld  "           ,  i,   uc->uc_mcontext.gregs[i]);
 594     st->print("  r%-2d = %23.1ld  "           ,  i+1, uc->uc_mcontext.gregs[i+1]);
 595     st->cr();
 596   }
 597   st->cr();
 598 
 599   st->print_cr("Access Registers:");
 600   st->print_cr("-----------------");
 601   for( int i = 0; i < 16; i+=2 ) {
 602     st->print("  ar%-2d = 0x%8.8x  ", i,   uc->uc_mcontext.aregs[i]);
 603     st->print("  ar%-2d = 0x%8.8x  ", i+1, uc->uc_mcontext.aregs[i+1]);
 604     st->cr();
 605   }
 606   st->cr();
 607 
 608   st->print_cr("Float Registers:");
 609   st->print_cr("----------------");
 610   for (int i = 0; i < 16; i += 2) {
 611     st->print("  fr%-2d = " INTPTR_FORMAT "  " , i,   (int64_t)(uc->uc_mcontext.fpregs.fprs[i].d));
 612     st->print("  fr%-2d = " INTPTR_FORMAT "  |", i+1, (int64_t)(uc->uc_mcontext.fpregs.fprs[i+1].d));
 613     st->print("  fr%-2d = %23.15e  "           , i,   (uc->uc_mcontext.fpregs.fprs[i].d));
 614     st->print("  fr%-2d = %23.15e  "           , i+1, (uc->uc_mcontext.fpregs.fprs[i+1].d));
 615     st->cr();
 616   }
 617   st->cr();
 618   st->cr();
 619 
 620   intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
 621   st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
 622   print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
 623   st->cr();
 624 
 625   // Note: it may be unsafe to inspect memory near pc. For example, pc may
 626   // point to garbage if entry point in an nmethod is corrupted. Leave
 627   // this at the end, and hope for the best.
 628   address pc = os::Linux::ucontext_get_pc(uc);
 629   if (Verbose) { st->print_cr("pc at " PTR_FORMAT, p2i(pc)); }
 630   st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc));
 631   print_hex_dump(st, pc-64, pc+64, /*intrsize=*/4);
 632   st->cr();
 633 }
 634 
 635 void os::print_register_info(outputStream *st, const void *context) {
 636   st->print("Not ported\n");
 637 }
 638 
 639 #ifndef PRODUCT
 640 void os::verify_stack_alignment() {
 641 }
 642 #endif
 643 
 644 int os::extra_bang_size_in_bytes() {
 645   // z/Architecture does not require the additional stack bang.
 646   return 0;
 647 }
--- EOF ---