thread.hpp revision 0
0N/A/*
0N/A * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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 *
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 *
0N/A */
0N/A
0N/Aclass ThreadSafepointState;
0N/Aclass ThreadProfiler;
0N/A
0N/Aclass JvmtiThreadState;
0N/Aclass JvmtiGetLoadedClassesClosure;
0N/Aclass ThreadStatistics;
0N/Aclass ConcurrentLocksDump;
0N/Aclass ParkEvent ;
0N/A
0N/Aclass ciEnv;
0N/Aclass CompileThread;
0N/Aclass CompileLog;
0N/Aclass CompileTask;
0N/Aclass CompileQueue;
0N/Aclass CompilerCounters;
0N/Aclass vframeArray;
0N/A
0N/Aclass DeoptResourceMark;
0N/Aclass jvmtiDeferredLocalVariableSet;
0N/A
0N/Aclass GCTaskQueue;
0N/Aclass ThreadClosure;
0N/Aclass IdealGraphPrinter;
0N/A
0N/A// Class hierarchy
0N/A// - Thread
0N/A// - VMThread
0N/A// - JavaThread
0N/A// - WatcherThread
0N/A
0N/Aclass Thread: public ThreadShadow {
0N/A friend class VMStructs;
0N/A private:
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
0N/A // Support for forcing alignment of thread objects for biased locking
0N/A void* _real_malloc_address;
0N/A public:
0N/A void* operator new(size_t size);
0N/A void operator delete(void* p);
0N/A private:
0N/A
0N/A // ***************************************************************
0N/A // Suspend and resume support
0N/A // ***************************************************************
0N/A //
0N/A // VM suspend/resume no longer exists - it was once used for various
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 // remains.
0N/A //
0N/A // External suspend/resume requests come from JVM_SuspendThread,
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 //
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 //
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 //
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 // improves overall suspend/query performance.
0N/A //
0N/A // _suspend_flags controls the behavior of java_ suspend/resume.
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 //
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 // Notes:
0N/A // 1. The suspend/resume logic no longer uses ThreadState in OSThread
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
0N/A // osThread.hpp).
0N/A //
0N/A // 2. It would be more natural if set_external_suspend() is private and
0N/A // part of java_suspend(), but that probably would affect the suspend/query
0N/A // performance. Need more investigation on this.
0N/A //
0N/A
0N/A // suspend/resume lock: used for self-suspend
0N/A Monitor* _SR_lock;
0N/A
0N/A protected:
0N/A enum SuspendFlags {
0N/A // NOTE: avoid using the sign-bit as cc generates different test code
0N/A // when the sign-bit is used, and sometimes incorrectly - see CR 6398077
0N/A
0N/A _external_suspend = 0x20000000U, // thread is asked to self suspend
0N/A _ext_suspended = 0x40000000U, // thread has self-suspended
0N/A _deopt_suspend = 0x10000000U, // thread needs to self suspend for deopt
0N/A
0N/A _has_async_exception = 0x00000001U // there is a pending async exception
0N/A };
0N/A
0N/A // various suspension related flags - atomically updated
0N/A // overloaded for async exception checking in check_special_condition_for_native_trans.
0N/A volatile uint32_t _suspend_flags;
0N/A
0N/A private:
0N/A int _num_nested_signal;
0N/A
0N/A public:
0N/A void enter_signal_handler() { _num_nested_signal++; }
0N/A void leave_signal_handler() { _num_nested_signal--; }
0N/A bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
0N/A
0N/A private:
0N/A // Debug tracing
0N/A static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
0N/A
0N/A // Active_handles points to a block of handles
0N/A JNIHandleBlock* _active_handles;
0N/A
0N/A // One-element thread local free list
0N/A JNIHandleBlock* _free_handle_block;
0N/A
0N/A // Point to the last handle mark
0N/A HandleMark* _last_handle_mark;
0N/A
0N/A // The parity of the last strong_roots iteration in which this thread was
0N/A // claimed as a task.
0N/A jint _oops_do_parity;
0N/A
0N/A public:
0N/A void set_last_handle_mark(HandleMark* mark) { _last_handle_mark = mark; }
0N/A HandleMark* last_handle_mark() const { return _last_handle_mark; }
0N/A private:
0N/A
0N/A // debug support for checking if code does allow safepoints or not
0N/A // GC points in the VM can happen because of allocation, invoking a VM operation, or blocking on
0N/A // mutex, or blocking on an object synchronizer (Java locking).
0N/A // If !allow_safepoint(), then an assertion failure will happen in any of the above cases
0N/A // If !allow_allocation(), then an assertion failure will happen during allocation
0N/A // (Hence, !allow_safepoint() => !allow_allocation()).
0N/A //
0N/A // The two classes No_Safepoint_Verifier and No_Allocation_Verifier are used to set these counters.
0N/A //
0N/A NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen
0N/A debug_only (int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops.
0N/A
0N/A // Record when GC is locked out via the GC_locker mechanism
0N/A CHECK_UNHANDLED_OOPS_ONLY(int _gc_locked_out_count;)
0N/A
0N/A friend class No_Alloc_Verifier;
0N/A friend class No_Safepoint_Verifier;
0N/A friend class Pause_No_Safepoint_Verifier;
0N/A friend class ThreadLocalStorage;
0N/A friend class GC_locker;
0N/A
0N/A // In order for all threads to be able to use fast locking, we need to know the highest stack
0N/A // address of where a lock is on the stack (stacks normally grow towards lower addresses). This
0N/A // variable is initially set to NULL, indicating no locks are used by the thread. During the thread's
0N/A // execution, it will be set whenever locking can happen, i.e., when we call out to Java code or use
0N/A // an ObjectLocker. The value is never decreased, hence, it will over the lifetime of a thread
0N/A // approximate the real stackbase.
0N/A address _highest_lock; // Highest stack address where a JavaLock exist
0N/A
0N/A ThreadLocalAllocBuffer _tlab; // Thread-local eden
0N/A
0N/A int _vm_operation_started_count; // VM_Operation support
0N/A int _vm_operation_completed_count; // VM_Operation support
0N/A
0N/A ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
0N/A // is waiting to lock
0N/A bool _current_pending_monitor_is_from_java; // locking is from Java code
0N/A
0N/A // ObjectMonitor on which this thread called Object.wait()
0N/A ObjectMonitor* _current_waiting_monitor;
0N/A
0N/A // Private thread-local objectmonitor list - a simple cache organized as a SLL.
0N/A public:
0N/A ObjectMonitor * omFreeList ;
0N/A int omFreeCount ; // length of omFreeList
0N/A int omFreeProvision ; // reload chunk size
0N/A
0N/A public:
0N/A enum {
0N/A is_definitely_current_thread = true
0N/A };
0N/A
0N/A // Constructor
0N/A Thread();
0N/A virtual ~Thread();
0N/A
0N/A // initializtion
0N/A void initialize_thread_local_storage();
0N/A
0N/A // thread entry point
0N/A virtual void run();
0N/A
0N/A // Testers
0N/A virtual bool is_VM_thread() const { return false; }
0N/A virtual bool is_Java_thread() const { return false; }
0N/A // Remove this ifdef when C1 is ported to the compiler interface.
0N/A virtual bool is_Compiler_thread() const { return false; }
0N/A virtual bool is_hidden_from_external_view() const { return false; }
0N/A virtual bool is_jvmti_agent_thread() const { return false; }
0N/A // True iff the thread can perform GC operations at a safepoint.
0N/A // Generally will be true only of VM thread and parallel GC WorkGang
0N/A // threads.
0N/A virtual bool is_GC_task_thread() const { return false; }
0N/A virtual bool is_Watcher_thread() const { return false; }
0N/A virtual bool is_ConcurrentGC_thread() const { return false; }
0N/A
0N/A virtual char* name() const { return (char*)"Unknown thread"; }
0N/A
0N/A // Returns the current thread
0N/A static inline Thread* current();
0N/A
0N/A // Common thread operations
0N/A static void set_priority(Thread* thread, ThreadPriority priority);
0N/A static ThreadPriority get_priority(const Thread* const thread);
0N/A static void start(Thread* thread);
0N/A static void interrupt(Thread* thr);
0N/A static bool is_interrupted(Thread* thr, bool clear_interrupted);
0N/A
0N/A Monitor* SR_lock() const { return _SR_lock; }
0N/A
0N/A bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; }
0N/A
0N/A void set_suspend_flag(SuspendFlags f) {
0N/A assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
0N/A uint32_t flags;
0N/A do {
0N/A flags = _suspend_flags;
0N/A }
0N/A while (Atomic::cmpxchg((jint)(flags | f),
0N/A (volatile jint*)&_suspend_flags,
0N/A (jint)flags) != (jint)flags);
0N/A }
0N/A void clear_suspend_flag(SuspendFlags f) {
0N/A assert(sizeof(jint) == sizeof(_suspend_flags), "size mismatch");
0N/A uint32_t flags;
0N/A do {
0N/A flags = _suspend_flags;
0N/A }
0N/A while (Atomic::cmpxchg((jint)(flags & ~f),
0N/A (volatile jint*)&_suspend_flags,
0N/A (jint)flags) != (jint)flags);
0N/A }
0N/A
0N/A void set_has_async_exception() {
0N/A set_suspend_flag(_has_async_exception);
0N/A }
0N/A void clear_has_async_exception() {
0N/A clear_suspend_flag(_has_async_exception);
0N/A }
0N/A
0N/A // Support for Unhandled Oop detection
0N/A#ifdef CHECK_UNHANDLED_OOPS
0N/A private:
0N/A UnhandledOops *_unhandled_oops;
0N/A public:
0N/A UnhandledOops* unhandled_oops() { return _unhandled_oops; }
0N/A // Mark oop safe for gc. It may be stack allocated but won't move.
0N/A void allow_unhandled_oop(oop *op) {
0N/A if (CheckUnhandledOops) unhandled_oops()->allow_unhandled_oop(op);
0N/A }
0N/A // Clear oops at safepoint so crashes point to unhandled oop violator
0N/A void clear_unhandled_oops() {
0N/A if (CheckUnhandledOops) unhandled_oops()->clear_unhandled_oops();
0N/A }
0N/A bool is_gc_locked_out() { return _gc_locked_out_count > 0; }
0N/A#endif // CHECK_UNHANDLED_OOPS
0N/A
0N/A public:
0N/A // Installs a pending exception to be inserted later
0N/A static void send_async_exception(oop thread_oop, oop java_throwable);
0N/A
0N/A // Resource area
0N/A ResourceArea* resource_area() const { return _resource_area; }
0N/A void set_resource_area(ResourceArea* area) { _resource_area = area; }
0N/A
0N/A OSThread* osthread() const { return _osthread; }
0N/A void set_osthread(OSThread* thread) { _osthread = thread; }
0N/A
0N/A // JNI handle support
0N/A JNIHandleBlock* active_handles() const { return _active_handles; }
0N/A void set_active_handles(JNIHandleBlock* block) { _active_handles = block; }
0N/A JNIHandleBlock* free_handle_block() const { return _free_handle_block; }
0N/A void set_free_handle_block(JNIHandleBlock* block) { _free_handle_block = block; }
0N/A
0N/A // Internal handle support
0N/A HandleArea* handle_area() const { return _handle_area; }
0N/A void set_handle_area(HandleArea* area) { _handle_area = area; }
0N/A
0N/A // Thread-Local Allocation Buffer (TLAB) support
0N/A ThreadLocalAllocBuffer& tlab() { return _tlab; }
0N/A void initialize_tlab() {
0N/A if (UseTLAB) {
0N/A tlab().initialize();
0N/A }
0N/A }
0N/A
0N/A // VM operation support
0N/A int vm_operation_ticket() { return ++_vm_operation_started_count; }
0N/A int vm_operation_completed_count() { return _vm_operation_completed_count; }
0N/A void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
0N/A
0N/A // For tracking the heavyweight monitor the thread is pending on.
0N/A ObjectMonitor* current_pending_monitor() {
0N/A return _current_pending_monitor;
0N/A }
0N/A void set_current_pending_monitor(ObjectMonitor* monitor) {
0N/A _current_pending_monitor = monitor;
0N/A }
0N/A void set_current_pending_monitor_is_from_java(bool from_java) {
0N/A _current_pending_monitor_is_from_java = from_java;
0N/A }
0N/A bool current_pending_monitor_is_from_java() {
0N/A return _current_pending_monitor_is_from_java;
0N/A }
0N/A
0N/A // For tracking the ObjectMonitor on which this thread called Object.wait()
0N/A ObjectMonitor* current_waiting_monitor() {
0N/A return _current_waiting_monitor;
0N/A }
0N/A void set_current_waiting_monitor(ObjectMonitor* monitor) {
0N/A _current_waiting_monitor = monitor;
0N/A }
0N/A
0N/A // GC support
0N/A // Apply "f->do_oop" to all root oops in "this".
0N/A void oops_do(OopClosure* f);
0N/A
0N/A // Handles the parallel case for the method below.
0N/Aprivate:
0N/A bool claim_oops_do_par_case(int collection_parity);
0N/Apublic:
0N/A // Requires that "collection_parity" is that of the current strong roots
0N/A // iteration. If "is_par" is false, sets the parity of "this" to
0N/A // "collection_parity", and returns "true". If "is_par" is true,
0N/A // uses an atomic instruction to set the current threads parity to
0N/A // "collection_parity", if it is not already. Returns "true" iff the
0N/A // calling thread does the update, this indicates that the calling thread
0N/A // has claimed the thread's stack as a root groop in the current
0N/A // collection.
0N/A bool claim_oops_do(bool is_par, int collection_parity) {
0N/A if (!is_par) {
0N/A _oops_do_parity = collection_parity;
0N/A return true;
0N/A } else {
0N/A return claim_oops_do_par_case(collection_parity);
0N/A }
0N/A }
0N/A
0N/A // Sweeper support
0N/A void nmethods_do();
0N/A
0N/A // Fast-locking support
0N/A address highest_lock() const { return _highest_lock; }
0N/A void update_highest_lock(address base) { if (base > _highest_lock) _highest_lock = base; }
0N/A
0N/A // Tells if adr belong to this thread. This is used
0N/A // for checking if a lock is owned by the running thread.
0N/A // Warning: the method can only be used on the running thread
0N/A // Fast lock support uses these methods
0N/A virtual bool lock_is_in_stack(address adr) const;
0N/A virtual bool is_lock_owned(address adr) const;
0N/A
0N/A // Check if address is in the stack of the thread (not just for locks).
0N/A bool is_in_stack(address adr) const;
0N/A
0N/A // Sets this thread as starting thread. Returns failure if thread
0N/A // creation fails due to lack of memory, too many threads etc.
0N/A bool set_as_starting_thread();
0N/A
0N/A protected:
0N/A // OS data associated with the thread
0N/A OSThread* _osthread; // Platform-specific thread information
0N/A
0N/A // Thread local resource area for temporary allocation within the VM
0N/A ResourceArea* _resource_area;
0N/A
0N/A // Thread local handle area for allocation of handles within the VM
0N/A HandleArea* _handle_area;
0N/A
0N/A // Support for stack overflow handling, get_thread, etc.
0N/A address _stack_base;
0N/A size_t _stack_size;
0N/A uintptr_t _self_raw_id; // used by get_thread (mutable)
0N/A int _lgrp_id;
0N/A
0N/A public:
0N/A // Stack overflow support
0N/A address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
0N/A
0N/A void set_stack_base(address base) { _stack_base = base; }
0N/A size_t stack_size() const { return _stack_size; }
0N/A void set_stack_size(size_t size) { _stack_size = size; }
0N/A void record_stack_base_and_size();
0N/A
0N/A int lgrp_id() const { return _lgrp_id; }
0N/A void set_lgrp_id(int value) { _lgrp_id = value; }
0N/A
0N/A // Printing
0N/A void print_on(outputStream* st) const;
0N/A void print() const { print_on(tty); }
0N/A virtual void print_on_error(outputStream* st, char* buf, int buflen) const;
0N/A
0N/A // Debug-only code
0N/A
0N/A#ifdef ASSERT
0N/A private:
0N/A // Deadlock detection support for Mutex locks. List of locks own by thread.
0N/A Monitor *_owned_locks;
0N/A // Mutex::set_owner_implementation is the only place where _owned_locks is modified,
0N/A // thus the friendship
0N/A friend class Mutex;
0N/A friend class Monitor;
0N/A
0N/A public:
0N/A void print_owned_locks_on(outputStream* st) const;
0N/A void print_owned_locks() const { print_owned_locks_on(tty); }
0N/A Monitor * owned_locks() const { return _owned_locks; }
0N/A bool owns_locks() const { return owned_locks() != NULL; }
0N/A bool owns_locks_but_compiled_lock() const;
0N/A
0N/A // Deadlock detection
0N/A bool allow_allocation() { return _allow_allocation_count == 0; }
0N/A#endif
0N/A
0N/A void check_for_valid_safepoint_state(bool potential_vm_operation) PRODUCT_RETURN;
0N/A
0N/A private:
0N/A volatile int _jvmti_env_iteration_count;
0N/A
0N/A public:
0N/A void entering_jvmti_env_iteration() { ++_jvmti_env_iteration_count; }
0N/A void leaving_jvmti_env_iteration() { --_jvmti_env_iteration_count; }
0N/A bool is_inside_jvmti_env_iteration() { return _jvmti_env_iteration_count > 0; }
0N/A
0N/A // Code generation
0N/A static ByteSize exception_file_offset() { return byte_offset_of(Thread, _exception_file ); }
0N/A static ByteSize exception_line_offset() { return byte_offset_of(Thread, _exception_line ); }
0N/A static ByteSize active_handles_offset() { return byte_offset_of(Thread, _active_handles ); }
0N/A
0N/A static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base ); }
0N/A static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size ); }
0N/A static ByteSize omFreeList_offset() { return byte_offset_of(Thread, omFreeList); }
0N/A
0N/A#define TLAB_FIELD_OFFSET(name) \
0N/A static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
0N/A
0N/A TLAB_FIELD_OFFSET(start)
0N/A TLAB_FIELD_OFFSET(end)
0N/A TLAB_FIELD_OFFSET(top)
0N/A TLAB_FIELD_OFFSET(pf_top)
0N/A TLAB_FIELD_OFFSET(size) // desired_size
0N/A TLAB_FIELD_OFFSET(refill_waste_limit)
0N/A TLAB_FIELD_OFFSET(number_of_refills)
0N/A TLAB_FIELD_OFFSET(fast_refill_waste)
0N/A TLAB_FIELD_OFFSET(slow_allocations)
0N/A
0N/A#undef TLAB_FIELD_OFFSET
0N/A
0N/A public:
0N/A volatile intptr_t _Stalled ;
0N/A volatile int _TypeTag ;
0N/A ParkEvent * _ParkEvent ; // for synchronized()
0N/A ParkEvent * _SleepEvent ; // for Thread.sleep
0N/A ParkEvent * _MutexEvent ; // for native internal Mutex/Monitor
0N/A ParkEvent * _MuxEvent ; // for low-level muxAcquire-muxRelease
0N/A int NativeSyncRecursion ; // diagnostic
0N/A
0N/A volatile int _OnTrap ; // Resume-at IP delta
0N/A jint _hashStateW ; // Marsaglia Shift-XOR thread-local RNG
0N/A jint _hashStateX ; // thread-specific hashCode generator state
0N/A jint _hashStateY ;
0N/A jint _hashStateZ ;
0N/A void * _schedctl ;
0N/A
0N/A intptr_t _ScratchA, _ScratchB ; // Scratch locations for fast-path sync code
0N/A static ByteSize ScratchA_offset() { return byte_offset_of(Thread, _ScratchA ); }
0N/A static ByteSize ScratchB_offset() { return byte_offset_of(Thread, _ScratchB ); }
0N/A
0N/A volatile jint rng [4] ; // RNG for spin loop
0N/A
0N/A // Low-level leaf-lock primitives used to implement synchronization
0N/A // and native monitor-mutex infrastructure.
0N/A // Not for general synchronization use.
0N/A static void SpinAcquire (volatile int * Lock, const char * Name) ;
0N/A static void SpinRelease (volatile int * Lock) ;
0N/A static void muxAcquire (volatile intptr_t * Lock, const char * Name) ;
0N/A static void muxAcquireW (volatile intptr_t * Lock, ParkEvent * ev) ;
0N/A static void muxRelease (volatile intptr_t * Lock) ;
0N/A
0N/A};
0N/A
0N/A// Inline implementation of Thread::current()
0N/A// Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of
0N/A// startup.
0N/A// ThreadLocalStorage::thread is warm -- it's called > 16K times in the same
0N/A// period. This is inlined in thread_<os_family>.inline.hpp.
0N/A
0N/Ainline Thread* Thread::current() {
0N/A#ifdef ASSERT
0N/A// This function is very high traffic. Define PARANOID to enable expensive
0N/A// asserts.
0N/A#ifdef PARANOID
0N/A // Signal handler should call ThreadLocalStorage::get_thread_slow()
0N/A Thread* t = ThreadLocalStorage::get_thread_slow();
0N/A assert(t != NULL && !t->is_inside_signal_handler(),
0N/A "Don't use Thread::current() inside signal handler");
0N/A#endif
0N/A#endif
0N/A Thread* thread = ThreadLocalStorage::thread();
0N/A assert(thread != NULL, "just checking");
0N/A return thread;
0N/A}
0N/A
0N/A// Name support for threads. non-JavaThread subclasses with multiple
0N/A// uniquely named instances should derive from this.
0N/Aclass NamedThread: public Thread {
0N/A friend class VMStructs;
0N/A enum {
0N/A max_name_len = 64
0N/A };
0N/A private:
0N/A char* _name;
0N/A public:
0N/A NamedThread();
0N/A ~NamedThread();
0N/A // May only be called once per thread.
0N/A void set_name(const char* format, ...);
0N/A virtual char* name() const { return _name == NULL ? (char*)"Unknown Thread" : _name; }
0N/A};
0N/A
0N/A// Worker threads are named and have an id of an assigned work.
0N/Aclass WorkerThread: public NamedThread {
0N/Aprivate:
0N/A uint _id;
0N/Apublic:
0N/A WorkerThread() : _id(0) { }
0N/A void set_id(uint work_id) { _id = work_id; }
0N/A uint id() const { return _id; }
0N/A};
0N/A
0N/A// A single WatcherThread is used for simulating timer interrupts.
0N/Aclass WatcherThread: public Thread {
0N/A friend class VMStructs;
0N/A public:
0N/A virtual void run();
0N/A
0N/A private:
0N/A static WatcherThread* _watcher_thread;
0N/A
0N/A static bool _should_terminate;
0N/A public:
0N/A enum SomeConstants {
0N/A delay_interval = 10 // interrupt delay in milliseconds
0N/A };
0N/A
0N/A // Constructor
0N/A WatcherThread();
0N/A
0N/A // Tester
0N/A bool is_Watcher_thread() const { return true; }
0N/A
0N/A // Printing
0N/A char* name() const { return (char*)"VM Periodic Task Thread"; }
0N/A void print_on(outputStream* st) const;
0N/A void print() const { print_on(tty); }
0N/A
0N/A // Returns the single instance of WatcherThread
0N/A static WatcherThread* watcher_thread() { return _watcher_thread; }
0N/A
0N/A // Create and start the single instance of WatcherThread, or stop it on shutdown
0N/A static void start();
0N/A static void stop();
0N/A};
0N/A
0N/A
0N/Aclass CompilerThread;
0N/A
0N/Atypedef void (*ThreadFunction)(JavaThread*, TRAPS);
0N/A
0N/Aclass JavaThread: public Thread {
0N/A friend class VMStructs;
0N/A private:
0N/A JavaThread* _next; // The next thread in the Threads list
0N/A oop _threadObj; // The Java level thread object
0N/A
0N/A#ifdef ASSERT
0N/A private:
0N/A int _java_call_counter;
0N/A
0N/A public:
0N/A int java_call_counter() { return _java_call_counter; }
0N/A void inc_java_call_counter() { _java_call_counter++; }
0N/A void dec_java_call_counter() {
0N/A assert(_java_call_counter > 0, "Invalid nesting of JavaCallWrapper");
0N/A _java_call_counter--;
0N/A }
0N/A private: // restore original namespace restriction
0N/A#endif // ifdef ASSERT
0N/A
0N/A#ifndef PRODUCT
0N/A public:
0N/A enum {
0N/A jump_ring_buffer_size = 16
0N/A };
0N/A private: // restore original namespace restriction
0N/A#endif
0N/A
0N/A JavaFrameAnchor _anchor; // Encapsulation of current java frame and it state
0N/A
0N/A ThreadFunction _entry_point;
0N/A
0N/A JNIEnv _jni_environment;
0N/A
0N/A // Deopt support
0N/A DeoptResourceMark* _deopt_mark; // Holds special ResourceMark for deoptimization
0N/A
0N/A intptr_t* _must_deopt_id; // id of frame that needs to be deopted once we
0N/A // transition out of native
0N/A
0N/A vframeArray* _vframe_array_head; // Holds the heap of the active vframeArrays
0N/A vframeArray* _vframe_array_last; // Holds last vFrameArray we popped
0N/A // Because deoptimization is lazy we must save jvmti requests to set locals
0N/A // in compiled frames until we deoptimize and we have an interpreter frame.
0N/A // This holds the pointer to array (yeah like there might be more than one) of
0N/A // description of compiled vframes that have locals that need to be updated.
0N/A GrowableArray<jvmtiDeferredLocalVariableSet*>* _deferred_locals_updates;
0N/A
0N/A // Handshake value for fixing 6243940. We need a place for the i2c
0N/A // adapter to store the callee methodOop. This value is NEVER live
0N/A // across a gc point so it does NOT have to be gc'd
0N/A // The handshake is open ended since we can't be certain that it will
0N/A // be NULLed. This is because we rarely ever see the race and end up
0N/A // in handle_wrong_method which is the backend of the handshake. See
0N/A // code in i2c adapters and handle_wrong_method.
0N/A
0N/A methodOop _callee_target;
0N/A
0N/A // Oop results of VM runtime calls
0N/A oop _vm_result; // Used to pass back an oop result into Java code, GC-preserved
0N/A oop _vm_result_2; // Used to pass back an oop result into Java code, GC-preserved
0N/A
0N/A MonitorChunk* _monitor_chunks; // Contains the off stack monitors
0N/A // allocated during deoptimization
0N/A // and by JNI_MonitorEnter/Exit
0N/A
0N/A // Async. requests support
0N/A enum AsyncRequests {
0N/A _no_async_condition = 0,
0N/A _async_exception,
0N/A _async_unsafe_access_error
0N/A };
0N/A AsyncRequests _special_runtime_exit_condition; // Enum indicating pending async. request
0N/A oop _pending_async_exception;
0N/A
0N/A // Safepoint support
0N/A public: // Expose _thread_state for SafeFetchInt()
0N/A volatile JavaThreadState _thread_state;
0N/A private:
0N/A ThreadSafepointState *_safepoint_state; // Holds information about a thread during a safepoint
0N/A address _saved_exception_pc; // Saved pc of instruction where last implicit exception happened
0N/A
0N/A // JavaThread termination support
0N/A enum TerminatedTypes {
0N/A _not_terminated = 0xDEAD - 2,
0N/A _thread_exiting, // JavaThread::exit() has been called for this thread
0N/A _thread_terminated, // JavaThread is removed from thread list
0N/A _vm_exited // JavaThread is still executing native code, but VM is terminated
0N/A // only VM_Exit can set _vm_exited
0N/A };
0N/A
0N/A // In general a JavaThread's _terminated field transitions as follows:
0N/A //
0N/A // _not_terminated => _thread_exiting => _thread_terminated
0N/A //
0N/A // _vm_exited is a special value to cover the case of a JavaThread
0N/A // executing native code after the VM itself is terminated.
0N/A TerminatedTypes _terminated;
0N/A // suspend/resume support
0N/A volatile bool _suspend_equivalent; // Suspend equivalent condition
0N/A jint _in_deopt_handler; // count of deoptimization
0N/A // handlers thread is in
0N/A volatile bool _doing_unsafe_access; // Thread may fault due to unsafe access
0N/A bool _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was
0N/A // never locked) when throwing an exception. Used by interpreter only.
0N/A
0N/A // Flag to mark a JNI thread in the process of attaching - See CR 6404306
0N/A // This flag is never set true other than at construction, and in that case
0N/A // is shortly thereafter set false
0N/A volatile bool _is_attaching;
0N/A
0N/A public:
0N/A // State of the stack guard pages for this thread.
0N/A enum StackGuardState {
0N/A stack_guard_unused, // not needed
0N/A stack_guard_yellow_disabled,// disabled (temporarily) after stack overflow
0N/A stack_guard_enabled // enabled
0N/A };
0N/A
0N/A private:
0N/A
0N/A StackGuardState _stack_guard_state;
0N/A
0N/A // Compiler exception handling (NOTE: The _exception_oop is *NOT* the same as _pending_exception. It is
0N/A // used to temp. parsing values into and out of the runtime system during exception handling for compiled
0N/A // code)
0N/A volatile oop _exception_oop; // Exception thrown in compiled code
0N/A volatile address _exception_pc; // PC where exception happened
0N/A volatile address _exception_handler_pc; // PC for handler of exception
0N/A volatile int _exception_stack_size; // Size of frame where exception happened
0N/A
0N/A // support for compilation
0N/A bool _is_compiling; // is true if a compilation is active inthis thread (one compilation per thread possible)
0N/A
0N/A // support for JNI critical regions
0N/A jint _jni_active_critical; // count of entries into JNI critical region
0N/A
0N/A // For deadlock detection.
0N/A int _depth_first_number;
0N/A
0N/A // JVMTI PopFrame support
0N/A // This is set to popframe_pending to signal that top Java frame should be popped immediately
0N/A int _popframe_condition;
0N/A
0N/A#ifndef PRODUCT
0N/A int _jmp_ring_index;
0N/A struct {
0N/A // We use intptr_t instead of address so debugger doesn't try and display strings
0N/A intptr_t _target;
0N/A intptr_t _instruction;
0N/A const char* _file;
0N/A int _line;
0N/A } _jmp_ring[ jump_ring_buffer_size ];
0N/A#endif /* PRODUCT */
0N/A
0N/A friend class VMThread;
0N/A friend class ThreadWaitTransition;
0N/A friend class VM_Exit;
0N/A
0N/A void initialize(); // Initialized the instance variables
0N/A
0N/A public:
0N/A // Constructor
0N/A JavaThread(bool is_attaching = false); // for main thread and JNI attached threads
0N/A JavaThread(ThreadFunction entry_point, size_t stack_size = 0);
0N/A ~JavaThread();
0N/A
0N/A#ifdef ASSERT
0N/A // verify this JavaThread hasn't be published in the Threads::list yet
0N/A void verify_not_published();
0N/A#endif
0N/A
0N/A //JNI functiontable getter/setter for JVMTI jni function table interception API.
0N/A void set_jni_functions(struct JNINativeInterface_* functionTable) {
0N/A _jni_environment.functions = functionTable;
0N/A }
0N/A struct JNINativeInterface_* get_jni_functions() {
0N/A return (struct JNINativeInterface_ *)_jni_environment.functions;
0N/A }
0N/A
0N/A // Executes Shutdown.shutdown()
0N/A void invoke_shutdown_hooks();
0N/A
0N/A // Cleanup on thread exit
0N/A enum ExitType {
0N/A normal_exit,
0N/A jni_detach
0N/A };
0N/A void exit(bool destroy_vm, ExitType exit_type = normal_exit);
0N/A
0N/A void cleanup_failed_attach_current_thread();
0N/A
0N/A // Testers
0N/A virtual bool is_Java_thread() const { return true; }
0N/A
0N/A // compilation
0N/A void set_is_compiling(bool f) { _is_compiling = f; }
0N/A bool is_compiling() const { return _is_compiling; }
0N/A
0N/A // Thread chain operations
0N/A JavaThread* next() const { return _next; }
0N/A void set_next(JavaThread* p) { _next = p; }
0N/A
0N/A // Thread oop. threadObj() can be NULL for initial JavaThread
0N/A // (or for threads attached via JNI)
0N/A oop threadObj() const { return _threadObj; }
0N/A void set_threadObj(oop p) { _threadObj = p; }
0N/A
0N/A ThreadPriority java_priority() const; // Read from threadObj()
0N/A
0N/A // Prepare thread and add to priority queue. If a priority is
0N/A // not specified, use the priority of the thread object. Threads_lock
0N/A // must be held while this function is called.
0N/A void prepare(jobject jni_thread, ThreadPriority prio=NoPriority);
0N/A
0N/A void set_saved_exception_pc(address pc) { _saved_exception_pc = pc; }
0N/A address saved_exception_pc() { return _saved_exception_pc; }
0N/A
0N/A
0N/A ThreadFunction entry_point() const { return _entry_point; }
0N/A
0N/A // Allocates a new Java level thread object for this thread. thread_name may be NULL.
0N/A void allocate_threadObj(Handle thread_group, char* thread_name, bool daemon, TRAPS);
0N/A
0N/A // Last frame anchor routines
0N/A
0N/A JavaFrameAnchor* frame_anchor(void) { return &_anchor; }
0N/A
0N/A // last_Java_sp
0N/A bool has_last_Java_frame() const { return _anchor.has_last_Java_frame(); }
0N/A intptr_t* last_Java_sp() const { return _anchor.last_Java_sp(); }
0N/A
0N/A // last_Java_pc
0N/A
0N/A address last_Java_pc(void) { return _anchor.last_Java_pc(); }
0N/A
0N/A // Safepoint support
0N/A JavaThreadState thread_state() const { return _thread_state; }
0N/A void set_thread_state(JavaThreadState s) { _thread_state=s; }
0N/A ThreadSafepointState *safepoint_state() const { return _safepoint_state; }
0N/A void set_safepoint_state(ThreadSafepointState *state) { _safepoint_state = state; }
0N/A bool is_at_poll_safepoint() { return _safepoint_state->is_at_poll_safepoint(); }
0N/A
0N/A // thread has called JavaThread::exit() or is terminated
0N/A bool is_exiting() { return _terminated == _thread_exiting || is_terminated(); }
0N/A // thread is terminated (no longer on the threads list); we compare
0N/A // against the two non-terminated values so that a freed JavaThread
0N/A // will also be considered terminated.
0N/A bool is_terminated() { return _terminated != _not_terminated && _terminated != _thread_exiting; }
0N/A void set_terminated(TerminatedTypes t) { _terminated = t; }
0N/A // special for Threads::remove() which is static:
0N/A void set_terminated_value() { _terminated = _thread_terminated; }
0N/A void block_if_vm_exited();
0N/A
0N/A bool doing_unsafe_access() { return _doing_unsafe_access; }
0N/A void set_doing_unsafe_access(bool val) { _doing_unsafe_access = val; }
0N/A
0N/A bool do_not_unlock_if_synchronized() { return _do_not_unlock_if_synchronized; }
0N/A void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; }
0N/A
0N/A
0N/A // Suspend/resume support for JavaThread
0N/A
0N/A private:
0N/A void set_ext_suspended() { set_suspend_flag (_ext_suspended); }
0N/A void clear_ext_suspended() { clear_suspend_flag(_ext_suspended); }
0N/A
0N/A public:
0N/A void java_suspend();
0N/A void java_resume();
0N/A int java_suspend_self();
0N/A
0N/A void check_and_wait_while_suspended() {
0N/A assert(JavaThread::current() == this, "sanity check");
0N/A
0N/A bool do_self_suspend;
0N/A do {
0N/A // were we externally suspended while we were waiting?
0N/A do_self_suspend = handle_special_suspend_equivalent_condition();
0N/A if (do_self_suspend) {
0N/A // don't surprise the thread that suspended us by returning
0N/A java_suspend_self();
0N/A set_suspend_equivalent();
0N/A }
0N/A } while (do_self_suspend);
0N/A }
0N/A static void check_safepoint_and_suspend_for_native_trans(JavaThread *thread);
0N/A // Check for async exception in addition to safepoint and suspend request.
0N/A static void check_special_condition_for_native_trans(JavaThread *thread);
0N/A
0N/A bool is_ext_suspend_completed(bool called_by_wait, int delay, uint32_t *bits);
0N/A bool is_ext_suspend_completed_with_lock(uint32_t *bits) {
0N/A MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
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 return is_ext_suspend_completed(false /*!called_by_wait */,
0N/A SuspendRetryDelay, bits);
0N/A }
0N/A
0N/A // We cannot allow wait_for_ext_suspend_completion() to run forever or
0N/A // we could hang. SuspendRetryCount and SuspendRetryDelay are normally
0N/A // passed as the count and delay parameters. Experiments with specific
0N/A // calls to wait_for_ext_suspend_completion() can be done by passing
0N/A // other values in the code. Experiments with all calls can be done
0N/A // via the appropriate -XX options.
0N/A bool wait_for_ext_suspend_completion(int count, int delay, uint32_t *bits);
0N/A
0N/A void set_external_suspend() { set_suspend_flag (_external_suspend); }
0N/A void clear_external_suspend() { clear_suspend_flag(_external_suspend); }
0N/A
0N/A void set_deopt_suspend() { set_suspend_flag (_deopt_suspend); }
0N/A void clear_deopt_suspend() { clear_suspend_flag(_deopt_suspend); }
0N/A bool is_deopt_suspend() { return (_suspend_flags & _deopt_suspend) != 0; }
0N/A
0N/A bool is_external_suspend() const {
0N/A return (_suspend_flags & _external_suspend) != 0;
0N/A }
0N/A // Whenever a thread transitions from native to vm/java it must suspend
0N/A // if external|deopt suspend is present.
0N/A bool is_suspend_after_native() const {
0N/A return (_suspend_flags & (_external_suspend | _deopt_suspend) ) != 0;
0N/A }
0N/A
0N/A // external suspend request is completed
0N/A bool is_ext_suspended() const {
0N/A return (_suspend_flags & _ext_suspended) != 0;
0N/A }
0N/A
0N/A // legacy method that checked for either external suspension or vm suspension
0N/A bool is_any_suspended() const {
0N/A return is_ext_suspended();
0N/A }
0N/A
0N/A bool is_external_suspend_with_lock() const {
0N/A MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
0N/A return is_external_suspend();
0N/A }
0N/A
0N/A // Special method to handle a pending external suspend request
0N/A // when a suspend equivalent condition lifts.
0N/A bool handle_special_suspend_equivalent_condition() {
0N/A assert(is_suspend_equivalent(),
0N/A "should only be called in a suspend equivalence condition");
0N/A MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
0N/A bool ret = is_external_suspend();
0N/A if (!ret) {
0N/A // not about to self-suspend so clear suspend equivalence
0N/A clear_suspend_equivalent();
0N/A }
0N/A // implied else:
0N/A // We have a pending external suspend request so we leave the
0N/A // suspend_equivalent flag set until java_suspend_self() sets
0N/A // the ext_suspended flag and clears the suspend_equivalent
0N/A // flag. This insures that wait_for_ext_suspend_completion()
0N/A // will return consistent values.
0N/A return ret;
0N/A }
0N/A
0N/A bool is_any_suspended_with_lock() const {
0N/A MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
0N/A return is_any_suspended();
0N/A }
0N/A // utility methods to see if we are doing some kind of suspension
0N/A bool is_being_ext_suspended() const {
0N/A MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
0N/A return is_ext_suspended() || is_external_suspend();
0N/A }
0N/A
0N/A bool is_suspend_equivalent() const { return _suspend_equivalent; }
0N/A
0N/A void set_suspend_equivalent() { _suspend_equivalent = true; };
0N/A void clear_suspend_equivalent() { _suspend_equivalent = false; };
0N/A
0N/A // Thread.stop support
0N/A void send_thread_stop(oop throwable);
0N/A AsyncRequests clear_special_runtime_exit_condition() {
0N/A AsyncRequests x = _special_runtime_exit_condition;
0N/A _special_runtime_exit_condition = _no_async_condition;
0N/A return x;
0N/A }
0N/A
0N/A // Are any async conditions present?
0N/A bool has_async_condition() { return (_special_runtime_exit_condition != _no_async_condition); }
0N/A
0N/A void check_and_handle_async_exceptions(bool check_unsafe_error = true);
0N/A
0N/A // these next two are also used for self-suspension and async exception support
0N/A void handle_special_runtime_exit_condition(bool check_asyncs = true);
0N/A
0N/A // Return true if JavaThread has an asynchronous condition or
0N/A // if external suspension is requested.
0N/A bool has_special_runtime_exit_condition() {
0N/A // We call is_external_suspend() last since external suspend should
0N/A // be less common. Because we don't use is_external_suspend_with_lock
0N/A // it is possible that we won't see an asynchronous external suspend
0N/A // request that has just gotten started, i.e., SR_lock grabbed but
0N/A // _external_suspend field change either not made yet or not visible
0N/A // yet. However, this is okay because the request is asynchronous and
0N/A // we will see the new flag value the next time through. It's also
0N/A // possible that the external suspend request is dropped after
0N/A // we have checked is_external_suspend(), we will recheck its value
0N/A // under SR_lock in java_suspend_self().
0N/A return (_special_runtime_exit_condition != _no_async_condition) ||
0N/A is_external_suspend() || is_deopt_suspend();
0N/A }
0N/A
0N/A void set_pending_unsafe_access_error() { _special_runtime_exit_condition = _async_unsafe_access_error; }
0N/A
0N/A void set_pending_async_exception(oop e) {
0N/A _pending_async_exception = e;
0N/A _special_runtime_exit_condition = _async_exception;
0N/A set_has_async_exception();
0N/A }
0N/A
0N/A // Fast-locking support
0N/A bool is_lock_owned(address adr) const;
0N/A
0N/A // Accessors for vframe array top
0N/A // The linked list of vframe arrays are sorted on sp. This means when we
0N/A // unpack the head must contain the vframe array to unpack.
0N/A void set_vframe_array_head(vframeArray* value) { _vframe_array_head = value; }
0N/A vframeArray* vframe_array_head() const { return _vframe_array_head; }
0N/A
0N/A // Side structure for defering update of java frame locals until deopt occurs
0N/A GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred_locals() const { return _deferred_locals_updates; }
0N/A void set_deferred_locals(GrowableArray<jvmtiDeferredLocalVariableSet *>* vf) { _deferred_locals_updates = vf; }
0N/A
0N/A // These only really exist to make debugging deopt problems simpler
0N/A
0N/A void set_vframe_array_last(vframeArray* value) { _vframe_array_last = value; }
0N/A vframeArray* vframe_array_last() const { return _vframe_array_last; }
0N/A
0N/A // The special resourceMark used during deoptimization
0N/A
0N/A void set_deopt_mark(DeoptResourceMark* value) { _deopt_mark = value; }
0N/A DeoptResourceMark* deopt_mark(void) { return _deopt_mark; }
0N/A
0N/A intptr_t* must_deopt_id() { return _must_deopt_id; }
0N/A void set_must_deopt_id(intptr_t* id) { _must_deopt_id = id; }
0N/A void clear_must_deopt_id() { _must_deopt_id = NULL; }
0N/A
0N/A methodOop callee_target() const { return _callee_target; }
0N/A void set_callee_target (methodOop x) { _callee_target = x; }
0N/A
0N/A // Oop results of vm runtime calls
0N/A oop vm_result() const { return _vm_result; }
0N/A void set_vm_result (oop x) { _vm_result = x; }
0N/A
0N/A oop vm_result_2() const { return _vm_result_2; }
0N/A void set_vm_result_2 (oop x) { _vm_result_2 = x; }
0N/A
0N/A // Exception handling for compiled methods
0N/A oop exception_oop() const { return _exception_oop; }
0N/A int exception_stack_size() const { return _exception_stack_size; }
0N/A address exception_pc() const { return _exception_pc; }
0N/A address exception_handler_pc() const { return _exception_handler_pc; }
0N/A
0N/A void set_exception_oop(oop o) { _exception_oop = o; }
0N/A void set_exception_pc(address a) { _exception_pc = a; }
0N/A void set_exception_handler_pc(address a) { _exception_handler_pc = a; }
0N/A void set_exception_stack_size(int size) { _exception_stack_size = size; }
0N/A
0N/A // Stack overflow support
0N/A inline size_t stack_available(address cur_sp);
0N/A address stack_yellow_zone_base()
0N/A { return (address)(stack_base() - (stack_size() - (stack_red_zone_size() + stack_yellow_zone_size()))); }
0N/A size_t stack_yellow_zone_size()
0N/A { return StackYellowPages * os::vm_page_size(); }
0N/A address stack_red_zone_base()
0N/A { return (address)(stack_base() - (stack_size() - stack_red_zone_size())); }
0N/A size_t stack_red_zone_size()
0N/A { return StackRedPages * os::vm_page_size(); }
0N/A bool in_stack_yellow_zone(address a)
0N/A { return (a <= stack_yellow_zone_base()) && (a >= stack_red_zone_base()); }
0N/A bool in_stack_red_zone(address a)
0N/A { return (a <= stack_red_zone_base()) && (a >= (address)((intptr_t)stack_base() - stack_size())); }
0N/A
0N/A void create_stack_guard_pages();
0N/A void remove_stack_guard_pages();
0N/A
0N/A void enable_stack_yellow_zone();
0N/A void disable_stack_yellow_zone();
0N/A void enable_stack_red_zone();
0N/A void disable_stack_red_zone();
0N/A
0N/A inline bool stack_yellow_zone_disabled();
0N/A inline bool stack_yellow_zone_enabled();
0N/A
0N/A // Attempt to reguard the stack after a stack overflow may have occurred.
0N/A // Returns true if (a) guard pages are not needed on this thread, (b) the
0N/A // pages are already guarded, or (c) the pages were successfully reguarded.
0N/A // Returns false if there is not enough stack space to reguard the pages, in
0N/A // which case the caller should unwind a frame and try again. The argument
0N/A // should be the caller's (approximate) sp.
0N/A bool reguard_stack(address cur_sp);
0N/A // Similar to above but see if current stackpoint is out of the guard area
0N/A // and reguard if possible.
0N/A bool reguard_stack(void);
0N/A
0N/A // Misc. accessors/mutators
0N/A void set_do_not_unlock(void) { _do_not_unlock_if_synchronized = true; }
0N/A void clr_do_not_unlock(void) { _do_not_unlock_if_synchronized = false; }
0N/A bool do_not_unlock(void) { return _do_not_unlock_if_synchronized; }
0N/A
0N/A#ifndef PRODUCT
0N/A void record_jump(address target, address instr, const char* file, int line);
0N/A#endif /* PRODUCT */
0N/A
0N/A // For assembly stub generation
0N/A static ByteSize threadObj_offset() { return byte_offset_of(JavaThread, _threadObj ); }
0N/A#ifndef PRODUCT
0N/A static ByteSize jmp_ring_index_offset() { return byte_offset_of(JavaThread, _jmp_ring_index ); }
0N/A static ByteSize jmp_ring_offset() { return byte_offset_of(JavaThread, _jmp_ring ); }
0N/A#endif /* PRODUCT */
0N/A static ByteSize jni_environment_offset() { return byte_offset_of(JavaThread, _jni_environment ); }
0N/A static ByteSize last_Java_sp_offset() {
0N/A return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
0N/A }
0N/A static ByteSize last_Java_pc_offset() {
0N/A return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
0N/A }
0N/A static ByteSize frame_anchor_offset() {
0N/A return byte_offset_of(JavaThread, _anchor);
0N/A }
0N/A static ByteSize callee_target_offset() { return byte_offset_of(JavaThread, _callee_target ); }
0N/A static ByteSize vm_result_offset() { return byte_offset_of(JavaThread, _vm_result ); }
0N/A static ByteSize vm_result_2_offset() { return byte_offset_of(JavaThread, _vm_result_2 ); }
0N/A static ByteSize thread_state_offset() { return byte_offset_of(JavaThread, _thread_state ); }
0N/A static ByteSize saved_exception_pc_offset() { return byte_offset_of(JavaThread, _saved_exception_pc ); }
0N/A static ByteSize osthread_offset() { return byte_offset_of(JavaThread, _osthread ); }
0N/A static ByteSize exception_oop_offset() { return byte_offset_of(JavaThread, _exception_oop ); }
0N/A static ByteSize exception_pc_offset() { return byte_offset_of(JavaThread, _exception_pc ); }
0N/A static ByteSize exception_handler_pc_offset() { return byte_offset_of(JavaThread, _exception_handler_pc); }
0N/A static ByteSize exception_stack_size_offset() { return byte_offset_of(JavaThread, _exception_stack_size); }
0N/A static ByteSize stack_guard_state_offset() { return byte_offset_of(JavaThread, _stack_guard_state ); }
0N/A static ByteSize suspend_flags_offset() { return byte_offset_of(JavaThread, _suspend_flags ); }
0N/A
0N/A static ByteSize do_not_unlock_if_synchronized_offset() { return byte_offset_of(JavaThread, _do_not_unlock_if_synchronized); }
0N/A
0N/A // Returns the jni environment for this thread
0N/A JNIEnv* jni_environment() { return &_jni_environment; }
0N/A
0N/A static JavaThread* thread_from_jni_environment(JNIEnv* env) {
0N/A JavaThread *thread_from_jni_env = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset()));
0N/A // Only return NULL if thread is off the thread list; starting to
0N/A // exit should not return NULL.
0N/A if (thread_from_jni_env->is_terminated()) {
0N/A thread_from_jni_env->block_if_vm_exited();
0N/A return NULL;
0N/A } else {
0N/A return thread_from_jni_env;
0N/A }
0N/A }
0N/A
0N/A // JNI critical regions. These can nest.
0N/A bool in_critical() { return _jni_active_critical > 0; }
0N/A void enter_critical() { assert(Thread::current() == this,
0N/A "this must be current thread");
0N/A _jni_active_critical++; }
0N/A void exit_critical() { assert(Thread::current() == this,
0N/A "this must be current thread");
0N/A _jni_active_critical--;
0N/A assert(_jni_active_critical >= 0,
0N/A "JNI critical nesting problem?"); }
0N/A
0N/A // For deadlock detection
0N/A int depth_first_number() { return _depth_first_number; }
0N/A void set_depth_first_number(int dfn) { _depth_first_number = dfn; }
0N/A
0N/A private:
0N/A void set_monitor_chunks(MonitorChunk* monitor_chunks) { _monitor_chunks = monitor_chunks; }
0N/A
0N/A public:
0N/A MonitorChunk* monitor_chunks() const { return _monitor_chunks; }
0N/A void add_monitor_chunk(MonitorChunk* chunk);
0N/A void remove_monitor_chunk(MonitorChunk* chunk);
0N/A bool in_deopt_handler() const { return _in_deopt_handler > 0; }
0N/A void inc_in_deopt_handler() { _in_deopt_handler++; }
0N/A void dec_in_deopt_handler() {
0N/A assert(_in_deopt_handler > 0, "mismatched deopt nesting");
0N/A if (_in_deopt_handler > 0) { // robustness
0N/A _in_deopt_handler--;
0N/A }
0N/A }
0N/A
0N/A private:
0N/A void set_entry_point(ThreadFunction entry_point) { _entry_point = entry_point; }
0N/A
0N/A public:
0N/A
0N/A // Frame iteration; calls the function f for all frames on the stack
0N/A void frames_do(void f(frame*, const RegisterMap*));
0N/A
0N/A // Memory operations
0N/A void oops_do(OopClosure* f);
0N/A
0N/A // Sweeper operations
0N/A void nmethods_do();
0N/A
0N/A // Memory management operations
0N/A void gc_epilogue();
0N/A void gc_prologue();
0N/A
0N/A // Misc. operations
0N/A char* name() const { return (char*)get_thread_name(); }
0N/A void print_on(outputStream* st) const;
0N/A void print() const { print_on(tty); }
0N/A void print_value();
0N/A void print_thread_state_on(outputStream* ) const PRODUCT_RETURN;
0N/A void print_thread_state() const PRODUCT_RETURN;
0N/A void print_on_error(outputStream* st, char* buf, int buflen) const;
0N/A void verify();
0N/A const char* get_thread_name() const;
0N/Aprivate:
0N/A // factor out low-level mechanics for use in both normal and error cases
0N/A const char* get_thread_name_string(char* buf = NULL, int buflen = 0) const;
0N/Apublic:
0N/A const char* get_threadgroup_name() const;
0N/A const char* get_parent_name() const;
0N/A
0N/A // Accessing frames
0N/A frame last_frame() {
0N/A _anchor.make_walkable(this);
0N/A return pd_last_frame();
0N/A }
0N/A javaVFrame* last_java_vframe(RegisterMap* reg_map);
0N/A
0N/A // Returns method at 'depth' java or native frames down the stack
0N/A // Used for security checks
0N/A klassOop security_get_caller_class(int depth);
0N/A
0N/A // Print stack trace in external format
0N/A void print_stack_on(outputStream* st);
0N/A void print_stack() { print_stack_on(tty); }
0N/A
0N/A // Print stack traces in various internal formats
0N/A void trace_stack() PRODUCT_RETURN;
0N/A void trace_stack_from(vframe* start_vf) PRODUCT_RETURN;
0N/A void trace_frames() PRODUCT_RETURN;
0N/A
0N/A // Returns the number of stack frames on the stack
0N/A int depth() const;
0N/A
0N/A // Function for testing deoptimization
0N/A void deoptimize();
0N/A void make_zombies();
0N/A
0N/A void deoptimized_wrt_marked_nmethods();
0N/A
0N/A // Profiling operation (see fprofile.cpp)
0N/A public:
0N/A bool profile_last_Java_frame(frame* fr);
0N/A
0N/A private:
0N/A ThreadProfiler* _thread_profiler;
0N/A private:
0N/A friend class FlatProfiler; // uses both [gs]et_thread_profiler.
0N/A friend class FlatProfilerTask; // uses get_thread_profiler.
0N/A friend class ThreadProfilerMark; // uses get_thread_profiler.
0N/A ThreadProfiler* get_thread_profiler() { return _thread_profiler; }
0N/A ThreadProfiler* set_thread_profiler(ThreadProfiler* tp) {
0N/A ThreadProfiler* result = _thread_profiler;
0N/A _thread_profiler = tp;
0N/A return result;
0N/A }
0N/A
0N/A // Static operations
0N/A public:
0N/A // Returns the running thread as a JavaThread
0N/A static inline JavaThread* current();
0N/A
0N/A // Returns the active Java thread. Do not use this if you know you are calling
0N/A // from a JavaThread, as it's slower than JavaThread::current. If called from
0N/A // the VMThread, it also returns the JavaThread that instigated the VMThread's
0N/A // operation. You may not want that either.
0N/A static JavaThread* active();
0N/A
0N/A inline CompilerThread* as_CompilerThread();
0N/A
0N/A public:
0N/A virtual void run();
0N/A void thread_main_inner();
0N/A
0N/A private:
0N/A // PRIVILEGED STACK
0N/A PrivilegedElement* _privileged_stack_top;
0N/A GrowableArray<oop>* _array_for_gc;
0N/A public:
0N/A
0N/A // Returns the privileged_stack information.
0N/A PrivilegedElement* privileged_stack_top() const { return _privileged_stack_top; }
0N/A void set_privileged_stack_top(PrivilegedElement *e) { _privileged_stack_top = e; }
0N/A void register_array_for_gc(GrowableArray<oop>* array) { _array_for_gc = array; }
0N/A
0N/A public:
0N/A // Thread local information maintained by JVMTI.
0N/A void set_jvmti_thread_state(JvmtiThreadState *value) { _jvmti_thread_state = value; }
0N/A JvmtiThreadState *jvmti_thread_state() const { return _jvmti_thread_state; }
0N/A static ByteSize jvmti_thread_state_offset() { return byte_offset_of(JavaThread, _jvmti_thread_state); }
0N/A void set_jvmti_get_loaded_classes_closure(JvmtiGetLoadedClassesClosure* value) { _jvmti_get_loaded_classes_closure = value; }
0N/A JvmtiGetLoadedClassesClosure* get_jvmti_get_loaded_classes_closure() const { return _jvmti_get_loaded_classes_closure; }
0N/A
0N/A // JVMTI PopFrame support
0N/A // Setting and clearing popframe_condition
0N/A // All of these enumerated values are bits. popframe_pending
0N/A // indicates that a PopFrame() has been requested and not yet been
0N/A // completed. popframe_processing indicates that that PopFrame() is in
0N/A // the process of being completed. popframe_force_deopt_reexecution_bit
0N/A // indicates that special handling is required when returning to a
0N/A // deoptimized caller.
0N/A enum PopCondition {
0N/A popframe_inactive = 0x00,
0N/A popframe_pending_bit = 0x01,
0N/A popframe_processing_bit = 0x02,
0N/A popframe_force_deopt_reexecution_bit = 0x04
0N/A };
0N/A PopCondition popframe_condition() { return (PopCondition) _popframe_condition; }
0N/A void set_popframe_condition(PopCondition c) { _popframe_condition = c; }
0N/A void set_popframe_condition_bit(PopCondition c) { _popframe_condition |= c; }
0N/A void clear_popframe_condition() { _popframe_condition = popframe_inactive; }
0N/A static ByteSize popframe_condition_offset() { return byte_offset_of(JavaThread, _popframe_condition); }
0N/A bool has_pending_popframe() { return (popframe_condition() & popframe_pending_bit) != 0; }
0N/A bool popframe_forcing_deopt_reexecution() { return (popframe_condition() & popframe_force_deopt_reexecution_bit) != 0; }
0N/A void clear_popframe_forcing_deopt_reexecution() { _popframe_condition &= ~popframe_force_deopt_reexecution_bit; }
0N/A#ifdef CC_INTERP
0N/A bool pop_frame_pending(void) { return ((_popframe_condition & popframe_pending_bit) != 0); }
0N/A void clr_pop_frame_pending(void) { _popframe_condition = popframe_inactive; }
0N/A bool pop_frame_in_process(void) { return ((_popframe_condition & popframe_processing_bit) != 0); }
0N/A void set_pop_frame_in_process(void) { _popframe_condition |= popframe_processing_bit; }
0N/A void clr_pop_frame_in_process(void) { _popframe_condition &= ~popframe_processing_bit; }
0N/A#endif
0N/A
0N/A private:
0N/A // Saved incoming arguments to popped frame.
0N/A // Used only when popped interpreted frame returns to deoptimized frame.
0N/A void* _popframe_preserved_args;
0N/A int _popframe_preserved_args_size;
0N/A
0N/A public:
0N/A void popframe_preserve_args(ByteSize size_in_bytes, void* start);
0N/A void* popframe_preserved_args();
0N/A ByteSize popframe_preserved_args_size();
0N/A WordSize popframe_preserved_args_size_in_words();
0N/A void popframe_free_preserved_args();
0N/A
0N/A
0N/A private:
0N/A JvmtiThreadState *_jvmti_thread_state;
0N/A JvmtiGetLoadedClassesClosure* _jvmti_get_loaded_classes_closure;
0N/A
0N/A // Used by the interpreter in fullspeed mode for frame pop, method
0N/A // entry, method exit and single stepping support. This field is
0N/A // only set to non-zero by the VM_EnterInterpOnlyMode VM operation.
0N/A // It can be set to zero asynchronously (i.e., without a VM operation
0N/A // or a lock) so we have to be very careful.
0N/A int _interp_only_mode;
0N/A
0N/A public:
0N/A // used by the interpreter for fullspeed debugging support (see above)
0N/A static ByteSize interp_only_mode_offset() { return byte_offset_of(JavaThread, _interp_only_mode); }
0N/A bool is_interp_only_mode() { return (_interp_only_mode != 0); }
0N/A int get_interp_only_mode() { return _interp_only_mode; }
0N/A void increment_interp_only_mode() { ++_interp_only_mode; }
0N/A void decrement_interp_only_mode() { --_interp_only_mode; }
0N/A
0N/A private:
0N/A ThreadStatistics *_thread_stat;
0N/A
0N/A public:
0N/A ThreadStatistics* get_thread_stat() const { return _thread_stat; }
0N/A
0N/A // Return a blocker object for which this thread is blocked parking.
0N/A oop current_park_blocker();
0N/A
0N/A private:
0N/A static size_t _stack_size_at_create;
0N/A
0N/A public:
0N/A static inline size_t stack_size_at_create(void) {
0N/A return _stack_size_at_create;
0N/A }
0N/A static inline void set_stack_size_at_create(size_t value) {
0N/A _stack_size_at_create = value;
0N/A }
0N/A
0N/A // Machine dependent stuff
0N/A #include "incls/_thread_pd.hpp.incl"
0N/A
0N/A public:
0N/A void set_blocked_on_compilation(bool value) {
0N/A _blocked_on_compilation = value;
0N/A }
0N/A
0N/A bool blocked_on_compilation() {
0N/A return _blocked_on_compilation;
0N/A }
0N/A protected:
0N/A bool _blocked_on_compilation;
0N/A
0N/A
0N/A // JSR166 per-thread parker
0N/Aprivate:
0N/A Parker* _parker;
0N/Apublic:
0N/A Parker* parker() { return _parker; }
0N/A
0N/A // Biased locking support
0N/Aprivate:
0N/A GrowableArray<MonitorInfo*>* _cached_monitor_info;
0N/Apublic:
0N/A GrowableArray<MonitorInfo*>* cached_monitor_info() { return _cached_monitor_info; }
0N/A void set_cached_monitor_info(GrowableArray<MonitorInfo*>* info) { _cached_monitor_info = info; }
0N/A
0N/A // clearing/querying jni attach status
0N/A bool is_attaching() const { return _is_attaching; }
0N/A void set_attached() { _is_attaching = false; OrderAccess::fence(); }
0N/A};
0N/A
0N/A// Inline implementation of JavaThread::current
0N/Ainline JavaThread* JavaThread::current() {
0N/A Thread* thread = ThreadLocalStorage::thread();
0N/A assert(thread != NULL && thread->is_Java_thread(), "just checking");
0N/A return (JavaThread*)thread;
0N/A}
0N/A
0N/Ainline CompilerThread* JavaThread::as_CompilerThread() {
0N/A assert(is_Compiler_thread(), "just checking");
0N/A return (CompilerThread*)this;
0N/A}
0N/A
0N/Ainline bool JavaThread::stack_yellow_zone_disabled() {
0N/A return _stack_guard_state == stack_guard_yellow_disabled;
0N/A}
0N/A
0N/Ainline bool JavaThread::stack_yellow_zone_enabled() {
0N/A#ifdef ASSERT
0N/A if (os::uses_stack_guard_pages()) {
0N/A assert(_stack_guard_state != stack_guard_unused, "guard pages must be in use");
0N/A }
0N/A#endif
0N/A return _stack_guard_state == stack_guard_enabled;
0N/A}
0N/A
0N/Ainline size_t JavaThread::stack_available(address cur_sp) {
0N/A // This code assumes java stacks grow down
0N/A address low_addr; // Limit on the address for deepest stack depth
0N/A if ( _stack_guard_state == stack_guard_unused) {
0N/A low_addr = stack_base() - stack_size();
0N/A } else {
0N/A low_addr = stack_yellow_zone_base();
0N/A }
0N/A return cur_sp > low_addr ? cur_sp - low_addr : 0;
0N/A}
0N/A
0N/A// A JavaThread for low memory detection support
0N/Aclass LowMemoryDetectorThread : public JavaThread {
0N/A friend class VMStructs;
0N/Apublic:
0N/A LowMemoryDetectorThread(ThreadFunction entry_point) : JavaThread(entry_point) {};
0N/A
0N/A // Hide this thread from external view.
0N/A bool is_hidden_from_external_view() const { return true; }
0N/A};
0N/A
0N/A// A thread used for Compilation.
0N/Aclass CompilerThread : public JavaThread {
0N/A friend class VMStructs;
0N/A private:
0N/A CompilerCounters* _counters;
0N/A
0N/A ciEnv* _env;
0N/A CompileLog* _log;
0N/A CompileTask* _task;
0N/A CompileQueue* _queue;
0N/A
0N/A public:
0N/A
0N/A static CompilerThread* current();
0N/A
0N/A CompilerThread(CompileQueue* queue, CompilerCounters* counters);
0N/A
0N/A bool is_Compiler_thread() const { return true; }
0N/A // Hide this compiler thread from external view.
0N/A bool is_hidden_from_external_view() const { return true; }
0N/A
0N/A CompileQueue* queue() { return _queue; }
0N/A CompilerCounters* counters() { return _counters; }
0N/A
0N/A // Get/set the thread's compilation environment.
0N/A ciEnv* env() { return _env; }
0N/A void set_env(ciEnv* env) { _env = env; }
0N/A
0N/A // Get/set the thread's logging information
0N/A CompileLog* log() { return _log; }
0N/A void init_log(CompileLog* log) {
0N/A // Set once, for good.
0N/A assert(_log == NULL, "set only once");
0N/A _log = log;
0N/A }
0N/A
0N/A#ifndef PRODUCT
0N/Aprivate:
0N/A IdealGraphPrinter *_ideal_graph_printer;
0N/Apublic:
0N/A IdealGraphPrinter *ideal_graph_printer() { return _ideal_graph_printer; }
0N/A void set_ideal_graph_printer(IdealGraphPrinter *n) { _ideal_graph_printer = n; }
0N/A#endif
0N/A
0N/A // Get/set the thread's current task
0N/A CompileTask* task() { return _task; }
0N/A void set_task(CompileTask* task) { _task = task; }
0N/A};
0N/A
0N/Ainline CompilerThread* CompilerThread::current() {
0N/A return JavaThread::current()->as_CompilerThread();
0N/A}
0N/A
0N/A
0N/A// The active thread queue. It also keeps track of the current used
0N/A// thread priorities.
0N/Aclass Threads: AllStatic {
0N/A friend class VMStructs;
0N/A private:
0N/A static JavaThread* _thread_list;
0N/A static int _number_of_threads;
0N/A static int _number_of_non_daemon_threads;
0N/A static int _return_code;
0N/A
0N/A public:
0N/A // Thread management
0N/A // force_daemon is a concession to JNI, where we may need to add a
0N/A // thread to the thread list before allocating its thread object
0N/A static void add(JavaThread* p, bool force_daemon = false);
0N/A static void remove(JavaThread* p);
0N/A static bool includes(JavaThread* p);
0N/A static JavaThread* first() { return _thread_list; }
0N/A static void threads_do(ThreadClosure* tc);
0N/A
0N/A // Initializes the vm and creates the vm thread
0N/A static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
0N/A static void convert_vm_init_libraries_to_agents();
0N/A static void create_vm_init_libraries();
0N/A static void create_vm_init_agents();
0N/A static void shutdown_vm_agents();
0N/A static bool destroy_vm();
0N/A // Supported VM versions via JNI
0N/A // Includes JNI_VERSION_1_1
0N/A static jboolean is_supported_jni_version_including_1_1(jint version);
0N/A // Does not include JNI_VERSION_1_1
0N/A static jboolean is_supported_jni_version(jint version);
0N/A
0N/A // Garbage collection
0N/A static void follow_other_roots(void f(oop*));
0N/A
0N/A // Apply "f->do_oop" to all root oops in all threads.
0N/A // This version may only be called by sequential code.
0N/A static void oops_do(OopClosure* f);
0N/A // This version may be called by sequential or parallel code.
0N/A static void possibly_parallel_oops_do(OopClosure* f);
0N/A // This creates a list of GCTasks, one per thread.
0N/A static void create_thread_roots_tasks(GCTaskQueue* q);
0N/A // This creates a list of GCTasks, one per thread, for marking objects.
0N/A static void create_thread_roots_marking_tasks(GCTaskQueue* q);
0N/A
0N/A // Apply "f->do_oop" to roots in all threads that
0N/A // are part of compiled frames
0N/A static void compiled_frame_oops_do(OopClosure* f);
0N/A
0N/A static void convert_hcode_pointers();
0N/A static void restore_hcode_pointers();
0N/A
0N/A // Sweeper
0N/A static void nmethods_do();
0N/A
0N/A static void gc_epilogue();
0N/A static void gc_prologue();
0N/A
0N/A // Verification
0N/A static void verify();
0N/A static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks);
0N/A static void print(bool print_stacks, bool internal_format) {
0N/A // this function is only used by debug.cpp
0N/A print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */);
0N/A }
0N/A static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
0N/A
0N/A // Get Java threads that are waiting to enter a monitor. If doLock
0N/A // is true, then Threads_lock is grabbed as needed. Otherwise, the
0N/A // VM needs to be at a safepoint.
0N/A static GrowableArray<JavaThread*>* get_pending_threads(int count,
0N/A address monitor, bool doLock);
0N/A
0N/A // Get owning Java thread from the monitor's owner field. If doLock
0N/A // is true, then Threads_lock is grabbed as needed. Otherwise, the
0N/A // VM needs to be at a safepoint.
0N/A static JavaThread *owning_thread_from_monitor_owner(address owner,
0N/A bool doLock);
0N/A
0N/A // Number of threads on the active threads list
0N/A static int number_of_threads() { return _number_of_threads; }
0N/A // Number of non-daemon threads on the active threads list
0N/A static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; }
0N/A
0N/A // Deoptimizes all frames tied to marked nmethods
0N/A static void deoptimized_wrt_marked_nmethods();
0N/A
0N/A};
0N/A
0N/A
0N/A// Thread iterator
0N/Aclass ThreadClosure: public StackObj {
0N/A public:
0N/A virtual void do_thread(Thread* thread) = 0;
0N/A};
0N/A
0N/Aclass SignalHandlerMark: public StackObj {
0N/Aprivate:
0N/A Thread* _thread;
0N/Apublic:
0N/A SignalHandlerMark(Thread* t) {
0N/A _thread = t;
0N/A if (_thread) _thread->enter_signal_handler();
0N/A }
0N/A ~SignalHandlerMark() {
0N/A if (_thread) _thread->leave_signal_handler();
0N/A _thread = NULL;
0N/A }
0N/A};
0N/A
0N/A// ParkEvents are type-stable and immortal.
0N/A//
0N/A// Lifecycle: Once a ParkEvent is associated with a thread that ParkEvent remains
0N/A// associated with the thread for the thread's entire lifetime - the relationship is
0N/A// stable. A thread will be associated at most one ParkEvent. When the thread
0N/A// expires, the ParkEvent moves to the EventFreeList. New threads attempt to allocate from
0N/A// the EventFreeList before creating a new Event. Type-stability frees us from
0N/A// worrying about stale Event or Thread references in the objectMonitor subsystem.
0N/A// (A reference to ParkEvent is always valid, even though the event may no longer be associated
0N/A// with the desired or expected thread. A key aspect of this design is that the callers of
0N/A// park, unpark, etc must tolerate stale references and spurious wakeups).
0N/A//
0N/A// Only the "associated" thread can block (park) on the ParkEvent, although
0N/A// any other thread can unpark a reachable parkevent. Park() is allowed to
0N/A// return spuriously. In fact park-unpark a really just an optimization to
0N/A// avoid unbounded spinning and surrender the CPU to be a polite system citizen.
0N/A// A degenerate albeit "impolite" park-unpark implementation could simply return.
0N/A// See http://blogs.sun.com/dave for more details.
0N/A//
0N/A// Eventually I'd like to eliminate Events and ObjectWaiters, both of which serve as
0N/A// thread proxies, and simply make the THREAD structure type-stable and persistent.
0N/A// Currently, we unpark events associated with threads, but ideally we'd just
0N/A// unpark threads.
0N/A//
0N/A// The base-class, PlatformEvent, is platform-specific while the ParkEvent is
0N/A// platform-independent. PlatformEvent provides park(), unpark(), etc., and
0N/A// is abstract -- that is, a PlatformEvent should never be instantiated except
0N/A// as part of a ParkEvent.
0N/A// Equivalently we could have defined a platform-independent base-class that
0N/A// exported Allocate(), Release(), etc. The platform-specific class would extend
0N/A// that base-class, adding park(), unpark(), etc.
0N/A//
0N/A// A word of caution: The JVM uses 2 very similar constructs:
0N/A// 1. ParkEvent are used for Java-level "monitor" synchronization.
0N/A// 2. Parkers are used by JSR166-JUC park-unpark.
0N/A//
0N/A// We'll want to eventually merge these redundant facilities and use ParkEvent.
0N/A
0N/A
0N/Aclass ParkEvent : public os::PlatformEvent {
0N/A private:
0N/A ParkEvent * FreeNext ;
0N/A
0N/A // Current association
0N/A Thread * AssociatedWith ;
0N/A intptr_t RawThreadIdentity ; // LWPID etc
0N/A volatile int Incarnation ;
0N/A
0N/A // diagnostic : keep track of last thread to wake this thread.
0N/A // this is useful for construction of dependency graphs.
0N/A void * LastWaker ;
0N/A
0N/A public:
0N/A // MCS-CLH list linkage and Native Mutex/Monitor
0N/A ParkEvent * volatile ListNext ;
0N/A ParkEvent * volatile ListPrev ;
0N/A volatile intptr_t OnList ;
0N/A volatile int TState ;
0N/A volatile int Notified ; // for native monitor construct
0N/A volatile int IsWaiting ; // Enqueued on WaitSet
0N/A
0N/A
0N/A private:
0N/A static ParkEvent * volatile FreeList ;
0N/A static volatile int ListLock ;
0N/A
0N/A // It's prudent to mark the dtor as "private"
0N/A // ensuring that it's not visible outside the package.
0N/A // Unfortunately gcc warns about such usage, so
0N/A // we revert to the less desirable "protected" visibility.
0N/A // The other compilers accept private dtors.
0N/A
0N/A protected: // Ensure dtor is never invoked
0N/A ~ParkEvent() { guarantee (0, "invariant") ; }
0N/A
0N/A ParkEvent() : PlatformEvent() {
0N/A AssociatedWith = NULL ;
0N/A FreeNext = NULL ;
0N/A ListNext = NULL ;
0N/A ListPrev = NULL ;
0N/A OnList = 0 ;
0N/A TState = 0 ;
0N/A Notified = 0 ;
0N/A IsWaiting = 0 ;
0N/A }
0N/A
0N/A // We use placement-new to force ParkEvent instances to be
0N/A // aligned on 256-byte address boundaries. This ensures that the least
0N/A // significant byte of a ParkEvent address is always 0.
0N/A
0N/A void * operator new (size_t sz) ;
0N/A void operator delete (void * a) ;
0N/A
0N/A public:
0N/A static ParkEvent * Allocate (Thread * t) ;
0N/A static void Release (ParkEvent * e) ;
0N/A} ;