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