< prev index next >

src/hotspot/share/runtime/thread.hpp

Print this page




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREAD_HPP
  26 #define SHARE_VM_RUNTIME_THREAD_HPP
  27 
  28 #include "jni.h"
  29 #include "gc/shared/gcThreadLocalData.hpp"
  30 #include "gc/shared/threadLocalAllocBuffer.hpp"
  31 #include "memory/allocation.hpp"
  32 #include "memory/vtBuffer.hpp"
  33 #include "oops/oop.hpp"
  34 #include "prims/jvmtiExport.hpp"
  35 #include "runtime/frame.hpp"
  36 #include "runtime/globals.hpp"
  37 #include "runtime/handshake.hpp"
  38 #include "runtime/javaFrameAnchor.hpp"
  39 #include "runtime/jniHandles.hpp"
  40 #include "runtime/mutexLocker.hpp"
  41 #include "runtime/os.hpp"
  42 #include "runtime/osThread.hpp"
  43 #include "runtime/park.hpp"
  44 #include "runtime/safepoint.hpp"
  45 #include "runtime/stubRoutines.hpp"
  46 #include "runtime/threadHeapSampler.hpp"
  47 #include "runtime/threadLocalStorage.hpp"
  48 #include "runtime/threadStatisticalInfo.hpp"
  49 #include "runtime/unhandledOops.hpp"
  50 #include "utilities/align.hpp"
  51 #include "utilities/exceptions.hpp"
  52 #include "utilities/macros.hpp"


 367   ObjectMonitor* omFreeList;
 368   int omFreeCount;                              // length of omFreeList
 369   int omFreeProvision;                          // reload chunk size
 370   ObjectMonitor* omInUseList;                   // SLL to track monitors in circulation
 371   int omInUseCount;                             // length of omInUseList
 372 
 373 #ifdef ASSERT
 374  private:
 375   bool _visited_for_critical_count;
 376 
 377  public:
 378   void set_visited_for_critical_count(bool z) { _visited_for_critical_count = z; }
 379   bool was_visited_for_critical_count() const   { return _visited_for_critical_count; }
 380 #endif
 381 
 382  public:
 383   enum {
 384     is_definitely_current_thread = true
 385   };
 386 
 387  private:
 388   friend class BufferedValuesDealiaser;
 389 
 390   BufferedValuesDealiaser* _buffered_values_dealiaser;
 391  public:
 392   BufferedValuesDealiaser* buffered_values_dealiaser() {
 393     assert(Thread::current() == this, "Should only be accessed locally");
 394     return _buffered_values_dealiaser;
 395   }
 396 
 397   // Constructor
 398   Thread();
 399   virtual ~Thread() = 0;        // Thread is abstract.
 400 
 401   // Manage Thread::current()
 402   void initialize_thread_current();
 403   void clear_thread_current(); // TLS cleanup needed before threads terminate
 404 
 405  public:
 406   // thread entry point
 407   virtual void run();
 408 
 409   // Testers
 410   virtual bool is_VM_thread()       const            { return false; }
 411   virtual bool is_Java_thread()     const            { return false; }
 412   virtual bool is_Compiler_thread() const            { return false; }
 413   virtual bool is_Code_cache_sweeper_thread() const  { return false; }
 414   virtual bool is_hidden_from_external_view() const  { return false; }
 415   virtual bool is_jvmti_agent_thread() const         { return false; }
 416   // True iff the thread can perform GC operations at a safepoint.


1112  private:
1113   // support for JNI critical regions
1114   jint    _jni_active_critical;                  // count of entries into JNI critical region
1115 
1116   // Checked JNI: function name requires exception check
1117   char* _pending_jni_exception_check_fn;
1118 
1119   // For deadlock detection.
1120   int _depth_first_number;
1121 
1122   // JVMTI PopFrame support
1123   // This is set to popframe_pending to signal that top Java frame should be popped immediately
1124   int _popframe_condition;
1125 
1126   // If reallocation of scalar replaced objects fails, we throw OOM
1127   // and during exception propagation, pop the top
1128   // _frames_to_pop_failed_realloc frames, the ones that reference
1129   // failed reallocations.
1130   int _frames_to_pop_failed_realloc;
1131 
1132   // Buffered value types support
1133   void* _vt_alloc_ptr;
1134   void* _vt_alloc_limit;
1135   VTBufferChunk* _local_free_chunk;
1136   VTBuffer::Mark _current_vtbuffer_mark;
1137   // Next 4 fields are used to monitor VT buffer memory consumption
1138   // We may want to not support them in PRODUCT builds
1139   jint _vtchunk_in_use;
1140   jint _vtchunk_max;
1141   jint _vtchunk_total_returned;
1142   jint _vtchunk_total_failed;
1143   jlong _vtchunk_total_memory_buffered;
1144 
1145 #ifndef PRODUCT
1146   int _jmp_ring_index;
1147   struct {
1148     // We use intptr_t instead of address so debugger doesn't try and display strings
1149     intptr_t _target;
1150     intptr_t _instruction;
1151     const char*  _file;
1152     int _line;
1153   }   _jmp_ring[jump_ring_buffer_size];
1154 #endif // PRODUCT
1155 
1156   friend class VMThread;
1157   friend class ThreadWaitTransition;
1158   friend class VM_Exit;
1159 
1160   void initialize();                             // Initialized the instance variables
1161 
1162  public:
1163   // Constructor
1164   JavaThread(bool is_attaching_via_jni = false); // for main thread and JNI attached threads


1827   void frames_do(void f(frame*, const RegisterMap*));
1828 
1829   // Memory operations
1830   void oops_do(OopClosure* f, CodeBlobClosure* cf);
1831 
1832   // Sweeper operations
1833   virtual void nmethods_do(CodeBlobClosure* cf);
1834 
1835   // RedefineClasses Support
1836   void metadata_do(void f(Metadata*));
1837 
1838   // Misc. operations
1839   char* name() const { return (char*)get_thread_name(); }
1840   void print_on(outputStream* st, bool print_extended_info) const;
1841   void print_on(outputStream* st) const { print_on(st, false); }
1842   void print_value();
1843   void print_thread_state_on(outputStream*) const      PRODUCT_RETURN;
1844   void print_thread_state() const                      PRODUCT_RETURN;
1845   void print_on_error(outputStream* st, char* buf, int buflen) const;
1846   void print_name_on_error(outputStream* st, char* buf, int buflen) const;
1847   void print_vt_buffer_stats_on(outputStream* st) const;
1848   void verify();
1849   const char* get_thread_name() const;
1850  private:
1851   // factor out low-level mechanics for use in both normal and error cases
1852   const char* get_thread_name_string(char* buf = NULL, int buflen = 0) const;
1853  public:
1854   const char* get_threadgroup_name() const;
1855   const char* get_parent_name() const;
1856 
1857   // Accessing frames
1858   frame last_frame() {
1859     _anchor.make_walkable(this);
1860     return pd_last_frame();
1861   }
1862   javaVFrame* last_java_vframe(RegisterMap* reg_map);
1863 
1864   // Returns method at 'depth' java or native frames down the stack
1865   // Used for security checks
1866   Klass* security_get_caller_class(int depth);
1867 


2009  private:
2010   ThreadStatistics *_thread_stat;
2011 
2012  public:
2013   ThreadStatistics* get_thread_stat() const    { return _thread_stat; }
2014 
2015   // Return a blocker object for which this thread is blocked parking.
2016   oop current_park_blocker();
2017 
2018  private:
2019   static size_t _stack_size_at_create;
2020 
2021  public:
2022   static inline size_t stack_size_at_create(void) {
2023     return _stack_size_at_create;
2024   }
2025   static inline void set_stack_size_at_create(size_t value) {
2026     _stack_size_at_create = value;
2027   }
2028 
2029   void* vt_alloc_ptr() const { return _vt_alloc_ptr; }
2030   void set_vt_alloc_ptr(void* ptr) { _vt_alloc_ptr = ptr; }
2031   void* vt_alloc_limit() const { return _vt_alloc_limit; }
2032   void set_vt_alloc_limit(void* ptr) { _vt_alloc_limit = ptr; }
2033   VTBufferChunk* local_free_chunk() const { return _local_free_chunk; }
2034   void set_local_free_chunk(VTBufferChunk* chunk) { _local_free_chunk = chunk; }
2035   VTBufferChunk* current_chunk() {
2036     if (_vt_alloc_ptr == NULL) return NULL;
2037     VTBufferChunk* chunk = VTBufferChunk::chunk(_vt_alloc_ptr);
2038     assert(chunk->owner() == this, "Sanity check");
2039     return chunk;
2040     // return _vt_alloc_ptr == NULL ? NULL : VTBufferChunk::chunk(_vt_alloc_ptr);
2041   }
2042   VTBuffer::Mark current_vtbuffer_mark() const { return _current_vtbuffer_mark; }
2043   void set_current_vtbuffer_mark(VTBuffer::Mark m) { _current_vtbuffer_mark = m ; }
2044 
2045   void increment_vtchunk_in_use() {
2046     _vtchunk_in_use++;
2047     if (_vtchunk_in_use > _vtchunk_max) _vtchunk_max = _vtchunk_in_use;
2048   }
2049   void decrement_vtchunk_in_use() { _vtchunk_in_use--; }
2050   jint vtchunk_in_use() const { return _vtchunk_in_use; }
2051   jint vtchunk_max() const { return _vtchunk_max; }
2052   void increment_vtchunk_returned() { _vtchunk_total_returned++; }
2053   jint vtchunk_total_returned() const { return _vtchunk_total_returned; }
2054   void increment_vtchunk_failed() { _vtchunk_total_failed++; }
2055   jint vtchunk_total_failed() const { return _vtchunk_total_failed; }
2056   void increment_vtchunk_total_memory_buffered(jlong size) { _vtchunk_total_memory_buffered += size; }
2057   jlong vtchunk_total_memory_buffered() const { return _vtchunk_total_memory_buffered; }
2058 
2059   static ByteSize vt_alloc_ptr_offset() { return byte_offset_of(JavaThread, _vt_alloc_ptr); }
2060 
2061 
2062   // Machine dependent stuff
2063 #include OS_CPU_HEADER(thread)
2064 
2065  public:
2066   void set_blocked_on_compilation(bool value) {
2067     _blocked_on_compilation = value;
2068   }
2069 
2070   bool blocked_on_compilation() {
2071     return _blocked_on_compilation;
2072   }
2073  protected:
2074   bool         _blocked_on_compilation;
2075 
2076 
2077   // JSR166 per-thread parker
2078  private:
2079   Parker*    _parker;
2080  public:
2081   Parker*     parker() { return _parker; }


2284   static size_t threads_before_barrier_set() {
2285     return _threads_before_barrier_set;
2286   }
2287 
2288   static void inc_threads_before_barrier_set() {
2289     ++_threads_before_barrier_set;
2290   }
2291 #endif // ASSERT
2292 
2293   // Verification
2294   static void verify();
2295   static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks, bool print_extended_info);
2296   static void print(bool print_stacks, bool internal_format) {
2297     // this function is only used by debug.cpp
2298     print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */, false /* simple format */);
2299   }
2300   static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
2301   static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
2302                              int buflen, bool* found_current);
2303   static void print_threads_compiling(outputStream* st, char* buf, int buflen);
2304   static void print_vt_buffer_stats_on(outputStream* st);
2305 
2306   // Get Java threads that are waiting to enter a monitor.
2307   static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
2308                                                          int count, address monitor);
2309 
2310   // Get owning Java thread from the monitor's owner field.
2311   static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
2312                                                       address owner);
2313 
2314   // Number of threads on the active threads list
2315   static int number_of_threads()                 { return _number_of_threads; }
2316   // Number of non-daemon threads on the active threads list
2317   static int number_of_non_daemon_threads()      { return _number_of_non_daemon_threads; }
2318 
2319   // Deoptimizes all frames tied to marked nmethods
2320   static void deoptimized_wrt_marked_nmethods();
2321 };
2322 
2323 
2324 // Thread iterator




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREAD_HPP
  26 #define SHARE_VM_RUNTIME_THREAD_HPP
  27 
  28 #include "jni.h"
  29 #include "gc/shared/gcThreadLocalData.hpp"
  30 #include "gc/shared/threadLocalAllocBuffer.hpp"
  31 #include "memory/allocation.hpp"

  32 #include "oops/oop.hpp"
  33 #include "prims/jvmtiExport.hpp"
  34 #include "runtime/frame.hpp"
  35 #include "runtime/globals.hpp"
  36 #include "runtime/handshake.hpp"
  37 #include "runtime/javaFrameAnchor.hpp"
  38 #include "runtime/jniHandles.hpp"
  39 #include "runtime/mutexLocker.hpp"
  40 #include "runtime/os.hpp"
  41 #include "runtime/osThread.hpp"
  42 #include "runtime/park.hpp"
  43 #include "runtime/safepoint.hpp"
  44 #include "runtime/stubRoutines.hpp"
  45 #include "runtime/threadHeapSampler.hpp"
  46 #include "runtime/threadLocalStorage.hpp"
  47 #include "runtime/threadStatisticalInfo.hpp"
  48 #include "runtime/unhandledOops.hpp"
  49 #include "utilities/align.hpp"
  50 #include "utilities/exceptions.hpp"
  51 #include "utilities/macros.hpp"


 366   ObjectMonitor* omFreeList;
 367   int omFreeCount;                              // length of omFreeList
 368   int omFreeProvision;                          // reload chunk size
 369   ObjectMonitor* omInUseList;                   // SLL to track monitors in circulation
 370   int omInUseCount;                             // length of omInUseList
 371 
 372 #ifdef ASSERT
 373  private:
 374   bool _visited_for_critical_count;
 375 
 376  public:
 377   void set_visited_for_critical_count(bool z) { _visited_for_critical_count = z; }
 378   bool was_visited_for_critical_count() const   { return _visited_for_critical_count; }
 379 #endif
 380 
 381  public:
 382   enum {
 383     is_definitely_current_thread = true
 384   };
 385 




 386  public:





 387   // Constructor
 388   Thread();
 389   virtual ~Thread() = 0;        // Thread is abstract.
 390 
 391   // Manage Thread::current()
 392   void initialize_thread_current();
 393   void clear_thread_current(); // TLS cleanup needed before threads terminate
 394 
 395  public:
 396   // thread entry point
 397   virtual void run();
 398 
 399   // Testers
 400   virtual bool is_VM_thread()       const            { return false; }
 401   virtual bool is_Java_thread()     const            { return false; }
 402   virtual bool is_Compiler_thread() const            { return false; }
 403   virtual bool is_Code_cache_sweeper_thread() const  { return false; }
 404   virtual bool is_hidden_from_external_view() const  { return false; }
 405   virtual bool is_jvmti_agent_thread() const         { return false; }
 406   // True iff the thread can perform GC operations at a safepoint.


1102  private:
1103   // support for JNI critical regions
1104   jint    _jni_active_critical;                  // count of entries into JNI critical region
1105 
1106   // Checked JNI: function name requires exception check
1107   char* _pending_jni_exception_check_fn;
1108 
1109   // For deadlock detection.
1110   int _depth_first_number;
1111 
1112   // JVMTI PopFrame support
1113   // This is set to popframe_pending to signal that top Java frame should be popped immediately
1114   int _popframe_condition;
1115 
1116   // If reallocation of scalar replaced objects fails, we throw OOM
1117   // and during exception propagation, pop the top
1118   // _frames_to_pop_failed_realloc frames, the ones that reference
1119   // failed reallocations.
1120   int _frames_to_pop_failed_realloc;
1121 













1122 #ifndef PRODUCT
1123   int _jmp_ring_index;
1124   struct {
1125     // We use intptr_t instead of address so debugger doesn't try and display strings
1126     intptr_t _target;
1127     intptr_t _instruction;
1128     const char*  _file;
1129     int _line;
1130   }   _jmp_ring[jump_ring_buffer_size];
1131 #endif // PRODUCT
1132 
1133   friend class VMThread;
1134   friend class ThreadWaitTransition;
1135   friend class VM_Exit;
1136 
1137   void initialize();                             // Initialized the instance variables
1138 
1139  public:
1140   // Constructor
1141   JavaThread(bool is_attaching_via_jni = false); // for main thread and JNI attached threads


1804   void frames_do(void f(frame*, const RegisterMap*));
1805 
1806   // Memory operations
1807   void oops_do(OopClosure* f, CodeBlobClosure* cf);
1808 
1809   // Sweeper operations
1810   virtual void nmethods_do(CodeBlobClosure* cf);
1811 
1812   // RedefineClasses Support
1813   void metadata_do(void f(Metadata*));
1814 
1815   // Misc. operations
1816   char* name() const { return (char*)get_thread_name(); }
1817   void print_on(outputStream* st, bool print_extended_info) const;
1818   void print_on(outputStream* st) const { print_on(st, false); }
1819   void print_value();
1820   void print_thread_state_on(outputStream*) const      PRODUCT_RETURN;
1821   void print_thread_state() const                      PRODUCT_RETURN;
1822   void print_on_error(outputStream* st, char* buf, int buflen) const;
1823   void print_name_on_error(outputStream* st, char* buf, int buflen) const;

1824   void verify();
1825   const char* get_thread_name() const;
1826  private:
1827   // factor out low-level mechanics for use in both normal and error cases
1828   const char* get_thread_name_string(char* buf = NULL, int buflen = 0) const;
1829  public:
1830   const char* get_threadgroup_name() const;
1831   const char* get_parent_name() const;
1832 
1833   // Accessing frames
1834   frame last_frame() {
1835     _anchor.make_walkable(this);
1836     return pd_last_frame();
1837   }
1838   javaVFrame* last_java_vframe(RegisterMap* reg_map);
1839 
1840   // Returns method at 'depth' java or native frames down the stack
1841   // Used for security checks
1842   Klass* security_get_caller_class(int depth);
1843 


1985  private:
1986   ThreadStatistics *_thread_stat;
1987 
1988  public:
1989   ThreadStatistics* get_thread_stat() const    { return _thread_stat; }
1990 
1991   // Return a blocker object for which this thread is blocked parking.
1992   oop current_park_blocker();
1993 
1994  private:
1995   static size_t _stack_size_at_create;
1996 
1997  public:
1998   static inline size_t stack_size_at_create(void) {
1999     return _stack_size_at_create;
2000   }
2001   static inline void set_stack_size_at_create(size_t value) {
2002     _stack_size_at_create = value;
2003   }
2004 

































2005   // Machine dependent stuff
2006 #include OS_CPU_HEADER(thread)
2007 
2008  public:
2009   void set_blocked_on_compilation(bool value) {
2010     _blocked_on_compilation = value;
2011   }
2012 
2013   bool blocked_on_compilation() {
2014     return _blocked_on_compilation;
2015   }
2016  protected:
2017   bool         _blocked_on_compilation;
2018 
2019 
2020   // JSR166 per-thread parker
2021  private:
2022   Parker*    _parker;
2023  public:
2024   Parker*     parker() { return _parker; }


2227   static size_t threads_before_barrier_set() {
2228     return _threads_before_barrier_set;
2229   }
2230 
2231   static void inc_threads_before_barrier_set() {
2232     ++_threads_before_barrier_set;
2233   }
2234 #endif // ASSERT
2235 
2236   // Verification
2237   static void verify();
2238   static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks, bool print_extended_info);
2239   static void print(bool print_stacks, bool internal_format) {
2240     // this function is only used by debug.cpp
2241     print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */, false /* simple format */);
2242   }
2243   static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
2244   static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
2245                              int buflen, bool* found_current);
2246   static void print_threads_compiling(outputStream* st, char* buf, int buflen);

2247 
2248   // Get Java threads that are waiting to enter a monitor.
2249   static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
2250                                                          int count, address monitor);
2251 
2252   // Get owning Java thread from the monitor's owner field.
2253   static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
2254                                                       address owner);
2255 
2256   // Number of threads on the active threads list
2257   static int number_of_threads()                 { return _number_of_threads; }
2258   // Number of non-daemon threads on the active threads list
2259   static int number_of_non_daemon_threads()      { return _number_of_non_daemon_threads; }
2260 
2261   // Deoptimizes all frames tied to marked nmethods
2262   static void deoptimized_wrt_marked_nmethods();
2263 };
2264 
2265 
2266 // Thread iterator


< prev index next >