< prev index next >

src/hotspot/share/runtime/thread.hpp

Print this page
rev 48154 : 8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
Reviewed-by:


  41 #include "runtime/safepoint.hpp"
  42 #include "runtime/stubRoutines.hpp"
  43 #include "runtime/threadLocalStorage.hpp"
  44 #include "runtime/thread_ext.hpp"
  45 #include "runtime/unhandledOops.hpp"
  46 #include "trace/traceBackend.hpp"
  47 #include "trace/traceMacros.hpp"
  48 #include "utilities/align.hpp"
  49 #include "utilities/exceptions.hpp"
  50 #include "utilities/macros.hpp"
  51 #if INCLUDE_ALL_GCS
  52 #include "gc/g1/dirtyCardQueue.hpp"
  53 #include "gc/g1/satbMarkQueue.hpp"
  54 #endif // INCLUDE_ALL_GCS
  55 #ifdef ZERO
  56 # include "stack_zero.hpp"
  57 #endif
  58 
  59 class ThreadSafepointState;
  60 class ThreadsList;

  61 class NestedThreadsList;
  62 
  63 class JvmtiThreadState;
  64 class JvmtiGetLoadedClassesClosure;
  65 class ThreadStatistics;
  66 class ConcurrentLocksDump;
  67 class ParkEvent;
  68 class Parker;
  69 
  70 class ciEnv;
  71 class CompileThread;
  72 class CompileLog;
  73 class CompileTask;
  74 class CompileQueue;
  75 class CompilerCounters;
  76 class vframeArray;
  77 
  78 class DeoptResourceMark;
  79 class jvmtiDeferredLocalVariableSet;
  80 


 104 
 105 class Thread: public ThreadShadow {
 106   friend class Threads;
 107   friend class VMStructs;
 108   friend class JVMCIVMStructs;
 109  private:
 110 
 111 #ifndef USE_LIBRARY_BASED_TLS_ONLY
 112   // Current thread is maintained as a thread-local variable
 113   static THREAD_LOCAL_DECL Thread* _thr_current;
 114 #endif
 115 
 116   // Exception handling
 117   // (Note: _pending_exception and friends are in ThreadShadow)
 118   //oop       _pending_exception;                // pending exception for current thread
 119   // const char* _exception_file;                   // file information for exception (debugging only)
 120   // int         _exception_line;                   // line information for exception (debugging only)
 121  protected:
 122   // Support for forcing alignment of thread objects for biased locking
 123   void*       _real_malloc_address;

 124   // JavaThread lifecycle support:
 125   friend class ScanHazardPtrGatherProtectedThreadsClosure;
 126   friend class ScanHazardPtrGatherThreadsListClosure;
 127   friend class ScanHazardPtrPrintMatchingThreadsClosure;
 128   friend class ThreadsListHandle;
 129   friend class ThreadsListSetter;

 130   ThreadsList* volatile _threads_hazard_ptr;
 131   ThreadsList*          cmpxchg_threads_hazard_ptr(ThreadsList* exchange_value, ThreadsList* compare_value);
 132   ThreadsList*          get_threads_hazard_ptr();
 133   void                  set_threads_hazard_ptr(ThreadsList* new_list);
 134   static bool           is_hazard_ptr_tagged(ThreadsList* list) {
 135     return (intptr_t(list) & intptr_t(1)) == intptr_t(1);
 136   }
 137   static ThreadsList*   tag_hazard_ptr(ThreadsList* list) {
 138     return (ThreadsList*)(intptr_t(list) | intptr_t(1));
 139   }
 140   static ThreadsList*   untag_hazard_ptr(ThreadsList* list) {
 141     return (ThreadsList*)(intptr_t(list) & ~intptr_t(1));
 142   }
 143   NestedThreadsList* _nested_threads_hazard_ptr;
 144   NestedThreadsList* get_nested_threads_hazard_ptr() {
 145     return _nested_threads_hazard_ptr;
 146   }
 147   void set_nested_threads_hazard_ptr(NestedThreadsList* value) {
 148     assert(Threads_lock->owned_by_self(),
 149            "must own Threads_lock for _nested_threads_hazard_ptr to be valid.");


2109   IdealGraphPrinter *_ideal_graph_printer;
2110  public:
2111   IdealGraphPrinter *ideal_graph_printer()           { return _ideal_graph_printer; }
2112   void set_ideal_graph_printer(IdealGraphPrinter *n) { _ideal_graph_printer = n; }
2113 #endif
2114 
2115   // Get/set the thread's current task
2116   CompileTask* task()                      { return _task; }
2117   void         set_task(CompileTask* task) { _task = task; }
2118 };
2119 
2120 inline CompilerThread* CompilerThread::current() {
2121   return JavaThread::current()->as_CompilerThread();
2122 }
2123 
2124 // The active thread queue. It also keeps track of the current used
2125 // thread priorities.
2126 class Threads: AllStatic {
2127   friend class VMStructs;
2128  private:
2129   // Safe Memory Reclamation (SMR) support:
2130   // The coordination between Threads::release_stable_list() and
2131   // Threads::smr_delete() uses the smr_delete_lock in order to
2132   // reduce the traffic on the Threads_lock.
2133   static Monitor*              _smr_delete_lock;
2134   // The '_cnt', '_max' and '_times" fields are enabled via
2135   // -XX:+EnableThreadSMRStatistics (see thread.cpp for a
2136   // description about each field):
2137   static uint                  _smr_delete_lock_wait_cnt;
2138   static uint                  _smr_delete_lock_wait_max;
2139   // The smr_delete_notify flag is used for proper double-check
2140   // locking in order to reduce the traffic on the smr_delete_lock.
2141   static volatile uint         _smr_delete_notify;
2142   static volatile uint         _smr_deleted_thread_cnt;
2143   static volatile uint         _smr_deleted_thread_time_max;
2144   static volatile uint         _smr_deleted_thread_times;
2145   static ThreadsList* volatile _smr_java_thread_list;
2146   static uint64_t              _smr_java_thread_list_alloc_cnt;
2147   static uint64_t              _smr_java_thread_list_free_cnt;
2148   static uint                  _smr_java_thread_list_max;
2149   static uint                  _smr_nested_thread_list_max;
2150   static volatile uint         _smr_tlh_cnt;
2151   static volatile uint         _smr_tlh_time_max;
2152   static volatile uint         _smr_tlh_times;
2153   static ThreadsList*          _smr_to_delete_list;
2154   static uint                  _smr_to_delete_list_cnt;
2155   static uint                  _smr_to_delete_list_max;
2156 
2157   static JavaThread*           _thread_list;
2158   static int                   _number_of_threads;
2159   static int                   _number_of_non_daemon_threads;
2160   static int                   _return_code;
2161   static int                   _thread_claim_parity;
2162 #ifdef ASSERT
2163   static bool                  _vm_complete;
2164 #endif
2165 
2166   static void initialize_java_lang_classes(JavaThread* main_thread, TRAPS);
2167   static void initialize_jsr292_core_classes(TRAPS);
2168 
2169   static ThreadsList *acquire_stable_list_fast_path(Thread *self);
2170   static ThreadsList *acquire_stable_list_nested_path(Thread *self);
2171   static void add_smr_deleted_thread_times(uint add_value);
2172   static void clear_smr_delete_notify();
2173   static ThreadsList* get_smr_java_thread_list();
2174   static void inc_smr_deleted_thread_cnt();
2175   static void release_stable_list_fast_path(Thread *self);
2176   static void release_stable_list_nested_path(Thread *self);
2177   static void release_stable_list_wake_up(char *log_str);
2178   static void set_smr_delete_notify();
2179   static Monitor* smr_delete_lock() { return _smr_delete_lock; }
2180   static bool smr_delete_notify();
2181   static void smr_free_list(ThreadsList* threads);
2182   static void update_smr_deleted_thread_time_max(uint new_value);
2183   static ThreadsList* xchg_smr_java_thread_list(ThreadsList* new_list);
2184 
2185  public:
2186   // Thread management
2187   // force_daemon is a concession to JNI, where we may need to add a
2188   // thread to the thread list before allocating its thread object
2189   static void add(JavaThread* p, bool force_daemon = false);
2190   static void remove(JavaThread* p);
2191   static void threads_do(ThreadClosure* tc);
2192   static void possibly_parallel_threads_do(bool is_par, ThreadClosure* tc);
2193 
2194   // SMR support:
2195   static ThreadsList *acquire_stable_list(Thread *self, bool is_ThreadsListSetter);
2196   static void release_stable_list(Thread *self);
2197   static bool is_a_protected_JavaThread(JavaThread *thread);
2198   static bool is_a_protected_JavaThread_with_lock(JavaThread *thread) {
2199     MutexLockerEx ml(Threads_lock->owned_by_self() ? NULL : Threads_lock);
2200     return is_a_protected_JavaThread(thread);
2201   }
2202   static void smr_delete(JavaThread *thread);
2203   static void inc_smr_tlh_cnt();
2204   static void update_smr_tlh_time_max(uint new_value);
2205   static void add_smr_tlh_times(uint add_value);
2206 
2207   // Initializes the vm and creates the vm thread
2208   static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
2209   static void convert_vm_init_libraries_to_agents();
2210   static void create_vm_init_libraries();
2211   static void create_vm_init_agents();
2212   static void shutdown_vm_agents();
2213   static bool destroy_vm();
2214   // Supported VM versions via JNI
2215   // Includes JNI_VERSION_1_1
2216   static jboolean is_supported_jni_version_including_1_1(jint version);
2217   // Does not include JNI_VERSION_1_1
2218   static jboolean is_supported_jni_version(jint version);
2219 
2220   // The "thread claim parity" provides a way for threads to be claimed
2221   // by parallel worker tasks.
2222   //
2223   // Each thread contains a a "parity" field. A task will claim the
2224   // thread only if its parity field is the same as the global parity,
2225   // which is updated by calling change_thread_claim_parity().
2226   //


2247   // Apply "f->do_oop" to roots in all threads that
2248   // are part of compiled frames
2249   static void compiled_frame_oops_do(OopClosure* f, CodeBlobClosure* cf);
2250 
2251   static void convert_hcode_pointers();
2252   static void restore_hcode_pointers();
2253 
2254   // Sweeper
2255   static void nmethods_do(CodeBlobClosure* cf);
2256 
2257   // RedefineClasses support
2258   static void metadata_do(void f(Metadata*));
2259   static void metadata_handles_do(void f(Metadata*));
2260 
2261 #ifdef ASSERT
2262   static bool is_vm_complete() { return _vm_complete; }
2263 #endif
2264 
2265   // Verification
2266   static void verify();
2267   static void log_smr_statistics();
2268   static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks);
2269   static void print_smr_info_on(outputStream* st);
2270   static void print_smr_info_elements_on(outputStream* st, ThreadsList* t_list);
2271   static void print(bool print_stacks, bool internal_format) {
2272     // this function is only used by debug.cpp
2273     print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */);
2274   }
2275   static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
2276   static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
2277                              int buflen, bool* found_current);
2278   static void print_threads_compiling(outputStream* st, char* buf, int buflen);
2279 
2280   // Get Java threads that are waiting to enter a monitor.
2281   static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
2282                                                          int count, address monitor);
2283 
2284   // Get owning Java thread from the monitor's owner field.
2285   static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
2286                                                       address owner);
2287 
2288   // Number of threads on the active threads list
2289   static int number_of_threads()                 { return _number_of_threads; }
2290   // Number of non-daemon threads on the active threads list




  41 #include "runtime/safepoint.hpp"
  42 #include "runtime/stubRoutines.hpp"
  43 #include "runtime/threadLocalStorage.hpp"
  44 #include "runtime/thread_ext.hpp"
  45 #include "runtime/unhandledOops.hpp"
  46 #include "trace/traceBackend.hpp"
  47 #include "trace/traceMacros.hpp"
  48 #include "utilities/align.hpp"
  49 #include "utilities/exceptions.hpp"
  50 #include "utilities/macros.hpp"
  51 #if INCLUDE_ALL_GCS
  52 #include "gc/g1/dirtyCardQueue.hpp"
  53 #include "gc/g1/satbMarkQueue.hpp"
  54 #endif // INCLUDE_ALL_GCS
  55 #ifdef ZERO
  56 # include "stack_zero.hpp"
  57 #endif
  58 
  59 class ThreadSafepointState;
  60 class ThreadsList;
  61 class ThreadsSMRSupport;
  62 class NestedThreadsList;
  63 
  64 class JvmtiThreadState;
  65 class JvmtiGetLoadedClassesClosure;
  66 class ThreadStatistics;
  67 class ConcurrentLocksDump;
  68 class ParkEvent;
  69 class Parker;
  70 
  71 class ciEnv;
  72 class CompileThread;
  73 class CompileLog;
  74 class CompileTask;
  75 class CompileQueue;
  76 class CompilerCounters;
  77 class vframeArray;
  78 
  79 class DeoptResourceMark;
  80 class jvmtiDeferredLocalVariableSet;
  81 


 105 
 106 class Thread: public ThreadShadow {
 107   friend class Threads;
 108   friend class VMStructs;
 109   friend class JVMCIVMStructs;
 110  private:
 111 
 112 #ifndef USE_LIBRARY_BASED_TLS_ONLY
 113   // Current thread is maintained as a thread-local variable
 114   static THREAD_LOCAL_DECL Thread* _thr_current;
 115 #endif
 116 
 117   // Exception handling
 118   // (Note: _pending_exception and friends are in ThreadShadow)
 119   //oop       _pending_exception;                // pending exception for current thread
 120   // const char* _exception_file;                   // file information for exception (debugging only)
 121   // int         _exception_line;                   // line information for exception (debugging only)
 122  protected:
 123   // Support for forcing alignment of thread objects for biased locking
 124   void*       _real_malloc_address;
 125 
 126   // JavaThread lifecycle support:
 127   friend class ScanHazardPtrGatherProtectedThreadsClosure;  // for cmpxchg_threads_hazard_ptr(), get_threads_hazard_ptr(), is_hazard_ptr_tagged() access
 128   friend class ScanHazardPtrGatherThreadsListClosure;  // for get_nested_threads_hazard_ptr(), get_threads_hazard_ptr(), untag_hazard_ptr() access
 129   friend class ScanHazardPtrPrintMatchingThreadsClosure;  // for get_threads_hazard_ptr(), is_hazard_ptr_tagged() access
 130   friend class ThreadsListSetter;  // for get_threads_hazard_ptr() access
 131   friend class ThreadsSMRSupport;  // for get_threads_hazard_ptr() access
 132 
 133   ThreadsList* volatile _threads_hazard_ptr;
 134   ThreadsList*          cmpxchg_threads_hazard_ptr(ThreadsList* exchange_value, ThreadsList* compare_value);
 135   ThreadsList*          get_threads_hazard_ptr();
 136   void                  set_threads_hazard_ptr(ThreadsList* new_list);
 137   static bool           is_hazard_ptr_tagged(ThreadsList* list) {
 138     return (intptr_t(list) & intptr_t(1)) == intptr_t(1);
 139   }
 140   static ThreadsList*   tag_hazard_ptr(ThreadsList* list) {
 141     return (ThreadsList*)(intptr_t(list) | intptr_t(1));
 142   }
 143   static ThreadsList*   untag_hazard_ptr(ThreadsList* list) {
 144     return (ThreadsList*)(intptr_t(list) & ~intptr_t(1));
 145   }
 146   NestedThreadsList* _nested_threads_hazard_ptr;
 147   NestedThreadsList* get_nested_threads_hazard_ptr() {
 148     return _nested_threads_hazard_ptr;
 149   }
 150   void set_nested_threads_hazard_ptr(NestedThreadsList* value) {
 151     assert(Threads_lock->owned_by_self(),
 152            "must own Threads_lock for _nested_threads_hazard_ptr to be valid.");


2112   IdealGraphPrinter *_ideal_graph_printer;
2113  public:
2114   IdealGraphPrinter *ideal_graph_printer()           { return _ideal_graph_printer; }
2115   void set_ideal_graph_printer(IdealGraphPrinter *n) { _ideal_graph_printer = n; }
2116 #endif
2117 
2118   // Get/set the thread's current task
2119   CompileTask* task()                      { return _task; }
2120   void         set_task(CompileTask* task) { _task = task; }
2121 };
2122 
2123 inline CompilerThread* CompilerThread::current() {
2124   return JavaThread::current()->as_CompilerThread();
2125 }
2126 
2127 // The active thread queue. It also keeps track of the current used
2128 // thread priorities.
2129 class Threads: AllStatic {
2130   friend class VMStructs;
2131  private:




























2132   static JavaThread* _thread_list;
2133   static int         _number_of_threads;
2134   static int         _number_of_non_daemon_threads;
2135   static int         _return_code;
2136   static int         _thread_claim_parity;
2137 #ifdef ASSERT
2138   static bool        _vm_complete;
2139 #endif
2140 
2141   static void initialize_java_lang_classes(JavaThread* main_thread, TRAPS);
2142   static void initialize_jsr292_core_classes(TRAPS);
2143 
















2144  public:
2145   // Thread management
2146   // force_daemon is a concession to JNI, where we may need to add a
2147   // thread to the thread list before allocating its thread object
2148   static void add(JavaThread* p, bool force_daemon = false);
2149   static void remove(JavaThread* p);
2150   static void threads_do(ThreadClosure* tc);
2151   static void possibly_parallel_threads_do(bool is_par, ThreadClosure* tc);
2152 













2153   // Initializes the vm and creates the vm thread
2154   static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
2155   static void convert_vm_init_libraries_to_agents();
2156   static void create_vm_init_libraries();
2157   static void create_vm_init_agents();
2158   static void shutdown_vm_agents();
2159   static bool destroy_vm();
2160   // Supported VM versions via JNI
2161   // Includes JNI_VERSION_1_1
2162   static jboolean is_supported_jni_version_including_1_1(jint version);
2163   // Does not include JNI_VERSION_1_1
2164   static jboolean is_supported_jni_version(jint version);
2165 
2166   // The "thread claim parity" provides a way for threads to be claimed
2167   // by parallel worker tasks.
2168   //
2169   // Each thread contains a a "parity" field. A task will claim the
2170   // thread only if its parity field is the same as the global parity,
2171   // which is updated by calling change_thread_claim_parity().
2172   //


2193   // Apply "f->do_oop" to roots in all threads that
2194   // are part of compiled frames
2195   static void compiled_frame_oops_do(OopClosure* f, CodeBlobClosure* cf);
2196 
2197   static void convert_hcode_pointers();
2198   static void restore_hcode_pointers();
2199 
2200   // Sweeper
2201   static void nmethods_do(CodeBlobClosure* cf);
2202 
2203   // RedefineClasses support
2204   static void metadata_do(void f(Metadata*));
2205   static void metadata_handles_do(void f(Metadata*));
2206 
2207 #ifdef ASSERT
2208   static bool is_vm_complete() { return _vm_complete; }
2209 #endif
2210 
2211   // Verification
2212   static void verify();

2213   static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks);


2214   static void print(bool print_stacks, bool internal_format) {
2215     // this function is only used by debug.cpp
2216     print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */);
2217   }
2218   static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
2219   static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
2220                              int buflen, bool* found_current);
2221   static void print_threads_compiling(outputStream* st, char* buf, int buflen);
2222 
2223   // Get Java threads that are waiting to enter a monitor.
2224   static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
2225                                                          int count, address monitor);
2226 
2227   // Get owning Java thread from the monitor's owner field.
2228   static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
2229                                                       address owner);
2230 
2231   // Number of threads on the active threads list
2232   static int number_of_threads()                 { return _number_of_threads; }
2233   // Number of non-daemon threads on the active threads list


< prev index next >