< prev index next >

src/hotspot/share/runtime/thread.hpp

Print this page
rev 47862 : imported patch 10.07.open.rebase_20171110.dcubed
rev 47865 : dholmes CR: Fix indents, trailing spaces and various typos. Add descriptions for the '_cnt', '_max' and '_times" fields, add impl notes to document the type choices.
rev 47866 : robinw CR: Fix some inefficient code, update some comments, fix some indents, and add some 'const' specifiers.


1159   // last_Java_pc
1160 
1161   address last_Java_pc(void)                     { return _anchor.last_Java_pc(); }
1162 
1163   // Safepoint support
1164 #if !(defined(PPC64) || defined(AARCH64))
1165   JavaThreadState thread_state() const           { return _thread_state; }
1166   void set_thread_state(JavaThreadState s)       { _thread_state = s;    }
1167 #else
1168   // Use membars when accessing volatile _thread_state. See
1169   // Threads::create_vm() for size checks.
1170   inline JavaThreadState thread_state() const;
1171   inline void set_thread_state(JavaThreadState s);
1172 #endif
1173   ThreadSafepointState *safepoint_state() const  { return _safepoint_state; }
1174   void set_safepoint_state(ThreadSafepointState *state) { _safepoint_state = state; }
1175   bool is_at_poll_safepoint()                    { return _safepoint_state->is_at_poll_safepoint(); }
1176 
1177   // JavaThread termination and lifecycle support:
1178   void smr_delete();
1179   bool on_thread_list() { return _on_thread_list; }
1180   void set_on_thread_list() { _on_thread_list = true; }
1181 
1182   // thread has called JavaThread::exit() or is terminated
1183   bool is_exiting() const;
1184   // thread is terminated (no longer on the threads list); we compare
1185   // against the two non-terminated values so that a freed JavaThread
1186   // will also be considered terminated.
1187   bool check_is_terminated(TerminatedTypes l_terminated) const {
1188     return l_terminated != _not_terminated && l_terminated != _thread_exiting;
1189   }
1190   bool is_terminated();
1191   void set_terminated(TerminatedTypes t);
1192   // special for Threads::remove() which is static:
1193   void set_terminated_value();
1194   void block_if_vm_exited();
1195 
1196   bool doing_unsafe_access()                     { return _doing_unsafe_access; }
1197   void set_doing_unsafe_access(bool val)         { _doing_unsafe_access = val; }
1198 
1199   bool do_not_unlock_if_synchronized()             { return _do_not_unlock_if_synchronized; }
1200   void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; }
1201 
1202   inline void set_polling_page(void* poll_value);
1203   inline volatile void* get_polling_page();
1204 
1205  private:
1206   // Support for thread handshake operations
1207   HandshakeState _handshake;
1208  public:
1209   void set_handshake_operation(HandshakeOperation* op) {
1210     _handshake.set_operation(this, op);


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   static Monitor*              _smr_delete_lock;
2131   // The '_cnt', '_max' and '_times" fields are enabled via
2132   // -XX:+EnableThreadSMRStatistics:

2133   static uint                  _smr_delete_lock_wait_cnt;

2134   static uint                  _smr_delete_lock_wait_max;
2135   static volatile jint         _smr_delete_notify;
2136   static volatile jint         _smr_deleted_thread_cnt;
2137   static volatile jint         _smr_deleted_thread_time_max;
2138   static volatile jint         _smr_deleted_thread_times;




2139   static ThreadsList* volatile _smr_java_thread_list;
2140   static ThreadsList*          get_smr_java_thread_list();
2141   static ThreadsList*          xchg_smr_java_thread_list(ThreadsList* new_list);
2142   static long                  _smr_java_thread_list_alloc_cnt;
2143   static long                  _smr_java_thread_list_free_cnt;



2144   static uint                  _smr_java_thread_list_max;

2145   static uint                  _smr_nested_thread_list_max;
2146   static volatile jint         _smr_tlh_cnt;
2147   static volatile jint         _smr_tlh_time_max;
2148   static volatile jint         _smr_tlh_times;



2149   static ThreadsList*          _smr_to_delete_list;

2150   static uint                  _smr_to_delete_list_cnt;

2151   static uint                  _smr_to_delete_list_max;
2152 
2153   static JavaThread*           _thread_list;
2154   static int                   _number_of_threads;
2155   static int                   _number_of_non_daemon_threads;
2156   static int                   _return_code;
2157   static int                   _thread_claim_parity;
2158 #ifdef ASSERT
2159   static bool                  _vm_complete;
2160 #endif
2161 
2162   static void initialize_java_lang_classes(JavaThread* main_thread, TRAPS);
2163   static void initialize_jsr292_core_classes(TRAPS);
2164 
2165   static void smr_free_list(ThreadsList* threads);
2166 
2167  public:
2168   // Thread management
2169   // force_daemon is a concession to JNI, where we may need to add a
2170   // thread to the thread list before allocating its thread object


2182   static void release_stable_list(Thread *self);
2183   static void release_stable_list_fast_path(Thread *self);
2184   static void release_stable_list_nested_path(Thread *self);
2185   static void release_stable_list_wake_up(char *log_str);
2186   static bool is_a_protected_JavaThread(JavaThread *thread);
2187   static bool is_a_protected_JavaThread_with_lock(JavaThread *thread) {
2188     MutexLockerEx ml(Threads_lock->owned_by_self() ? NULL : Threads_lock);
2189     return is_a_protected_JavaThread(thread);
2190   }
2191   static void smr_delete(JavaThread *thread);
2192   // The coordination between Threads::release_stable_list() and
2193   // Threads::smr_delete() uses the smr_delete_lock in order to
2194   // reduce the traffic on the Threads_lock.
2195   static Monitor* smr_delete_lock() { return _smr_delete_lock; }
2196   // The smr_delete_notify flag is used for proper double-check
2197   // locking in order to reduce the traffic on the smr_delete_lock.
2198   static bool smr_delete_notify();
2199   static void set_smr_delete_notify();
2200   static void clear_smr_delete_notify();
2201   static void inc_smr_deleted_thread_cnt();
2202   static void update_smr_deleted_thread_time_max(jint new_value);
2203   static void add_smr_deleted_thread_times(jint add_value);
2204   static void inc_smr_tlh_cnt();
2205   static void update_smr_tlh_time_max(jint new_value);
2206   static void add_smr_tlh_times(jint add_value);
2207 
2208   // Initializes the vm and creates the vm thread
2209   static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
2210   static void convert_vm_init_libraries_to_agents();
2211   static void create_vm_init_libraries();
2212   static void create_vm_init_agents();
2213   static void shutdown_vm_agents();
2214   static bool destroy_vm();
2215   // Supported VM versions via JNI
2216   // Includes JNI_VERSION_1_1
2217   static jboolean is_supported_jni_version_including_1_1(jint version);
2218   // Does not include JNI_VERSION_1_1
2219   static jboolean is_supported_jni_version(jint version);
2220 
2221   // The "thread claim parity" provides a way for threads to be claimed
2222   // by parallel worker tasks.
2223   //
2224   // Each thread contains a a "parity" field. A task will claim the
2225   // thread only if its parity field is the same as the global parity,
2226   // which is updated by calling change_thread_claim_parity().




1159   // last_Java_pc
1160 
1161   address last_Java_pc(void)                     { return _anchor.last_Java_pc(); }
1162 
1163   // Safepoint support
1164 #if !(defined(PPC64) || defined(AARCH64))
1165   JavaThreadState thread_state() const           { return _thread_state; }
1166   void set_thread_state(JavaThreadState s)       { _thread_state = s;    }
1167 #else
1168   // Use membars when accessing volatile _thread_state. See
1169   // Threads::create_vm() for size checks.
1170   inline JavaThreadState thread_state() const;
1171   inline void set_thread_state(JavaThreadState s);
1172 #endif
1173   ThreadSafepointState *safepoint_state() const  { return _safepoint_state; }
1174   void set_safepoint_state(ThreadSafepointState *state) { _safepoint_state = state; }
1175   bool is_at_poll_safepoint()                    { return _safepoint_state->is_at_poll_safepoint(); }
1176 
1177   // JavaThread termination and lifecycle support:
1178   void smr_delete();
1179   bool on_thread_list() const { return _on_thread_list; }
1180   void set_on_thread_list() { _on_thread_list = true; }
1181 
1182   // thread has called JavaThread::exit() or is terminated
1183   bool is_exiting() const;
1184   // thread is terminated (no longer on the threads list); we compare
1185   // against the two non-terminated values so that a freed JavaThread
1186   // will also be considered terminated.
1187   bool check_is_terminated(TerminatedTypes l_terminated) const {
1188     return l_terminated != _not_terminated && l_terminated != _thread_exiting;
1189   }
1190   bool is_terminated() const;
1191   void set_terminated(TerminatedTypes t);
1192   // special for Threads::remove() which is static:
1193   void set_terminated_value();
1194   void block_if_vm_exited();
1195 
1196   bool doing_unsafe_access()                     { return _doing_unsafe_access; }
1197   void set_doing_unsafe_access(bool val)         { _doing_unsafe_access = val; }
1198 
1199   bool do_not_unlock_if_synchronized()             { return _do_not_unlock_if_synchronized; }
1200   void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; }
1201 
1202   inline void set_polling_page(void* poll_value);
1203   inline volatile void* get_polling_page();
1204 
1205  private:
1206   // Support for thread handshake operations
1207   HandshakeState _handshake;
1208  public:
1209   void set_handshake_operation(HandshakeOperation* op) {
1210     _handshake.set_operation(this, op);


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   static Monitor*              _smr_delete_lock;
2131   // The '_cnt', '_max' and '_times" fields are enabled via
2132   // -XX:+EnableThreadSMRStatistics:
2133                                        // # of parallel threads in _smr_delete_lock->wait().
2134   static uint                  _smr_delete_lock_wait_cnt;
2135                                        // Max # of parallel threads in _smr_delete_lock->wait().
2136   static uint                  _smr_delete_lock_wait_max;
2137                                        // Flag to indicate when an _smr_delete_lock->notify() is needed.
2138   static volatile uint         _smr_delete_notify;
2139                                        // # of threads deleted over VM lifetime.
2140   static volatile uint         _smr_deleted_thread_cnt;
2141                                        // Max time in millis to delete a thread.
2142   static volatile uint         _smr_deleted_thread_time_max;
2143                                        // Cumulative time in millis to delete threads.
2144   static volatile uint         _smr_deleted_thread_times;
2145   static ThreadsList* volatile _smr_java_thread_list;
2146   static ThreadsList*          get_smr_java_thread_list();
2147   static ThreadsList*          xchg_smr_java_thread_list(ThreadsList* new_list);
2148                                        // # of ThreadsLists allocated over VM lifetime.
2149   static uint64_t              _smr_java_thread_list_alloc_cnt;
2150                                        // # of ThreadsLists freed over VM lifetime.
2151   static uint64_t              _smr_java_thread_list_free_cnt;
2152                                        // Max size ThreadsList allocated.
2153   static uint                  _smr_java_thread_list_max;
2154                                        // Max # of nested ThreadsLists for a thread.
2155   static uint                  _smr_nested_thread_list_max;
2156                                        // # of ThreadsListHandles deleted over VM lifetime.
2157   static volatile uint         _smr_tlh_cnt;
2158                                        // Max time in millis to delete a ThreadsListHandle.
2159   static volatile uint         _smr_tlh_time_max;
2160                                        // Cumulative time in millis to delete ThreadsListHandles.
2161   static volatile uint         _smr_tlh_times;
2162   static ThreadsList*          _smr_to_delete_list;
2163                                        // # of parallel ThreadsLists on the to-delete list.
2164   static uint                  _smr_to_delete_list_cnt;
2165                                        // Max # of parallel ThreadsLists on the to-delete list.
2166   static uint                  _smr_to_delete_list_max;
2167 
2168   static JavaThread*           _thread_list;
2169   static int                   _number_of_threads;
2170   static int                   _number_of_non_daemon_threads;
2171   static int                   _return_code;
2172   static int                   _thread_claim_parity;
2173 #ifdef ASSERT
2174   static bool                  _vm_complete;
2175 #endif
2176 
2177   static void initialize_java_lang_classes(JavaThread* main_thread, TRAPS);
2178   static void initialize_jsr292_core_classes(TRAPS);
2179 
2180   static void smr_free_list(ThreadsList* threads);
2181 
2182  public:
2183   // Thread management
2184   // force_daemon is a concession to JNI, where we may need to add a
2185   // thread to the thread list before allocating its thread object


2197   static void release_stable_list(Thread *self);
2198   static void release_stable_list_fast_path(Thread *self);
2199   static void release_stable_list_nested_path(Thread *self);
2200   static void release_stable_list_wake_up(char *log_str);
2201   static bool is_a_protected_JavaThread(JavaThread *thread);
2202   static bool is_a_protected_JavaThread_with_lock(JavaThread *thread) {
2203     MutexLockerEx ml(Threads_lock->owned_by_self() ? NULL : Threads_lock);
2204     return is_a_protected_JavaThread(thread);
2205   }
2206   static void smr_delete(JavaThread *thread);
2207   // The coordination between Threads::release_stable_list() and
2208   // Threads::smr_delete() uses the smr_delete_lock in order to
2209   // reduce the traffic on the Threads_lock.
2210   static Monitor* smr_delete_lock() { return _smr_delete_lock; }
2211   // The smr_delete_notify flag is used for proper double-check
2212   // locking in order to reduce the traffic on the smr_delete_lock.
2213   static bool smr_delete_notify();
2214   static void set_smr_delete_notify();
2215   static void clear_smr_delete_notify();
2216   static void inc_smr_deleted_thread_cnt();
2217   static void update_smr_deleted_thread_time_max(uint new_value);
2218   static void add_smr_deleted_thread_times(uint add_value);
2219   static void inc_smr_tlh_cnt();
2220   static void update_smr_tlh_time_max(uint new_value);
2221   static void add_smr_tlh_times(uint add_value);
2222 
2223   // Initializes the vm and creates the vm thread
2224   static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
2225   static void convert_vm_init_libraries_to_agents();
2226   static void create_vm_init_libraries();
2227   static void create_vm_init_agents();
2228   static void shutdown_vm_agents();
2229   static bool destroy_vm();
2230   // Supported VM versions via JNI
2231   // Includes JNI_VERSION_1_1
2232   static jboolean is_supported_jni_version_including_1_1(jint version);
2233   // Does not include JNI_VERSION_1_1
2234   static jboolean is_supported_jni_version(jint version);
2235 
2236   // The "thread claim parity" provides a way for threads to be claimed
2237   // by parallel worker tasks.
2238   //
2239   // Each thread contains a a "parity" field. A task will claim the
2240   // thread only if its parity field is the same as the global parity,
2241   // which is updated by calling change_thread_claim_parity().


< prev index next >