/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_RUNTIME_THREAD_HPP
#define SHARE_VM_RUNTIME_THREAD_HPP
#include "memory/allocation.hpp"
#include "memory/threadLocalAllocBuffer.hpp"
#include "prims/jvmtiExport.hpp"
#include "runtime/javaFrameAnchor.hpp"
#include "runtime/jniHandles.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/osThread.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/threadLocalStorage.hpp"
#include "runtime/unhandledOops.hpp"
#include "services/memRecorder.hpp"
#include "trace/traceBackend.hpp"
#include "trace/traceMacros.hpp"
#include "utilities/exceptions.hpp"
#ifndef SERIALGC
#include "gc_implementation/g1/dirtyCardQueue.hpp"
#include "gc_implementation/g1/satbQueue.hpp"
#endif
#ifdef ZERO
#ifdef TARGET_ARCH_zero
# include "stack_zero.hpp"
#endif
#endif
class ThreadSafepointState;
class ThreadProfiler;
class JvmtiThreadState;
class JvmtiGetLoadedClassesClosure;
class ThreadStatistics;
class ConcurrentLocksDump;
class ParkEvent;
class Parker;
class ciEnv;
class CompileThread;
class CompileLog;
class CompileTask;
class CompileQueue;
class CompilerCounters;
class vframeArray;
class DeoptResourceMark;
class GCTaskQueue;
class ThreadClosure;
class IdealGraphPrinter;
class WorkerThread;
// Class hierarchy
// - Thread
// - NamedThread
// - VMThread
// - ConcurrentGCThread
// - WorkerThread
// - GangWorker
// - GCTaskThread
// - JavaThread
// - WatcherThread
friend class VMStructs;
private:
// Exception handling
// (Note: _pending_exception and friends are in ThreadShadow)
//oop _pending_exception; // pending exception for current thread
// const char* _exception_file; // file information for exception (debugging only)
// int _exception_line; // line information for exception (debugging only)
protected:
// Support for forcing alignment of thread objects for biased locking
void* _real_malloc_address;
public:
void operator delete(void* p);
protected:
private:
// ***************************************************************
// Suspend and resume support
// ***************************************************************
//
// things including safepoints but was deprecated and finally removed
// in Java 7. Because VM suspension was considered "internal" Java-level
// suspension was considered "external", and this legacy naming scheme
// remains.
//
// JVM_ResumeThread, JVMTI SuspendThread, and finally JVMTI
// ResumeThread. External
// suspend requests cause _external_suspend to be set and external
// resume requests cause _external_suspend to be cleared.
// External suspend requests do not nest on top of other external
// suspend requests. The higher level APIs reject suspend requests
// for already suspended threads.
//
// The external_suspend
// flag is checked by has_special_runtime_exit_condition() and java thread
// will self-suspend when handle_special_runtime_exit_condition() is
// called. Most uses of the _thread_blocked state in JavaThreads are
// considered the same as being externally suspended; if the blocking
// condition lifts, the JavaThread will self-suspend. Other places
// where VM checks for external_suspend include:
// + mutex granting (do not enter monitors when thread is suspended)
// + state transitions from _thread_in_native
//
// In general, java_suspend() does not wait for an external suspend
// request to complete. When it returns, the only guarantee is that
// the _external_suspend field is true.
//
// wait_for_ext_suspend_completion() is used to wait for an external
// suspend request to complete. External suspend requests are usually
// followed by some other interface call that requires the thread to
// be quiescent, e.g., GetCallTrace(). By moving the "wait time" into
// the interface that requires quiescence, we give the JavaThread a
// chance to self-suspend before we need it to be quiescent. This
//
// It must be set under the protection of SR_lock. Read from the flag is
// OK without SR_lock as long as the value is only used as a hint.
// (e.g., check _external_suspend first without lock and then recheck
// inside SR_lock and finish the suspension)
//
// _suspend_flags is also overloaded for other "special conditions" so
// that a single check indicates whether any special action is needed
// eg. for async exceptions.
// -------------------------------------------------------------------
// Notes:
// but we still update its value to keep other part of the system (mainly
// JVMTI) happy. ThreadState is legacy code (see notes in
// osThread.hpp).
//
// 2. It would be more natural if set_external_suspend() is private and
// performance. Need more investigation on this.
//
protected:
enum SuspendFlags {
// NOTE: avoid using the sign-bit as cc generates different test code
// when the sign-bit is used, and sometimes incorrectly - see CR 6398077
};
// various suspension related flags - atomically updated
// overloaded for async exception checking in check_special_condition_for_native_trans.
private:
int _num_nested_signal;
public:
private:
// Debug tracing
// 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
// claimed as a task.
public:
private:
// 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
friend class No_Alloc_Verifier;
friend class No_Safepoint_Verifier;
friend class Pause_No_Safepoint_Verifier;
friend class ThreadLocalStorage;
friend class GC_locker;
// the Java heap
// is waiting to lock
// ObjectMonitor on which this thread called Object.wait()
// Private thread-local objectmonitor list - a simple cache organized as a SLL.
public:
#ifdef ASSERT
private:
public:
#endif
public:
enum {
is_definitely_current_thread = true
};
// Constructor
Thread();
virtual ~Thread();
// initializtion
void initialize_thread_local_storage();
// thread entry point
virtual void run();
// Testers
virtual bool is_VM_thread() const { return false; }
virtual bool is_Java_thread() const { return false; }
virtual bool is_Compiler_thread() const { return false; }
virtual bool is_hidden_from_external_view() const { return false; }
virtual bool is_jvmti_agent_thread() const { return false; }
// True iff the thread can perform GC operations at a safepoint.
// Generally will be true only of VM thread and parallel GC WorkGang
// threads.
virtual bool is_GC_task_thread() const { return false; }
virtual bool is_Watcher_thread() const { return false; }
virtual bool is_ConcurrentGC_thread() const { return false; }
virtual bool is_Named_thread() const { return false; }
virtual bool is_Worker_thread() const { return false; }
// Casts
// Returns the current thread
// Common thread operations
assert(Thread::current() == this, "set_native_thread_name can only be called on the current thread");
}
do {
}
(volatile jint*)&_suspend_flags,
}
do {
}
(volatile jint*)&_suspend_flags,
}
void set_has_async_exception() {
}
void clear_has_async_exception() {
}
void set_critical_native_unlock() {
}
void clear_critical_native_unlock() {
}
// Support for Unhandled Oop detection
#ifdef CHECK_UNHANDLED_OOPS
private:
public:
// 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
void clear_unhandled_oops() {
}
#endif // CHECK_UNHANDLED_OOPS
#ifndef PRODUCT
#endif
public:
// Installs a pending exception to be inserted later
// Resource area
// JNI handle support
// Internal handle support
// Thread-Local Allocation Buffer (TLAB) support
void initialize_tlab() {
if (UseTLAB) {
tlab().initialize();
}
}
if (UseTLAB) {
if ((ssize_t)used_bytes > 0) {
// More-or-less valid tlab. The load_acquire above should ensure
// that the result of the add is <= the instantaneous value
return allocated_bytes + used_bytes;
}
}
return allocated_bytes;
}
// VM operation support
// For tracking the heavyweight monitor the thread is pending on.
return _current_pending_monitor;
}
}
}
bool current_pending_monitor_is_from_java() {
}
// For tracking the ObjectMonitor on which this thread called Object.wait()
return _current_waiting_monitor;
}
}
// GC support
// 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.
private:
bool claim_oops_do_par_case(int collection_parity);
public:
// 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
// collection.
if (!is_par) {
return true;
} else {
return claim_oops_do_par_case(collection_parity);
}
}
// Sweeper support
// 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.
bool set_as_starting_thread();
protected:
// 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.
int _lgrp_id;
public:
// Stack overflow support
void record_stack_base_and_size();
/* QQQ this has knowledge of direction, ought to be a stack method */
}
// Printing
// Debug-only code
#ifdef ASSERT
private:
// 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,
// thus the friendship
friend class Mutex;
friend class Monitor;
public:
bool owns_locks_but_compiled_lock() const;
// Deadlock detection
#endif
private:
volatile int _jvmti_env_iteration_count;
public:
// Code generation
static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
public:
volatile int _TypeTag ;
void * _schedctl ;
// Low-level leaf-lock primitives used to implement synchronization
// and native monitor-mutex infrastructure.
// Not for general synchronization use.
static void SpinRelease (volatile int * Lock) ;
};
// Inline implementation of Thread::current()
// Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of
// startup.
// ThreadLocalStorage::thread is warm -- it's called > 16K times in the same
// period. This is inlined in thread_<os_family>.inline.hpp.
#ifdef ASSERT
// This function is very high traffic. Define PARANOID to enable expensive
// asserts.
#ifdef PARANOID
// Signal handler should call ThreadLocalStorage::get_thread_slow()
"Don't use Thread::current() inside signal handler");
#endif
#endif
return thread;
}
// Name support for threads. non-JavaThread subclasses with multiple
// uniquely named instances should derive from this.
friend class VMStructs;
enum {
};
private:
char* _name;
// log JavaThread being processed by oops_do
public:
NamedThread();
~NamedThread();
// May only be called once per thread.
virtual bool is_Named_thread() const { return true; }
};
// Worker threads are named and have an id of an assigned work.
private:
public:
virtual bool is_Worker_thread() const { return true; }
return (WorkerThread*) this;
}
};
// A single WatcherThread is used for simulating timer interrupts.
friend class VMStructs;
public:
virtual void run();
private:
static bool _startable;
public:
enum SomeConstants {
};
// Constructor
// Tester
bool is_Watcher_thread() const { return true; }
// Printing
void unpark();
// Returns the single instance of WatcherThread
// Create and start the single instance of WatcherThread, or stop it on shutdown
static void start();
static void stop();
// Only allow start once the VM is sufficiently initialized
// Otherwise the first task to enroll will trigger the start
static void make_startable();
private:
int sleep() const;
};
class CompilerThread;
friend class VMStructs;
private:
#ifdef ASSERT
private:
int _java_call_counter;
public:
void dec_java_call_counter() {
}
private: // restore original namespace restriction
#endif // ifdef ASSERT
#ifndef PRODUCT
public:
enum {
};
private: // restore original namespace restriction
#endif
// Deopt support
// 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
// 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
// and by JNI_MonitorEnter/Exit
// Async. requests support
enum AsyncRequests {
_no_async_condition = 0,
};
// Safepoint support
public: // Expose _thread_state for SafeFetchInt()
private:
// JavaThread termination support
enum TerminatedTypes {
// 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.
// handlers thread is in
bool _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was
// never locked) when throwing an exception. Used by interpreter only.
// JNI attach states:
enum JNIAttachStates {
};
// A regular JavaThread's _jni_attach_state is _not_attaching_via_jni.
// A native thread that is attaching via JNI starts with a value
// of _attaching_via_jni and transitions to _attached_via_jni.
public:
// State of the stack guard pages for this thread.
enum StackGuardState {
};
private:
// 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
// code)
volatile int _is_method_handle_return; // true (== 1) if the current exception PC is a MethodHandle call site.
// 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.
int _depth_first_number;
// JVMTI PopFrame support
// This is set to popframe_pending to signal that top Java frame should be popped immediately
int _popframe_condition;
#ifndef PRODUCT
int _jmp_ring_index;
struct {
// We use intptr_t instead of address so debugger doesn't try and display strings
const char* _file;
int _line;
#endif /* PRODUCT */
#ifndef SERIALGC
// Support for G1 barriers
// Set of all such queues.
// Set of all such queues.
void flush_barrier_queues();
#endif // !SERIALGC
friend class VMThread;
friend class ThreadWaitTransition;
friend class VM_Exit;
void initialize(); // Initialized the instance variables
public:
// Constructor
~JavaThread();
#ifdef ASSERT
// verify this JavaThread hasn't be published in the Threads::list yet
void verify_not_published();
#endif
}
}
// This function is called at thread creation to allow
// platform specific thread variables to be initialized.
void cache_global_variables();
// Executes Shutdown.shutdown()
void invoke_shutdown_hooks();
// Cleanup on thread exit
enum ExitType {
};
// Testers
virtual bool is_Java_thread() const { return true; }
// compilation
// 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
// last_Java_sp
// last_Java_pc
// Safepoint support
// 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:
void block_if_vm_exited();
// native memory tracking
private:
// per-thread memory recorder
private:
public:
void java_suspend();
void java_resume();
int java_suspend_self();
void check_and_wait_while_suspended() {
bool do_self_suspend;
do {
// were we externally suspended while we were waiting?
if (do_self_suspend) {
// don't surprise the thread that suspended us by returning
}
} while (do_self_suspend);
}
// Check for async exception in addition to safepoint and suspend request.
// Same as check_special_condition_for_native_trans but finishes the
// transition into thread_in_Java mode so that it can potentially
// block.
// 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.
return is_ext_suspend_completed(false /*!called_by_wait */,
}
// 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.
bool is_external_suspend() const {
return (_suspend_flags & _external_suspend) != 0;
}
// if external|deopt suspend is present.
bool is_suspend_after_native() const {
}
// external suspend request is completed
bool is_ext_suspended() const {
return (_suspend_flags & _ext_suspended) != 0;
}
bool is_external_suspend_with_lock() const {
return is_external_suspend();
}
// Special method to handle a pending external suspend request
// when a suspend equivalent condition lifts.
"should only be called in a suspend equivalence condition");
if (!ret) {
// not about to self-suspend so clear suspend equivalence
}
// implied else:
// 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.
return ret;
}
// utility methods to see if we are doing some kind of suspension
bool is_being_ext_suspended() const {
return is_ext_suspended() || is_external_suspend();
}
// Thread.stop support
return x;
}
// Are any async conditions present?
void check_and_handle_async_exceptions(bool check_unsafe_error = true);
// these next two are also used for self-suspension and async exception support
void handle_special_runtime_exit_condition(bool check_asyncs = true);
// Return true if JavaThread has an asynchronous condition or
// if external suspension is requested.
bool has_special_runtime_exit_condition() {
// 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().
return (_special_runtime_exit_condition != _no_async_condition) ||
is_external_suspend() || is_deopt_suspend();
}
void set_pending_unsafe_access_error() { _special_runtime_exit_condition = _async_unsafe_access_error; }
}
// Fast-locking support
// 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
GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred_locals() const { return _deferred_locals_updates; }
void set_deferred_locals(GrowableArray<jvmtiDeferredLocalVariableSet *>* vf) { _deferred_locals_updates = vf; }
// 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
{ return (address)(stack_base() - (stack_size() - (stack_red_zone_size() + stack_yellow_zone_size()))); }
{ return (a <= stack_yellow_zone_base()) && (a >= stack_red_zone_base()); }
void create_stack_guard_pages();
void remove_stack_guard_pages();
void enable_stack_yellow_zone();
void disable_stack_yellow_zone();
void enable_stack_red_zone();
void disable_stack_red_zone();
inline bool stack_guard_zone_unused();
inline bool stack_yellow_zone_disabled();
inline bool stack_yellow_zone_enabled();
// 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.
bool reguard_stack(void);
#ifndef PRODUCT
#endif /* PRODUCT */
// For assembly stub generation
#ifndef PRODUCT
#endif /* PRODUCT */
}
}
}
static ByteSize saved_exception_pc_offset() { return byte_offset_of(JavaThread, _saved_exception_pc ); }
static ByteSize exception_handler_pc_offset() { return byte_offset_of(JavaThread, _exception_handler_pc); }
static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
static ByteSize stack_guard_state_offset() { return byte_offset_of(JavaThread, _stack_guard_state ); }
static ByteSize do_not_unlock_if_synchronized_offset() { return byte_offset_of(JavaThread, _do_not_unlock_if_synchronized); }
}
#ifndef SERIALGC
#endif // !SERIALGC
// Returns the jni environment for this thread
JavaThread *thread_from_jni_env = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset()));
// Only return NULL if thread is off the thread list; starting to
// exit should not return NULL.
if (thread_from_jni_env->is_terminated()) {
return NULL;
} else {
return thread_from_jni_env;
}
}
// JNI critical regions. These can nest.
"this must be current thread or synchronizing");
_jni_active_critical++; }
"this must be current thread");
assert(_jni_active_critical >= 0,
"JNI critical nesting problem?"); }
// For deadlock detection
private:
public:
void dec_in_deopt_handler() {
if (_in_deopt_handler > 0) { // robustness
}
}
private:
public:
// Frame iteration; calls the function f for all frames on the stack
// Memory operations
// Sweeper operations
// Memory management operations
void gc_epilogue();
void gc_prologue();
// Misc. operations
void print_value();
void verify();
const char* get_thread_name() const;
private:
// factor out low-level mechanics for use in both normal and error cases
public:
const char* get_threadgroup_name() const;
const char* get_parent_name() const;
// Accessing frames
_anchor.make_walkable(this);
return pd_last_frame();
}
// 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
// Print an annotated view of the stack frames
void validate_frame_layout() {
print_frame_layout(0, true);
}
// Returns the number of stack frames on the stack
int depth() const;
// Function for testing deoptimization
void deoptimize();
void make_zombies();
void deoptimized_wrt_marked_nmethods();
// Profiling operation (see fprofile.cpp)
public:
private:
private:
friend class FlatProfiler; // uses both [gs]et_thread_profiler.
friend class FlatProfilerTask; // uses get_thread_profiler.
friend class ThreadProfilerMark; // uses get_thread_profiler.
return result;
}
// NMT (Native memory tracking) support.
// This flag helps NMT to determine if this JavaThread will be blocked
// at safepoint. If not, ThreadCritical is needed for writing memory records.
// JavaThread is only safepoint visible when it is in Threads' thread list,
// it is not visible until it is added to the list and becomes invisible
// once it is removed from the list.
public:
private:
bool _safepoint_visible;
// Static operations
public:
// Returns the running thread as a JavaThread
static inline JavaThread* current();
// 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.
static JavaThread* active();
inline CompilerThread* as_CompilerThread();
public:
virtual void run();
void thread_main_inner();
private:
// PRIVILEGED STACK
public:
// Returns the privileged_stack information.
public:
// 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.
static ByteSize jvmti_thread_state_offset() { return byte_offset_of(JavaThread, _jvmti_thread_state); }
void set_jvmti_get_loaded_classes_closure(JvmtiGetLoadedClassesClosure* value) { _jvmti_get_loaded_classes_closure = value; }
JvmtiGetLoadedClassesClosure* get_jvmti_get_loaded_classes_closure() const { return _jvmti_get_loaded_classes_closure; }
// 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
// deoptimized caller.
enum PopCondition {
};
static ByteSize popframe_condition_offset() { return byte_offset_of(JavaThread, _popframe_condition); }
bool popframe_forcing_deopt_reexecution() { return (popframe_condition() & popframe_force_deopt_reexecution_bit) != 0; }
void clear_popframe_forcing_deopt_reexecution() { _popframe_condition &= ~popframe_force_deopt_reexecution_bit; }
#ifdef CC_INTERP
#endif
private:
// Saved incoming arguments to popped frame.
// Used only when popped interpreted frame returns to deoptimized frame.
void* _popframe_preserved_args;
public:
void* popframe_preserved_args();
void popframe_free_preserved_args();
private:
// 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.
int _interp_only_mode;
public:
// 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
private:
public:
private:
public:
// Return a blocker object for which this thread is blocked parking.
private:
public:
return _stack_size_at_create;
}
}
#ifndef SERIALGC
// SATB marking queue support
return _satb_mark_queue_set;
}
// Dirty card queue support
return _dirty_card_queue_set;
}
#endif // !SERIALGC
// 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).
#ifndef SERIALGC
void initialize_queues();
#else // !SERIALGC
void initialize_queues() { }
#endif // !SERIALGC
// Machine dependent stuff
#ifdef TARGET_OS_ARCH_linux_x86
# include "thread_linux_x86.hpp"
#endif
#ifdef TARGET_OS_ARCH_linux_sparc
# include "thread_linux_sparc.hpp"
#endif
#ifdef TARGET_OS_ARCH_linux_zero
# include "thread_linux_zero.hpp"
#endif
#ifdef TARGET_OS_ARCH_solaris_x86
# include "thread_solaris_x86.hpp"
#endif
#ifdef TARGET_OS_ARCH_solaris_sparc
# include "thread_solaris_sparc.hpp"
#endif
#ifdef TARGET_OS_ARCH_windows_x86
# include "thread_windows_x86.hpp"
#endif
#ifdef TARGET_OS_ARCH_linux_arm
# include "thread_linux_arm.hpp"
#endif
#ifdef TARGET_OS_ARCH_linux_ppc
# include "thread_linux_ppc.hpp"
#endif
#ifdef TARGET_OS_ARCH_bsd_x86
# include "thread_bsd_x86.hpp"
#endif
#ifdef TARGET_OS_ARCH_bsd_zero
# include "thread_bsd_zero.hpp"
#endif
public:
}
bool blocked_on_compilation() {
return _blocked_on_compilation;
}
protected:
bool _blocked_on_compilation;
// JSR166 per-thread parker
private:
public:
// Biased locking support
private:
public:
bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; }
private:
// 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.
int _claimed_par_id;
public:
};
// Inline implementation of JavaThread::current
return (JavaThread*)thread;
}
return (CompilerThread*)this;
}
return _stack_guard_state == stack_guard_unused;
}
return _stack_guard_state == stack_guard_yellow_disabled;
}
#ifdef ASSERT
if (os::uses_stack_guard_pages()) {
}
#endif
return _stack_guard_state == stack_guard_enabled;
}
// This code assumes java stacks grow down
if ( _stack_guard_state == stack_guard_unused) {
} else {
}
}
// A thread used for Compilation.
friend class VMStructs;
private:
public:
static CompilerThread* current();
bool is_Compiler_thread() const { return true; }
// Hide this compiler thread from external view.
bool is_hidden_from_external_view() const { return true; }
// Set once, for good.
}
// GC support
// Apply "f->do_oop" to all root oops in "this".
// Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames
#ifndef PRODUCT
private:
public:
#endif
// Track the nmethod currently being scanned by the sweeper
}
};
}
// The active thread queue. It also keeps track of the current used
// thread priorities.
friend class VMStructs;
private:
static int _number_of_threads;
static int _number_of_non_daemon_threads;
static int _return_code;
public:
// Thread management
// force_daemon is a concession to JNI, where we may need to add a
// thread to the thread list before allocating its thread object
static void remove(JavaThread* p);
static bool includes(JavaThread* p);
// Initializes the vm and creates the vm thread
static void convert_vm_init_libraries_to_agents();
static void create_vm_init_libraries();
static void create_vm_init_agents();
static void shutdown_vm_agents();
static bool destroy_vm();
// Supported VM versions via JNI
// Includes JNI_VERSION_1_1
// Does not include JNI_VERSION_1_1
// Garbage collection
static void follow_other_roots(void f(oop*));
// 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.
static void create_thread_roots_tasks(GCTaskQueue* q);
// This creates a list of GCTasks, one per thread, for marking objects.
static void create_thread_roots_marking_tasks(GCTaskQueue* q);
// Apply "f->do_oop" to roots in all threads that
// are part of compiled frames
static void convert_hcode_pointers();
static void restore_hcode_pointers();
// Sweeper
static void gc_epilogue();
static void gc_prologue();
// Verification
static void verify();
static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks);
// this function is only used by debug.cpp
}
// 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.
bool doLock);
// 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
static void deoptimized_wrt_marked_nmethods();
};
// Thread iterator
public:
};
private:
public:
_thread = t;
}
~SignalHandlerMark() {
}
};
#endif // SHARE_VM_RUNTIME_THREAD_HPP