4278N/A * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 2796N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2796N/A * This code is free software; you can redistribute it and/or modify it 2796N/A * under the terms of the GNU General Public License version 2 only, as 2796N/A * published by the Free Software Foundation. 2796N/A * This code is distributed in the hope that it will be useful, but WITHOUT 2796N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2796N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2796N/A * version 2 for more details (a copy is included in the LICENSE file that 2796N/A * You should have received a copy of the GNU General Public License version 2796N/A * 2 along with this work; if not, write to the Free Software Foundation, 2796N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2796N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2796N/A// for timer info max values which include all bits 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A// For diagnostics to print a message once. see run_periodic_checks 2796N/A/* do not use any signal number less than SIGSEGV, see 4355769 */ 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A // XXXBSD: this is just a stopgap implementation 2796N/A // values in struct sysinfo are "unsigned long" 2796N/A // See comments under solaris for alignment considerations 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A// Return true if user is running as root. 2796N/A// i386: 224, ia64: 1105, amd64: 186, sparc 143 2796N/A// Returns the kernel thread id of the currently running thread. Kernel 2796N/A// thread id is used to access /proc. 2796N/A// (Note that getpid() on BsdThreads returns kernel thread id too; but 2796N/A// on NPTL, it returns the same pid for all threads, as required by POSIX.) 2796N/A // old kernel, no NPTL support 2796N/A// Most versions of bsd have a bug where the number of processors are 2796N/A// determined by looking at the /proc file system. In a chroot environment, 2796N/A// the system call returns 1. This causes the VM to act as if it is 2796N/A// a single processor and elide locking (see is_MP() call). 2796N/A "Java may be unstable running multithreaded in a chroot " 2796N/A "environment on Bsd when /proc filesystem is not mounted.";
2796N/A /* get processors count via hw.ncpus sysctl */ 4156N/A /* get physical memory via hw.memsize sysctl (hw.memsize is used 4156N/A * since it returns a 64 bit value) 2796N/A // limit _physical_memory memory view on OpenBSD since 2796N/A // datasize rlimit restricts us anyway. 2796N/A// sysinfo(SI_ARCHITECTURE, arch, sizeof(arch)); 2796N/A // The next steps are taken in the product version: 2796N/A // Obtain the JAVA_HOME value from the location of libjvm[_g].so. 2796N/A // This library should be located at: 2796N/A // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm[_g].so. 2796N/A // If "/jre/lib/" appears at the right place in the path, then we 2796N/A // assume libjvm[_g].so is installed in a JDK and we use this path. 2796N/A // Otherwise exit with message: "Could not create the Java virtual machine." 2796N/A // The following extra steps are taken in the debugging version: 2796N/A // If "/jre/lib/" does NOT appear at the right place in the path 2796N/A // instead of exit check for $JAVA_HOME environment variable. 2796N/A // it looks like libjvm[_g].so is installed there 2796N/A // code needs to be changed accordingly. 2796N/A // The next few definitions allow the code to be verbatim: 2796N/A * The linker uses the following search paths to locate required 2796N/A * 7: The default directories, normally /lib and /usr/lib. 2842N/A // the null in SYS_EXTENSIONS_DIRS counts for the size of the colon after user_home_dir 2796N/A /* sysclasspath, java_home, dll_dir */ 2796N/A // Now cut the path to <java_home>/jre if we can. 2796N/A *
pslash =
'\0';
/* get rid of /{client|server|hotspot} */ 2842N/A *
pslash =
'\0';
/* get rid of /<arch> (/lib on macosx) */ 2796N/A * Where to look for native libraries 2796N/A * Note: Due to a legacy implementation, most of the library path 2796N/A * is set in the launcher. This was to accomodate linking restrictions 2796N/A * on legacy Bsd implementations (which are no longer supported). 2796N/A * Eventually, all the library path setting will be done here. 2796N/A * However, to prevent the proliferation of improperly built native 2796N/A * Eventually, all the library path setting will be done here. 2796N/A * Construct the invariant part of ld_library_path. Note that the 2796N/A * space for the colon and the trailing null are provided by the 2796N/A * nulls included by the sizeof operator (so actually we allocate 2796N/A * a byte more than necessary). 2796N/A * Get the user setting of LD_LIBRARY_PATH, and prepended it. It 2796N/A * should always exist (until the legacy problem cited above is 2842N/A // Prepend the default path with the JAVA_LIBRARY_PATH so that the app launcher code can specify a directory inside an app wrapper 2842N/A /* That's +1 for the colon and +1 for the trailing '\0' */ 2796N/A /* That's +1 for the colon and +1 for the trailing '\0' */ 3340N/A // Apple's Java6 has "." at the beginning of java.library.path. 3340N/A // OpenJDK on Windows has "." at the end of java.library.path. 3340N/A // OpenJDK on Linux and Solaris don't have "." in java.library.path 3340N/A // at all. To ease the transition from Apple's Java6 to OpenJDK7, 3340N/A // "." is appended to the end of java.library.path. Yes, this 3340N/A // could cause a change in behavior, but Apple's Java6 behavior 3340N/A // can be achieved by putting "." at the beginning of the 3340N/A // JAVA_LIBRARY_PATH environment variable. 3340N/A // that's +3 for appending ":." and the trailing '\0' 2796N/A * Note that the space for the colon and the trailing null are provided 2796N/A * by the nulls included by the sizeof operator (so actually one byte more 2796N/A * than necessary is allocated). 2796N/A /* Endorsed standards default directory. */ 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A // use debugger to set breakpoint here 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A // Should also have an assertion stating we are still single-threaded. 2796N/A // Fill in signals that are necessarily unblocked for all threads in 2796N/A // the VM. Currently, we unblock the following signals: 2796N/A // SHUTDOWN{1,2,3}_SIGNAL: for shutdown hooks support (unless over-ridden 2796N/A // by -Xrs (=ReduceSignalUsage)); 2796N/A // BREAK_SIGNAL which is unblocked only by the VM thread and blocked by all 2796N/A // other threads. The "ReduceSignalUsage" boolean tells us not to alter 2796N/A // the dispositions or masks wrt these signals. 2796N/A // Programs embedding the VM that want to use the above signals for their 2796N/A // own purposes must, at this time, use the "-Xrs" option to prevent 2796N/A // interference with shutdown hooks and BREAK_SIGNAL thread dumping. 2796N/A // (See bug 4345157, and other related bugs). 2796N/A // In reality, though, unblocking these signals is really a nop, since 2796N/A // these signals are not blocked by default. 2796N/A // Fill in signals that are blocked by all but the VM thread. 2796N/A// These are signals that are unblocked while a thread is running Java. 2796N/A// (For some reason, they get blocked by default.) 2796N/A// These are the signals that are blocked while a (non-VM) thread is 2796N/A// running Java. Only the VM thread handles these signals. 2796N/A// These are signals that are blocked during cond_wait to allow debugger in 2796N/A //Save caller's signal mask before setting VM signal mask 2796N/A // Only the VM thread handles BREAK_SIGNAL ... 2796N/A // ... all other threads block BREAK_SIGNAL 2796N/A////////////////////////////////////////////////////////////////////////////// 2796N/A// detecting pthread library 2796N/A // Save glibc and pthread version strings. Note that _CS_GNU_LIBC_VERSION 2796N/A // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a 2796N/A // generic name for earlier versions. 2796N/A // Define macros here so we can build HotSpot on old systems. 2796N/A // _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version() 2796N/A // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells 2796N/A // us "NPTL-0.29" even we are running with BsdThreads. Check if this 2796N/A // is the case. BsdThreads has a hard limit on max number of threads. 2796N/A // So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value. 2796N/A // On the other hand, NPTL does not have such a limit, sysconf() 2796N/A // will return -1 and errno is not changed. Check if it is really NPTL. 2796N/A // glibc before 2.3.2 only has BsdThreads. 2796N/A // BsdThreads have two flavors: floating-stack mode, which allows variable 2796N/A // stack size; and fixed-stack mode. NPTL is always floating-stack. 2796N/A///////////////////////////////////////////////////////////////////////////// 2796N/A// Force Bsd kernel to expand current thread stack. If "bottom" is close 2796N/A// to the stack guard, caller should block all signals. 2796N/A// A special mmap() flag that is used to implement thread stacks. It tells 2796N/A// kernel that the memory region should extend downwards when needed. This 2796N/A// allows early versions of BsdThreads to only mmap the first few pages 2796N/A// when creating a new thread. Bsd kernel will automatically expand thread 2796N/A// stack as needed (on page faults). 2796N/A// However, because the memory region of a MAP_GROWSDOWN stack can grow on 2796N/A// demand, if a page fault happens outside an already mapped MAP_GROWSDOWN 2796N/A// region, it's hard to tell if the fault is due to a legitimate stack 2796N/A// overrun). As a rule, if the fault happens below current stack pointer, 2796N/A// Bsd kernel does not expand stack, instead a SIGSEGV is sent to the 2796N/A// This Bsd feature can cause SIGSEGV when VM bangs thread stack for 2796N/A// stack overflow detection. 2796N/A// Newer version of BsdThreads (since glibc-2.2, or, RH-7.x) and NPTL do 2796N/A// not use this flag. However, the stack of initial thread is not created 2796N/A// by pthread, it is still MAP_GROWSDOWN. Also it's possible (though 2796N/A// unlikely) that user code can create a thread with MAP_GROWSDOWN stack 2796N/A// and then attach the thread to JVM. 2796N/A// To get around the problem and allow stack banging on Bsd, we need to 2796N/A// manually expand thread stack after receiving the SIGSEGV. 2796N/A// There are two ways to expand thread stack to address "bottom", we used 2796N/A// both of them in JVM before 1.5: 2796N/A// 1. adjust stack pointer first so that it is below "bottom", and then 2796N/A// 2. mmap() the page in question 2796N/A// Now alternate signal stack is gone, it's harder to use 2. For instance, 2796N/A// if current sp is already near the lower end of page 101, and we need to 2796N/A// call mmap() to map page 100, it is possible that part of the mmap() frame 2796N/A// will be placed in page 100. When page 100 is mapped, it is zero-filled. 2796N/A// That will destroy the mmap() frame and cause VM to crash. 2796N/A// The following code works by adjusting sp first, then accessing the "bottom" 2796N/A// page to force a page fault. Bsd kernel will then automatically expand the 2796N/A// _expand_stack_to() assumes its frame size is less than page size, which 2796N/A// should always be true if the function is not inlined. 2796N/A // Adjust bottom to point to the largest address within the same page, it 2796N/A // gives us a one-page buffer if alloca() allocates slightly more memory. 2796N/A // sp might be slightly above current stack pointer; if that's the case, we 2796N/A // will alloca() a little more space than necessary, which is OK. Don't use 2796N/A // os::current_stack_pointer(), as its result can be slightly below current 2796N/A // stack pointer, causing us to not alloca enough to reach "bottom". 2796N/A////////////////////////////////////////////////////////////////////////////// 2796N/A// check if it's safe to start a new thread 2796N/A // Fixed stack BsdThreads (SuSE Bsd/x86, and some versions of Redhat) 2796N/A // Heap is mmap'ed at lower end of memory space. Thread stacks are 2796N/A // allocated (MAP_FIXED) from high address space. Every thread stack 2796N/A // occupies a fixed size slot (usually 2Mbytes, but user can change 2796N/A // it to other values if they rebuild BsdThreads). 2796N/A // Problem with MAP_FIXED is that mmap() can still succeed even part of 2796N/A // the memory region has already been mmap'ed. That means if we have too 2796N/A // many threads and/or very large heap, eventually thread stack will 2796N/A // stack bottom with the highest address that has been mmap'ed by JVM 2796N/A // plus a safety margin for memory maps created by native code. 2796N/A // This feature can be disabled by setting ThreadSafetyMargin to 0 2796N/A // not safe if our stack extends below the safety margin 2796N/A // Floating stack BsdThreads or NPTL: 2796N/A // Unlike fixed stack BsdThreads, thread stacks are not MAP_FIXED. When 2796N/A // there's not enough space left, pthread_create() will fail. If we come 2796N/A // here, that means enough space has been reserved for stack. 2842N/A// library handle for calling objc_registerThreadWithCollector() 2842N/A// without static linking to the libobjc library 4420N/A // Additional thread_id used to correlate threads in SA 2796N/A// Thread start routine for all newly created threads 2796N/A // Try to randomize the cache line index of hot stack frames. 2796N/A // This helps when threads of the same stack traces evict each other's 2796N/A // cache lines. The threads can be either from the same JVM instance, or 2796N/A // from different JVM instances. The benefit is especially true for 2796N/A // processors with hyperthreading technology. 2796N/A // non floating stack BsdThreads needs extra check, see above 3362N/A // thread_id is mach thread on macos 2796N/A // thread_id is pthread_id on BSD 2796N/A // thread_id is kernel thread id (similar to Solaris LWP id) 2796N/A // initialize signal mask for this thread 2796N/A // initialize floating point control register 2842N/A // register thread with objc gc 2796N/A // handshaking with parent thread 2796N/A // wait until os::start_thread() 2796N/A // call one more level start routine 2796N/A // Allocate the OSThread object 2796N/A // set the correct thread state 2796N/A // Initial state is ALLOCATED but not INITIALIZED 2796N/A // calculate stack size if it's not specified by caller 2796N/A // Java threads use ThreadStackSize which default value can be 2796N/A // changed with the flag -Xss 2796N/A // use VMThreadStackSize if CompilerThreadStackSize is not defined 2796N/A // let pthread_create() pick the default value. 2796N/A // Serialize thread creation if we are running with fixed stack BsdThreads 2796N/A // Need to clean up stuff we've allocated so far 2796N/A // Store pthread info into the OSThread 2796N/A // Wait until child thread is either initialized or aborted 2796N/A // Aborted due to thread limit being reached 2796N/A // The thread is returned suspended (in state INITIALIZED), 2796N/A // and is started higher up in the call chain 2796N/A///////////////////////////////////////////////////////////////////////////// 2796N/A// bootstrap the main thread 2796N/A // Allocate the OSThread object 2796N/A // Store pthread info into the OSThread 2796N/A // initialize floating point control register 2796N/A // Initial thread state is RUNNABLE 2796N/A // If current thread is initial thread, its stack is mapped on demand, 2796N/A // see notes about MAP_GROWSDOWN. Here we try to force kernel to map 2796N/A // the entire stack region to avoid SEGV in stack banging. 2796N/A // It is also useful to get around the heap-stack-gap problem on SuSE 2796N/A // kernel (see 4821821 for details). We first expand stack to the top 2796N/A // of yellow zone, then enable stack yellow zone (order is significant, 2796N/A // enabling yellow zone first will crash JVM on SuSE Bsd), so there 2796N/A // is no gap between the last two virtual memory regions. 2796N/A // initialize signal mask for this thread 2796N/A // and save the caller's signal mask 2796N/A// Free Bsd resources related to the OSThread 2796N/A // Restore caller's signal mask 2796N/A////////////////////////////////////////////////////////////////////////////// 2796N/A// Note: This is currently not used by VM, as we don't destroy TLS key 2796N/A////////////////////////////////////////////////////////////////////////////// 2796N/A// Check if current thread is the initial thread, similar to Solaris thr_main. 2796N/A // If called before init complete, thread stack bottom will be null. 2796N/A // Can be called if fatal error occurs before initialization. 2796N/A "os::init did not locate initial thread's stack region");
2796N/A// Find the virtual memory area that contains addr 2796N/A// Locate initial thread stack. This special handling of initial thread stack 2796N/A// is needed because pthread_getattr_np() on most (all?) Bsd distros returns 2796N/A// bogus value for initial thread. 2796N/A // stack size is the easy part, get it from RLIMIT_STACK 2796N/A // 6308388: a bug in ld.so will relocate its own .data section to the 2796N/A // lower end of primordial stack; reduce ulimit -s value a little bit 2796N/A // so we won't install guard page on ld.so's data section. 2796N/A // 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat 2796N/A // 7.1, in both cases we will get 2G in return value. 2796N/A // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0, 2796N/A // SuSE 7.2, Debian) can not handle alternate signal stack correctly 2796N/A // for initial thread if its stack size exceeds 6M. Cap it at 2M, 2796N/A // in case other parts in glibc still assumes 2M max stack size. 2796N/A // FIXME: alt signal stack is gone, maybe we can relax this constraint? 2796N/A // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small 2796N/A // Try to figure out where the stack base (top) is. This is harder. 2796N/A // When an application is started, glibc saves the initial stack pointer in 2796N/A // a global variable "__libc_stack_end", which is then used by system 2796N/A // libraries. __libc_stack_end should be pretty close to stack top. The 2796N/A // variable is available since the very early days. However, because it is 2796N/A // a private interface, it could disappear in the future. 2796N/A // Bsd kernel saves start_stack information in /proc/<pid>/stat. Similar 2796N/A // to __libc_stack_end, it is very close to stack top, but isn't the real 2796N/A // stack top. Note that /proc may not exist if VM is running as a chroot 2796N/A // program, so reading /proc/<pid>/stat could fail. Also the contents of 2796N/A // /proc/<pid>/stat could change in the future (though unlikely). 2796N/A // We try __libc_stack_end first. If that doesn't work, look for 2796N/A // /proc/<pid>/stat. If neither of them works, we use current stack pointer 2796N/A // as a hint, which should work well in most cases. 2796N/A // try __libc_stack_end first 2796N/A // Figure what the primordial thread stack base is. Code is inspired 2796N/A // followed by command name surrounded by parentheses, state, etc. 2796N/A // Skip pid and the command string. Note that we could be dealing with 2796N/A // weird command names, e.g. user could decide to rename java launcher 2796N/A // to "java 1.4.2 :)", then the stat file would look like 2796N/A // 1234 (java 1.4.2 :)) R ... ... 2796N/A // We don't really need to know the command string, just find the last 2796N/A // occurrence of ")" and then start parsing from there. See bug 4726580. 2796N/A /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 */ 2796N/A /* 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 */ 2796N/A // product mode - assume we are the initial thread, good luck in the 2796N/A warning(
"Can't detect initial thread stack location - bad conversion");
2796N/A // FreeBSD with a Bsd emulator, or inside chroot), this should work for 2796N/A // most cases, so don't abort: 2796N/A // Now we have a pointer (stack_start) very close to the stack top, the 2796N/A // next thing to do is to figure out the exact location of stack top. We 2796N/A // can find out the virtual memory area that contains stack_start by 2796N/A // and its upper limit is the real stack top. (again, this would fail if 2796N/A // running inside chroot, because /proc may not exist.) 2796N/A // success, "high" is the true stack top. (ignore "low", because initial 2796N/A // thread stack grows on demand, its real bottom is high - RLIMIT_STACK.) 2796N/A warning(
"Can't detect initial thread stack location - find_vma failed");
2796N/A // best effort: stack_start is normally within a few pages below the real 2796N/A // stack top, use it as stack top, and reduce stack size so we won't put 2796N/A // guard page outside stack. 2796N/A // stack_top could be partially down the page so align it 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A// Time since start-up in seconds to a fine granularity. 2796N/A// Used by VMSelfDestructTimer and the MemProfiler. 2796N/A// XXX: For now, code this as if BSD does not support vtime. 2796N/A // better than nothing, but not much 2796N/A // XXXDARWIN: Investigate replacement monotonic clock 2796N/A // yes, monotonic clock is supported 2796N/A // we do dlopen's in this particular order due to bug in bsd 2796N/A // dynamical loader (see 6348968) leading to crash on exit 2796N/A // See if monotonic clock is supported by the kernel. Note that some 2796N/A // early implementations simply return kernel jiffies (updated every 2796N/A // 1/100 or 1/1000 second). It would be bad to use such a low res clock 2796N/A // for nano time (though the monotonic property is still nice to have). 2796N/A // It's fixed in newer kernels, however clock_getres() still returns 2796N/A // 1/HZ. We check if clock_getres() works, but will ignore its reported 2796N/A // resolution for now. Hopefully as people move to new kernels, this 2796N/A // yes, monotonic clock is supported 2796N/A // close librt if there is no monotonic clock 2796N/A#
warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" 2796N/A // Switch to using fast clocks for thread cpu time if 2796N/A // the sys_clock_getres() returns 0 error code. 2796N/A // Note, that some kernels may support the current thread 2796N/A // clock (CLOCK_THREAD_CPUTIME_ID) but not the clocks 2796N/A // returned by the pthread_getcpuclockid(). 2796N/A // If the fast Posix clocks are supported then the sys_clock_getres() 2796N/A // must return at least tp.tv_sec == 0 which means a resolution 2796N/A // better than 1 sec. This is extra check for reliability. 2796N/A // CLOCK_MONOTONIC - amount of time since some arbitrary point in the past 2796N/A // gettimeofday - based on time in seconds since the Epoch thus does not wrap 2796N/A // gettimeofday is a real time clock so it skips 2796N/A// Return the real, user, and system times in seconds from an 2796N/A// arbitrary fixed point in the past. 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A// Note: os::shutdown() might be called very early during initialization, or 2796N/A// called from signal handler. Before adding something to os::shutdown(), make 2796N/A// sure it is async-safe and can handle partially initialized VM. 2796N/A // allow PerfMemory to attempt cleanup of any persistent resources 2796N/A // needs to remove object in file system 2796N/A // flush buffered output, finish log files 2796N/A// Note: os::abort() might be called very early during initialization, or 2796N/A// called from signal handler. Before adding something to os::abort(), make 2796N/A// sure it is async-safe and can handle partially initialized VM. 2796N/A// Die immediately, no exit hook, no abort hook, no cleanup. 2796N/A // _exit() on BsdThreads only kills current thread 2796N/A// This method is a copy of JDK's sysGetLastErrorString 2796N/A // Under the old bsd thread library, bsd gives each thread 2796N/A // its own process id. Because of this each thread will return 2796N/A // a different pid if this method were to return the result 2796N/A // of getpid(2). Bsd provides no api that returns the pid 2796N/A // of the launcher thread for the vm. This implementation 2796N/A // returns a unique pid, the pid of the launcher thread 2796N/A // that starts the vm 'process'. 2796N/A // Under the NPTL, getpid() returns the same pid as the 2796N/A // launcher thread rather than a unique pid per thread. 2796N/A // Use gettid() if you want the old pre NPTL behaviour. 2796N/A // if you are looking for the result of a call to getpid() that 2796N/A // returns a unique pid for the calling thread, then look at the 2796N/A// This must be hard coded because it's the system's temporary 2796N/A// directory not the java application's temp directory, ala java.io.tmpdir. 2842N/A// macosx has a secure per-user temporary directory 2796N/A // Quietly truncate on buffer overflow. Should be an error. 2796N/A for (
int i = 0 ; i < n ; i++) {
2796N/A // Really shouldn't be NULL, but check can't hurt 2796N/A continue;
// skip the empty path values 2796N/A for (
int i = 0 ; i < n ; i++) {
2796N/A// check if addr is inside libjvm[_g].so 3924N/A // dladdr will find names of dynamic functions only, but does 3924N/A // it set dli_fbase with mach_header address when it "fails" ? 3924N/A // Handle non-dymanic manually: 2796N/A// ported from solaris version 2796N/A // iterate through all loadable segments 2796N/A // base address of a library is the lowest address of its loaded 2796N/A // see if 'addr' is within current segment 2796N/A // dlpi_name is NULL or empty if the ELF file is executable, return 0 2796N/A // so dll_address_to_library_name() can fall through to use dladdr() which 2796N/A // can figure out executable name from argv[0]. 2796N/A // There is a bug in old glibc dladdr() implementation that it could resolve 2796N/A // to wrong library name if the .so file has a base address != NULL. Here 2796N/A // we iterate through the program headers of all loaded libraries to find 2796N/A // out which library 'addr' really belongs to. This workaround can be 2796N/A // removed once the minimum requirement for glibc is moved to 2.3.x. 2796N/A // buf already contains library name 2796N/A // in case of error it checks if .dll/.so was built for the 2796N/A // same architecture as Hotspot is running on 2796N/A // Read system error message into ebuf 2796N/A // Read system error message into ebuf 2796N/A // It may or may not be overwritten below 2796N/A // No more space in ebuf for additional diagnostics message 2796N/A // Can't open library, report dlerror() message 2796N/A // file i/o error - report dlerror() msg 2796N/A IA32,
AMD64,
IA64,
__sparc,
__powerpc__,
ARM,
S390,
ALPHA,
MIPS,
MIPSEL,
PARISC,
M68K 2796N/A // Identify compatability class for VM's architecture and library's architecture 2796N/A // Obtain string descriptions for architectures 2796N/A "Didn't find running architecture code (running_arch_code) in arch_array");
2796N/A // Even though running architecture detection failed 2796N/A // we may still continue with reporting dlerror() message 2796N/A " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
2796N/A " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
2796N/A// XXX: Do we need a lock around this as per Linux? 2796N/A // values in struct sysinfo are "unsigned long" 2796N/A// but they're the same for all the bsd arch that we support 2796N/A// and they're the same for solaris but there's no common place to put this. 2796N/Aconst char *
ill_names[] = {
"ILL0",
"ILL_ILLOPC",
"ILL_ILLOPN",
"ILL_ILLADR",
2796N/A "ILL_ILLTRP",
"ILL_PRVOPC",
"ILL_PRVREG",
2796N/A "ILL_COPROC",
"ILL_BADSTK" };
2796N/Aconst char *
fpe_names[] = {
"FPE0",
"FPE_INTDIV",
"FPE_INTOVF",
"FPE_FLTDIV",
2796N/A "FPE_FLTOVF",
"FPE_FLTUND",
"FPE_FLTRES",
2796N/A "FPE_FLTINV",
"FPE_FLTSUB",
"FPE_FLTDEN" };
2796N/Aconst char *
bus_names[] = {
"BUS0",
"BUS_ADRALN",
"BUS_ADRERR",
"BUS_OBJERR" };
2796N/A " Mapped file inaccessible during execution, " \
3129N/A// Find the full path to the current module, libjvm or libjvm_g 2796N/A // Lazy resolve the path to current module. 2796N/A // Support for the gamma launcher. Typical value for buf is 2796N/A // the right place in the string, then assume we are installed in a JDK and 3129N/A // we're done. Otherwise, check for a JAVA_HOME environment variable and 3129N/A // construct a path to the JVM being overridden. 2796N/A // Look for JAVA_HOME in the environment. 3129N/A // Check the current module name "libjvm" or "libjvm_g". 2796N/A // determine if this is a legacy image or modules image 2796N/A // modules image doesn't have "jre" subdirectory 3129N/A // Add the appropriate library subdir 3129N/A // Add the appropriate client or server subdir 3129N/A // If the path exists within JAVA_HOME, add the JVM library name 3129N/A // to complete the path to JVM being overridden. Otherwise fallback 3129N/A // to the path to the current library. 3129N/A // Use current module name "libjvm[_g]" instead of 3129N/A // "libjvm"debug_only("_g")"" since for fastdebug version 3129N/A // we should have "libjvm" but debug_only("_g") adds "_g"! 3129N/A // Fall back to path of current library 2796N/A // no prefix required, not even "_" 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A // 4511530 - sem_post is serialized and handled by the manager thread. When 2796N/A // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We 2796N/A // don't want to flood the manager thread with sem_post requests. 2796N/A // Ctrl-C is pressed during error reporting, likely because the error 2796N/A // handler fails to abort. Let VM die immediately. 2796N/A // -1 means registration failed 2796N/A * The following code is moved from os.cpp for making this 2796N/A * code platform specific, which it is by its very nature. 2796N/A// Will be modified when max signal is changed to be dynamic 2796N/A// a counter for each possible signal value 2796N/A// Bsd(POSIX) specific hand shaking semaphore. 2796N/A // Initialize signal structures 2796N/A // Initialize signal semaphore 2796N/A // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() 2796N/A // were we externally suspended while we were waiting? 2796N/A // The semaphore has been incremented, but while we were waiting 2796N/A // another thread suspended us. We don't want to continue running 2796N/A // while suspended because that would surprise the thread that 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A // Seems redundant as all get out 2796N/A// Solaris allocates memory by pages. 2796N/A// Rationale behind this function: 2796N/A// current (Mon Apr 25 20:12:18 MSD 2005) oprofile drops samples without executable 2796N/A// mapping for address (see lookup_dcookie() in the kernel module), thus we cannot get 2796N/A// samples for JITted code. Here we create private executable mapping over the code cache 2796N/A// and then we can use standard (well, almost, as mapping can change) way to provide 2796N/A// info for the reporting script by storing timestamp and location of symbol 2796N/A// NOTE: Bsd kernel does not really reserve the pages for us. 2796N/A// All it does is to check if there are enough free pages 2796N/A// left at the time of mmap(). This could be a potential 4552N/A // Warn about any commit errors we see in non-product builds just 4552N/A // in case mmap() doesn't work as described on the man page. 2796N/A// Define MAP_HUGETLB here so we can build HotSpot on old systems. 2796N/A// Define MADV_HUGEPAGE here so we can build HotSpot on old systems. 4552N/A // alignment_hint is ignored on this OS 4552N/A // add extra info in product mode for vm_exit_out_of_memory(): 4552N/A // alignment_hint is ignored on this OS 2796N/A // We don't check the return value: madvise(MADV_HUGEPAGE) may not 2796N/A // be supported or the memory may already be backed by huge pages. 2796N/A// Something to do with the numa-aware allocator needs these symbols 2796N/A// If we are running with libnuma version > 2, then we should 2796N/A// be trying to use symbols with versions 1.1 2796N/A// If we are running with earlier version, which did not have symbol versions, 2796N/A// we should use the base version. 2796N/A // sched_getcpu() should be in libc. 2796N/A // Create a cpu -> node mapping 2796N/A// rebuild_cpu_to_node_map() constructs a table mapping cpud id to node id. 2796N/A// The table is later used in get_node_by_cpu(). 2796N/A // in libnuma (possible values are starting from 16, 2796N/A // and continuing up with every other power of 2, but less 2796N/A // than the maximum number of CPUs supported by kernel), and 2796N/A // is a subject to change (in libnuma version 2 the requirements 2796N/A // are more reasonable) we'll just hardcode the number they use 2796N/A// If this is a growable mapping, remove the guard pages entirely by 2796N/A// munmap()ping them. If not, just call uncommit_memory(). 2796N/A// If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory 2796N/A// at 'requested_addr'. If there are existing memory mappings at the same 2796N/A// location, however, they will be overwritten. If 'fixed' is false, 2796N/A// 'requested_addr' is only treated as a hint, the return value may or 2796N/A// may not start from the requested address. Unlike Bsd mmap(), this 2796N/A// function returns NULL to indicate failure. 2796N/A // Map uncommitted pages PROT_READ and PROT_WRITE, change access 2796N/A // to PROT_EXEC if executable when we commit the page. 2796N/A // anon_mmap() should only get called during VM initialization, 2796N/A // don't need lock (actually we can skip locking even it can be called 2796N/A // from multiple threads, because _highest_vm_reserved_address is just a 2796N/A // hint about the upper limit of non-stack memory regions.) 2796N/A// Don't update _highest_vm_reserved_address, because there might be memory 2796N/A// regions above addr + size. If so, releasing a memory region only creates 2796N/A// a hole in the address space, it doesn't help prevent heap-stack collision. 2796N/A // Bsd wants the mprotect address argument to be page aligned. 2796N/A // According to SUSv3, mprotect() should only be used with mappings 2796N/A // established by mmap(), and mmap() always maps whole pages. Unaligned 2796N/A // 'addr' likely indicates problem in the VM (e.g. trying to change 2796N/A // protection of malloc'ed or statically allocated memory). Check the 2796N/A // caller if you hit this assert. 2796N/A// Set protections specified 2796N/A // We don't know if this really is a huge page or not. 2796N/A warning(
"HugeTLBFS is not supported by the operating system.");
2796N/A* Set the coredump_filter bits to include largepages in core dump (bit 6) 2796N/A* From the coredump_filter documentation: 2796N/A* - (bit 0) anonymous private memory 2796N/A* - (bit 1) anonymous shared memory 2796N/A* - (bit 2) file-backed private memory 2796N/A* - (bit 3) file-backed shared memory 2796N/A* - (bit 4) ELF header pages in file-backed private memory areas (it is 2796N/A* effective only if the bit 2 is cleared) 2796N/A* - (bit 5) hugetlb private memory 2796N/A* - (bit 6) hugetlb shared memory 2796N/A // If UseLargePages is specified on the command line try both methods, 2796N/A // if it's default, then try only HugeTLBFS. 2796N/A // large_page_size on Bsd is used to round up heap size. x86 uses either 2796N/A // 2M or 4M page, depending on whether PAE (Physical Address Extensions) 2796N/A // for a line with the following format: 2796N/A // If we can't determine the value (e.g. /proc is not mounted, or the text 2796N/A // format has been changed), we'll use the largest page size supported by 2796N/A // print a warning if any large page related flag is specified on command line 2796N/A // "exec" is passed in but not used. Creating the shared image for 2796N/A // the code cache doesn't have an SHM_X executable permission to check. 2796N/A // Create a large shared memory region to attach to based on size. 2796N/A // Currently, size is the total size of the heap 2796N/A // Possible reasons for shmget failure: 2796N/A // 1. shmmax is too small for Java heap. 2796N/A // 2. not enough large page memory. 2796N/A // > increase amount of large pages: 2796N/A // Note 1: different Bsd may use different name for this property, 2796N/A // e.g. on Redhat AS-3 it is "hugetlb_pool". 2796N/A // Note 2: it's possible there's enough physical memory available but 2796N/A // they are so fragmented after a long run that they can't 2796N/A // coalesce into large pages. Try to reserve large pages when 2796N/A // the system is still "fresh". 2796N/A // Remove shmid. If shmat() is successful, the actual shared memory segment 2796N/A // will be deleted when it's detached by shmdt() or when the process 2796N/A // terminates. If shmat() is not successful this will remove the shared 2796N/A // detaching the SHM segment will also delete it, see reserve_memory_special() 2796N/A// HugeTLBFS allows application to commit large page memory on demand; 2796N/A// with SysV SHM the entire memory region must be allocated as shared 2796N/A// Reserve memory at an arbitrary address, only if that area is 2796N/A// available (and not reserved for something else). 2796N/A // Assert only that the size is a multiple of the page size, since 2796N/A // that's all that mmap requires, and since that's all we really know 2796N/A // about at this low abstraction level. If we need higher alignment, 2796N/A // we can either pass an alignment to this method or verify alignment 2796N/A // in one of the methods further up the call chain. See bug 5044738. 2796N/A // Repeatedly allocate blocks until the block is allocated at the 2796N/A // right spot. Give up after max_tries. Note that reserve_memory() will 2796N/A // automatically update _highest_vm_reserved_address if the call is 2796N/A // successful. The variable tracks the highest memory address every reserved 2796N/A // by JVM. It is used to detect heap-stack collision if running with 2796N/A // fixed-stack BsdThreads. Because here we may attempt to reserve more 2796N/A // space than needed, it could confuse the collision detecting code. To 2796N/A // solve the problem, save current _highest_vm_reserved_address and 2796N/A // calculate the correct value before return. 2796N/A // Bsd mmap allows caller to pass an address as hint; give it a try first, 2796N/A // if kernel honors the hint then we can return immediately. 2796N/A // mmap() is successful but it fails to reserve at the requested address 2796N/A // Is this the block we wanted? 2796N/A // Does this overlap the block we wanted? Give back the overlapped 2796N/A // Give back the unused reserved pieces. 2796N/A for (
int j = 0; j < i; ++j) {
2796N/A// TODO-FIXME: reconcile Solaris' os::sleep with the bsd variation. 2796N/A// Solaris uses poll(), bsd uses park(). 2796N/A// Poll() is likely a better choice, assuming that Thread.interrupt() 2796N/A// generates a SIGUSRx signal. Note that SIGUSR1 can interfere with 2796N/A // time moving backwards, should only happen if no monotonic clock 2796N/A // cleared by handle_special_suspend_equivalent_condition() or 2796N/A // java_suspend_self() via check_and_wait_while_suspended() 2796N/A // were we externally suspended while we were waiting? 2796N/A // It'd be nice to avoid the back-to-back javaTimeNanos() calls on 2796N/A // time moving backwards, should only happen if no monotonic clock 2796N/A // %% make the sleep time an integer flag. for now use 1 millisec. 2796N/A// Sleep forever; naked call to OS-specific sleep; use with CAUTION 2796N/A while (
true) {
// sleep forever ... 2796N/A// Used to convert frequent JVM_Yield() to nops 2796N/A // Yields to all threads, including threads with lower priorities 2796N/A // Threads on Bsd are all with same priority. The Solaris style 2796N/A // os::yield_all() with nanosleep(1ms) is not necessary. 2796N/A// Called from the tight loops to possibly influence time-sharing heuristics 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A// Note: Normal Bsd applications are run with SCHED_OTHER policy. SCHED_OTHER 2796N/A// only supports dynamic priority, static priority must be zero. For real-time 2796N/A// applications, Bsd supports SCHED_RR which allows static priority (1-99). 2796N/A// However, for large multi-threaded applications, SCHED_RR is not only slower 2796N/A// than SCHED_OTHER, but also very unstable (my volano tests hang hard 4 out 2796N/A// not the entire user process, and user level threads are 1:1 mapped to kernel 2796N/A// threads. It has always been the case, but could change in the future. For 2796N/A// this reason, the code should not be used as default (ThreadPriorityPolicy=0). 2796N/A// It is only used when ThreadPriorityPolicy=1 and requires root privilege. 2796N/A 19,
// 0 Entry should never be used 2796N/A/* Using Mach high-level priority assignments */ 2796N/A 0,
// 0 Entry should never be used (MINPRI_USER) 2796N/A 31,
// 5 NormPriority (BASEPRI_DEFAULT) 2796N/A 19,
// 0 Entry should never be used 2796N/A // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1 2796N/A // if effective uid is not root. Perhaps, a more elegant way of doing 2796N/A // this is to test CAP_SYS_NICE capability, but that will require libcap.so 2796N/A warning(
"-XX:ThreadPriorityPolicy requires root privilege on Bsd");
2796N/A // OpenBSD pthread_setprio starves low priority threads 2796N/A// Hint to the underlying OS that a task switch would not be good. 2796N/A// Void return because it's a hint and can fail. 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A// old VM-suspension that used to be for java-suspension, safepoints etc, 2796N/A// within hotspot. Now there is a single use-case for this: 2796N/A// - calling get_thread_pc() on the VMThread by the flat-profiler task 2796N/A// that runs in the watcher thread. 2796N/A// The remaining code is greatly simplified from the more general suspension 2796N/A// code that used to be used. 2796N/A// The protocol is quite simple: 2796N/A// - sends a signal to the target thread 2796N/A// - polls the suspend state of the osthread using a yield loop 2796N/A// - target thread signal handler (SR_handler) sets suspend state 2796N/A// and blocks in sigsuspend until continued 2796N/A// - sets target osthread state to continue 2796N/A// - sends signal to end the sigsuspend loop in the SR_handler 2796N/A// Handler function invoked when a thread's execution is suspended or 2796N/A// resumed. We have to be careful that only async-safe functions are 2796N/A// called here (Note: most pthread functions are not async safe and 2796N/A// Note: sigwait() is a more natural fit than sigsuspend() from an 2796N/A// interface point of view, but sigwait() prevents the signal hander 2796N/A// from being run. libpthread would get very confused by not having 2796N/A// its signal handlers run and prevents sigwait()'s use with the 2796N/A// mutex granting granting signal. 4141N/A// Currently only ever called on the VMThread or JavaThread 2796N/A // Save and restore errno to avoid confusing native code with EINTR 4141N/A // attempt to switch the state, we assume we had a SUSPEND_REQUEST 4141N/A // get current set of blocked signals and unblock resume signal 4141N/A // wait here until we are resumed 4141N/A // request was cancelled, continue 4141N/A // request was cancelled, continue 2796N/A "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
2796N/A // SR_signum is blocked by default. 2796N/A // 4528190 - We also need to block pthread restart signal (32 on all 2796N/A // supported Bsd platforms). Note that BsdThreads need to block 2796N/A // this signal for all threads to work properly. So we don't have 2796N/A // to use hard-coded signal number when setting up the mask. 4141N/A// "Randomly" selected value for how long we want to spin 4141N/A// before bailing out on suspending a thread, also how often 4141N/A// we send a signal to a thread we want to resume 2796N/A// returns true on success and false on error - really an error is fatal 2796N/A// but this seems the normal response to library errors 2796N/A // mark as suspended and send signal 4141N/A // failed to switch, state wasn't running? 4141N/A // managed to send the signal and switch to SUSPEND_REQUEST, now wait for SUSPENDED 4433N/A // make sure that we consume the signal on the semaphore as well 4141N/A // failed to switch to WAKEUP_REQUEST 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A "possibility of dangling Thread pointer");
2796N/A // More than one thread can get here with the same value of osthread, 2796N/A // resulting in multiple notifications. We do, however, want the store 2796N/A // to interrupted() to be visible to other threads before we execute unpark(). 2796N/A // For JSR166. Unpark even if interrupt status already was set 2796N/A "possibility of dangling Thread pointer");
2796N/A // consider thread->_SleepEvent->reset() ... optional optimization 2796N/A/////////////////////////////////////////////////////////////////////////////////// 2796N/A// This routine may be used by user applications as a "hook" to catch signals. 2796N/A// The user-defined signal handler must pass unrecognized signals to this 2796N/A// routine, and if it returns true (non-zero), then the signal handler must 2796N/A// return immediately. If the flag "abort_if_unrecognized" is true, then this 2796N/A// routine will never retun false (zero), but instead will execute a VM panic 2796N/A// routine kill the process. 2796N/A// If this routine returns false, it is OK to call it again. This allows 2796N/A// the user-defined signal handler to perform checks either before or after 2796N/A// the VM performs its own checks. Naturally, the user code would be making 2796N/A// a serious error if it tried to handle an exception (such as a null check 2796N/A// or breakpoint) that the VM was generating for its own correct operation. 2796N/A// This routine may recognize any of the following kinds of signals: 2796N/A// SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1. 2796N/A// It should be consulted by handlers for any of those signals. 2796N/A// The caller of this routine must pass in the three arguments supplied 2796N/A// to the function referred to in the "sa_sigaction" (not the "sa_handler") 2796N/A// field of the structure passed to sigaction(). This routine assumes that 2796N/A// the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART. 2796N/A// Note that the VM will print warnings if it detects conflicting signal 2796N/A// handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". 2796N/A// This boolean allows users to forward their own non-matching signals 2796N/A// to JVM_handle_bsd_signal, harmlessly. 2796N/A // Retrieve the old signal handler from libjsig 2796N/A // Retrieve the preinstalled signal handler from jvm 2796N/A // Call the old signal handler 2796N/A // It's more reasonable to let jvm treat it as an unexpected exception 2796N/A // instead of taking the default action. 2796N/A // automaticlly block the signal 2796N/A // retrieve the chained handler 2796N/A // try to honor the signal mask 2796N/A // call into the chained handler 2796N/A // Tell jvm's signal handler the signal is taken care of. 2796N/A // Do not overwrite; user takes responsibility to forward to us. 2796N/A // save the old handler in jvm 2796N/A // libjsig also interposes the sigaction() call below and saves the 2796N/A // old sigaction on it own. 4545N/A // Needed for main thread as XNU (Mac OS X kernel) will only deliver SIGSEGV 4545N/A // (which starts as SIGBUS) on main thread with faulting address inside "stack+guard pages" 4545N/A // if the signal handler declares it will handle it on alternate stack. 4545N/A // Notice we only declare we will handle it on alt stack, but we are not 4545N/A // actually going to use real alt stack - this is just a workaround. 2796N/A // Save flags, which are set by ours 2796N/A// install signal handlers for signals that HotSpot needs to 2796N/A// handle in order to support Java-level exception handling. 2796N/A // Tell libjsig jvm is setting signal handlers 2796N/A // In Mac OS X 10.4, CrashReporter will write a crash log for all 'fatal' signals, including 2796N/A // signals caught and handled by the JVM. To work around this, we reset the mach task 2796N/A // signal handler that's placed on our process by CrashReporter. This disables 2796N/A // CrashReporter-based reporting. 2796N/A // This work-around is not necessary for 10.5+, as CrashReporter no longer intercedes 2796N/A // on caught fatal signals. 2796N/A // Additionally, gdb installs both standard BSD signal handlers, and mach exception 2796N/A // handlers. By replacing the existing task exception handler, we disable gdb's mach 2796N/A // exception handling, while leaving the standard BSD signal handlers functional. 2796N/A // Tell libjsig jvm finishes setting signal handlers 2796N/A // We don't activate signal checker if libjsig is in place, we trust ourselves 2796N/A // and if UserSignalHandler is installed all bets are off 2796N/A tty->
print_cr(
"Info: libjsig is activated, all active signal checking is disabled");
2796N/A tty->
print_cr(
"Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
2796N/A// This is the fastest way to get thread cpu time on Bsd. 2796N/A// Returns cpu time (user+sys) for any thread, not only for current. 2796N/A// POSIX compliant clocks are implemented in the kernels 2.6.16+. 2796N/A// For reference, please, see IEEE Std 1003.1-2004: 2796N/A// glibc on Bsd platform uses non-documented flag 2796N/A// to indicate, that some special sort of signal 2796N/A// We will never set this flag, and we should 2796N/A// ignore this flag in our diagnostic 2796N/A // See comment for SIGNIFICANT_SIGNAL_MASK define 2796N/A // May be, handler was resetted by VMError? 2796N/A // Check: is it our handler? 2796N/A // It is our signal handler 2796N/A // check for flags, reset system-used one! 2796N/A// This method is a periodic task to check for misbehaving JNI applications 2796N/A// under CheckJNI, we can add any periodic checks here 2796N/A // SEGV and BUS if overridden could potentially prevent 2796N/A // generation of hs*.log in the event of a crash, debugging 2796N/A // such a case can be very challenging, so we absolutely 2796N/A // check the following for a good measure: 2796N/A // ReduceSignalUsage allows the user to override these handlers 2796N/A // only trust the default sigaction, in case it has been interposed 2796N/A // No need to check this sig any longer 2796N/A // No need to check this sig any longer 2796N/A// this is called _before_ the most of global arguments have been parsed 2796N/A char dummy;
/* used to get a guess on initial stack address */ 2796N/A// first_hrtime = gethrtime(); 2796N/A // With BsdThreads the JavaMain thread pid (primordial thread) 2796N/A // is different than the pid of the java launcher thread. 2796N/A // So, on Bsd, the launcher thread pid is passed to the VM 2796N/A // Use this property instead of getpid() if it was correctly passed. 2796N/A // main_thread points to the aboriginal thread 2796N/A // Work around the unaligned VM callbacks in hotspot's 2796N/A // sharedRuntime. The callbacks don't use SSE2 instructions, and work on 2796N/A // Linux, Solaris, and FreeBSD. On Mac OS X, dyld (rightly so) enforces 2796N/A // alignment when doing symbol lookup. To work around this, we force early 2796N/A // binding of all symbols now, thus binding when alignment is known-good. 2796N/A// To install functions for atexit system call 2796N/A// this is called _after_ the global arguments have been parsed 2796N/A // Allocate a single page and mark it as readable for safepoint polling 2796N/A // Check minimum allowable stack size for thread creation and to initialize 2796N/A // the java system classes, including StackOverflowError - depends on page 2796N/A // size. Add a page for compiler2 recursion in main thread. 2796N/A // Add in 2*BytesPerWord times page size to account for VM stack during 2796N/A // class initialization depending on 32 or 64 bit VM. 2796N/A // Make the stack size a multiple of the page size so that 2796N/A // There's only one node(they start from 0), disable NUMA. 2796N/A // With SHM large pages we cannot uncommit a page, so there's not way 2796N/A // we can make the adaptive lgrp chunk resizing work. If the user specified 2796N/A // both UseNUMA and UseLargePages (or UseSHM) on the command line - warn and 2796N/A // disable adaptive resizing. 2796N/A warning(
"UseNUMA is not fully compatible with SHM large pages, disabling adaptive resizing");
2796N/A // set the number of file descriptors to max. print out error 2796N/A // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if 2796N/A // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must 2796N/A // Initialize lock used to serialize thread creation (see os::create_thread) 2796N/A // at-exit methods are called in the reverse order of their registration. 2796N/A // atexit functions are called on return from main or as a result of a 2796N/A // call to exit(3C). There can be only 32 of these functions registered 2796N/A // and atexit() does not set errno. 2796N/A // only register atexit functions if PerfAllowAtExitRegistration is set. 2796N/A // atexit functions can be delayed until process exit time, which 2796N/A // can be problematic for embedded VM situations. Embedded VMs should 2796N/A // call DestroyJavaVM() to assure that VM resources are released. 2796N/A // note: perfMemory_exit_helper atexit function may be removed in 2796N/A // the future if the appropriate cleanup code can be added to the 2796N/A // VM_Exit VMOperation's doit method. 2796N/A // initialize thread priority policy 2842N/A // dynamically link to objective c gc registration 2796N/A// this is called at the end of vm_initialization 2796N/A// Mark the polling page as unreadable 2796N/A// Mark the polling page as readable 2796N/A // Bsd doesn't yet have a (official) notion of processor sets, 2796N/A // so just return the number of online processors. 2842N/A // This is only supported in Snow Leopard and beyond 2842N/A // Add a "Java: " prefix to the name 4141N/A // NULL context is unexpected, double-check this is the VMThread 2796N/A// Suspends the target using the signal mechanism and then grabs the PC before 2796N/A// resuming the target. Used by the flat-profiler only 2796N/A // Make sure that it is called by the watcher for the VMThread 2796N/A // 6292965: BsdThreads pthread_cond_timedwait() resets FPU control 2796N/A // word back to default 64bit precision if condvar is signaled. Java 2796N/A // wants 53bit precision. Save and restore current value. 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A // decode some bytes around the PC 2796N/A//////////////////////////////////////////////////////////////////////////////// 2796N/A// This does not do anything on Bsd. This is basically a hook for being 2796N/A// able to use structured exception handling (thread-local exception filters) 2796N/A // Prevent process from exiting upon "read error" without consuming all CPU 2796N/A// Is a (classpath) directory empty? 2796N/A// This code originates from JDK's sysOpen and open64_w 2796N/A// Open a file. Unlink the file immediately after open returns 2796N/A// if the specified oflag has the O_DELETE flag set. 2796N/A //If the open succeeded, the file might still be a directory 2796N/A * All file descriptors that are opened in the JVM and not 2796N/A * specifically destined for a subprocess should have the 2796N/A * close-on-exec flag set. If we don't set it, then careless 3rd 2796N/A * party native code might fork and exec without closing all 2796N/A * appropriate file descriptors (e.g. as we do in closeDescriptors in 2796N/A * - cause end-of-file to fail to be detected on some file 2796N/A * descriptors, resulting in mysterious hangs, or 2796N/A * - might cause an fopen in the subprocess to fail on a system 2796N/A * suffering from bug 1085341. 2796N/A * (Yes, the default setting of the close-on-exec flag is a Unix 2796N/A * 1085341: 32-bit stdio routines should support file descriptors >255 2796N/A * 4843136: (process) pipe file descriptor from Runtime.exec not being closed 2796N/A * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 2796N/A// create binary file, rewriting existing file if required 2796N/A// return current position of file pointer 2796N/A// move file pointer to the specified offset 2796N/A// This code originates from JDK's sysAvailable 2796N/A * XXX: is the following call interruptible? If so, this might 2796N/A * need to go through the INTERRUPT_IO() wrapper as for other 2796N/A * blocking, interruptible calls in this file. 2796N/A //%% note ioctl can return 0 when successful, JVM_SocketAvailable 2796N/A // is expected to return 0 on failure and 1 on success to the jdk. 2796N/A // same as map_memory() on this OS 2796N/A assert(
rc == 0,
"pthread_getcpuclockid is expected to return 0 code");
2796N/A// current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool) 2796N/A// are used by JVM M&M and JVMTI to get user+sys or user CPU time 2796N/A// current_thread_cpu_time() and thread_cpu_time(Thread*) returns 2796N/A// the fast estimate available on the platform. 2796N/A // return user + sys since the cost is the same 2796N/A // consistent with what current_thread_cpu_time() returns 2796N/A // We first try accessing /proc/<pid>/cpu since this is faster to 2796N/A // process. If this file is not present (bsd kernels 2.5 and above) 2796N/A // then we open /proc/<pid>/stat. 2796N/A // The /proc/<tid>/stat aggregates per-process usage on 2796N/A // new Bsd kernels 2.6+ where NPTL is supported. 2796N/A // and possibly in some other cases, so we check its availability. 2796N/A // This is executed only once 2796N/A // Skip pid and the command string. Note that we could be dealing with 2796N/A // weird command names, e.g. user could decide to rename java launcher 2796N/A // to "java 1.4.2 :)", then the stat file would look like 2796N/A // 1234 (java 1.4.2 :)) R ... ... 2796N/A // We don't really need to know the command string, just find the last 2796N/A // occurrence of ")" and then start parsing from there. See bug 4726580. 2796N/A// System loadavg support. Returns -1 if load average cannot be obtained. 2796N/A// Bsd doesn't yet have a (official) notion of processor sets, 2796N/A// so just return the system wide load average. 2796N/A "Could not open pause file '%s', continuing immediately.\n",
filename);
2796N/A// Beware -- Some versions of NPTL embody a flaw where pthread_cond_timedwait() can 2796N/A// hang indefinitely. For instance NPTL 0.60 on 2.4.21-4ELsmp is vulnerable. 2796N/A// For specifics regarding the bug see GLIBC BUGID 261237 : 2796N/A// Briefly, pthread_cond_timedwait() calls with an expiry time that's not in the future 2796N/A// will either hang or corrupt the condvar, resulting in subsequent hangs if the condvar 2796N/A// is used. (The simple C test-case provided in the GLIBC bug report manifests the 2796N/A// hang). The JVM is vulernable via sleep(), Object.wait(timo), LockSupport.parkNanos() 2796N/A// and monitorenter when we're using 1-0 locking. All those operations may result in 2796N/A// calls to pthread_cond_timedwait(). Using LD_ASSUME_KERNEL to use an older version 2796N/A// of libpthread avoids the problem, but isn't practical. 2796N/A// 1. Establish a minimum relative wait time. 50 to 100 msecs seems to work. 2796N/A// This is palliative and probabilistic, however. If the thread is preempted 2796N/A// between the call to compute_abstime() and pthread_cond_timedwait(), more 2796N/A// than the minimum period may have passed, and the abstime may be stale (in the 2796N/A// past) resultin in a hang. Using this technique reduces the odds of a hang 2796N/A// but the JVM is still vulnerable, particularly on heavily loaded systems. 2796N/A// 2. Modify park-unpark to use per-thread (per ParkEvent) pipe-pairs instead 2796N/A// of the usual flag-condvar-mutex idiom. The write side of the pipe is set 2796N/A// NDELAY. unpark() reduces to write(), park() reduces to read() and park(timo) 2796N/A// reduces to poll()+read(). This works well, but consumes 2 FDs per extant 2796N/A// 3. Embargo pthread_cond_timedwait() and implement a native "chron" thread 2796N/A// that manages timeouts. We'd emulate pthread_cond_timedwait() by enqueuing 2796N/A// a timeout request to the chron thread and then blocking via pthread_cond_wait(). 2796N/A// This also works well. In fact it avoids kernel-level scalability impediments 2796N/A// on certain platforms that don't handle lots of active pthread_cond_timedwait() 2796N/A// timers in a graceful fashion. 2796N/A// 4. When the abstime value is in the past it appears that control returns 2796N/A// correctly from pthread_cond_timedwait(), but the condvar is left corrupt. 2796N/A// can avoid the problem by reinitializing the condvar -- by cond_destroy() 2796N/A// followed by cond_init() -- after all calls to pthread_cond_timedwait(). 2796N/A// It may be possible to avoid reinitialization by checking the return 2796N/A// value from pthread_cond_timedwait(). In addition to reinitializing the 2796N/A// condvar we must establish the invariant that cond_signal() is only called 2796N/A// within critical sections protected by the adjunct mutex. This prevents 2796N/A// cond_signal() from "seeing" a condvar that's in the midst of being 2796N/A// reinitialized or that is corrupt. Sadly, this invariant obviates the 2796N/A// desirable signal-after-unlock optimization that avoids futile context switching. 2796N/A// I'm also concerned that some versions of NTPL might allocate an auxilliary 2796N/A// structure when a condvar is used or initialized. cond_destroy() would 2796N/A// release the helper structure. Our reinitialize-after-timedwait fix 2796N/A// We currently use (4). See the WorkAroundNTPLTimedWaitHang flag. 2796N/A// It may be possible to refine (4) by checking the kernel and NTPL verisons 2796N/A// and only enabling the work-around for vulnerable environments. 2796N/A// utility to compute the abstime argument to timedwait: 2796N/A// millis is the relative timeout time 2796N/A// abstime will be the absolute timeout time 2796N/A// TODO: replace compute_abstime() with unpackTime() 2796N/A// Test-and-clear _Event, always leaves _Event set to 0, returns immediately. 2796N/A// Conceptually TryPark() should be equivalent to park(0). 2796N/A // TODO: assert that _Assoc != NULL or _Assoc == Self 2796N/A // Do this the hard way by blocking ... 2796N/A // for some reason, under 2.7 lwp_cond_wait() may return ETIME ... 2796N/A // Treat this the same as if the wait was interrupted 4278N/A // Paranoia to ensure our locked and lock-free paths interact 4278N/A // correctly with each other. 2796N/A // We do this the hard way, by blocking the thread. 2796N/A // Consider enforcing a minimum timeout value. 2796N/A // Object.wait(timo) will return because of 2796N/A // Thread.interrupt and object.notify{All} both call Event::set. 2796N/A // That is, we treat thread.interrupt as a special case of notification. 2796N/A // The underlying Solaris implementation, cond_timedwait, admits 2796N/A // JVM from making those visible to Java code. As such, we must 2796N/A // filter out spurious wakeups. We assume all ETIME returns are valid. 2796N/A // TODO: properly differentiate simultaneous notify+interrupt. 2796N/A // In that case, we should propagate the notify to another waiter. 2796N/A // We consume and ignore EINTR and spurious wakeups. 4278N/A // Paranoia to ensure our locked and lock-free paths interact 4278N/A // correctly with each other. 4278N/A // -1 :=> either 0 or 1; must signal target thread 4278N/A // That is, we can safely transition _Event from -1 to either 4278N/A // 0 or 1. Forcing 1 is slightly more efficient for back-to-back 4278N/A // See also: "Semaphores in Plan 9" by Mullender & Cox 4278N/A // Note: Forcing a transition from "-1" to "1" on an unpark() means 4278N/A // that it will take two back-to-back park() calls for the owning 4278N/A // thread to block. This has the benefit of forcing a spurious return 4278N/A // from the first park() call after an unpark() call which will help 4278N/A // shake out uses of park() and unpark() without condition variables. 4278N/A // Wait for the thread associated with the event to vacate 2796N/A // Note that we signal() _after dropping the lock for "immortal" Events. 2796N/A // This is safe and avoids a common class of futile wakeups. In rare 2796N/A // circumstances this can cause a thread to return prematurely from 2796N/A // cond_{timed}wait() but the spurious wakeup is benign and the victim will 2796N/A // simply re-test the condition and re-park itself. 2796N/A// ------------------------------------------------------- 2796N/A * conservative for now, but can be improved. They currently use a 2796N/A * Park decrements count if > 0, else does a condvar wait. Unpark 2796N/A * sets count to 1 and signals condvar. Only one thread ever waits 2796N/A * on the condvar. Contention seen when trying to park implies that someone 2796N/A * is unparking you, so don't wait. And spurious returns are fine, so there 2796N/A * is no need to track notifications. 2796N/A * This code is common to bsd and solaris and will be moved to a 2796N/A * The passed in time value is either a relative time in nanoseconds 2796N/A * or an absolute time in milliseconds. Either way it has to be unpacked 2796N/A * into suitable seconds and nanoseconds components and stored in the 2796N/A * given timespec structure. 2796N/A * Given time is a 64-bit value and the time_t used in the timespec is only 2796N/A * a signed-32-bit value (except on 64-bit Bsd) we have to watch for 2796N/A * overflow if times way in the future are given. Further on Solaris versions 2796N/A * prior to 10 there is a restriction (see cond_timedwait) that the specified 2796N/A * number of seconds, in abstime, is less than current_time + 100,000,000. 2796N/A * As it will be 28 years before "now + 100000000" will overflow we can 2796N/A * ignore overflow and just impose a hard-limit on seconds using the value 2796N/A * of "now + 100,000,000". This places a limit on the timeout of about 3.17 4278N/A // Ideally we'd do something useful while spinning, such 4278N/A // as calling unpackTime(). 2796N/A // Optional fast-path check: 2796N/A // Return immediately if a permit is available. 4278N/A // We depend on Atomic::xchg() having full barrier semantics 4278N/A // since we are doing a lock-free update to _counter. 2796N/A // Optional optimization -- avoid state transitions if there's an interrupt pending. 2796N/A // Check interrupt before trying to wait 2796N/A // Beware of deadlocks such as 6317397. 2796N/A // The per-thread Parker:: mutex is a classic leaf-lock. 2796N/A // In particular a thread must never block on the Threads_lock while 2796N/A // holding the Parker:: mutex. If safepoints are pending both the 2796N/A // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock. 2796N/A // Don't wait if cannot get lock since interference arises from 2796N/A // unblocking. Also. check interrupt before trying wait 4278N/A // Paranoia to ensure our locked and lock-free paths interact 4278N/A // correctly with each other and Java-level accesses. 2796N/A // Don't catch signals while blocked; let the running threads have the signals. 2796N/A // (This allows a debugger to break into the running thread.) 2796N/A // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() 4278N/A // Paranoia to ensure our locked and lock-free paths interact 4278N/A // correctly with each other and Java-level accesses. 2796N/A // If externally suspended while waiting, re-suspend 2796N/A/* Darwin has no "environ" in a dynamic library. */ 2796N/A// Run the specified command in a separate process. Return its exit value, 2796N/A// or -1 on failure (e.g. can't fork a new process). 2796N/A// Unlike system(), this function can be called from signal handler. It 2796N/A// doesn't block SIGINT et al. 2796N/A // pthread_atfork handlers and reset pthread library. All we need is a 2796N/A // separate process to execve. Make a direct syscall to fork process. 2796N/A // On IA64 there's no fork syscall, we have to use fork() and hope for 2796N/A // execve() in BsdThreads will call pthread_kill_other_threads_np() 2796N/A // first to kill every thread on the thread list. Because this list is 2796N/A // not reset by fork() (see notes above), execve() will instead kill 2796N/A // every thread in the parent process. We know this is the only thread 2796N/A // in the new process, so make a system call directly. 2796N/A // IA64 should use normal execve() from glibc to match the glibc fork() 2796N/A // care about the actual exit code, for now. 2796N/A // Wait for the child process to exit. This returns immediately if 2796N/A // the child has already exited. */ 2796N/A // The child exited normally; get its exit code. 2796N/A // The child exited because of a signal 2796N/A // The best value to return is 0x80 + signal number, 2796N/A // because that is what all Unix shells do, and because 2796N/A // it allows callers to distinguish between process exit and 2796N/A // process death by signal. 2796N/A // Unknown exit code; pass it through 2796N/A// in order to report if we are running in a headless jre 2796N/A // Get rid of client or server 3866N/A// Get the default path to the core file 3866N/A// Returns the length of the string 3866N/A // Truncate if theoretical string was longer than bufferSize