thread.cpp revision 1135
844N/A * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A#
include "incls/_precompiled.incl" 0N/A// Only bother with this argument setup if dtrace is available 0N/A#
else // ndef DTRACE_ENABLED 0N/A#
endif // ndef DTRACE_ENABLED 0N/A// - ConcurrentMarkSweepThread 0N/A// ======= Thread ======== 0N/A// Support for forcing alignment of thread objects for biased locking 0N/A "JavaThread alignment code overflowed allocated storage");
0N/A// Base class for all threads: VMThread, WatcherThread, ConcurrentMarkSweepThread, 0N/A // allocated data structures 0N/A // This initial value ==> never claimed. 0N/A // the handle mark links itself to last_handle_mark 0N/A // plain initialization 0N/A // thread-specific hashCode stream generator state - Marsaglia shift-xor form 0N/A // Many of the following fields are effectively final - immutable 0N/A // Note that nascent threads can't use the Native Monitor-Mutex 0N/A // construct until the _MutexEvent is initialized ... 0N/A // CONSIDER: instead of using a fixed set of purpose-dedicated ParkEvents 0N/A // we might instead use a stack of ParkEvents that we could provision on-demand. 0N/A // The stack would act as a cache to avoid calls to ParkEvent::Allocate() 0N/A#
endif // CHECK_UNHANDLED_OOPS 0N/A "bug in forced alignment of thread objects");
0N/A // Note: Make sure this method only calls 0N/A // non-blocking operations. Otherwise, it might not work 0N/A // During Java thread startup, safepoint code should allow this 0N/A // method to complete because it may need to allocate memory to 0N/A // store information for the new thread. 0N/A // initialize structure dependent on thread local storage 0N/A // set up any platform-specific state. 0N/A // Reclaim the objectmonitors from the omFreeList of the moribund thread. 0N/A // deallocate data structures 0N/A // since the handle marks are using the handle area, we have to deallocated the root 0N/A // handle mark before deallocating the thread's handle area, 0N/A // It's possible we can encounter a null _ParkEvent, etc., in stillborn threads. 0N/A // We NULL out the fields for good hygiene. 0N/A // osthread() can be NULL, if creation of thread failed. 0N/A // clear thread local storage if the Thread is deleting itself 0N/A // In the case where we're not the current thread, invalidate all the 0N/A // caches in case some code tries to get the current thread or the 0N/A // thread that was destroyed, and gets stale information. 0N/A// NOTE: dummy function for assertion purpose. 0N/A// Private method to check for dangling thread pointer 0N/A "possibility of dangling Thread pointer");
0N/A// Tracing method for basic thread operations 0N/A const char *
name =
"non-Java thread";
0N/A // The Threads_lock must be held to get information about 0N/A // this thread but may not be in some situations when 0N/A // tracing thread events. 0N/A // Can return an error! 0N/A // Can return an error! 0N/A // Start is different from resume in that its safety is guaranteed by context or 0N/A // being called from a Java method synchronized on the Thread object. 0N/A // Initialize the thread state to RUNNABLE before starting this thread. 0N/A // Can not set it after the thread started because we do not know the 0N/A // exact thread state at that time. It could be in MONITOR_WAIT or 0N/A // in SLEEPING or some other state. 0N/A// Enqueue a VM_Operation to do the job for us - sometime later 0N/A// Check if an external suspend request has completed (or has been 0N/A// cancelled). Returns true if the thread is externally suspended and 0N/A// The bits parameter returns information about the code path through 0N/A// the routine. Useful for debugging: 0N/A// set in is_ext_suspend_completed(): 0N/A// 0x00000001 - routine was entered 0N/A// 0x00000010 - routine return false at end 0N/A// 0x00000100 - thread exited (return false) 0N/A// 0x00000200 - suspend request cancelled (return false) 0N/A// 0x00000400 - thread suspended (return true) 0N/A// 0x00001000 - thread is in a suspend equivalent state (return true) 0N/A// 0x00002000 - thread is native and walkable (return true) 0N/A// 0x00004000 - thread is native_trans and walkable (needed retry) 0N/A// set in wait_for_ext_suspend_completion(): 0N/A// 0x00010000 - routine was entered 0N/A// 0x00020000 - suspend request cancelled before loop (return false) 0N/A// 0x00040000 - thread suspended before loop (return true) 0N/A// 0x00080000 - suspend request cancelled in loop (return false) 0N/A// 0x00100000 - thread suspended in loop (return true) 0N/A// 0x00200000 - suspend not completed during retry loop (return false) 0N/A// Helper class for tracing suspend wait debug bits. 0N/A// 0x00000100 indicates that the target thread exited before it could 0N/A// self-suspend which is not a wait failure. 0x00000200, 0x00020000 and 0N/A// 0x00080000 each indicate a cancelled suspend request so they don't 0N/A// count as wait failures either. 0N/A // By default, don't trace bits for is_ext_suspend_completed() calls. 0N/A // That trace is very chatty. 0N/A // If tracing for is_ext_suspend_completed() is enabled, then only 0N/A // trace calls to it from wait_for_ext_suspend_completion() 0N/A "Failed wait_for_ext_suspend_completion(thread=%s, debug_bits=%x)",
0N/A // Thread is in the process of exiting. This is always checked 0N/A // first to reduce the risk of dereferencing a freed JavaThread. 0N/A // Suspend request is cancelled. This is always checked before 0N/A // is_ext_suspended() to reduce the risk of a rogue resume 0N/A // confusing the thread that made the suspend request. 0N/A // thread is suspended 0N/A // Now that we no longer do hard suspends of threads running 0N/A // native code, the target thread can be changing thread state 0N/A // while we are in this routine: 0N/A // _thread_in_native -> _thread_in_native_trans -> _thread_blocked 0N/A // We save a copy of the thread state as observed at this moment 0N/A // and make our decision about suspend completeness based on the 0N/A // copy. This closes the race where the thread state is seen as 0N/A // _thread_in_native_trans in the if-thread_blocked check, but is 0N/A // seen as _thread_blocked in if-thread_in_native_trans check. 0N/A // If the thread's state is _thread_blocked and this blocking 0N/A // condition is known to be equivalent to a suspend, then we can 0N/A // consider the thread to be externally suspended. This means that 0N/A // the code that sets _thread_blocked has been modified to do 0N/A // self-suspension if the blocking condition releases. We also 0N/A // used to check for CONDVAR_WAIT here, but that is now covered by 0N/A // the _thread_blocked with self-suspension check. 0N/A // Return true since we wouldn't be here unless there was still an 0N/A // external suspend request. 0N/A // Threads running native code will self-suspend on native==>VM/Java 0N/A // transitions. If its stack is walkable (should always be the case 0N/A // unless this function is called before the actual java_suspend() 0N/A // call), then the wait is done. 0N/A // The thread is transitioning from thread_in_native to another 0N/A // thread state. check_safepoint_and_suspend_for_native_trans() 0N/A // will force the thread to self-suspend. If it hasn't gotten 0N/A // there yet we may have caught the thread in-between the native 0N/A // code check above and the self-suspend. Lucky us. If we were 0N/A // called by wait_for_ext_suspend_completion(), then it 0N/A // will be doing the retries so we don't have to. 0N/A // Since we use the saved thread state in the if-statement above, 0N/A // there is a chance that the thread has already transitioned to 0N/A // _thread_blocked by the time we get here. In that case, we will 0N/A // make a single unnecessary pass through the logic below. This 0N/A // doesn't hurt anything since we still do the trans retry. 0N/A // Once the thread leaves thread_in_native_trans for another 0N/A // thread state, we break out of this retry loop. We shouldn't 0N/A // need this flag to prevent us from getting back here, but 0N/A // sometimes paranoia is good. 0N/A // We wait for the thread to transition to a more usable state. 0N/A // We used to do an "os::yield_all(i)" call here with the intention 0N/A // that yielding would increase on each retry. However, the parameter 0N/A // is ignored on Linux which means the yield didn't scale up. Waiting 0N/A // on the SR_lock below provides a much more predictable scale up for 0N/A // safepoint requests from the VMThread 0N/A // temporarily drops SR_lock while doing wait with safepoint check 0N/A // (if we're a JavaThread - the WatcherThread can also call this) 0N/A // and increase delay with each retry 0N/A // check the actual thread state instead of what we saved above 0N/A // the thread has transitioned to another thread state so 0N/A // try all the checks (except this one) one more time. 0N/A// Wait for an external suspend request to complete (or be cancelled). 0N/A// Returns true if the thread is externally suspended and false otherwise. 0N/A false /* !called_by_wait */,
bits);
0N/A // local flag copies to minimize SR_lock hold time 0N/A // set a marker so is_ext_suspend_completed() knows we are the caller 0N/A // We use reset_bits to reinitialize the bits value at the top of 0N/A // each retry loop. This allows the caller to make use of any 0N/A // unused bits for their own marking purposes. 0N/A // must release SR_lock to allow suspension to complete 0N/A // A cancelled suspend request is the only false return from 0N/A // is_ext_suspend_completed() that keeps us from entering the 0N/A // We used to do an "os::yield_all(i)" call here with the intention 0N/A // that yielding would increase on each retry. However, the parameter 0N/A // is ignored on Linux which means the yield didn't scale up. Waiting 0N/A // on the SR_lock below provides a much more predictable scale up for 0N/A // safepoint requests from the VMThread 0N/A // wait with safepoint check (if we're a JavaThread - the WatcherThread 0N/A // can also call this) and increase delay with each retry 0N/A // It is possible for the external suspend request to be cancelled 0N/A // (by a resume) before the actual suspend operation is completed. 0N/A // Refresh our local copy to see if we still need to wait. 0N/A // A cancelled suspend request is the only false return from 0N/A // is_ext_suspend_completed() that keeps us from staying in the 0N/A // thread did not suspend after all our retries 0N/A // This should not need to be atomic as the only way for simultaneous 0N/A // updates is via interrupts. Even then this should be rare or non-existant 0N/A // and we don't care that much anyway. 0N/A// Called by flat profiler 0N/A// Callers have already called wait_for_ext_suspend_completion 0N/A// The assertion for that is currently too complex to put here: 0N/A // self suspension saves needed state. 0N/A // Note: If clear_interrupted==false, this simply fetches and 0N/A // returns the value of the field osthread()->interrupted(). 0N/A "Should only fail when parallel.");
0N/A "Should only fail when parallel.");
0N/A // Do oop for ThreadShadow 989N/A // no nmethods in a generic thread... 0N/A // get_priority assumes osthread initialized 0N/A// Thread::print_on_error() is called by fatal error handler. Don't use 0N/A// any lock or allocate memory. 0N/A// The flag: potential_vm_operation notifies if this particular safepoint state could potential 0N/A// invoke the vm-thread (i.e., and oop allocation). In that case, we also have to make sure that 0N/A// no threads which allow_vm_block's are held 0N/A // Check if current thread is allowed to block at a safepoint 0N/A fatal(
"Possible safepoint reached by thread that does not allow it");
0N/A // Make sure we do not hold any locks that the VM thread also uses. 0N/A // This could potentially lead to deadlocks 0N/A // Threads_lock is special, since the safepoint synchronization will not start before this is 0N/A // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock, 0N/A // since it is used to transfer control between JavaThreads and the VMThread 0N/A // Do not *exclude* any locks unless you are absolutly sure it is correct. Ask someone else first! 0N/A cur !=
Compile_lock &&
// Temporary: should not be necessary when we get spearate compilation 0N/A // We could enter a safepoint here and thus have a gc 0N/A// We had to move these methods here, because vm threads get into ObjectSynchronizer::enter 0N/A// However, there is a note in JavaThread::is_lock_owned() about the VM threads not being 0N/A// used for compilation in the future. If that change is made, the need for these methods 0N/A// should be revisited, and they should be removed if possible. 0N/A // NOTE: this must be called inside the main thread. 0N/A// Creates the initial ThreadGroup 0N/A// Creates the initial Thread 0N/A // the vm info string 0N/A // java.lang.System class 0N/A // setProperty arguments 0N/A // public static String setProperty(String key, String value); 0N/A // Thread gets assigned specified name and null target 0N/A // Thread gets assigned name "Thread-nnn" and null target 0N/A // (java.lang.Thread doesn't have a constructor taking only a ThreadGroup argument) 0N/A// NamedThread -- non-JavaThread subclasses with multiple 0N/A// uniquely named instances should derive from this. 0N/A// ======= WatcherThread ======== 0N/A// The watcher thread exists to simulate timer interrupts. It should 0N/A// be replaced by an abstraction over whatever native support for 0N/A// timer interrupts exists on the platform. 0N/A // Set the watcher thread to the highest OS priority which should not be 0N/A // used, unless a Java thread with priority java.lang.Thread.MAX_PRIORITY 0N/A // is created. The only normal thread using this priority is the reference 0N/A // handler thread, which runs for very short intervals only. 0N/A // If the VMThread's priority is not lower than the WatcherThread profiling 0N/A // will be inaccurate. 0N/A // Calculate how long it'll be until the next PeriodicTask work 0N/A // should be done, and sleep that amount of time. 0N/A // A fatal error has happened, the error handler(VMError::report_and_die) 0N/A // should abort JVM after creating an error log file. However in some 0N/A // rare cases, the error handler itself might deadlock. Here we try to 0N/A // kill JVM if the fatal error handler fails to abort in 2 minutes. 0N/A // This code is in WatcherThread because WatcherThread wakes up 0N/A // periodically so the fatal error handler doesn't need to do anything; 0N/A // also because the WatcherThread is less likely to crash than other 0N/A // Wake up 5 seconds later, the fatal handler may reset OnError or 0N/A // ShowMessageBoxOnError when it is ready to abort. 0N/A // If we have no more tasks left due to dynamic disenrollment, 0N/A // shut down the thread since we don't currently support dynamic enrollment 0N/A // Signal that it is terminated 0N/A // Thread destructor usually does this.. 0N/A // Create the single instance of WatcherThread 0N/A // it is ok to take late safepoints here, if needed 0N/A // This wait should make safepoint checks, wait without a timeout, 0N/A // and wait as a suspend-equivalent condition. 0N/A // Note: If the FlatProfiler is running, then this thread is waiting 0N/A // for the WatcherThread to terminate and the WatcherThread, via the 0N/A // FlatProfiler task, is waiting for the external suspend request on 0N/A // this thread to complete. wait_for_ext_suspend_completion() will 0N/A // eventually timeout, but that takes time. Making this wait a 0N/A // suspend-equivalent condition solves that timeout problem. 0N/A// ======= JavaThread ======== 0N/A// A JavaThread is a normal Java thread 0N/A // Initialize fields 342N/A // Set the claimed par_id to -1 (ie not claiming any par_ids) 0N/A // This is where we would decide to either give each thread it's own profiler 0N/A // or use one global one from FlatProfiler, 0N/A // or up to some count of the number of profiled threads, etc. 0N/A // Setup safepoint state info for this thread 0N/A // JVMTI PopFrame support 0N/A return true;
// Stack already guarded or guard pages not needed. 0N/A // For those architectures which have separate register and 0N/A // memory stacks, we must check the register stack to see if 0N/A // it has overflowed. 0N/A // Java code never executes within the yellow zone: the latter is only 0N/A // there to provoke an exception during stack banging. If java code 0N/A // is executing there, either StackShadowPages should be larger, or 0N/A // some exception code in c1, c2 or the interpreter isn't unwinding 0N/A // _vm_exited is set at safepoint, and Threads_lock is never released 0N/A // we will block here forever 0N/A// Remove this ifdef when C1 is ported to the compiler interface. 0N/A // Create the native thread itself. 0N/A // The _osthread may be NULL here because we ran out of memory (too many threads active). 0N/A // We need to throw and OutOfMemoryError - however we cannot do this here because the caller 0N/A // may hold a lock and all locks must be unlocked before throwing the exception (throwing 0N/A // the exception consists of creating the exception object & initializing it, initialization 0N/A // will leave the VM via a JavaCall and then all locks must be unlocked). 0N/A // The thread is still suspended when we reach here. Thread must be explicit started 0N/A // by creator! Furthermore, the thread must also explicitly be added to the Threads list 0N/A // by calling Threads:add. The reason why this is not done here, is because the thread 0N/A // object must be fully initialized (take a look at JVM_Start) 0N/A // JSR166 -- return the parker to the free list 0N/A // Free any remaining previous UnrollBlock 0N/A // This can only happen if thread is destroyed before deoptimization occurs. 0N/A // individual jvmtiDeferredLocalVariableSet are CHeapObj's 0N/A // All Java related clean up happens in exit 0N/A// The first routine called by a new Java thread 0N/A // initialize thread-local alloc buffer related fields 0N/A // used to test validitity of stack trace backs 0N/A // Record real stack base and size. 0N/A // Initialize thread local storage; set before calling MutexLocker 0N/A // Thread is now sufficient initialized to be handled by the safepoint code as being 0N/A // in the VM. Change thread state from _thread_new to _thread_in_vm 0N/A // This operation might block. We call that after all safepoint checks for a new thread has 0N/A // We call another function to do the rest so we are sure that the stack addresses used 0N/A // from there will be lower than the stack base just computed 0N/A // Note, thread is no longer valid at this point! 0N/A // Execute thread entry point. If this thread is being asked to restart, 0N/A // or has been stopped before starting, do not reexecute entry point. 0N/A // Note: Due to JVM_StopThread we can have pending exceptions already! 0N/A // enter the thread's entry point only if we have no pending exceptions 0N/A // We do not need to grap the Threads_lock, since we are operating on ourself. 0N/A // Ignore pending exception (ThreadDeath), since we are exiting anyway 0N/A // It is of profound importance that we set the stillborn bit and reset the thread object, 0N/A // before we do the notify. Since, changing these two variable will make JVM_IsAlive return 0N/A // false. So in case another thread is doing a join on this thread , it will detect that the thread 0N/A // is dead when it gets notified. 0N/A // Thread is exiting. So set thread_status field in java.lang.Thread class to TERMINATED. 0N/A // Ignore pending exception (ThreadDeath), since we are exiting anyway 0N/A// For any new cleanup additions, please check to see if they need to be applied to 0N/A// cleanup_failed_attach_current_thread as well. 0N/A // FIXIT: This code should be moved into else part, when reliable 1.2/1.3 check is in place 0N/A // FIXIT: The is_null check is only so it works better on JDK1.2 VM's. This 0N/A // has to be fixed by a runtime query method 0N/A // JSR-166: change call from from ThreadGroup.uncaughtException to 0N/A // java.lang.Thread.dispatchUncaughtException 0N/A Events::
log(
"uncaught exception INTPTR_FORMAT " " INTPTR_FORMAT " " INTPTR_FORMAT",
0N/A // Check if the method Thread.dispatchUncaughtException() exists. If so 0N/A // call it. Otherwise we have an older library without the JSR-166 changes, 0N/A // so call ThreadGroup.uncaughtException() 0N/A // Call Thread.exit(). We try 3 times in case we got another Thread.stop during 0N/A // the execution of the method. If that is not enough, then we don't really care. Thread.stop 0N/A // is deprecated anyhow. 0N/A // We have notified the agents that we are exiting, before we go on, 0N/A // we must check for a pending external suspend request and honor it 0N/A // in order to not surprise the thread that made the suspend request. 0N/A // Things get a little tricky here. We have a pending external 0N/A // suspend request, but we are holding the SR_lock so we 0N/A // can't just self-suspend. So we temporarily drop the lock 0N/A // and then self-suspend. 0N/A // We're done with this suspend request, but we have to loop around 0N/A // and check again. Eventually we will get SR_lock without a pending 0N/A // external suspend request and will be able to mark ourselves as 0N/A // no more external suspends are allowed at this point 0N/A // before_exit() has already posted JVMTI THREAD_END events 0N/A // Notify waiters on thread object. This has to be done after exit() is called 0N/A // on the thread (if the thread is the last thread in a daemon ThreadGroup the 0N/A // group should have the destroyed bit set before waiters are notified). 0N/A // 6282335 JNI DetachCurrentThread spec states that all Java monitors 0N/A // held by this thread must be released. A detach operation must only 0N/A // get here if there are no Java frames on the stack. Therefore, any 0N/A // owned monitors at this point MUST be JNI-acquired monitors which are 0N/A // pre-inflated and in the monitor cache. 0N/A // ensure_join() ignores IllegalThreadStateExceptions, and so does this. 0N/A // These things needs to be done while we are still a Java Thread. Make sure that thread 0N/A // is in a consistent state, in case GC happens 0N/A // These have to be removed while this is still a valid thread. 441N/A // We must flush G1-related buffers before removing a thread from 441N/A // the list of active threads. 0N/A // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread 441N/A// Flush G1-related queues. 0N/A// Note: this function shouldn't block if it's called in 0N/A// _thread_in_native_trans state (such as from 0N/A// check_special_condition_for_native_trans()). 0N/A // If we are at a polling page safepoint (not a poll return) 0N/A // then we must defer async exception because live registers 0N/A // will be clobbered by the exception path. Poll return is 0N/A // ok because the call we a returning from already collides 0N/A // with exception handling registers and so there is no issue. 0N/A // (The exception handling path kills call result registers but 0N/A // this is ok since the exception kills the result anyway). 0N/A // if the code we are returning to has deoptimized we must defer 0N/A // the exception otherwise live registers get clobbered on the 0N/A // exception path before deoptimization is able to retrieve them. 0N/A // Conditions have changed since has_special_runtime_exit_condition() 0N/A // - if we were here only because of an external suspend request, 0N/A // then that was taken care of above (or cancelled) so we are done 0N/A // - if we were here because of another async request, then it has 0N/A // been cleared between the has_special_runtime_exit_condition() 0N/A // and now so again we are done 0N/A // Check for pending async. exception 0N/A // Only overwrite an already pending exception, if it is not a threadDeath. 0N/A // We cannot call Exceptions::_throw(...) here because we cannot block 0N/A "must have handled the async condition, if no exception");
0N/A // Check for pending external suspend. Internal suspend requests do 0N/A // not use handle_special_runtime_exit_condition(). 0N/A // If JNIEnv proxies are allowed, don't self-suspend if the target 0N/A // thread is not the current thread. In older versions of jdbx, jdbx 0N/A // threads could call into the VM with another thread's JNIEnv so we 0N/A // can be here operating on behalf of a suspended thread (4432884). 0N/A // Because thread is external suspended the safepoint code will count 0N/A // thread as at a safepoint. This can be odd because we can be here 0N/A // as _thread_in_Java which would normally transition to _thread_blocked 0N/A // at a safepoint. We would like to mark the thread as _thread_blocked 0N/A // before calling java_suspend_self like all other callers of it but 0N/A // we must then observe proper safepoint protocol. (We can't leave 0N/A // _thread_blocked with a safepoint in progress). However we can be 0N/A // here as _thread_in_native_trans so we can't use a normal transition 0N/A // transition. We could do something like: 0N/A // JavaThreadState state = thread_state(); 0N/A // set_thread_state(_thread_in_vm); 0N/A // ThreadBlockInVM tbivm(this); 0N/A // java_suspend_self() 0N/A // set_thread_state(_thread_in_vm_trans); 0N/A // if (safepoint) block; 0N/A // set_thread_state(state); 0N/A // but that is pretty messy. Instead we just go with the way the 0N/A // code has worked before and note that this is the only path to 0N/A // java_suspend_self that doesn't put the thread in _thread_blocked 0N/A // We might be here for reasons in addition to the self-suspend request 0N/A // so check for other async requests. 0N/A // Do not throw asynchronous exceptions against the compiler thread 0N/A // (the compiler thread should not be a Java thread -- fix in 1.4.2) 0N/A // This is a change from JDK 1.1, but JDK 1.2 will also do it: 0N/A // Actually throw the Throwable against the target Thread - however 0N/A // only if there is no thread death exception installed already. 0N/A // If the topmost frame is a runtime stub, then we are calling into 0N/A // OptoRuntime from compiled code. Some runtime stubs (new, monitor_exit..) 0N/A // must deoptimize the caller before continuing, as the compiled exception handler table 0N/A // BiasedLocking needs an updated RegisterMap for the revoke monitors pass 0N/A // Set async. pending exception in thread. 0N/A // for AbortVMOnException flag 0N/A // Interrupt thread so it will wake up from a potential wait() 0N/A// External suspension mechanism. 0N/A// Tell the VM to suspend a thread when ever it knows that it does not hold on 0N/A// to any VM_locks and it is at a transition 0N/A// Self-suspension will happen on the transition out of the vm. 0N/A// Catch "this" coming in from JNIEnv pointers when the thread has been freed 0N/A// Guarantees on return: 0N/A// + Target thread will not execute any new bytecode (that's why we need to 0N/A// force a safepoint) 0N/A// + Target thread will not enter any new monitors 0N/A // a racing resume has cancelled us; bail out now 0N/A // Warning: is_ext_suspend_completed() may temporarily drop the 0N/A // SR_lock to allow the thread to reach a stable thread state if 0N/A // it is currently in a transient thread state. 0N/A// Part II of external suspension. 0N/A// A JavaThread self suspends when it detects a pending external suspend 0N/A// request. This is usually on transitions. It is also done in places 0N/A// where continuing to the next transition would surprise the caller, 0N/A// e.g., monitor entry. 0N/A// Returns the number of times that the thread self-suspended. 0N/A// Note: DO NOT call java_suspend_self() when you just want to block current 0N/A// thread. java_suspend_self() is the second stage of cooperative 0N/A// suspension for external suspend requests and should only be used 0N/A// to complete an external suspend request. 0N/A // we are in the process of exiting so don't suspend 0N/A "must have walkable stack");
0N/A "a thread trying to self-suspend should not already be suspended");
0N/A // If we are self-suspending as a result of the lifting of a 0N/A // suspend equivalent condition, then the suspend_equivalent 0N/A // flag is not cleared until we set the ext_suspended flag so 0N/A // that wait_for_ext_suspend_completion() returns consistent 0N/A // A racing resume may have cancelled us before we grabbed SR_lock 0N/A // above. Or another external suspend request could be waiting for us 0N/A // by the time we return from SR_lock()->wait(). The thread 0N/A // that requested the suspension may already be trying to walk our 0N/A // stack and if we return now, we can change the stack out from under 0N/A // it. This would be a "bad thing (TM)" and cause the stack walker 0N/A // to crash. We stay self-suspended until there are no more pending 0N/A // external suspend requests. 0N/A // _ext_suspended flag is cleared by java_resume() 0N/A// verify the JavaThread has not yet been published in the Threads::list, and 0N/A// hence doesn't need protection from concurrent access at this stage 0N/A "java thread shouldn't have been published yet!");
0N/A "java thread shouldn't have been published yet!");
0N/A// Slow path when the native==>VM/Java barriers detect a safepoint is in 0N/A// progress or when _suspend_flags is non-zero. 0N/A// Current thread needs to self-suspend if there is a suspend request and/or 0N/A// block if a safepoint is in progress. 0N/A// Async exception ISN'T checked. 0N/A// Note only the ThreadInVMfromNative transition can call this function 0N/A// directly and when thread state is _thread_in_native_trans 0N/A // If JNIEnv proxies are allowed, don't self-suspend if the target 0N/A // thread is not the current thread. In older versions of jdbx, jdbx 0N/A // threads could call into the VM with another thread's JNIEnv so we 0N/A // can be here operating on behalf of a suspended thread (4432884). 0N/A // We mark this thread_blocked state as a suspend-equivalent so 0N/A // that a caller to is_ext_suspend_completed() won't be confused. 0N/A // The suspend-equivalent state is cleared by java_suspend_self(). 0N/A // If the safepoint code sees the _thread_in_native_trans state, it will 0N/A // wait until the thread changes to other thread state. There is no 0N/A // guarantee on how soon we can obtain the SR_lock and complete the 0N/A // self-suspend request. It would be a bad idea to let safepoint wait for 0N/A // too long. Temporarily change the state to _thread_blocked to 0N/A // let the VM thread know that this thread is ready for GC. The problem 0N/A // of changing thread state is that safepoint could happen just after 0N/A // java_suspend_self() returns after being resumed, and VM thread will 0N/A // see the _thread_blocked state. We must check for safepoint 0N/A // after restoring the state and make sure we won't leave while a safepoint 0N/A // Make sure new state is seen by VM thread 0N/A // Force a fence between the write above and read below 0N/A // Must use this rather than serialization page in particular on Windows 0N/A // If we are safepointing, then block the caller which may not be 0N/A // the same as the target thread (see above). 0N/A // Since we know we're safe to deopt the current state is a safe state 0N/A// Slow path when the native==>VM/Java barriers detect a safepoint is in 0N/A// progress or when _suspend_flags is non-zero. 0N/A// Current thread needs to self-suspend if there is a suspend request and/or 0N/A// block if a safepoint is in progress. 0N/A// Also check for pending async exception (not including unsafe access error). 0N/A// Note only the native==>VM/Java barriers can call this function and when 0N/A// thread state is _thread_in_native_trans. 0N/A // We are in _thread_in_native_trans state, don't handle unsafe 0N/A // access error since that may block. 0N/A// We need to guarantee the Threads_lock here, since resumes are not 0N/A// allowed during safepoint synchronization 0N/A// Can only resume from an external suspension 0N/A // Sanity check: thread is gone, has started exiting or the thread 0N/A // was not externally suspended. 0N/A // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len); 0N/A warning(
"Attempt to allocate stack guard pages failed.");
0N/A warning(
"Attempt to protect stack guard pages failed.");
0N/A warning(
"Attempt to deallocate stack guard pages failed.");
0N/A warning(
"Attempt to deallocate stack guard pages failed.");
0N/A warning(
"Attempt to unprotect stack guard pages failed.");
0N/A // The base notation is from the stacks point of view, growing downward. 0N/A // We need to adjust it to work correctly with guard_memory() 0N/A warning(
"Attempt to guard stack yellow zone failed.");
0N/A // Simply return if called for a thread that does not use guard pages. 0N/A // The base notation is from the stacks point of view, growing downward. 0N/A // We need to adjust it to work correctly with guard_memory() 0N/A warning(
"Attempt to unguard stack yellow zone failed.");
0N/A // The base notation is from the stacks point of view, growing downward. 0N/A // We need to adjust it to work correctly with guard_memory() 0N/A warning(
"Attempt to guard stack red zone failed.");
0N/A // The base notation is from the stacks point of view, growing downward. 0N/A // We need to adjust it to work correctly with guard_memory() 0N/A warning(
"Attempt to unguard stack red zone failed.");
0N/A // ignore is there is no stack 0N/A // traverse the stack frames. Starts from top frame. 0N/A// Function for testing deoptimization 0N/A // BiasedLocking needs an updated RegisterMap for the revoke monitors pass 0N/A bool deopt =
false;
// Dump stack only if a deopt actually happens. 0N/A // Iterate over all frames in the thread and deoptimize 0N/A // Deoptimize only at particular bcis. DeoptimizeOnlyAt 0N/A // consists of comma or carriage return separated numbers so 0N/A // search for the current bci in that string. 0N/A // Check that the bci found is bracketed by terminators. 0N/A deopt =
true;
// One-time only print before deopt 0N/A // it is a Java nmethod 0N/A // BiasedLocking needs an updated RegisterMap for the revoke monitors pass 1027N/A // Flush deferred store-barriers, if any, associated with 1027N/A // initializing stores done by this JavaThread in the current epoch. 0N/A // The ThreadProfiler oops_do is done from FlatProfiler::oops_do 0N/A // since there may be more than one thread using each ThreadProfiler. 0N/A // Traverse the GCHandles 0N/A // Traverse the privileged stack 0N/A // traverse the registered growable array 0N/A // Traverse the monitor chunks 0N/A // Traverse the execution stack 0N/A // callee_target is never live across a gc point so NULL it here should 0N/A // it still contain a methdOop. 0N/A // If we have deferred set_locals there might be oops waiting to be 0N/A // Traverse instance variables at the end since the GC may be moving things 0N/A // around using this function 0N/A // Traverse the execution stack 0N/A default:
return "unknown thread state";
0N/A// Called by Threads::print() for VM_PrintThreads operation 0N/A // print guess for valid stack memory region (assume 4K pages); helps lock debugging 0N/A// Called by fatal error handler. The difference between this and 0N/A// JavaThread::print() is that we can't grab lock or allocate memory. 0N/A // Verify oops in the thread. 0N/A // Verify the stack frames. 0N/A// CR 6300358 (sub-CR 2137150) 0N/A// Most callers of this method assume that it can't return NULL but a 0N/A// thread may not have a name whilst it is in the process of attaching to 0N/A// the VM - see CR 6412693, and there are places where a JavaThread can be 0N/A// seen prior to having it's threadObj set (eg JNI attaching threads and 0N/A// if vm exit occurs during initialization). These cases can all be accounted 0N/A// for such that this method never returns NULL. 0N/A // early safepoints can hit while current thread does not yet have TLS 0N/A // Current JavaThreads are allowed to get their own name without 0N/A // the Threads_lock. 0N/A// Returns a non-NULL representation of this thread's name, or a suitable 0N/A// descriptive string if there is no set name 0N/A // ThreadGroup.name can be null 0N/A // ThreadGroup.name can be null 0N/A // Link Java Thread object <-> C++ Thread 0N/A // Get the C++ thread object (an oop) from the JNI handle (a jthread) 0N/A // and put it into a new Handle. The Handle "thread_oop" can then 0N/A // be used to pass the C++ thread object to other methods. 0N/A // Set the Java level thread object (jthread) field of the 0N/A // new thread (a JavaThread *) to C++ thread object using the 0N/A // "thread_oop" handle. 0N/A // Set the thread field (a JavaThread *) of the 0N/A // oop representing the java_lang_Thread to the new thread (a JavaThread *). 0N/A "must be initialized");
0N/A // Push the Java priority down to the native thread; needs Threads_lock 0N/A // Add the new thread to the Threads list and set it in motion. 0N/A // We must have threads lock in order to call Threads::add. 0N/A // It is crucial that we do not block before the thread is 0N/A // added to the Threads list for if a GC happens, then the java_thread oop 0N/A // will not be visited by GC. 0N/A // Support for JSR-166 locks 0N/A // Print out lock information 0N/A // Ignore non-Java frames 0N/A // Bail-out case for too deep stacks 0N/A// JVMTI PopFrame support 0N/A// Create a CompilerThread 0N/A// ======= Threads ======== 0N/A// The Threads class links together all active threads, and provides 0N/A// operations over all threads. It is protected by its own Mutex 0N/A// lock, which is also used in other contexts to protect thread 0N/A// operations from having the thread being operated on from exiting 0N/A// and going away unexpectedly (e.g., safepoint synchronization) 0N/A// All JavaThreads + all non-JavaThreads (i.e., every thread in the system) 0N/A // ALL_JAVA_THREADS iterates through all JavaThreads 0N/A // Someday we could have a table or list of all non-JavaThreads. 0N/A // For now, just manually iterate through them. 323N/A // Strictly speaking, the following NULL check isn't sufficient to make sure 323N/A // the data for WatcherThread is still valid upon being examined. However, 323N/A // considering that WatchThread terminates when the VM is on the way to 323N/A // exit at safepoint, the chance of the above is extremely small. The right 323N/A // way to prevent termination of WatcherThread would be to acquire 323N/A // Terminator_lock, but we can't do that without violating the lock rank 323N/A // checking in some cases. 0N/A // If CompilerThreads ever become non-JavaThreads, add them here 0N/A // Initialize the output stream module 0N/A // Process java launcher properties. 0N/A // Initialize the os module before using TLS 0N/A // Initialize system properties. 242N/A // So that JDK version can be used as a discrimintor when parsing arguments 0N/A // Record VM creation timing statistics 0N/A // Timing (must come after argument parsing) 0N/A // Initialize the os module after parsing the args 0N/A // Initialize output stream logging 0N/A // Convert -Xrun to -agentlib: if there is no JVM_OnLoad 0N/A // Must be before create_vm_init_agents() 0N/A // Launch -agentlib/-agentpath and converted -Xrun agents 0N/A // Initialize Threads state 0N/A // Initialize global data structures and create system classes in heap 0N/A // Attach the main thread to this os thread 0N/A // must do this before set_active_handles and initialize_thread_local_storage 0N/A // Note: on solaris initialize_thread_local_storage() will (indirectly) 0N/A // change the stack size recorded here to one based on the java thread 0N/A // stacksize. This adjusted size is what is used to figure the placement 0N/A // of the guard pages. 0N/A "Failed necessary internal allocation. Out of swap space");
0N/A // Enable guard page *after* os::create_main_thread(), otherwise it would 0N/A // Initialize Java-Leve synchronization subsystem 0N/A // Initialize global modules 0N/A // Any JVMTI raw monitors entered in onload will transition into 0N/A // real raw monitor. VM is setup enough here for raw monitor enter. 0N/A // Create the VMThread 0N/A // Wait for the VM thread to become ready, and VMThread::run to initialize 0N/A // Monitors can have spurious returns, must always check another state flag 0N/A // At this point, the Universe is initialized, but we have not executed 0N/A // any byte code. Now is a good time (the only time) to dump out the 0N/A // internal state of the JVM for sharing. 0N/A // Always call even when there are not JVMTI environments yet, since environments 0N/A // may be attached late and JVMTI must track phases of VM execution 0N/A // Notify JVMTI agents that VM has started (JNI is up) - nop if no agents. 192N/A // static final "frontCacheEnabled" field before we start creating instances 192N/A // Possible we might not find this field; if so, don't break 192N/A // static final "stringCacheEnabled" field before we start creating instances 669N/A // Possible that StringValue isn't present: if so, silently don't break 669N/A // Possible we might not find this field: if so, silently don't break 0N/A // Initialize java_lang.System (needed before creating the thread) 0N/A // Set thread status to running since main thread has 0N/A // been started and running. 0N/A // The VM preresolve methods to these classes. Make sure that get initialized 0N/A // The VM creates & returns objects of this class. Make sure it's initialized. 0N/A // an instance of OutOfMemory exception has been allocated earlier 0N/A warning(
"java.lang.OutOfMemoryError has not been initialized");
0N/A warning(
"java.lang.NullPointerException has not been initialized");
0N/A warning(
"java.lang.ClassCastException has not been initialized");
0N/A warning(
"java.lang.ArrayStoreException has not been initialized");
0N/A warning(
"java.lang.ArithmeticException has not been initialized");
0N/A warning(
"java.lang.StackOverflowError has not been initialized");
1135N/A // JSR 292: An intialized java.dyn.InvokeDynamic is required in 0N/A // See : bugid 4211085. 0N/A // Background : the static initializer of java.lang.Compiler tries to read 0N/A // property"java.compiler" and read & write property "java.vm.info". 0N/A // When a security manager is installed through the command line 0N/A // option "-Djava.security.manager", the above properties are not 0N/A // readable and the static initializer for java.lang.Compiler fails 0N/A // resulting in a NoClassDefFoundError. This can happen in any 0N/A // user code which calls methods in java.lang.Compiler. 0N/A // Hack : the hack is to pre-load and initialize this class, so that only 0N/A // system domains are on the stack when the properties are read. 0N/A // Currently even the AWT code has calls to methods in java.lang.Compiler. 0N/A // On the classic VM, java.lang.Compiler is loaded very early to load the JIT. 0N/A // Future Fix : the best fix is to grant everyone permissions to read "java.compiler" and 0N/A // read and write"java.vm.info" in the default policy file. See bugid 4211383 0N/A // Once that is done, we should remove this hack. 0N/A // More hackery - the static initializer of java.lang.Compiler adds the string "nojit" to 0N/A // the java.vm.info property if no jit gets loaded through java.lang.Compiler (the hotspot 0N/A // compiler does not get loaded through java.lang.Compiler). "java -version" with the 0N/A // hotspot vm says "nojit" all the time which is confusing. So, we reset it here. 0N/A // This should also be taken out as soon as 4211383 gets fixed. 0N/A // Set flag that basic initialization has completed. Used by exceptions and various 0N/A // debug stuff, that does not work until all basic classes have been initialized. 0N/A // record VM initialization completion time 0N/A // Compute system loader. Note that this has to occur after set_init_completed, since 0N/A // valid exceptions may be thrown in the process. 0N/A // Note that we do not use CHECK_0 here since we are inside an EXCEPTION_MARK and 0N/A // set_init_completed has just been called, causing exceptions not to be shortcut 0N/A // anymore. We call vm_exit_during_initialization directly instead. 0N/A // Support for ConcurrentMarkSweep. This should be cleaned up 342N/A // and better encapsulated. The ugly nested if test would go away 342N/A // once things are properly refactored. XXX YSR 0N/A // Always call even when there are not JVMTI environments yet, since environments 0N/A // may be attached late and JVMTI must track phases of VM execution 0N/A // Signal Dispatcher needs to be started before VMInit event is posted 0N/A // Start Attach Listener if +StartAttachListener or it can't be started lazily 0N/A // Launch -Xrun agents 0N/A // Must be done in the JVMTI live phase so that for backward compatibility the JDWP 0N/A // back-end can launch with -Xdebug -Xrunjdwp. 0N/A // Notify JVMTI agents that VM initialization is complete - nop if no agents. 0N/A // initialize compiler(s) 0N/A // management agent fails to start possibly due to 0N/A // configuration problem and is responsible for printing 0N/A // stack trace if appropriate. Simply exit VM. 0N/A // Start up the WatcherThread if there are any periodic tasks 0N/A // NOTE: All PeriodicTasks should be registered by now. If they 0N/A // aren't, late joiners might appear to start slowly (we might 0N/A // take a while to process their first tick). 0N/A// type for the Agent_OnLoad and JVM_OnLoad entry points 0N/A// Find a command line agent library and return its entry point for 0N/A// -agentlib: -agentpath: -Xrun 0N/A// num_symbol_entries must be passed-in since only the caller knows the number of symbols in the array. 0N/A // If we can't find the agent, exit. 0N/A // Try to load the agent from the standard dll directory 0N/A // Download instrument dll 0N/A " sun.jkernel.DownloadManager -download client_jvm";
0N/A // when this comes back the instrument.dll should be where it belongs. 0N/A // If we can't find the agent, exit. 0N/A // Find the OnLoad function. 0N/A// Find the JVM_OnLoad entry point 0N/A// Find the Agent_OnLoad entry point 0N/A// For backwards compatibility with -Xrun 0N/A// Convert libraries with no JVM_OnLoad, but which have Agent_OnLoad to be 0N/A// treated like -agentpath: 0N/A// Must be called before agent libraries are created 0N/A next =
agent->
next();
// cache the next agent now as this agent may get moved off this list 0N/A // If there is an JVM_OnLoad function it will get called later, 0N/A // otherwise see if there is an Agent_OnLoad 0N/A // switch it to the agent list -- so that Agent_OnLoad will be called, 0N/A // JVM_OnLoad won't be attempted and Agent_OnUnload will 0N/A// Create agents for -agentlib: -agentpath: and converted -Xrun 0N/A// Invokes Agent_OnLoad 0N/A// Called very early -- before JavaThreads exist 0N/A // Invoke the Agent_OnLoad function 0N/A // Send any Agent_OnUnload notifications 0N/A // Find the Agent_OnUnload function. 0N/A // Invoke the Agent_OnUnload function 0N/A// Called for after the VM is initialized for -Xrun libraries which have not been converted to agent libraries 0N/A// Invokes JVM_OnLoad 0N/A // Invoke the JVM_OnLoad function 0N/A // We could get here with a pending exception, if so clear it now. 0N/A // SystemDictionary::resolve_or_null will return null if there was 0N/A // an exception. If we cannot load the Shutdown class, just don't 0N/A // call Shutdown.shutdown() at all. This will mean the shutdown hooks 0N/A // and finalizers (if runFinalizersOnExit is set) won't be run. 0N/A // Note that if a shutdown hook was registered or runFinalizersOnExit 0N/A // was called, the Shutdown class would have already been loaded 0N/A // (Runtime.addShutdownHook and runFinalizersOnExit will load it). 0N/A// Threads::destroy_vm() is normally called from jni_DestroyJavaVM() when 0N/A// the program falls off the end of main(). Another VM exit path is through 0N/A// vm_exit() when the program calls System.exit() to return a value or when 0N/A// there is a serious error in VM. The two shutdown paths are not exactly 0N/A// the same, but they share Shutdown.shutdown() at Java level and before_exit() 0N/A// and VM_Exit op at VM level. 0N/A// Shutdown sequence: 0N/A// + Wait until we are the last non-daemon thread to execute 0N/A// <-- every thing is still working at this moment --> 0N/A// shutdown hooks, run finalizers if finalization-on-exit 0N/A// + Call before_exit(), prepare for VM exit 0N/A// > run VM level shutdown hooks (they are registered through JVM_OnExit(), 0N/A// currently the only user of this mechanism is File.deleteOnExit()) 0N/A// > stop flat profiler, StatSampler, watcher thread, CMS threads, 0N/A// post thread end and vm death events to JVMTI, 0N/A// stop signal thread 0N/A// + Call JavaThread::exit(), it will: 0N/A// > release JNI handle blocks, remove stack guard pages 0N/A// > remove this thread from Threads list 0N/A// <-- no more Java code from this thread after this point --> 0N/A// + Stop VM thread, it will bring the remaining VM to a safepoint and stop 0N/A// the compiler threads at safepoint 0N/A// <-- do not use anything that could get blocked by Safepoint --> 0N/A// + Set _vm_exited flag for threads that are still running native code 0N/A// + Delete this thread 0N/A// + Call exit_globals() 0N/A// > deletes PerfMemory resources 0N/A// + Return to caller 0N/A // Wait until we are the last non-daemon thread to execute 0N/A // This wait should make safepoint checks, wait without a timeout, 0N/A // and wait as a suspend-equivalent condition. 0N/A // Note: If the FlatProfiler is running and this thread is waiting 0N/A // for another non-daemon thread to finish, then the FlatProfiler 0N/A // is waiting for the external suspend request on this thread to 0N/A // complete. wait_for_ext_suspend_completion() will eventually 0N/A // timeout, but that takes time. Making this wait a suspend- 0N/A // equivalent condition solves that timeout problem. 0N/A // Hang forever on exit if we are reporting an error. 0N/A // We are the last thread running, so check if finalizers should be run. 0N/A // For 1.3 or later this is done in thread->invoke_shutdown_hooks() 0N/A // run Java level shutdown hooks 0N/A // 4945125 The vm thread comes to a safepoint during exit. 0N/A // GC vm_operations can get caught at the safepoint, and the 0N/A // heap is unparseable if they are caught. Grab the Heap_lock 0N/A // to prevent this. The GC vm_operations will not be able to 0N/A // queue until after the vm thread is dead. 0N/A // clean up ideal graph printers 0N/A // Now, all Java threads are gone except daemon threads. Daemon threads 0N/A // running Java code or in VM are stopped by the Safepoint. However, 0N/A // daemon threads executing native code are still running. But they 0N/A // will be stopped at native=>Java/VM barriers. Note that we can't 0N/A // simply kill or suspend them, as it is inherently deadlock-prone. 0N/A // disable function tracing at JNI/JVM barriers 0N/A // exit_globals() will delete tty 0N/A // The threads lock must be owned at this point 0N/A // Bootstrapping problem: threadObj can be null for initial 0N/A // JavaThread (or for threads attached via JNI) 0N/A // Possible GC point. 0N/A // Extra scope needed for Thread_lock, so we can check 0N/A // that we do not remove thread without safepoint code notice 0N/A // Only one thread left, do a notify on the Threads_lock so a thread waiting 0N/A // on destroy_vm will wake up. 0N/A // Make sure that safepoint code disregard this thread. This is needed since 0N/A // the thread might mess around with locks after this point. This can cause it 0N/A // to do callbacks into the safepoint code. However, the safepoint code is not aware 0N/A // of this thread since it is removed from the queue. 0N/A }
// unlock Threads_lock 0N/A // Since Events::log uses a lock, we grab it outside the Threads_lock 0N/A// Threads_lock must be held when this is called (or must be called during a safepoint) 0N/A// Operations on the Threads list for GC. These are not explicitly locked, 0N/A// but the garbage collector must provide a safe context for them to run. 0N/A// In particular, these things should never be called when the Threads_lock 0N/A// is held by some other thread. (Note: the Safepoint abstraction also 0N/A// uses the Threads_lock to gurantee this property. It also makes sure that 0N/A// all threads gets blocked when exiting or starting). 0N/A // Introduce a mechanism allowing parallel threads to claim threads as 0N/A // root groups. Overhead should be small enough to use all the time, 0N/A // even in sequential code. 0N/A// Used by ParallelScavenge 0N/A// Used by Parallel Old 0N/A// Get count Java threads that are waiting to enter the specified monitor. 0N/A "must grab Threads_lock or be at safepoint");
0N/A "must grab Threads_lock or be at safepoint");
0N/A // NULL owner means not locked so we can skip the search 0N/A // first, see if owner is the address of a Java thread 0N/A // If we didn't find a matching Java thread and we didn't force use of 0N/A // heavyweight monitors, then the owner is the stack address of the 0N/A // Lock Word in the owning Java thread's stack. 0N/A// Threads::print_on() is called at safepoint by VM_PrintThreads operation. 0N/A // Dump concurrent locks 0N/A// Threads::print_on_error() is called by fatal error handler. It's possible 0N/A// that VM is not at safepoint and/or current thread is inside signal handler. 0N/A// Don't print stack trace, as the stack may not be walkable. Don't allocate 0N/A// memory (even in resource area), it might deadlock the error handler. 0N/A// Lifecycle management for TSM ParkEvents. 0N/A// ParkEvents are type-stable (TSM). 0N/A// In our particular implementation they happen to be immortal. 0N/A// We manage concurrency on the FreeList with a CAS-based 0N/A// detach-modify-reattach idiom that avoids the ABA problems 0N/A// that would otherwise be present in a simple CAS-based 0N/A// push-pop implementation. (push-one and pop-all) 0N/A// Caveat: Allocate() and Release() may be called from threads 0N/A// other than the thread associated with the Event! 0N/A// If we need to call Allocate() when running as the thread in 0N/A// question then look for the PD calls to initialize native TLS. 0N/A// accessed by the associated thread. 0N/A// See also pd_initialize(). 0N/A// Note that we could defer associating a ParkEvent with a thread 0N/A// until the 1st time the thread calls park(). unpark() calls to 0N/A// an unprovisioned thread would be ignored. The first park() call 0N/A// for a thread would allocate and associate a ParkEvent and return 0N/A // In rare cases -- JVM_RawMonitor* operations -- we can find t == null. 0N/A // Start by trying to recycle an existing but unassociated 0N/A // ParkEvent from the global free list. 0N/A // 1: Detach - sequester or privatize the list 0N/A // Tantamount to ev = Swap (&FreeList, NULL) 0N/A // We've detached the list. The list in-hand is now 0N/A // local to this thread. This thread can operate on the 0N/A // list without risk of interference from other threads. 0N/A // 2: Extract -- pop the 1st element from the list. 0N/A // 3: Try to reattach the residual list 0N/A // New nodes arrived. Try to detach the recent arrivals. 0N/A // 4: Merge Arv into List 0N/A // Do this the hard way -- materialize a new ParkEvent. 0N/A // In rare cases an allocating thread might detach a long list -- 0N/A // installing null into FreeList -- and then stall or be obstructed. 0N/A // A 2nd thread calling Allocate() would see FreeList == null. 0N/A // The list held privately by the 1st thread is unavailable to the 2nd thread. 0N/A // In that case the 2nd thread would have to materialize a new ParkEvent, 0N/A // even though free ParkEvents existed in the system. In this case we end up 0N/A // with more ParkEvents in circulation than we need, but the race is 0N/A // rare and the outcome is benign. Ideally, the # of extant ParkEvents 0N/A // is equal to the maximum # of threads that existed at any one time. 0N/A // Because of the race mentioned above, segments of the freelist 0N/A // can be transiently inaccessible. At worst we may end up with the 0N/A // # of ParkEvents in circulation slightly above the ideal. 0N/A // when reattaching, above, we could trim the list. 0N/A // Push ev onto FreeList 0N/A // The mechanism is "half" lock-free. 0N/A// Override operator new and delete so we can ensure that the 0N/A// least significant byte of ParkEvent addresses is 0. 0N/A// Beware that excessive address alignment is undesirable 0N/A// as it can result in D$ index usage imbalance as 0N/A// well as bank access imbalance on Niagara-like platforms, 0N/A// although Niagara's hash function should help. 0N/A // ParkEvents are type-stable and immortal ... 0N/A// 6399321 As a temporary measure we copied & modified the ParkEvent:: 0N/A// allocate() and release() code for use by Parkers. The Parker:: forms 0N/A// will eventually be removed as we consolide and shift over to ParkEvents 0N/A// for both builtin synchronization and JSR166 operations. 0N/A // Start by trying to recycle an existing but unassociated 0N/A // Parker from the global free list. 0N/A // Tantamount to p = Swap (&FreeList, NULL) 0N/A // We've detached the list. The list in-hand is now 0N/A // local to this thread. This thread can operate on the 0N/A // list without risk of interference from other threads. 0N/A // 2: Extract -- pop the 1st element from the list. 0N/A // 3: Try to reattach the residual list 0N/A // New nodes arrived. Try to detach the recent arrivals. 0N/A // 4: Merge Arv into List 0N/A // Do this the hard way -- materialize a new Parker.. 0N/A // In rare cases an allocating thread might detach 0N/A // a long list -- installing null into FreeList --and 0N/A // then stall. Another thread calling Allocate() would see 0N/A // FreeList == null and then invoke the ctor. In this case we 0N/A // end up with more Parkers in circulation than we need, but 0N/A // the race is rare and the outcome is benign. 0N/A // Ideally, the # of extant Parkers is equal to the 0N/A // maximum # of threads that existed at any one time. 0N/A // Because of the race mentioned above, segments of the 0N/A // freelist can be transiently inaccessible. At worst 0N/A // we may end up with the # of Parkers in circulation 0N/A // slightly above the ideal. 0N/A // Push p onto FreeList