1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012, 2018 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/safepointMechanism.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 static address ucontext_get_lr(const ucontext_t * uc) {
 115   return (address)uc->uc_mcontext.jmp_context.lr;
 116 }
 117 
 118 ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
 119                                         intptr_t** ret_sp, intptr_t** ret_fp) {
 120 
 121   ExtendedPC  epc;
 122   const ucontext_t* uc = (const ucontext_t*)ucVoid;
 123 
 124   if (uc != NULL) {
 125     epc = ExtendedPC(os::Aix::ucontext_get_pc(uc));
 126     if (ret_sp) *ret_sp = os::Aix::ucontext_get_sp(uc);
 127     if (ret_fp) *ret_fp = os::Aix::ucontext_get_fp(uc);
 128   } else {
 129     // construct empty ExtendedPC for return value checking
 130     epc = ExtendedPC(NULL);
 131     if (ret_sp) *ret_sp = (intptr_t *)NULL;
 132     if (ret_fp) *ret_fp = (intptr_t *)NULL;
 133   }
 134 
 135   return epc;
 136 }
 137 
 138 frame os::fetch_frame_from_context(const void* ucVoid) {
 139   intptr_t* sp;
 140   intptr_t* fp;
 141   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
 142   // Avoid crash during crash if pc broken.
 143   if (epc.pc()) {
 144     frame fr(sp, epc.pc());
 145     return fr;
 146   }
 147   frame fr(sp);
 148   return fr;
 149 }
 150 
 151 bool os::Aix::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
 152   address pc = (address) os::Aix::ucontext_get_pc(uc);
 153   if (Interpreter::contains(pc)) {
 154     // Interpreter performs stack banging after the fixed frame header has
 155     // been generated while the compilers perform it before. To maintain
 156     // semantic consistency between interpreted and compiled frames, the
 157     // method returns the Java sender of the current frame.
 158     *fr = os::fetch_frame_from_context(uc);
 159     if (!fr->is_first_java_frame()) {
 160       assert(fr->safe_for_sender(thread), "Safety check");
 161       *fr = fr->java_sender();
 162     }
 163   } else {
 164     // More complex code with compiled code.
 165     assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
 166     CodeBlob* cb = CodeCache::find_blob(pc);
 167     if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
 168       // Not sure where the pc points to, fallback to default
 169       // stack overflow handling. In compiled code, we bang before
 170       // the frame is complete.
 171       return false;
 172     } else {
 173       intptr_t* sp = os::Aix::ucontext_get_sp(uc);
 174       address lr = ucontext_get_lr(uc);
 175       *fr = frame(sp, lr);
 176       if (!fr->is_java_frame()) {
 177         assert(fr->safe_for_sender(thread), "Safety check");
 178         assert(!fr->is_first_frame(), "Safety check");
 179         *fr = fr->java_sender();
 180       }
 181     }
 182   }
 183   assert(fr->is_java_frame(), "Safety check");
 184   return true;
 185 }
 186 
 187 frame os::get_sender_for_C_frame(frame* fr) {
 188   if (*fr->sp() == NULL) {
 189     // fr is the last C frame
 190     return frame(NULL, NULL);
 191   }
 192   return frame(fr->sender_sp(), fr->sender_pc());
 193 }
 194 
 195 
 196 frame os::current_frame() {
 197   intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
 198   // hack.
 199   frame topframe(csp, (address)0x8);
 200   // Return sender of sender of current topframe which hopefully
 201   // both have pc != NULL.
 202   frame tmp = os::get_sender_for_C_frame(&topframe);
 203   return os::get_sender_for_C_frame(&tmp);
 204 }
 205 
 206 // Utility functions
 207 
 208 extern "C" JNIEXPORT int
 209 JVM_handle_aix_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrecognized) {
 210 
 211   ucontext_t* uc = (ucontext_t*) ucVoid;
 212 
 213   Thread* t = Thread::current_or_null_safe();
 214 
 215   SignalHandlerMark shm(t);
 216 
 217   // Note: it's not uncommon that JNI code uses signal/sigset to install
 218   // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
 219   // or have a SIGILL handler when detecting CPU type). When that happens,
 220   // JVM_handle_aix_signal() might be invoked with junk info/ucVoid. To
 221   // avoid unnecessary crash when libjsig is not preloaded, try handle signals
 222   // that do not require siginfo/ucontext first.
 223 
 224   if (sig == SIGPIPE) {
 225     if (os::Aix::chained_handler(sig, info, ucVoid)) {
 226       return 1;
 227     } else {
 228       // Ignoring SIGPIPE - see bugs 4229104
 229       return 1;
 230     }
 231   }
 232 
 233   JavaThread* thread = NULL;
 234   VMThread* vmthread = NULL;
 235   if (os::Aix::signal_handlers_are_installed) {
 236     if (t != NULL) {
 237       if(t->is_Java_thread()) {
 238         thread = (JavaThread*)t;
 239       }
 240       else if(t->is_VM_thread()) {
 241         vmthread = (VMThread *)t;
 242       }
 243     }
 244   }
 245 
 246   // Decide if this trap can be handled by a stub.
 247   address stub = NULL;
 248 
 249   // retrieve program counter
 250   address const pc = uc ? os::Aix::ucontext_get_pc(uc) : NULL;
 251 
 252   // retrieve crash address
 253   address const addr = info ? (const address) info->si_addr : NULL;
 254 
 255   // SafeFetch 32 handling:
 256   // - make it work if _thread is null
 257   // - make it use the standard os::...::ucontext_get/set_pc APIs
 258   if (uc) {
 259     address const pc = os::Aix::ucontext_get_pc(uc);
 260     if (pc && StubRoutines::is_safefetch_fault(pc)) {
 261       os::Aix::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
 262       return true;
 263     }
 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 ((SafepointMechanism::uses_thread_local_poll() && USE_POLL_BIT_ONLY)
 384                ? (sig == SIGTRAP && ((NativeInstruction*)pc)->is_safepoint_poll())
 385                : (sig == SIGSEGV && os::is_poll_address(addr))) {
 386         if (TraceTraps) {
 387           tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (%s)", p2i(pc),
 388                         (SafepointMechanism::uses_thread_local_poll() && USE_POLL_BIT_ONLY) ? "SIGTRAP" : "SIGSEGV");
 389         }
 390         stub = SharedRuntime::get_poll_stub(pc);
 391         goto run_stub;
 392       }
 393 
 394       // SIGTRAP-based ic miss check in compiled code.
 395       else if (sig == SIGTRAP && TrapBasedICMissChecks &&
 396                nativeInstruction_at(pc)->is_sigtrap_ic_miss_check()) {
 397         if (TraceTraps) {
 398           tty->print_cr("trap: ic_miss_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
 399         }
 400         stub = SharedRuntime::get_ic_miss_stub();
 401         goto run_stub;
 402       }
 403 
 404       // SIGTRAP-based implicit null check in compiled code.
 405       else if (sig == SIGTRAP && TrapBasedNullChecks &&
 406                nativeInstruction_at(pc)->is_sigtrap_null_check()) {
 407         if (TraceTraps) {
 408           tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
 409         }
 410         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 411         goto run_stub;
 412       }
 413 
 414       // SIGSEGV-based implicit null check in compiled code.
 415       else if (sig == SIGSEGV && ImplicitNullChecks &&
 416                CodeCache::contains((void*) pc) &&
 417                !MacroAssembler::needs_explicit_null_check((intptr_t) info->si_addr)) {
 418         if (TraceTraps) {
 419           tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", pc);
 420         }
 421         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 422       }
 423 
 424 #ifdef COMPILER2
 425       // SIGTRAP-based implicit range check in compiled code.
 426       else if (sig == SIGTRAP && TrapBasedRangeChecks &&
 427                nativeInstruction_at(pc)->is_sigtrap_range_check()) {
 428         if (TraceTraps) {
 429           tty->print_cr("trap: range_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
 430         }
 431         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 432         goto run_stub;
 433       }
 434 #endif
 435 
 436       else if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
 437         if (TraceTraps) {
 438           tty->print_raw_cr("Fix SIGFPE handler, trying divide by zero handler.");
 439         }
 440         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
 441         goto run_stub;
 442       }
 443 
 444       else if (sig == SIGBUS) {
 445         // BugId 4454115: A read from a MappedByteBuffer can fault here if the
 446         // underlying file has been truncated. Do not crash the VM in such a case.
 447         CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 448         CompiledMethod* nm = cb->as_compiled_method_or_null();
 449         if (nm != NULL && nm->has_unsafe_access()) {
 450           address next_pc = pc + 4;
 451           next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);
 452           os::Aix::ucontext_set_pc(uc, next_pc);
 453           return 1;
 454         }
 455       }
 456     }
 457 
 458     else { // thread->thread_state() != _thread_in_Java
 459       // Detect CPU features. This is only done at the very start of the VM. Later, the
 460       // VM_Version::is_determine_features_test_running() flag should be false.
 461 
 462       if (sig == SIGILL && VM_Version::is_determine_features_test_running()) {
 463         // SIGILL must be caused by VM_Version::determine_features().
 464         *(int *)pc = 0; // patch instruction to 0 to indicate that it causes a SIGILL,
 465                         // flushing of icache is not necessary.
 466         stub = pc + 4;  // continue with next instruction.
 467         goto run_stub;
 468       }
 469       else if (thread->thread_state() == _thread_in_vm &&
 470                sig == SIGBUS && thread->doing_unsafe_access()) {
 471         address next_pc = pc + 4;
 472         next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);
 473         os::Aix::ucontext_set_pc(uc, next_pc);
 474         return 1;
 475       }
 476     }
 477 
 478     // Check to see if we caught the safepoint code in the
 479     // process of write protecting the memory serialization page.
 480     // It write enables the page immediately after protecting it
 481     // so we can just return to retry the write.
 482     if ((sig == SIGSEGV) &&
 483         os::is_memory_serialize_page(thread, addr)) {
 484       // Synchronization problem in the pseudo memory barrier code (bug id 6546278)
 485       // Block current thread until the memory serialize page permission restored.
 486       os::block_on_serialize_page_trap();
 487       return true;
 488     }
 489   }
 490 
 491 run_stub:
 492 
 493   // One of the above code blocks ininitalized the stub, so we want to
 494   // delegate control to that stub.
 495   if (stub != NULL) {
 496     // Save all thread context in case we need to restore it.
 497     if (thread != NULL) thread->set_saved_exception_pc(pc);
 498     os::Aix::ucontext_set_pc(uc, stub);
 499     return 1;
 500   }
 501 
 502 run_chained_handler:
 503 
 504   // signal-chaining
 505   if (os::Aix::chained_handler(sig, info, ucVoid)) {
 506     return 1;
 507   }
 508   if (!abort_if_unrecognized) {
 509     // caller wants another chance, so give it to him
 510     return 0;
 511   }
 512 
 513 report_and_die:
 514 
 515   // Use sigthreadmask instead of sigprocmask on AIX and unmask current signal.
 516   sigset_t newset;
 517   sigemptyset(&newset);
 518   sigaddset(&newset, sig);
 519   sigthreadmask(SIG_UNBLOCK, &newset, NULL);
 520 
 521   VMError::report_and_die(t, sig, pc, info, ucVoid);
 522 
 523   ShouldNotReachHere();
 524   return 0;
 525 }
 526 
 527 void os::Aix::init_thread_fpu_state(void) {
 528 #if !defined(USE_XLC_BUILTINS)
 529   // Disable FP exceptions.
 530   __asm__ __volatile__ ("mtfsfi 6,0");
 531 #else
 532   __mtfsfi(6, 0);
 533 #endif
 534 }
 535 
 536 ////////////////////////////////////////////////////////////////////////////////
 537 // thread stack
 538 
 539 // Minimum usable stack sizes required to get to user code. Space for
 540 // HotSpot guard pages is added later.
 541 size_t os::Posix::_compiler_thread_min_stack_allowed = 192 * K;
 542 size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
 543 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 544 
 545 // Return default stack size for thr_type.
 546 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
 547   // Default stack size (compiler thread needs larger stack).
 548   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
 549   return s;
 550 }
 551 
 552 /////////////////////////////////////////////////////////////////////////////
 553 // helper functions for fatal error handler
 554 
 555 void os::print_context(outputStream *st, const void *context) {
 556   if (context == NULL) return;
 557 
 558   const ucontext_t* uc = (const ucontext_t*)context;
 559 
 560   st->print_cr("Registers:");
 561   st->print("pc =" INTPTR_FORMAT "  ", uc->uc_mcontext.jmp_context.iar);
 562   st->print("lr =" INTPTR_FORMAT "  ", uc->uc_mcontext.jmp_context.lr);
 563   st->print("ctr=" INTPTR_FORMAT "  ", uc->uc_mcontext.jmp_context.ctr);
 564   st->cr();
 565   for (int i = 0; i < 32; i++) {
 566     st->print("r%-2d=" INTPTR_FORMAT "  ", i, uc->uc_mcontext.jmp_context.gpr[i]);
 567     if (i % 3 == 2) st->cr();
 568   }
 569   st->cr();
 570   st->cr();
 571 
 572   intptr_t *sp = (intptr_t *)os::Aix::ucontext_get_sp(uc);
 573   st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
 574   print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
 575   st->cr();
 576 
 577   // Note: it may be unsafe to inspect memory near pc. For example, pc may
 578   // point to garbage if entry point in an nmethod is corrupted. Leave
 579   // this at the end, and hope for the best.
 580   address pc = os::Aix::ucontext_get_pc(uc);
 581   st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
 582   print_hex_dump(st, pc - 64, pc + 64, /*instrsize=*/4);
 583   st->cr();
 584 
 585   // Try to decode the instructions.
 586   st->print_cr("Decoded instructions: (pc=" PTR_FORMAT ")", pc);
 587   st->print("<TODO: PPC port - print_context>");
 588   // TODO: PPC port Disassembler::decode(pc, 16, 16, st);
 589   st->cr();
 590 }
 591 
 592 void os::print_register_info(outputStream *st, const void *context) {
 593   if (context == NULL) return;
 594 
 595   ucontext_t *uc = (ucontext_t*)context;
 596 
 597   st->print_cr("Register to memory mapping:");
 598   st->cr();
 599 
 600   st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.iar);
 601   st->print("lr ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.lr);
 602   st->print("sp ="); print_location(st, (intptr_t)os::Aix::ucontext_get_sp(uc));
 603   for (int i = 0; i < 32; i++) {
 604     st->print("r%-2d=", i);
 605     print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.gpr[i]);
 606   }
 607 
 608   st->cr();
 609 }
 610 
 611 extern "C" {
 612   int SpinPause() {
 613     return 0;
 614   }
 615 }
 616 
 617 #ifndef PRODUCT
 618 void os::verify_stack_alignment() {
 619   assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
 620 }
 621 #endif
 622 
 623 int os::extra_bang_size_in_bytes() {
 624   // PPC does not require the additional stack bang.
 625   return 0;
 626 }
 627 
 628 bool os::platform_print_native_stack(outputStream* st, void* context, char *buf, int buf_size) {
 629   AixNativeCallstack::print_callstack_for_context(st, (const ucontext_t*)context, true, buf, (size_t) buf_size);
 630   return true;
 631 }
 632 
 633