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