1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012, 2017 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 // no precompiled headers
  27 #include "jvm.h"
  28 #include "asm/assembler.inline.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "classfile/vmSymbols.hpp"
  32 #include "code/codeCache.hpp"
  33 #include "code/icBuffer.hpp"
  34 #include "code/vtableStubs.hpp"
  35 #include "interpreter/interpreter.hpp"
  36 #include "memory/allocation.inline.hpp"
  37 #include "nativeInst_ppc.hpp"
  38 #include "os_share_aix.hpp"
  39 #include "prims/jniFastGetField.hpp"
  40 #include "prims/jvm_misc.hpp"
  41 #include "porting_aix.hpp"
  42 #include "runtime/arguments.hpp"
  43 #include "runtime/extendedPC.hpp"
  44 #include "runtime/frame.inline.hpp"
  45 #include "runtime/interfaceSupport.hpp"
  46 #include "runtime/java.hpp"
  47 #include "runtime/javaCalls.hpp"
  48 #include "runtime/mutexLocker.hpp"
  49 #include "runtime/osThread.hpp"
  50 #include "runtime/sharedRuntime.hpp"
  51 #include "runtime/stubRoutines.hpp"
  52 #include "runtime/thread.inline.hpp"
  53 #include "runtime/timer.hpp"
  54 #include "utilities/events.hpp"
  55 #include "utilities/vmError.hpp"
  56 #ifdef COMPILER1
  57 #include "c1/c1_Runtime1.hpp"
  58 #endif
  59 #ifdef COMPILER2
  60 #include "opto/runtime.hpp"
  61 #endif
  62 
  63 // put OS-includes here
  64 # include <ucontext.h>
  65 
  66 address os::current_stack_pointer() {
  67   address csp;
  68 
  69 #if !defined(USE_XLC_BUILTINS)
  70   // inline assembly for `mr regno(csp), R1_SP':
  71   __asm__ __volatile__ ("mr %0, 1":"=r"(csp):);
  72 #else
  73   csp = (address) __builtin_frame_address(0);
  74 #endif
  75 
  76   return csp;
  77 }
  78 
  79 char* os::non_memory_address_word() {
  80   // Must never look like an address returned by reserve_memory,
  81   // even in its subfields (as defined by the CPU immediate fields,
  82   // if the CPU splits constants across multiple instructions).
  83 
  84   return (char*) -1;
  85 }
  86 
  87 // OS specific thread initialization
  88 //
  89 // Calculate and store the limits of the memory stack.
  90 void os::initialize_thread(Thread *thread) { }
  91 
  92 // Frame information (pc, sp, fp) retrieved via ucontext
  93 // always looks like a C-frame according to the frame
  94 // conventions in frame_ppc.hpp.
  95 
  96 address os::Aix::ucontext_get_pc(const ucontext_t * uc) {
  97   return (address)uc->uc_mcontext.jmp_context.iar;
  98 }
  99 
 100 intptr_t* os::Aix::ucontext_get_sp(const ucontext_t * uc) {
 101   // gpr1 holds the stack pointer on aix
 102   return (intptr_t*)uc->uc_mcontext.jmp_context.gpr[1/*REG_SP*/];
 103 }
 104 
 105 intptr_t* os::Aix::ucontext_get_fp(const ucontext_t * uc) {
 106   return NULL;
 107 }
 108 
 109 void os::Aix::ucontext_set_pc(ucontext_t* uc, address new_pc) {
 110   uc->uc_mcontext.jmp_context.iar = (uint64_t) new_pc;
 111 }
 112 
 113 ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
 114                                         intptr_t** ret_sp, intptr_t** ret_fp) {
 115 
 116   ExtendedPC  epc;
 117   const ucontext_t* uc = (const ucontext_t*)ucVoid;
 118 
 119   if (uc != NULL) {
 120     epc = ExtendedPC(os::Aix::ucontext_get_pc(uc));
 121     if (ret_sp) *ret_sp = os::Aix::ucontext_get_sp(uc);
 122     if (ret_fp) *ret_fp = os::Aix::ucontext_get_fp(uc);
 123   } else {
 124     // construct empty ExtendedPC for return value checking
 125     epc = ExtendedPC(NULL);
 126     if (ret_sp) *ret_sp = (intptr_t *)NULL;
 127     if (ret_fp) *ret_fp = (intptr_t *)NULL;
 128   }
 129 
 130   return epc;
 131 }
 132 
 133 frame os::fetch_frame_from_context(const void* ucVoid) {
 134   intptr_t* sp;
 135   intptr_t* fp;
 136   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
 137   // Avoid crash during crash if pc broken.
 138   if (epc.pc()) {
 139     frame fr(sp, epc.pc());
 140     return fr;
 141   }
 142   frame fr(sp);
 143   return fr;
 144 }
 145 
 146 bool os::Aix::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
 147   address pc = (address) os::Aix::ucontext_get_pc(uc);
 148   if (Interpreter::contains(pc)) {
 149     // Interpreter performs stack banging after the fixed frame header has
 150     // been generated while the compilers perform it before. To maintain
 151     // semantic consistency between interpreted and compiled frames, the
 152     // method returns the Java sender of the current frame.
 153     *fr = os::fetch_frame_from_context(uc);
 154     if (!fr->is_first_java_frame()) {
 155       assert(fr->safe_for_sender(thread), "Safety check");
 156       *fr = fr->java_sender();
 157     }
 158   } else {
 159     // More complex code with compiled code.
 160     assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
 161     CodeBlob* cb = CodeCache::find_blob(pc);
 162     if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
 163       // Not sure where the pc points to, fallback to default
 164       // stack overflow handling. In compiled code, we bang before
 165       // the frame is complete.
 166       return false;
 167     } else {
 168       intptr_t* sp = os::Aix::ucontext_get_sp(uc);
 169       *fr = frame(sp, (address)*sp);
 170       if (!fr->is_java_frame()) {
 171         assert(fr->safe_for_sender(thread), "Safety check");
 172         assert(!fr->is_first_frame(), "Safety check");
 173         *fr = fr->java_sender();
 174       }
 175     }
 176   }
 177   assert(fr->is_java_frame(), "Safety check");
 178   return true;
 179 }
 180 
 181 frame os::get_sender_for_C_frame(frame* fr) {
 182   if (*fr->sp() == NULL) {
 183     // fr is the last C frame
 184     return frame(NULL, NULL);
 185   }
 186   return frame(fr->sender_sp(), fr->sender_pc());
 187 }
 188 
 189 
 190 frame os::current_frame() {
 191   intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
 192   // hack.
 193   frame topframe(csp, (address)0x8);
 194   // Return sender of sender of current topframe which hopefully
 195   // both have pc != NULL.
 196   frame tmp = os::get_sender_for_C_frame(&topframe);
 197   return os::get_sender_for_C_frame(&tmp);
 198 }
 199 
 200 // Utility functions
 201 
 202 extern "C" JNIEXPORT int
 203 JVM_handle_aix_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) {
 204 
 205   ucontext_t* uc = (ucontext_t*) ucVoid;
 206 
 207   Thread* t = Thread::current_or_null_safe();
 208 
 209   SignalHandlerMark shm(t);
 210 
 211   // Note: it's not uncommon that JNI code uses signal/sigset to install
 212   // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
 213   // or have a SIGILL handler when detecting CPU type). When that happens,
 214   // JVM_handle_aix_signal() might be invoked with junk info/ucVoid. To
 215   // avoid unnecessary crash when libjsig is not preloaded, try handle signals
 216   // that do not require siginfo/ucontext first.
 217 
 218   if (sig == SIGPIPE) {
 219     if (os::Aix::chained_handler(sig, info, ucVoid)) {
 220       return 1;
 221     } else {
 222       // Ignoring SIGPIPE - see bugs 4229104
 223       return 1;
 224     }
 225   }
 226 
 227   JavaThread* thread = NULL;
 228   VMThread* vmthread = NULL;
 229   if (os::Aix::signal_handlers_are_installed) {
 230     if (t != NULL) {
 231       if(t->is_Java_thread()) {
 232         thread = (JavaThread*)t;
 233       }
 234       else if(t->is_VM_thread()) {
 235         vmthread = (VMThread *)t;
 236       }
 237     }
 238   }
 239 
 240   // Decide if this trap can be handled by a stub.
 241   address stub = NULL;
 242 
 243   // retrieve program counter
 244   address const pc = uc ? os::Aix::ucontext_get_pc(uc) : NULL;
 245 
 246   // retrieve crash address
 247   address const addr = info ? (const address) info->si_addr : NULL;
 248 
 249   // SafeFetch 32 handling:
 250   // - make it work if _thread is null
 251   // - make it use the standard os::...::ucontext_get/set_pc APIs
 252   if (uc) {
 253     address const pc = os::Aix::ucontext_get_pc(uc);
 254     if (pc && StubRoutines::is_safefetch_fault(pc)) {
 255       os::Aix::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
 256       return true;
 257     }
 258   }
 259 
 260   if (info == NULL || uc == NULL || thread == NULL && vmthread == NULL) {
 261     goto run_chained_handler;
 262   }
 263 
 264   // If we are a java thread...
 265   if (thread != NULL) {
 266 
 267     // Handle ALL stack overflow variations here
 268     if (sig == SIGSEGV && thread->on_local_stack(addr)) {
 269       // stack overflow
 270       //
 271       // If we are in a yellow zone and we are inside java, we disable the yellow zone and
 272       // throw a stack overflow exception.
 273       // If we are in native code or VM C code, we report-and-die. The original coding tried
 274       // to continue with yellow zone disabled, but that doesn't buy us much and prevents
 275       // hs_err_pid files.
 276       if (thread->in_stack_yellow_reserved_zone(addr)) {
 277         if (thread->thread_state() == _thread_in_Java) {
 278             if (thread->in_stack_reserved_zone(addr)) {
 279               frame fr;
 280               if (os::Aix::get_frame_at_stack_banging_point(thread, uc, &fr)) {
 281                 assert(fr.is_java_frame(), "Must be a Javac frame");
 282                 frame activation =
 283                   SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
 284                 if (activation.sp() != NULL) {
 285                   thread->disable_stack_reserved_zone();
 286                   if (activation.is_interpreted_frame()) {
 287                     thread->set_reserved_stack_activation((address)activation.fp());
 288                   } else {
 289                     thread->set_reserved_stack_activation((address)activation.unextended_sp());
 290                   }
 291                   return 1;
 292                 }
 293               }
 294             }
 295           // Throw a stack overflow exception.
 296           // Guard pages will be reenabled while unwinding the stack.
 297           thread->disable_stack_yellow_reserved_zone();
 298           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
 299           goto run_stub;
 300         } else {
 301           // Thread was in the vm or native code. Return and try to finish.
 302           thread->disable_stack_yellow_reserved_zone();
 303           return 1;
 304         }
 305       } else if (thread->in_stack_red_zone(addr)) {
 306         // Fatal red zone violation. Disable the guard pages and fall through
 307         // to handle_unexpected_exception way down below.
 308         thread->disable_stack_red_zone();
 309         tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 310         goto report_and_die;
 311       } else {
 312         // This means a segv happened inside our stack, but not in
 313         // the guarded zone. I'd like to know when this happens,
 314         tty->print_raw_cr("SIGSEGV happened inside stack but outside yellow and red zone.");
 315         goto report_and_die;
 316       }
 317 
 318     } // end handle SIGSEGV inside stack boundaries
 319 
 320     if (thread->thread_state() == _thread_in_Java) {
 321       // Java thread running in Java code
 322 
 323       // The following signals are used for communicating VM events:
 324       //
 325       // SIGILL: the compiler generates illegal opcodes
 326       //   at places where it wishes to interrupt the VM:
 327       //   Safepoints, Unreachable Code, Entry points of Zombie methods,
 328       //    This results in a SIGILL with (*pc) == inserted illegal instruction.
 329       //
 330       //   (so, SIGILLs with a pc inside the zero page are real errors)
 331       //
 332       // SIGTRAP:
 333       //   The ppc trap instruction raises a SIGTRAP and is very efficient if it
 334       //   does not trap. It is used for conditional branches that are expected
 335       //   to be never taken. These are:
 336       //     - zombie methods
 337       //     - IC (inline cache) misses.
 338       //     - null checks leading to UncommonTraps.
 339       //     - range checks leading to Uncommon Traps.
 340       //   On Aix, these are especially null checks, as the ImplicitNullCheck
 341       //   optimization works only in rare cases, as the page at address 0 is only
 342       //   write protected.      //
 343       //   Note: !UseSIGTRAP is used to prevent SIGTRAPS altogether, to facilitate debugging.
 344       //
 345       // SIGSEGV:
 346       //   used for safe point polling:
 347       //     To notify all threads that they have to reach a safe point, safe point polling is used:
 348       //     All threads poll a certain mapped memory page. Normally, this page has read access.
 349       //     If the VM wants to inform the threads about impending safe points, it puts this
 350       //     page to read only ("poisens" the page), and the threads then reach a safe point.
 351       //   used for null checks:
 352       //     If the compiler finds a store it uses it for a null check. Unfortunately this
 353       //     happens rarely.  In heap based and disjoint base compressd oop modes also loads
 354       //     are used for null checks.
 355 
 356       // A VM-related SIGILL may only occur if we are not in the zero page.
 357       // On AIX, we get a SIGILL if we jump to 0x0 or to somewhere else
 358       // in the zero page, because it is filled with 0x0. We ignore
 359       // explicit SIGILLs in the zero page.
 360       if (sig == SIGILL && (pc < (address) 0x200)) {
 361         if (TraceTraps) {
 362           tty->print_raw_cr("SIGILL happened inside zero page.");
 363         }
 364         goto report_and_die;
 365       }
 366 
 367       // Handle signal from NativeJump::patch_verified_entry().
 368       if (( TrapBasedNotEntrantChecks && sig == SIGTRAP && nativeInstruction_at(pc)->is_sigtrap_zombie_not_entrant()) ||
 369           (!TrapBasedNotEntrantChecks && sig == SIGILL  && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant())) {
 370         if (TraceTraps) {
 371           tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL");
 372         }
 373         stub = SharedRuntime::get_handle_wrong_method_stub();
 374         goto run_stub;
 375       }
 376 
 377       else if (sig == SIGSEGV && os::is_poll_address(addr)) {
 378         if (TraceTraps) {
 379           tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", pc);
 380         }
 381         stub = SharedRuntime::get_poll_stub(pc);
 382         goto run_stub;
 383       }
 384 
 385       // SIGTRAP-based ic miss check in compiled code.
 386       else if (sig == SIGTRAP && TrapBasedICMissChecks &&
 387                nativeInstruction_at(pc)->is_sigtrap_ic_miss_check()) {
 388         if (TraceTraps) {
 389           tty->print_cr("trap: ic_miss_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
 390         }
 391         stub = SharedRuntime::get_ic_miss_stub();
 392         goto run_stub;
 393       }
 394 
 395       // SIGTRAP-based implicit null check in compiled code.
 396       else if (sig == SIGTRAP && TrapBasedNullChecks &&
 397                nativeInstruction_at(pc)->is_sigtrap_null_check()) {
 398         if (TraceTraps) {
 399           tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
 400         }
 401         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 402         goto run_stub;
 403       }
 404 
 405       // SIGSEGV-based implicit null check in compiled code.
 406       else if (sig == SIGSEGV && ImplicitNullChecks &&
 407                CodeCache::contains((void*) pc) &&
 408                !MacroAssembler::needs_explicit_null_check((intptr_t) info->si_addr)) {
 409         if (TraceTraps) {
 410           tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", pc);
 411         }
 412         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 413       }
 414 
 415 #ifdef COMPILER2
 416       // SIGTRAP-based implicit range check in compiled code.
 417       else if (sig == SIGTRAP && TrapBasedRangeChecks &&
 418                nativeInstruction_at(pc)->is_sigtrap_range_check()) {
 419         if (TraceTraps) {
 420           tty->print_cr("trap: range_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
 421         }
 422         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 423         goto run_stub;
 424       }
 425 #endif
 426 
 427       else if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
 428         if (TraceTraps) {
 429           tty->print_raw_cr("Fix SIGFPE handler, trying divide by zero handler.");
 430         }
 431         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
 432         goto run_stub;
 433       }
 434 
 435       else if (sig == SIGBUS) {
 436         // BugId 4454115: A read from a MappedByteBuffer can fault here if the
 437         // underlying file has been truncated. Do not crash the VM in such a case.
 438         CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 439         CompiledMethod* nm = cb->as_compiled_method_or_null();
 440         if (nm != NULL && nm->has_unsafe_access()) {
 441           address next_pc = pc + 4;
 442           next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);
 443           os::Aix::ucontext_set_pc(uc, next_pc);
 444           return 1;
 445         }
 446       }
 447     }
 448 
 449     else { // thread->thread_state() != _thread_in_Java
 450       // Detect CPU features. This is only done at the very start of the VM. Later, the
 451       // VM_Version::is_determine_features_test_running() flag should be false.
 452 
 453       if (sig == SIGILL && VM_Version::is_determine_features_test_running()) {
 454         // SIGILL must be caused by VM_Version::determine_features().
 455         *(int *)pc = 0; // patch instruction to 0 to indicate that it causes a SIGILL,
 456                         // flushing of icache is not necessary.
 457         stub = pc + 4;  // continue with next instruction.
 458         goto run_stub;
 459       }
 460       else if (sig == SIGBUS && thread->doing_unsafe_access()) {
 461         address next_pc = pc + 4;
 462         next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);
 463         os::Aix::ucontext_set_pc(uc, next_pc);
 464         return 1;
 465       }
 466     }
 467 
 468     // Check to see if we caught the safepoint code in the
 469     // process of write protecting the memory serialization page.
 470     // It write enables the page immediately after protecting it
 471     // so we can just return to retry the write.
 472     if ((sig == SIGSEGV) &&
 473         os::is_memory_serialize_page(thread, addr)) {
 474       // Synchronization problem in the pseudo memory barrier code (bug id 6546278)
 475       // Block current thread until the memory serialize page permission restored.
 476       os::block_on_serialize_page_trap();
 477       return true;
 478     }
 479   }
 480 
 481 run_stub:
 482 
 483   // One of the above code blocks ininitalized the stub, so we want to
 484   // delegate control to that stub.
 485   if (stub != NULL) {
 486     // Save all thread context in case we need to restore it.
 487     if (thread != NULL) thread->set_saved_exception_pc(pc);
 488     os::Aix::ucontext_set_pc(uc, stub);
 489     return 1;
 490   }
 491 
 492 run_chained_handler:
 493 
 494   // signal-chaining
 495   if (os::Aix::chained_handler(sig, info, ucVoid)) {
 496     return 1;
 497   }
 498   if (!abort_if_unrecognized) {
 499     // caller wants another chance, so give it to him
 500     return 0;
 501   }
 502 
 503 report_and_die:
 504 
 505   // Use sigthreadmask instead of sigprocmask on AIX and unmask current signal.
 506   sigset_t newset;
 507   sigemptyset(&newset);
 508   sigaddset(&newset, sig);
 509   sigthreadmask(SIG_UNBLOCK, &newset, NULL);
 510 
 511   VMError::report_and_die(t, sig, pc, info, ucVoid);
 512 
 513   ShouldNotReachHere();
 514   return 0;
 515 }
 516 
 517 void os::Aix::init_thread_fpu_state(void) {
 518 #if !defined(USE_XLC_BUILTINS)
 519   // Disable FP exceptions.
 520   __asm__ __volatile__ ("mtfsfi 6,0");
 521 #else
 522   __mtfsfi(6, 0);
 523 #endif
 524 }
 525 
 526 ////////////////////////////////////////////////////////////////////////////////
 527 // thread stack
 528 
 529 // Minimum usable stack sizes required to get to user code. Space for
 530 // HotSpot guard pages is added later.
 531 size_t os::Posix::_compiler_thread_min_stack_allowed = 192 * K;
 532 size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
 533 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 534 
 535 // Return default stack size for thr_type.
 536 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
 537   // Default stack size (compiler thread needs larger stack).
 538   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
 539   return s;
 540 }
 541 
 542 /////////////////////////////////////////////////////////////////////////////
 543 // helper functions for fatal error handler
 544 
 545 void os::print_context(outputStream *st, const void *context) {
 546   if (context == NULL) return;
 547 
 548   const ucontext_t* uc = (const ucontext_t*)context;
 549 
 550   st->print_cr("Registers:");
 551   st->print("pc =" INTPTR_FORMAT "  ", uc->uc_mcontext.jmp_context.iar);
 552   st->print("lr =" INTPTR_FORMAT "  ", uc->uc_mcontext.jmp_context.lr);
 553   st->print("ctr=" INTPTR_FORMAT "  ", uc->uc_mcontext.jmp_context.ctr);
 554   st->cr();
 555   for (int i = 0; i < 32; i++) {
 556     st->print("r%-2d=" INTPTR_FORMAT "  ", i, uc->uc_mcontext.jmp_context.gpr[i]);
 557     if (i % 3 == 2) st->cr();
 558   }
 559   st->cr();
 560   st->cr();
 561 
 562   intptr_t *sp = (intptr_t *)os::Aix::ucontext_get_sp(uc);
 563   st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
 564   print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
 565   st->cr();
 566 
 567   // Note: it may be unsafe to inspect memory near pc. For example, pc may
 568   // point to garbage if entry point in an nmethod is corrupted. Leave
 569   // this at the end, and hope for the best.
 570   address pc = os::Aix::ucontext_get_pc(uc);
 571   st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
 572   print_hex_dump(st, pc - 64, pc + 64, /*instrsize=*/4);
 573   st->cr();
 574 
 575   // Try to decode the instructions.
 576   st->print_cr("Decoded instructions: (pc=" PTR_FORMAT ")", pc);
 577   st->print("<TODO: PPC port - print_context>");
 578   // TODO: PPC port Disassembler::decode(pc, 16, 16, st);
 579   st->cr();
 580 }
 581 
 582 void os::print_register_info(outputStream *st, const void *context) {
 583   if (context == NULL) return;
 584 
 585   ucontext_t *uc = (ucontext_t*)context;
 586 
 587   st->print_cr("Register to memory mapping:");
 588   st->cr();
 589 
 590   st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.iar);
 591   st->print("lr ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.lr);
 592   st->print("sp ="); print_location(st, (intptr_t)os::Aix::ucontext_get_sp(uc));
 593   for (int i = 0; i < 32; i++) {
 594     st->print("r%-2d=", i);
 595     print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.gpr[i]);
 596   }
 597 
 598   st->cr();
 599 }
 600 
 601 extern "C" {
 602   int SpinPause() {
 603     return 0;
 604   }
 605 }
 606 
 607 #ifndef PRODUCT
 608 void os::verify_stack_alignment() {
 609   assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
 610 }
 611 #endif
 612 
 613 int os::extra_bang_size_in_bytes() {
 614   // PPC does not require the additional stack bang.
 615   return 0;
 616 }
 617 
 618 bool os::platform_print_native_stack(outputStream* st, void* context, char *buf, int buf_size) {
 619   AixNativeCallstack::print_callstack_for_context(st, (const ucontext_t*)context, true, buf, (size_t) buf_size);
 620   return true;
 621 }
 622 
 623