class JavaThread; class Monitor; class outputStream; class Thread; class ThreadClosure; class ThreadsList;
// Thread Safe Memory Reclamation (Thread-SMR) support. // // ThreadsListHandles are used to safely perform operations on one or more // threads without the risk of the thread or threads exiting during the // operation. It is no longer necessary to hold the Threads_lock to safely // perform an operation on a target thread. // // There are several different ways to refer to java.lang.Thread objects // so we have a few ways to get a protected JavaThread *: // // JNI jobject example: // jobject jthread = ...; // : // ThreadsListHandle tlh; // JavaThread* jt = NULL; // bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &jt, NULL); // if (is_alive) { // : // do stuff with 'jt'... // } // // JVM/TI jthread example: // jthread thread = ...; // : // JavaThread* jt = NULL; // ThreadsListHandle tlh; // jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &jt, NULL); // if (err != JVMTI_ERROR_NONE) { // return err; // } // : // do stuff with 'jt'... // // JVM/TI oop example (this one should be very rare): // oop thread_obj = ...; // : // JavaThread *jt = NULL; // ThreadsListHandle tlh; // jvmtiError err = JvmtiExport::cv_oop_to_JavaThread(tlh.list(), thread_obj, &jt); // if (err != JVMTI_ERROR_NONE) { // return err; // } // : // do stuff with 'jt'... // // A JavaThread * that is included in the ThreadsList that is held by // a ThreadsListHandle is protected as long as the ThreadsListHandle // remains in scope. The target JavaThread * may have logically exited, // but that target JavaThread * will not be deleted until it is no // longer protected by a ThreadsListHandle. // // SMR Support for the Threads class. // class ThreadsSMRSupport : AllStatic {
friend class VMStructs;
friend class SafeThreadsListPtr; // for _nested_thread_list_max, delete_notify(), release_stable_list_wake_up() access
// The coordination between ThreadsSMRSupport::release_stable_list() and // ThreadsSMRSupport::smr_delete() uses the delete_lock in order to // reduce the traffic on the Threads_lock. static Monitor* delete_lock() { return ThreadsSMRDelete_lock; }
// The '_cnt', '_max' and '_times" fields are enabled via // -XX:+EnableThreadSMRStatistics (see thread.cpp for a // description about each field): static uint _delete_lock_wait_cnt; static uint _delete_lock_wait_max; // The delete_notify flag is used for proper double-check // locking in order to reduce the traffic on the system wide // Thread-SMR delete_lock. staticvolatile uint _delete_notify; staticvolatile uint _deleted_thread_cnt; staticvolatile uint _deleted_thread_time_max; staticvolatile uint _deleted_thread_times; static ThreadsList _bootstrap_list; static ThreadsList* volatile _java_thread_list; static uint64_t _java_thread_list_alloc_cnt; static uint64_t _java_thread_list_free_cnt; static uint _java_thread_list_max; static uint _nested_thread_list_max; staticvolatile uint _tlh_cnt; staticvolatile uint _tlh_time_max; staticvolatile uint _tlh_times; static ThreadsList* _to_delete_list; static uint _to_delete_list_cnt; static uint _to_delete_list_max;
// A fast list of JavaThreads. // class ThreadsList : public CHeapObj<mtThread> {
enum { THREADS_LIST_MAGIC = (int)(('T' << 24) | ('L' << 16) | ('S' << 8) | 'T') };
friend class VMStructs;
friend class SafeThreadsListPtr; // for {dec,inc}_nested_handle_cnt() access
friend class ThreadsSMRSupport; // for _nested_handle_cnt, {add,remove}_thread(), {,set_}next_list() access
friend class ThreadsListHandleTest; // for _nested_handle_cnt access
// An abstract safe ptr to a ThreadsList comprising either a stable hazard ptr // for leaves, or a retained reference count for nested uses. The user of this // API does not need to know which mechanism is providing the safety. class SafeThreadsListPtr {
friend class ThreadsListHandleTest; // for access to the fields
friend class ThreadsListSetter;
// A helper to optionally set the hazard ptr in ourself. This helper can // be used by ourself or by another thread. If the hazard ptr is set(), // then the destructor will release it. // class ThreadsListSetter : public StackObj { private:
SafeThreadsListPtr _list_ptr;
// This stack allocated ThreadsListHandle keeps all JavaThreads in the // ThreadsList from being deleted until it is safe. // class ThreadsListHandle : public StackObj {
friend class ThreadsListHandleTest; // for _list_ptr access
SafeThreadsListPtr _list_ptr;
elapsedTimer _timer; // Enabled via -XX:+EnableThreadSMRStatistics.
// This stack allocated JavaThreadIterator is used to walk the // specified ThreadsList using the following style: // // JavaThreadIterator jti(t_list); // for (JavaThread *jt = jti.first(); jt != NULL; jt = jti.next()) { // ... // } // class JavaThreadIterator : public StackObj {
ThreadsList * _list;
uint _index;
public:
JavaThreadIterator(ThreadsList *list) : _list(list), _index(0) {
assert(list != NULL, "ThreadsList must not be NULL.");
}
// This stack allocated ThreadsListHandle and JavaThreadIterator combo // is used to walk the ThreadsList in the included ThreadsListHandle // using the following style: // // for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) { // ... // } // class JavaThreadIteratorWithHandle : public StackObj {
ThreadsListHandle _tlh;
uint _index;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.