Path: blob/master/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp
40930 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2012, 2021 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425// no precompiled headers26#include "jvm.h"27#include "assembler_ppc.hpp"28#include "asm/assembler.inline.hpp"29#include "classfile/vmSymbols.hpp"30#include "code/codeCache.hpp"31#include "code/icBuffer.hpp"32#include "code/vtableStubs.hpp"33#include "interpreter/interpreter.hpp"34#include "memory/allocation.inline.hpp"35#include "nativeInst_ppc.hpp"36#include "os_share_aix.hpp"37#include "prims/jniFastGetField.hpp"38#include "prims/jvm_misc.hpp"39#include "porting_aix.hpp"40#include "runtime/arguments.hpp"41#include "runtime/frame.inline.hpp"42#include "runtime/interfaceSupport.inline.hpp"43#include "runtime/java.hpp"44#include "runtime/javaCalls.hpp"45#include "runtime/mutexLocker.hpp"46#include "runtime/osThread.hpp"47#include "runtime/safepointMechanism.hpp"48#include "runtime/sharedRuntime.hpp"49#include "runtime/stubRoutines.hpp"50#include "runtime/thread.inline.hpp"51#include "runtime/timer.hpp"52#include "signals_posix.hpp"53#include "utilities/events.hpp"54#include "utilities/vmError.hpp"55#ifdef COMPILER156#include "c1/c1_Runtime1.hpp"57#endif58#ifdef COMPILER259#include "opto/runtime.hpp"60#endif6162// put OS-includes here63# include <ucontext.h>6465address os::current_stack_pointer() {66return (address)__builtin_frame_address(0);67}6869char* os::non_memory_address_word() {70// Must never look like an address returned by reserve_memory,71// even in its subfields (as defined by the CPU immediate fields,72// if the CPU splits constants across multiple instructions).7374return (char*) -1;75}7677// Frame information (pc, sp, fp) retrieved via ucontext78// always looks like a C-frame according to the frame79// conventions in frame_ppc.hpp.8081address os::Posix::ucontext_get_pc(const ucontext_t * uc) {82return (address)uc->uc_mcontext.jmp_context.iar;83}8485intptr_t* os::Aix::ucontext_get_sp(const ucontext_t * uc) {86// gpr1 holds the stack pointer on aix87return (intptr_t*)uc->uc_mcontext.jmp_context.gpr[1/*REG_SP*/];88}8990intptr_t* os::Aix::ucontext_get_fp(const ucontext_t * uc) {91return NULL;92}9394void os::Posix::ucontext_set_pc(ucontext_t* uc, address new_pc) {95uc->uc_mcontext.jmp_context.iar = (uint64_t) new_pc;96}9798static address ucontext_get_lr(const ucontext_t * uc) {99return (address)uc->uc_mcontext.jmp_context.lr;100}101102address os::fetch_frame_from_context(const void* ucVoid,103intptr_t** ret_sp, intptr_t** ret_fp) {104105address epc;106const ucontext_t* uc = (const ucontext_t*)ucVoid;107108if (uc != NULL) {109epc = os::Posix::ucontext_get_pc(uc);110if (ret_sp) *ret_sp = os::Aix::ucontext_get_sp(uc);111if (ret_fp) *ret_fp = os::Aix::ucontext_get_fp(uc);112} else {113epc = NULL;114if (ret_sp) *ret_sp = (intptr_t *)NULL;115if (ret_fp) *ret_fp = (intptr_t *)NULL;116}117118return epc;119}120121frame os::fetch_frame_from_context(const void* ucVoid) {122intptr_t* sp;123intptr_t* fp;124address epc = fetch_frame_from_context(ucVoid, &sp, &fp);125// Avoid crash during crash if pc broken.126if (epc) {127frame fr(sp, epc);128return fr;129}130frame fr(sp);131return fr;132}133134frame os::fetch_compiled_frame_from_context(const void* ucVoid) {135const ucontext_t* uc = (const ucontext_t*)ucVoid;136intptr_t* sp = os::Aix::ucontext_get_sp(uc);137address lr = ucontext_get_lr(uc);138return frame(sp, lr);139}140141frame os::get_sender_for_C_frame(frame* fr) {142if (*fr->sp() == NULL) {143// fr is the last C frame144return frame(NULL, NULL);145}146return frame(fr->sender_sp(), fr->sender_pc());147}148149150frame os::current_frame() {151intptr_t* csp = *(intptr_t**) __builtin_frame_address(0);152frame topframe(csp, CAST_FROM_FN_PTR(address, os::current_frame));153return os::get_sender_for_C_frame(&topframe);154}155156bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,157ucontext_t* uc, JavaThread* thread) {158159// Decide if this trap can be handled by a stub.160address stub = NULL;161162// retrieve program counter163address const pc = uc ? os::Posix::ucontext_get_pc(uc) : NULL;164165// retrieve crash address166address const addr = info ? (const address) info->si_addr : NULL;167168if (info == NULL || uc == NULL) {169return false; // Fatal error170}171172// If we are a java thread...173if (thread != NULL) {174175// Handle ALL stack overflow variations here176if (sig == SIGSEGV && thread->is_in_full_stack(addr)) {177// stack overflow178if (os::Posix::handle_stack_overflow(thread, addr, pc, uc, &stub)) {179return true; // continue180} else if (stub != NULL) {181goto run_stub;182} else {183return false; // Fatal error184}185} // end handle SIGSEGV inside stack boundaries186187if (thread->thread_state() == _thread_in_Java) {188// Java thread running in Java code189190// The following signals are used for communicating VM events:191//192// SIGILL: the compiler generates illegal opcodes193// at places where it wishes to interrupt the VM:194// Safepoints, Unreachable Code, Entry points of Zombie methods,195// This results in a SIGILL with (*pc) == inserted illegal instruction.196//197// (so, SIGILLs with a pc inside the zero page are real errors)198//199// SIGTRAP:200// The ppc trap instruction raises a SIGTRAP and is very efficient if it201// does not trap. It is used for conditional branches that are expected202// to be never taken. These are:203// - zombie methods204// - IC (inline cache) misses.205// - null checks leading to UncommonTraps.206// - range checks leading to Uncommon Traps.207// On Aix, these are especially null checks, as the ImplicitNullCheck208// optimization works only in rare cases, as the page at address 0 is only209// write protected. //210// Note: !UseSIGTRAP is used to prevent SIGTRAPS altogether, to facilitate debugging.211//212// SIGSEGV:213// used for safe point polling:214// To notify all threads that they have to reach a safe point, safe point polling is used:215// All threads poll a certain mapped memory page. Normally, this page has read access.216// If the VM wants to inform the threads about impending safe points, it puts this217// page to read only ("poisens" the page), and the threads then reach a safe point.218// used for null checks:219// If the compiler finds a store it uses it for a null check. Unfortunately this220// happens rarely. In heap based and disjoint base compressd oop modes also loads221// are used for null checks.222223CodeBlob *cb = NULL;224int stop_type = -1;225// Handle signal from NativeJump::patch_verified_entry().226if (sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) {227if (TraceTraps) {228tty->print_cr("trap: zombie_not_entrant");229}230stub = SharedRuntime::get_handle_wrong_method_stub();231goto run_stub;232}233234else if ((sig == USE_POLL_BIT_ONLY ? SIGTRAP : SIGSEGV) &&235((NativeInstruction*)pc)->is_safepoint_poll() &&236CodeCache::contains((void*) pc) &&237((cb = CodeCache::find_blob(pc)) != NULL) &&238cb->is_compiled()) {239if (TraceTraps) {240tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (%s)", p2i(pc),241USE_POLL_BIT_ONLY ? "SIGTRAP" : "SIGSEGV");242}243stub = SharedRuntime::get_poll_stub(pc);244goto run_stub;245}246247else if (UseSIGTRAP && sig == SIGTRAP &&248((NativeInstruction*)pc)->is_safepoint_poll_return() &&249CodeCache::contains((void*) pc) &&250((cb = CodeCache::find_blob(pc)) != NULL) &&251cb->is_compiled()) {252if (TraceTraps) {253tty->print_cr("trap: safepoint_poll at return at " INTPTR_FORMAT " (nmethod)", p2i(pc));254}255stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();256goto run_stub;257}258259// SIGTRAP-based ic miss check in compiled code.260else if (sig == SIGTRAP && TrapBasedICMissChecks &&261nativeInstruction_at(pc)->is_sigtrap_ic_miss_check()) {262if (TraceTraps) {263tty->print_cr("trap: ic_miss_check at " INTPTR_FORMAT " (SIGTRAP)", pc);264}265stub = SharedRuntime::get_ic_miss_stub();266goto run_stub;267}268269// SIGTRAP-based implicit null check in compiled code.270else if (sig == SIGTRAP && TrapBasedNullChecks &&271nativeInstruction_at(pc)->is_sigtrap_null_check()) {272if (TraceTraps) {273tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGTRAP)", pc);274}275stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);276goto run_stub;277}278279// SIGSEGV-based implicit null check in compiled code.280else if (sig == SIGSEGV && ImplicitNullChecks &&281CodeCache::contains((void*) pc) &&282MacroAssembler::uses_implicit_null_check(info->si_addr)) {283if (TraceTraps) {284tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", pc);285}286stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);287}288289#ifdef COMPILER2290// SIGTRAP-based implicit range check in compiled code.291else if (sig == SIGTRAP && TrapBasedRangeChecks &&292nativeInstruction_at(pc)->is_sigtrap_range_check()) {293if (TraceTraps) {294tty->print_cr("trap: range_check at " INTPTR_FORMAT " (SIGTRAP)", pc);295}296stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);297goto run_stub;298}299#endif300301else if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {302if (TraceTraps) {303tty->print_raw_cr("Fix SIGFPE handler, trying divide by zero handler.");304}305stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);306goto run_stub;307}308309// stop on request310else if (sig == SIGTRAP && (stop_type = nativeInstruction_at(pc)->get_stop_type()) != -1) {311bool msg_present = (stop_type & MacroAssembler::stop_msg_present);312stop_type = (stop_type &~ MacroAssembler::stop_msg_present);313314const char *msg = NULL;315switch (stop_type) {316case MacroAssembler::stop_stop : msg = "stop"; break;317case MacroAssembler::stop_untested : msg = "untested"; break;318case MacroAssembler::stop_unimplemented : msg = "unimplemented"; break;319case MacroAssembler::stop_shouldnotreachhere: msg = "shouldnotreachhere"; break;320default: msg = "unknown"; break;321}322323const char **detail_msg_ptr = (const char**)(pc + 4);324const char *detail_msg = msg_present ? *detail_msg_ptr : "no details provided";325326if (TraceTraps) {327tty->print_cr("trap: %s: %s (SIGTRAP, stop type %d)", msg, detail_msg, stop_type);328}329330// End life with a fatal error, message and detail message and the context.331// Note: no need to do any post-processing here (e.g. signal chaining)332va_list va_dummy;333VMError::report_and_die(thread, uc, NULL, 0, msg, detail_msg, va_dummy);334va_end(va_dummy);335336ShouldNotReachHere();337}338339else if (sig == SIGBUS) {340// BugId 4454115: A read from a MappedByteBuffer can fault here if the341// underlying file has been truncated. Do not crash the VM in such a case.342CodeBlob* cb = CodeCache::find_blob_unsafe(pc);343CompiledMethod* nm = cb ? cb->as_compiled_method_or_null() : NULL;344bool is_unsafe_arraycopy = (thread->doing_unsafe_access() && UnsafeCopyMemory::contains_pc(pc));345if ((nm != NULL && nm->has_unsafe_access()) || is_unsafe_arraycopy) {346address next_pc = pc + 4;347if (is_unsafe_arraycopy) {348next_pc = UnsafeCopyMemory::page_error_continue_pc(pc);349}350next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);351os::Posix::ucontext_set_pc(uc, next_pc);352return true;353}354}355}356357else { // thread->thread_state() != _thread_in_Java358// Detect CPU features. This is only done at the very start of the VM. Later, the359// VM_Version::is_determine_features_test_running() flag should be false.360361if (sig == SIGILL && VM_Version::is_determine_features_test_running()) {362// SIGILL must be caused by VM_Version::determine_features().363*(int *)pc = 0; // patch instruction to 0 to indicate that it causes a SIGILL,364// flushing of icache is not necessary.365stub = pc + 4; // continue with next instruction.366goto run_stub;367}368else if ((thread->thread_state() == _thread_in_vm ||369thread->thread_state() == _thread_in_native) &&370sig == SIGBUS && thread->doing_unsafe_access()) {371address next_pc = pc + 4;372if (UnsafeCopyMemory::contains_pc(pc)) {373next_pc = UnsafeCopyMemory::page_error_continue_pc(pc);374}375next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);376os::Posix::ucontext_set_pc(uc, next_pc);377return true;378}379}380381// jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in382// and the heap gets shrunk before the field access.383if ((sig == SIGSEGV) || (sig == SIGBUS)) {384address addr = JNI_FastGetField::find_slowcase_pc(pc);385if (addr != (address)-1) {386stub = addr;387}388}389}390391run_stub:392393// One of the above code blocks ininitalized the stub, so we want to394// delegate control to that stub.395if (stub != NULL) {396// Save all thread context in case we need to restore it.397if (thread != NULL) thread->set_saved_exception_pc(pc);398os::Posix::ucontext_set_pc(uc, stub);399return true;400}401402return false; // Fatal error403}404405void os::Aix::init_thread_fpu_state(void) {406#if !defined(USE_XLC_BUILTINS)407// Disable FP exceptions.408__asm__ __volatile__ ("mtfsfi 6,0");409#else410__mtfsfi(6, 0);411#endif412}413414////////////////////////////////////////////////////////////////////////////////415// thread stack416417// Minimum usable stack sizes required to get to user code. Space for418// HotSpot guard pages is added later.419size_t os::Posix::_compiler_thread_min_stack_allowed = 192 * K;420size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;421size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;422423// Return default stack size for thr_type.424size_t os::Posix::default_stack_size(os::ThreadType thr_type) {425// Default stack size (compiler thread needs larger stack).426size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);427return s;428}429430/////////////////////////////////////////////////////////////////////////////431// helper functions for fatal error handler432433void os::print_context(outputStream *st, const void *context) {434if (context == NULL) return;435436const ucontext_t* uc = (const ucontext_t*)context;437438st->print_cr("Registers:");439st->print("pc =" INTPTR_FORMAT " ", uc->uc_mcontext.jmp_context.iar);440st->print("lr =" INTPTR_FORMAT " ", uc->uc_mcontext.jmp_context.lr);441st->print("ctr=" INTPTR_FORMAT " ", uc->uc_mcontext.jmp_context.ctr);442st->cr();443for (int i = 0; i < 32; i++) {444st->print("r%-2d=" INTPTR_FORMAT " ", i, uc->uc_mcontext.jmp_context.gpr[i]);445if (i % 3 == 2) st->cr();446}447st->cr();448st->cr();449450intptr_t *sp = (intptr_t *)os::Aix::ucontext_get_sp(uc);451st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);452print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));453st->cr();454455// Note: it may be unsafe to inspect memory near pc. For example, pc may456// point to garbage if entry point in an nmethod is corrupted. Leave457// this at the end, and hope for the best.458address pc = os::Posix::ucontext_get_pc(uc);459print_instructions(st, pc, /*instrsize=*/4);460st->cr();461462// Try to decode the instructions.463st->print_cr("Decoded instructions: (pc=" PTR_FORMAT ")", pc);464st->print("<TODO: PPC port - print_context>");465// TODO: PPC port Disassembler::decode(pc, 16, 16, st);466st->cr();467}468469void os::print_register_info(outputStream *st, const void *context) {470if (context == NULL) return;471472ucontext_t *uc = (ucontext_t*)context;473474st->print_cr("Register to memory mapping:");475st->cr();476477st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.iar);478st->print("lr ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.lr);479st->print("sp ="); print_location(st, (intptr_t)os::Aix::ucontext_get_sp(uc));480for (int i = 0; i < 32; i++) {481st->print("r%-2d=", i);482print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.gpr[i]);483}484485st->cr();486}487488extern "C" {489int SpinPause() {490return 0;491}492}493494#ifndef PRODUCT495void os::verify_stack_alignment() {496assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");497}498#endif499500int os::extra_bang_size_in_bytes() {501// PPC does not require the additional stack bang.502return 0;503}504505bool os::platform_print_native_stack(outputStream* st, void* context, char *buf, int buf_size) {506AixNativeCallstack::print_callstack_for_context(st, (const ucontext_t*)context, true, buf, (size_t) buf_size);507return true;508}509510// HAVE_FUNCTION_DESCRIPTORS511void* os::resolve_function_descriptor(void* p) {512return ((const FunctionDescriptor*)p)->entry();513}514515516