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