thread.hpp revision 1881
1703N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// - ConcurrentGCThread 0N/A // Exception handling 0N/A // (Note: _pending_exception and friends are in ThreadShadow) 0N/A //oop _pending_exception; // pending exception for current thread 0N/A // const char* _exception_file; // file information for exception (debugging only) 0N/A // int _exception_line; // line information for exception (debugging only) 0N/A // Support for forcing alignment of thread objects for biased locking 0N/A void operator delete(
void* p);
0N/A // *************************************************************** 0N/A // Suspend and resume support 0N/A // *************************************************************** 0N/A // things including safepoints but was deprecated and finally removed 0N/A // in Java 7. Because VM suspension was considered "internal" Java-level 0N/A // suspension was considered "external", and this legacy naming scheme 0N/A // JVM_ResumeThread, JVMTI SuspendThread, and finally JVMTI 0N/A // ResumeThread. External 0N/A // suspend requests cause _external_suspend to be set and external 0N/A // resume requests cause _external_suspend to be cleared. 0N/A // External suspend requests do not nest on top of other external 0N/A // suspend requests. The higher level APIs reject suspend requests 0N/A // for already suspended threads. 0N/A // The external_suspend 0N/A // flag is checked by has_special_runtime_exit_condition() and java thread 0N/A // will self-suspend when handle_special_runtime_exit_condition() is 0N/A // called. Most uses of the _thread_blocked state in JavaThreads are 0N/A // considered the same as being externally suspended; if the blocking 0N/A // condition lifts, the JavaThread will self-suspend. Other places 0N/A // where VM checks for external_suspend include: 0N/A // + mutex granting (do not enter monitors when thread is suspended) 0N/A // + state transitions from _thread_in_native 0N/A // In general, java_suspend() does not wait for an external suspend 0N/A // request to complete. When it returns, the only guarantee is that 0N/A // the _external_suspend field is true. 0N/A // wait_for_ext_suspend_completion() is used to wait for an external 0N/A // suspend request to complete. External suspend requests are usually 0N/A // followed by some other interface call that requires the thread to 0N/A // be quiescent, e.g., GetCallTrace(). By moving the "wait time" into 0N/A // the interface that requires quiescence, we give the JavaThread a 0N/A // chance to self-suspend before we need it to be quiescent. This 0N/A // It must be set under the protection of SR_lock. Read from the flag is 0N/A // OK without SR_lock as long as the value is only used as a hint. 0N/A // (e.g., check _external_suspend first without lock and then recheck 0N/A // inside SR_lock and finish the suspension) 0N/A // _suspend_flags is also overloaded for other "special conditions" so 0N/A // that a single check indicates whether any special action is needed 0N/A // eg. for async exceptions. 0N/A // ------------------------------------------------------------------- 0N/A // but we still update its value to keep other part of the system (mainly 0N/A // JVMTI) happy. ThreadState is legacy code (see notes in // 2. It would be more natural if set_external_suspend() is private and // part of java_suspend(), but that probably would affect the suspend/query // performance. Need more investigation on this. // NOTE: avoid using the sign-bit as cc generates different test code // when the sign-bit is used, and sometimes incorrectly - see CR 6398077 _deopt_suspend =
0x10000000U,
// thread needs to self suspend for deopt // various suspension related flags - atomically updated // overloaded for async exception checking in check_special_condition_for_native_trans. // Active_handles points to a block of handles // One-element thread local free list // Point to the last handle mark // The parity of the last strong_roots iteration in which this thread was // debug support for checking if code does allow safepoints or not // GC points in the VM can happen because of allocation, invoking a VM operation, or blocking on // mutex, or blocking on an object synchronizer (Java locking). // If !allow_safepoint(), then an assertion failure will happen in any of the above cases // If !allow_allocation(), then an assertion failure will happen during allocation // (Hence, !allow_safepoint() => !allow_allocation()). // The two classes No_Safepoint_Verifier and No_Allocation_Verifier are used to set these counters. // Used by SkipGCALot class. // Record when GC is locked out via the GC_locker mechanism // ObjectMonitor on which this thread called Object.wait() // Private thread-local objectmonitor list - a simple cache organized as a SLL. // Remove this ifdef when C1 is ported to the compiler interface. // True iff the thread can perform GC operations at a safepoint. // Generally will be true only of VM thread and parallel GC WorkGang virtual char*
name()
const {
return (
char*)
"Unknown thread"; }
// Returns the current thread // Common thread operations // Support for Unhandled Oop detection // Mark oop safe for gc. It may be stack allocated but won't move. // Clear oops at safepoint so crashes point to unhandled oop violator #
endif // CHECK_UNHANDLED_OOPS // Installs a pending exception to be inserted later // Internal handle support // Thread-Local Allocation Buffer (TLAB) support // For tracking the heavyweight monitor the thread is pending on. // For tracking the ObjectMonitor on which this thread called Object.wait() // Apply "f->do_oop" to all root oops in "this". // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames // Handles the parallel case for the method below. // Requires that "collection_parity" is that of the current strong roots // iteration. If "is_par" is false, sets the parity of "this" to // "collection_parity", and returns "true". If "is_par" is true, // uses an atomic instruction to set the current threads parity to // "collection_parity", if it is not already. Returns "true" iff the // calling thread does the update, this indicates that the calling thread // has claimed the thread's stack as a root groop in the current // Used by fast lock support // Check if address is in the stack of the thread (not just for locks). // Warning: the method can only be used on the running thread // Sets this thread as starting thread. Returns failure if thread // creation fails due to lack of memory, too many threads etc. // OS data associated with the thread // Thread local resource area for temporary allocation within the VM // Thread local handle area for allocation of handles within the VM // Support for stack overflow handling, get_thread, etc. // Stack overflow support /* QQQ this has knowledge of direction, ought to be a stack method */ // Deadlock detection support for Mutex locks. List of locks own by thread. // Mutex::set_owner_implementation is the only place where _owned_locks is modified, volatile int _OnTrap ;
// Resume-at IP delta volatile jint rng [
4] ;
// RNG for spin loop // Low-level leaf-lock primitives used to implement synchronization // and native monitor-mutex infrastructure. // Not for general synchronization use. // Inline implementation of Thread::current() // Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of // ThreadLocalStorage::thread is warm -- it's called > 16K times in the same // period. This is inlined in thread_<os_family>.inline.hpp. // This function is very high traffic. Define PARANOID to enable expensive // Signal handler should call ThreadLocalStorage::get_thread_slow() "Don't use Thread::current() inside signal handler");
// Name support for threads. non-JavaThread subclasses with multiple // uniquely named instances should derive from this. // log JavaThread being processed by oops_do // May only be called once per thread. // Worker threads are named and have an id of an assigned work. // A single WatcherThread is used for simulating timer interrupts. char*
name()
const {
return (
char*)
"VM Periodic Task Thread"; }
// Returns the single instance of WatcherThread // Create and start the single instance of WatcherThread, or stop it on shutdown private:
// restore original namespace restriction private:
// restore original namespace restriction // transition out of native // Because deoptimization is lazy we must save jvmti requests to set locals // in compiled frames until we deoptimize and we have an interpreter frame. // This holds the pointer to array (yeah like there might be more than one) of // description of compiled vframes that have locals that need to be updated. // Handshake value for fixing 6243940. We need a place for the i2c // adapter to store the callee methodOop. This value is NEVER live // across a gc point so it does NOT have to be gc'd // The handshake is open ended since we can't be certain that it will // be NULLed. This is because we rarely ever see the race and end up // in handle_wrong_method which is the backend of the handshake. See // code in i2c adapters and handle_wrong_method. // Oop results of VM runtime calls oop _vm_result;
// Used to pass back an oop result into Java code, GC-preserved oop _vm_result_2;
// Used to pass back an oop result into Java code, GC-preserved // See ReduceInitialCardMarks: this holds the precise space interval of // the most recent slow path allocation for which compiled code has // elided card-marks for performance along the fast-path. // allocated during deoptimization // Async. requests support public:
// Expose _thread_state for SafeFetchInt() // JavaThread termination support _vm_exited // JavaThread is still executing native code, but VM is terminated // only VM_Exit can set _vm_exited // In general a JavaThread's _terminated field transitions as follows: // _not_terminated => _thread_exiting => _thread_terminated // _vm_exited is a special value to cover the case of a JavaThread // executing native code after the VM itself is terminated. // never locked) when throwing an exception. Used by interpreter only. // Flag to mark a JNI thread in the process of attaching - See CR 6404306 // This flag is never set true other than at construction, and in that case // is shortly thereafter set false // State of the stack guard pages for this thread. // Compiler exception handling (NOTE: The _exception_oop is *NOT* the same as _pending_exception. It is // used to temp. parsing values into and out of the runtime system during exception handling for compiled // support for compilation bool _is_compiling;
// is true if a compilation is active inthis thread (one compilation per thread possible) // support for JNI critical regions // For deadlock detection. // JVMTI PopFrame support // This is set to popframe_pending to signal that top Java frame should be popped immediately // We use intptr_t instead of address so debugger doesn't try and display strings // Support for G1 barriers // Set of all such queues. // Set of all such queues. void initialize();
// Initialized the instance variables // verify this JavaThread hasn't be published in the Threads::list yet //JNI functiontable getter/setter for JVMTI jni function table interception API. // This function is called at thread creation to allow // platform specific thread variables to be initialized. // Cleanup on thread exit // Thread chain operations // Thread oop. threadObj() can be NULL for initial JavaThread // (or for threads attached via JNI) // Prepare thread and add to priority queue. If a priority is // not specified, use the priority of the thread object. Threads_lock // must be held while this function is called. // Allocates a new Java level thread object for this thread. thread_name may be NULL. // Last frame anchor routines // thread has called JavaThread::exit() or is terminated // thread is terminated (no longer on the threads list); we compare // against the two non-terminated values so that a freed JavaThread // will also be considered terminated. // special for Threads::remove() which is static: // were we externally suspended while we were waiting? // don't surprise the thread that suspended us by returning // Check for async exception in addition to safepoint and suspend request. // Warning: is_ext_suspend_completed() may temporarily drop the // SR_lock to allow the thread to reach a stable thread state if // it is currently in a transient thread state. // We cannot allow wait_for_ext_suspend_completion() to run forever or // we could hang. SuspendRetryCount and SuspendRetryDelay are normally // passed as the count and delay parameters. Experiments with specific // calls to wait_for_ext_suspend_completion() can be done by passing // other values in the code. Experiments with all calls can be done // via the appropriate -XX options. // Whenever a thread transitions from native to vm/java it must suspend // if external|deopt suspend is present. // external suspend request is completed // Special method to handle a pending external suspend request // when a suspend equivalent condition lifts. "should only be called in a suspend equivalence condition");
// not about to self-suspend so clear suspend equivalence // We have a pending external suspend request so we leave the // suspend_equivalent flag set until java_suspend_self() sets // the ext_suspended flag and clears the suspend_equivalent // flag. This insures that wait_for_ext_suspend_completion() // will return consistent values. // utility methods to see if we are doing some kind of suspension // Are any async conditions present? // these next two are also used for self-suspension and async exception support // Return true if JavaThread has an asynchronous condition or // if external suspension is requested. // We call is_external_suspend() last since external suspend should // be less common. Because we don't use is_external_suspend_with_lock // it is possible that we won't see an asynchronous external suspend // request that has just gotten started, i.e., SR_lock grabbed but // _external_suspend field change either not made yet or not visible // yet. However, this is okay because the request is asynchronous and // we will see the new flag value the next time through. It's also // possible that the external suspend request is dropped after // we have checked is_external_suspend(), we will recheck its value // under SR_lock in java_suspend_self(). // Accessors for vframe array top // The linked list of vframe arrays are sorted on sp. This means when we // unpack the head must contain the vframe array to unpack. // Side structure for defering update of java frame locals until deopt occurs // These only really exist to make debugging deopt problems simpler // The special resourceMark used during deoptimization // Oop results of vm runtime calls // Exception handling for compiled methods // Stack overflow support // Attempt to reguard the stack after a stack overflow may have occurred. // Returns true if (a) guard pages are not needed on this thread, (b) the // pages are already guarded, or (c) the pages were successfully reguarded. // Returns false if there is not enough stack space to reguard the pages, in // which case the caller should unwind a frame and try again. The argument // should be the caller's (approximate) sp. // Similar to above but see if current stackpoint is out of the guard area // and reguard if possible. // For assembly stub generation // Returns the jni environment for this thread // Only return NULL if thread is off the thread list; starting to // exit should not return NULL. // JNI critical regions. These can nest. "this must be current thread");
"this must be current thread");
"JNI critical nesting problem?"); }
// For deadlock detection // Frame iteration; calls the function f for all frames on the stack // Memory management operations // factor out low-level mechanics for use in both normal and error cases // Returns method at 'depth' java or native frames down the stack // Used for security checks // Print stack trace in external format // Print stack traces in various internal formats // Returns the number of stack frames on the stack // Function for testing deoptimization friend class FlatProfiler;
// uses both [gs]et_thread_profiler. // Returns the running thread as a JavaThread // Returns the active Java thread. Do not use this if you know you are calling // from a JavaThread, as it's slower than JavaThread::current. If called from // the VMThread, it also returns the JavaThread that instigated the VMThread's // operation. You may not want that either. // Returns the privileged_stack information. // Thread local information maintained by JVMTI. // A JvmtiThreadState is lazily allocated. This jvmti_thread_state() // getter is used to get this JavaThread's JvmtiThreadState if it has // one which means NULL can be returned. JvmtiThreadState::state_for() // is used to get the specified JavaThread's JvmtiThreadState if it has // one or it allocates a new JvmtiThreadState for the JavaThread and // returns it. JvmtiThreadState::state_for() will return NULL only if // the specified JavaThread is exiting. // JVMTI PopFrame support // Setting and clearing popframe_condition // All of these enumerated values are bits. popframe_pending // indicates that a PopFrame() has been requested and not yet been // completed. popframe_processing indicates that that PopFrame() is in // the process of being completed. popframe_force_deopt_reexecution_bit // indicates that special handling is required when returning to a // Saved incoming arguments to popped frame. // Used only when popped interpreted frame returns to deoptimized frame. // Used by the interpreter in fullspeed mode for frame pop, method // entry, method exit and single stepping support. This field is // only set to non-zero by the VM_EnterInterpOnlyMode VM operation. // It can be set to zero asynchronously (i.e., without a VM operation // or a lock) so we have to be very careful. // used by the interpreter for fullspeed debugging support (see above) // support for cached flag that indicates whether exceptions need to be posted for this thread // if this is false, we can avoid deoptimizing when events are thrown // this gets set to reflect whether jvmtiExport::post_exception_throw would actually do anything // Return a blocker object for which this thread is blocked parking. // SATB marking queue support // Dirty card queue support // This method initializes the SATB and dirty card queues before a // JavaThread is added to the Java thread list. Right now, we don't // have to do anything to the dirty card queue (it should have been // activated when the thread was created), but we have to activate // the SATB queue if the thread is created while a marking cycle is // in progress. The activation / de-activation of the SATB queues at // the beginning / end of a marking cycle is done during safepoints // so we have to make sure this method is called outside one to be // able to safely read the active field of the SATB queue set. Right // now, it is called just before the thread is added to the Java // thread list in the Threads::add() method. That method is holding // the Threads_lock which ensures we are outside a safepoint. We // cannot do the obvious and set the active field of the SATB queue // when the thread is created given that, in some cases, safepoints // might happen between the JavaThread constructor being called and the // thread being added to the Java thread list (an example of this is // when the structure for the DestroyJavaVM thread is created). // Machine dependent stuff // JSR166 per-thread parker // Biased locking support // This field is used to determine if a thread has claimed // a par_id: it is -1 if the thread has not claimed a par_id; // otherwise its value is the par_id that has been claimed. // Inline implementation of JavaThread::current // This code assumes java stacks grow down // A JavaThread for low memory detection support // Hide this thread from external view. // A thread used for Compilation. // Hide this compiler thread from external view. // Get/set the thread's compilation environment. // Get/set the thread's logging information // Get/set the thread's current task // The active thread queue. It also keeps track of the current used // force_daemon is a concession to JNI, where we may need to add a // thread to the thread list before allocating its thread object // Initializes the vm and creates the vm thread // Supported VM versions via JNI // Includes JNI_VERSION_1_1 // Does not include JNI_VERSION_1_1 // Apply "f->do_oop" to all root oops in all threads. // This version may only be called by sequential code. // This version may be called by sequential or parallel code. // This creates a list of GCTasks, one per thread. // This creates a list of GCTasks, one per thread, for marking objects. // Apply "f->do_oop" to roots in all threads that // are part of compiled frames // Get Java threads that are waiting to enter a monitor. If doLock // is true, then Threads_lock is grabbed as needed. Otherwise, the // VM needs to be at a safepoint. // Get owning Java thread from the monitor's owner field. If doLock // is true, then Threads_lock is grabbed as needed. Otherwise, the // VM needs to be at a safepoint. // Number of threads on the active threads list // Number of non-daemon threads on the active threads list // Deoptimizes all frames tied to marked nmethods #
endif // SHARE_VM_RUNTIME_THREAD_HPP