Path: blob/master/src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp
40951 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016, 2019 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// This file is organized as os_linux_x86.cpp.2627// no precompiled headers28#include "jvm.h"29#include "asm/assembler.inline.hpp"30#include "classfile/vmSymbols.hpp"31#include "code/icBuffer.hpp"32#include "code/nativeInst.hpp"33#include "code/vtableStubs.hpp"34#include "compiler/disassembler.hpp"35#include "interpreter/interpreter.hpp"36#include "memory/allocation.inline.hpp"37#include "nativeInst_s390.hpp"38#include "os_share_linux.hpp"39#include "prims/jniFastGetField.hpp"40#include "prims/jvm_misc.hpp"41#include "runtime/arguments.hpp"42#include "runtime/frame.inline.hpp"43#include "runtime/interfaceSupport.inline.hpp"44#include "runtime/java.hpp"45#include "runtime/javaCalls.hpp"46#include "runtime/mutexLocker.hpp"47#include "runtime/osThread.hpp"48#include "runtime/safepointMechanism.hpp"49#include "runtime/sharedRuntime.hpp"50#include "runtime/stubRoutines.hpp"51#include "runtime/thread.inline.hpp"52#include "runtime/timer.hpp"53#include "signals_posix.hpp"54#include "utilities/events.hpp"55#include "utilities/debug.hpp"56#include "utilities/vmError.hpp"5758// put OS-includes here59# include <sys/types.h>60# include <sys/mman.h>61# include <pthread.h>62# include <signal.h>63# include <errno.h>64# include <dlfcn.h>65# include <stdlib.h>66# include <stdio.h>67# include <unistd.h>68# include <sys/resource.h>69# include <pthread.h>70# include <sys/stat.h>71# include <sys/time.h>72# include <sys/utsname.h>73# include <sys/socket.h>74# include <sys/wait.h>75# include <pwd.h>76# include <poll.h>77# include <ucontext.h>7879address os::current_stack_pointer() {80intptr_t* csp;8182// Inline assembly for `z_lgr regno(csp), Z_SP' (Z_SP = Z_R15):83__asm__ __volatile__ ("lgr %0, 15":"=r"(csp):);8485assert(((uint64_t)csp & (frame::alignment_in_bytes-1)) == 0, "SP must be aligned");86return (address) csp;87}8889char* os::non_memory_address_word() {90// Must never look like an address returned by reserve_memory,91// even in its subfields (as defined by the CPU immediate fields,92// if the CPU splits constants across multiple instructions).93return (char*) -1;94}9596// Frame information (pc, sp, fp) retrieved via ucontext97// always looks like a C-frame according to the frame98// conventions in frame_s390.hpp.99address os::Posix::ucontext_get_pc(const ucontext_t * uc) {100return (address)uc->uc_mcontext.psw.addr;101}102103void os::Posix::ucontext_set_pc(ucontext_t * uc, address pc) {104uc->uc_mcontext.psw.addr = (unsigned long)pc;105}106107static address ucontext_get_lr(const ucontext_t * uc) {108return (address)uc->uc_mcontext.gregs[14/*LINK*/];109}110111intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {112return (intptr_t*)uc->uc_mcontext.gregs[15/*REG_SP*/];113}114115intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {116return NULL;117}118119address os::fetch_frame_from_context(const void* ucVoid,120intptr_t** ret_sp, intptr_t** ret_fp) {121122address epc;123const ucontext_t* uc = (const ucontext_t*)ucVoid;124125if (uc != NULL) {126epc = os::Posix::ucontext_get_pc(uc);127if (ret_sp) { *ret_sp = os::Linux::ucontext_get_sp(uc); }128if (ret_fp) { *ret_fp = os::Linux::ucontext_get_fp(uc); }129} else {130epc = NULL;131if (ret_sp) { *ret_sp = (intptr_t *)NULL; }132if (ret_fp) { *ret_fp = (intptr_t *)NULL; }133}134135return epc;136}137138frame os::fetch_frame_from_context(const void* ucVoid) {139intptr_t* sp;140intptr_t* fp;141address epc = fetch_frame_from_context(ucVoid, &sp, &fp);142return frame(sp, epc);143}144145frame os::fetch_compiled_frame_from_context(const void* ucVoid) {146const ucontext_t* uc = (const ucontext_t*)ucVoid;147intptr_t* sp = os::Linux::ucontext_get_sp(uc);148address lr = ucontext_get_lr(uc);149return frame(sp, lr);150}151152frame os::get_sender_for_C_frame(frame* fr) {153if (*fr->sp() == 0) {154// fr is the last C frame.155return frame();156}157158// If its not one of our frames, the return pc is saved at gpr14159// stack slot. The call_stub stores the return_pc to the stack slot160// of gpr10.161if ((Interpreter::code() != NULL && Interpreter::contains(fr->pc())) ||162(CodeCache::contains(fr->pc()) && !StubRoutines::contains(fr->pc()))) {163return frame(fr->sender_sp(), fr->sender_pc());164} else {165if (StubRoutines::contains(fr->pc())) {166StubCodeDesc* desc = StubCodeDesc::desc_for(fr->pc());167if (desc && !strcmp(desc->name(),"call_stub")) {168return frame(fr->sender_sp(), fr->callstub_sender_pc());169} else {170return frame(fr->sender_sp(), fr->sender_pc());171}172} else {173return frame(fr->sender_sp(), fr->native_sender_pc());174}175}176}177178frame os::current_frame() {179// Expected to return the stack pointer of this method.180// But if inlined, returns the stack pointer of our caller!181intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());182assert (csp != NULL, "sp should not be NULL");183// Pass a dummy pc. This way we don't have to load it from the184// stack, since we don't know in which slot we can find it.185frame topframe(csp, (address)0x8);186if (os::is_first_C_frame(&topframe)) {187// Stack is not walkable.188return frame();189} else {190frame senderFrame = os::get_sender_for_C_frame(&topframe);191assert(senderFrame.pc() != NULL, "Sender pc should not be NULL");192// Return sender of sender of current topframe which hopefully193// both have pc != NULL.194#ifdef _NMT_NOINLINE_ // Is set in slowdebug builds.195// Current_stack_pointer is not inlined, we must pop one more frame.196frame tmp = os::get_sender_for_C_frame(&topframe);197return os::get_sender_for_C_frame(&tmp);198#else199return os::get_sender_for_C_frame(&topframe);200#endif201}202}203204bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,205ucontext_t* uc, JavaThread* thread) {206207// Decide if this trap can be handled by a stub.208address stub = NULL;209address pc = NULL; // Pc as retrieved from PSW. Usually points past failing instruction.210address trap_pc = NULL; // Pc of the instruction causing the trap.211212//%note os_trap_1213if (info != NULL && uc != NULL && thread != NULL) {214pc = os::Posix::ucontext_get_pc(uc);215if (TraceTraps) {216tty->print_cr(" pc at " INTPTR_FORMAT, p2i(pc));217}218if ((unsigned long)(pc - (address)info->si_addr) <= (unsigned long)Assembler::instr_maxlen() ) {219trap_pc = (address)info->si_addr;220if (TraceTraps) {221tty->print_cr("trap_pc at " INTPTR_FORMAT, p2i(trap_pc));222}223}224225// Handle ALL stack overflow variations here226if (sig == SIGSEGV) {227address addr = (address)info->si_addr; // Address causing SIGSEGV, usually mem ref target.228229// Check if fault address is within thread stack.230if (thread->is_in_full_stack(addr)) {231// stack overflow232if (os::Posix::handle_stack_overflow(thread, addr, pc, uc, &stub)) {233return true; // continue234}235}236}237238if (thread->thread_state() == _thread_in_Java) {239// Java thread running in Java code => find exception handler if any240// a fault inside compiled code, the interpreter, or a stub241242// Handle signal from NativeJump::patch_verified_entry().243if (sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) {244if (TraceTraps) {245tty->print_cr("trap: zombie_not_entrant (SIGILL)");246}247stub = SharedRuntime::get_handle_wrong_method_stub();248}249250else if (sig == SIGSEGV &&251SafepointMechanism::is_poll_address((address)info->si_addr)) {252if (TraceTraps) {253tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));254}255stub = SharedRuntime::get_poll_stub(pc);256257// Info->si_addr only points to the page base address, so we258// must extract the real si_addr from the instruction and the259// ucontext.260assert(((NativeInstruction*)pc)->is_safepoint_poll(), "must be safepoint poll");261const address real_si_addr = ((NativeInstruction*)pc)->get_poll_address(uc);262}263264// SIGTRAP-based implicit null check in compiled code.265else if ((sig == SIGFPE) &&266TrapBasedNullChecks &&267(trap_pc != NULL) &&268Assembler::is_sigtrap_zero_check(trap_pc)) {269if (TraceTraps) {270tty->print_cr("trap: NULL_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));271}272stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);273}274275else if (sig == SIGSEGV && ImplicitNullChecks &&276CodeCache::contains((void*) pc) &&277MacroAssembler::uses_implicit_null_check(info->si_addr)) {278if (TraceTraps) {279tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));280}281stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);282}283284#ifdef COMPILER2285// SIGTRAP-based implicit range check in compiled code.286else if (sig == SIGFPE && TrapBasedRangeChecks &&287(trap_pc != NULL) &&288Assembler::is_sigtrap_range_check(trap_pc)) {289if (TraceTraps) {290tty->print_cr("trap: RANGE_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));291}292stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);293}294#endif295296else if (sig == SIGFPE && info->si_code == FPE_INTDIV) {297stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);298}299300else if (sig == SIGBUS) {301// BugId 4454115: A read from a MappedByteBuffer can fault here if the302// underlying file has been truncated. Do not crash the VM in such a case.303CodeBlob* cb = CodeCache::find_blob_unsafe(pc);304CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;305if (nm != NULL && nm->has_unsafe_access()) {306// We don't really need a stub here! Just set the pending exeption and307// continue at the next instruction after the faulting read. Returning308// garbage from this read is ok.309thread->set_pending_unsafe_access_error();310uc->uc_mcontext.psw.addr = ((unsigned long)pc) + Assembler::instr_len(pc);311return true;312}313}314}315316else { // thread->thread_state() != _thread_in_Java317if ((sig == SIGILL) && VM_Version::is_determine_features_test_running()) {318// SIGILL must be caused by VM_Version::determine_features()319// when attempting to execute a non-existing instruction.320//*(int *) (pc-6)=0; // Patch instruction to 0 to indicate that it causes a SIGILL.321// Flushing of icache is not necessary.322stub = pc; // Continue with next instruction.323} else if ((sig == SIGFPE) && VM_Version::is_determine_features_test_running()) {324// SIGFPE is known to be caused by trying to execute a vector instruction325// when the vector facility is installed, but operating system support is missing.326VM_Version::reset_has_VectorFacility();327stub = pc; // Continue with next instruction.328} else if ((thread->thread_state() == _thread_in_vm ||329thread->thread_state() == _thread_in_native) &&330sig == SIGBUS && thread->doing_unsafe_access()) {331// We don't really need a stub here! Just set the pending exeption and332// continue at the next instruction after the faulting read. Returning333// garbage from this read is ok.334thread->set_pending_unsafe_access_error();335os::Posix::ucontext_set_pc(uc, pc + Assembler::instr_len(pc));336return true;337}338}339340// jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in341// and the heap gets shrunk before the field access.342if ((sig == SIGSEGV) || (sig == SIGBUS)) {343address addr = JNI_FastGetField::find_slowcase_pc(pc);344if (addr != (address)-1) {345stub = addr;346}347}348}349350if (stub != NULL) {351// Save all thread context in case we need to restore it.352if (thread != NULL) thread->set_saved_exception_pc(pc);353os::Posix::ucontext_set_pc(uc, stub);354return true;355}356357return false;358}359360void os::Linux::init_thread_fpu_state(void) {361// Nothing to do on z/Architecture.362}363364int os::Linux::get_fpu_control_word(void) {365// Nothing to do on z/Architecture.366return 0;367}368369void os::Linux::set_fpu_control_word(int fpu_control) {370// Nothing to do on z/Architecture.371}372373////////////////////////////////////////////////////////////////////////////////374// thread stack375376// Minimum usable stack sizes required to get to user code. Space for377// HotSpot guard pages is added later.378size_t os::Posix::_compiler_thread_min_stack_allowed = (52 DEBUG_ONLY(+ 32)) * K;379size_t os::Posix::_java_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 8)) * K;380size_t os::Posix::_vm_internal_thread_min_stack_allowed = 32 * K;381382// Return default stack size for thr_type.383size_t os::Posix::default_stack_size(os::ThreadType thr_type) {384// Default stack size (compiler thread needs larger stack).385size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K);386return s;387}388389/////////////////////////////////////////////////////////////////////////////390// helper functions for fatal error handler391392void os::print_context(outputStream *st, const void *context) {393if (context == NULL) return;394395const ucontext_t* uc = (const ucontext_t*)context;396397st->print_cr("Processor state:");398st->print_cr("----------------");399st->print_cr(" ip = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.addr);400st->print_cr(" proc mask = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.mask);401st->print_cr(" fpc reg = 0x%8.8x " , uc->uc_mcontext.fpregs.fpc);402st->cr();403404st->print_cr("General Purpose Registers:");405st->print_cr("--------------------------");406for( int i = 0; i < 16; i+=2 ) {407st->print(" r%-2d = " INTPTR_FORMAT " " , i, uc->uc_mcontext.gregs[i]);408st->print(" r%-2d = " INTPTR_FORMAT " |", i+1, uc->uc_mcontext.gregs[i+1]);409st->print(" r%-2d = %23.1ld " , i, uc->uc_mcontext.gregs[i]);410st->print(" r%-2d = %23.1ld " , i+1, uc->uc_mcontext.gregs[i+1]);411st->cr();412}413st->cr();414415st->print_cr("Access Registers:");416st->print_cr("-----------------");417for( int i = 0; i < 16; i+=2 ) {418st->print(" ar%-2d = 0x%8.8x ", i, uc->uc_mcontext.aregs[i]);419st->print(" ar%-2d = 0x%8.8x ", i+1, uc->uc_mcontext.aregs[i+1]);420st->cr();421}422st->cr();423424st->print_cr("Float Registers:");425st->print_cr("----------------");426for (int i = 0; i < 16; i += 2) {427st->print(" fr%-2d = " INTPTR_FORMAT " " , i, (int64_t)(uc->uc_mcontext.fpregs.fprs[i].d));428st->print(" fr%-2d = " INTPTR_FORMAT " |", i+1, (int64_t)(uc->uc_mcontext.fpregs.fprs[i+1].d));429st->print(" fr%-2d = %23.15e " , i, (uc->uc_mcontext.fpregs.fprs[i].d));430st->print(" fr%-2d = %23.15e " , i+1, (uc->uc_mcontext.fpregs.fprs[i+1].d));431st->cr();432}433st->cr();434st->cr();435436intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);437st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));438print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));439st->cr();440441// Note: it may be unsafe to inspect memory near pc. For example, pc may442// point to garbage if entry point in an nmethod is corrupted. Leave443// this at the end, and hope for the best.444address pc = os::Posix::ucontext_get_pc(uc);445print_instructions(st, pc, /*intrsize=*/4);446st->cr();447}448449void os::print_register_info(outputStream *st, const void *context) {450if (context == NULL) return;451452const ucontext_t *uc = (const ucontext_t*)context;453454st->print_cr("Register to memory mapping:");455st->cr();456457st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.psw.addr);458for (int i = 0; i < 16; i++) {459st->print("r%-2d=", i);460print_location(st, uc->uc_mcontext.gregs[i]);461}462st->cr();463}464465#ifndef PRODUCT466void os::verify_stack_alignment() {467}468#endif469470int os::extra_bang_size_in_bytes() {471// z/Architecture does not require the additional stack bang.472return 0;473}474475476