Path: blob/master/src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp
40949 views
/*1* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright 2007, 2008, 2009, 2010 Red Hat, Inc.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#if !defined(__APPLE__) && !defined(__NetBSD__)26#include <pthread.h>27# include <pthread_np.h> /* For pthread_attr_get_np */28#endif2930// no precompiled headers31#include "jvm.h"32#include "asm/assembler.inline.hpp"33#include "classfile/vmSymbols.hpp"34#include "code/icBuffer.hpp"35#include "code/vtableStubs.hpp"36#include "interpreter/interpreter.hpp"37#include "memory/allocation.inline.hpp"38#include "nativeInst_zero.hpp"39#include "os_share_bsd.hpp"40#include "prims/jniFastGetField.hpp"41#include "prims/jvm_misc.hpp"42#include "runtime/arguments.hpp"43#include "runtime/frame.inline.hpp"44#include "runtime/interfaceSupport.inline.hpp"45#include "runtime/java.hpp"46#include "runtime/javaCalls.hpp"47#include "runtime/mutexLocker.hpp"48#include "runtime/osThread.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/vmError.hpp"5657address os::current_stack_pointer() {58address dummy = (address) &dummy;59return dummy;60}6162frame os::get_sender_for_C_frame(frame* fr) {63ShouldNotCallThis();64return frame();65}6667frame os::current_frame() {68// The only thing that calls this is the stack printing code in69// VMError::report:70// - Step 110 (printing stack bounds) uses the sp in the frame71// to determine the amount of free space on the stack. We72// set the sp to a close approximation of the real value in73// order to allow this step to complete.74// - Step 120 (printing native stack) tries to walk the stack.75// The frame we create has a NULL pc, which is ignored as an76// invalid frame.77frame dummy = frame();78dummy.set_sp((intptr_t *) current_stack_pointer());79return dummy;80}8182char* os::non_memory_address_word() {83// Must never look like an address returned by reserve_memory,84// even in its subfields (as defined by the CPU immediate fields,85// if the CPU splits constants across multiple instructions).86// This is the value for x86; works pretty well for PPC too.87return (char *) -1;88}8990address os::Posix::ucontext_get_pc(const ucontext_t* uc) {91ShouldNotCallThis();92return NULL;93}9495void os::Posix::ucontext_set_pc(ucontext_t * uc, address pc) {96ShouldNotCallThis();97}9899address os::fetch_frame_from_context(const void* ucVoid,100intptr_t** ret_sp,101intptr_t** ret_fp) {102ShouldNotCallThis();103return NULL;104}105106frame os::fetch_frame_from_context(const void* ucVoid) {107ShouldNotCallThis();108return frame();109}110111bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,112ucontext_t* uc, JavaThread* thread) {113114if (info != NULL && thread != NULL) {115// Handle ALL stack overflow variations here116if (sig == SIGSEGV || sig == SIGBUS) {117address addr = (address) info->si_addr;118119// check if fault address is within thread stack120if (thread->is_in_full_stack(addr)) {121StackOverflow* overflow_state = thread->stack_overflow_state();122// stack overflow123if (overflow_state->in_stack_yellow_reserved_zone(addr)) {124overflow_state->disable_stack_yellow_reserved_zone();125ShouldNotCallThis();126}127else if (overflow_state->in_stack_red_zone(addr)) {128overflow_state->disable_stack_red_zone();129ShouldNotCallThis();130}131}132}133134/*if (thread->thread_state() == _thread_in_Java) {135ShouldNotCallThis();136}137else*/ if ((thread->thread_state() == _thread_in_vm ||138thread->thread_state() == _thread_in_native) &&139sig == SIGBUS && thread->doing_unsafe_access()) {140ShouldNotCallThis();141}142143// jni_fast_Get<Primitive>Field can trap at certain pc's if a GC144// kicks in and the heap gets shrunk before the field access.145/*if (sig == SIGSEGV || sig == SIGBUS) {146address addr = JNI_FastGetField::find_slowcase_pc(pc);147if (addr != (address)-1) {148stub = addr;149}150}*/151}152153return false;154}155156void os::Bsd::init_thread_fpu_state(void) {157// Nothing to do158}159160///////////////////////////////////////////////////////////////////////////////161// thread stack162163size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;164size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;165size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;166167size_t os::Posix::default_stack_size(os::ThreadType thr_type) {168#ifdef _LP64169size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);170#else171size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);172#endif // _LP64173return s;174}175176static void current_stack_region(address *bottom, size_t *size) {177address stack_bottom;178address stack_top;179size_t stack_bytes;180181#ifdef __APPLE__182pthread_t self = pthread_self();183stack_top = (address) pthread_get_stackaddr_np(self);184stack_bytes = pthread_get_stacksize_np(self);185stack_bottom = stack_top - stack_bytes;186#elif defined(__OpenBSD__)187stack_t ss;188int rslt = pthread_stackseg_np(pthread_self(), &ss);189190if (rslt != 0)191fatal("pthread_stackseg_np failed with error = " INT32_FORMAT, rslt);192193stack_top = (address) ss.ss_sp;194stack_bytes = ss.ss_size;195stack_bottom = stack_top - stack_bytes;196#else197pthread_attr_t attr;198199int rslt = pthread_attr_init(&attr);200201// JVM needs to know exact stack location, abort if it fails202if (rslt != 0)203fatal("pthread_attr_init failed with error = " INT32_FORMAT, rslt);204205rslt = pthread_attr_get_np(pthread_self(), &attr);206207if (rslt != 0)208fatal("pthread_attr_get_np failed with error = " INT32_FORMAT, rslt);209210if (pthread_attr_getstackaddr(&attr, (void **) &stack_bottom) != 0 ||211pthread_attr_getstacksize(&attr, &stack_bytes) != 0) {212fatal("Can not locate current stack attributes!");213}214215pthread_attr_destroy(&attr);216217stack_top = stack_bottom + stack_bytes;218#endif219220assert(os::current_stack_pointer() >= stack_bottom, "should do");221assert(os::current_stack_pointer() < stack_top, "should do");222223*bottom = stack_bottom;224*size = stack_top - stack_bottom;225}226227address os::current_stack_base() {228address bottom;229size_t size;230current_stack_region(&bottom, &size);231return bottom + size;232}233234size_t os::current_stack_size() {235// stack size includes normal stack and HotSpot guard pages236address bottom;237size_t size;238current_stack_region(&bottom, &size);239return size;240}241242/////////////////////////////////////////////////////////////////////////////243// helper functions for fatal error handler244245void os::print_context(outputStream* st, const void* context) {246ShouldNotCallThis();247}248249void os::print_register_info(outputStream *st, const void *context) {250ShouldNotCallThis();251}252253/////////////////////////////////////////////////////////////////////////////254// Stubs for things that would be in bsd_zero.s if it existed.255// You probably want to disassemble these monkeys to check they're ok.256257extern "C" {258int SpinPause() {259return 1;260}261262void _Copy_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) {263if (from > to) {264const jshort *end = from + count;265while (from < end)266*(to++) = *(from++);267}268else if (from < to) {269const jshort *end = from;270from += count - 1;271to += count - 1;272while (from >= end)273*(to--) = *(from--);274}275}276void _Copy_conjoint_jints_atomic(const jint* from, jint* to, size_t count) {277if (from > to) {278const jint *end = from + count;279while (from < end)280*(to++) = *(from++);281}282else if (from < to) {283const jint *end = from;284from += count - 1;285to += count - 1;286while (from >= end)287*(to--) = *(from--);288}289}290void _Copy_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) {291if (from > to) {292const jlong *end = from + count;293while (from < end)294os::atomic_copy64(from++, to++);295}296else if (from < to) {297const jlong *end = from;298from += count - 1;299to += count - 1;300while (from >= end)301os::atomic_copy64(from--, to--);302}303}304305void _Copy_arrayof_conjoint_bytes(const HeapWord* from,306HeapWord* to,307size_t count) {308memmove(to, from, count);309}310void _Copy_arrayof_conjoint_jshorts(const HeapWord* from,311HeapWord* to,312size_t count) {313memmove(to, from, count * 2);314}315void _Copy_arrayof_conjoint_jints(const HeapWord* from,316HeapWord* to,317size_t count) {318memmove(to, from, count * 4);319}320void _Copy_arrayof_conjoint_jlongs(const HeapWord* from,321HeapWord* to,322size_t count) {323memmove(to, from, count * 8);324}325};326327/////////////////////////////////////////////////////////////////////////////328// Implementations of atomic operations not supported by processors.329// -- http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Atomic-Builtins.html330331#ifndef _LP64332extern "C" {333long long unsigned int __sync_val_compare_and_swap_8(334volatile void *ptr,335long long unsigned int oldval,336long long unsigned int newval) {337ShouldNotCallThis();338return 0; // silence compiler warnings339}340};341#endif // !_LP64342343#ifndef PRODUCT344void os::verify_stack_alignment() {345}346#endif347348int os::extra_bang_size_in_bytes() {349// Zero does not require an additional stack bang.350return 0;351}352353354