src/share/vm/runtime/thread.hpp

Print this page
rev 6567 : Thread and management extension support.


  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREAD_HPP
  26 #define SHARE_VM_RUNTIME_THREAD_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/threadLocalAllocBuffer.hpp"
  30 #include "oops/oop.hpp"
  31 #include "prims/jni.h"
  32 #include "prims/jvmtiExport.hpp"
  33 #include "runtime/frame.hpp"
  34 #include "runtime/javaFrameAnchor.hpp"
  35 #include "runtime/jniHandles.hpp"
  36 #include "runtime/mutexLocker.hpp"
  37 #include "runtime/os.hpp"
  38 #include "runtime/osThread.hpp"
  39 #include "runtime/park.hpp"
  40 #include "runtime/safepoint.hpp"
  41 #include "runtime/stubRoutines.hpp"
  42 #include "runtime/threadLocalStorage.hpp"

  43 #include "runtime/unhandledOops.hpp"
  44 #include "utilities/macros.hpp"
  45 
  46 #include "trace/traceBackend.hpp"
  47 #include "trace/traceMacros.hpp"
  48 #include "utilities/exceptions.hpp"
  49 #include "utilities/top.hpp"
  50 #if INCLUDE_ALL_GCS
  51 #include "gc_implementation/g1/dirtyCardQueue.hpp"
  52 #include "gc_implementation/g1/satbQueue.hpp"
  53 #endif // INCLUDE_ALL_GCS
  54 #ifdef ZERO
  55 #ifdef TARGET_ARCH_zero
  56 # include "stack_zero.hpp"
  57 #endif
  58 #endif
  59 
  60 class ThreadSafepointState;
  61 class ThreadProfiler;
  62 


 240   // The two classes No_Safepoint_Verifier and No_Allocation_Verifier are used to set these counters.
 241   //
 242   NOT_PRODUCT(int _allow_safepoint_count;)      // If 0, thread allow a safepoint to happen
 243   debug_only (int _allow_allocation_count;)     // If 0, the thread is allowed to allocate oops.
 244 
 245   // Used by SkipGCALot class.
 246   NOT_PRODUCT(bool _skip_gcalot;)               // Should we elide gc-a-lot?
 247 
 248   friend class No_Alloc_Verifier;
 249   friend class No_Safepoint_Verifier;
 250   friend class Pause_No_Safepoint_Verifier;
 251   friend class ThreadLocalStorage;
 252   friend class GC_locker;
 253 
 254   ThreadLocalAllocBuffer _tlab;                 // Thread-local eden
 255   jlong _allocated_bytes;                       // Cumulative number of bytes allocated on
 256                                                 // the Java heap
 257 
 258   TRACE_DATA _trace_data;                       // Thread-local data for tracing
 259 


 260   int   _vm_operation_started_count;            // VM_Operation support
 261   int   _vm_operation_completed_count;          // VM_Operation support
 262 
 263   ObjectMonitor* _current_pending_monitor;      // ObjectMonitor this thread
 264                                                 // is waiting to lock
 265   bool _current_pending_monitor_is_from_java;   // locking is from Java code
 266 
 267   // ObjectMonitor on which this thread called Object.wait()
 268   ObjectMonitor* _current_waiting_monitor;
 269 
 270   // Private thread-local objectmonitor list - a simple cache organized as a SLL.
 271  public:
 272   ObjectMonitor* omFreeList;
 273   int omFreeCount;                              // length of omFreeList
 274   int omFreeProvision;                          // reload chunk size
 275   ObjectMonitor* omInUseList;                   // SLL to track monitors in circulation
 276   int omInUseCount;                             // length of omInUseList
 277 
 278 #ifdef ASSERT
 279  private:


 419   void set_handle_area(HandleArea* area)         { _handle_area = area; }
 420 
 421   GrowableArray<Metadata*>* metadata_handles() const          { return _metadata_handles; }
 422   void set_metadata_handles(GrowableArray<Metadata*>* handles){ _metadata_handles = handles; }
 423 
 424   // Thread-Local Allocation Buffer (TLAB) support
 425   ThreadLocalAllocBuffer& tlab()                 { return _tlab; }
 426   void initialize_tlab() {
 427     if (UseTLAB) {
 428       tlab().initialize();
 429     }
 430   }
 431 
 432   jlong allocated_bytes()               { return _allocated_bytes; }
 433   void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
 434   void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
 435   inline jlong cooked_allocated_bytes();
 436 
 437   TRACE_DATA* trace_data()              { return &_trace_data; }
 438 



 439   // VM operation support
 440   int vm_operation_ticket()                      { return ++_vm_operation_started_count; }
 441   int vm_operation_completed_count()             { return _vm_operation_completed_count; }
 442   void increment_vm_operation_completed_count()  { _vm_operation_completed_count++; }
 443 
 444   // For tracking the heavyweight monitor the thread is pending on.
 445   ObjectMonitor* current_pending_monitor() {
 446     return _current_pending_monitor;
 447   }
 448   void set_current_pending_monitor(ObjectMonitor* monitor) {
 449     _current_pending_monitor = monitor;
 450   }
 451   void set_current_pending_monitor_is_from_java(bool from_java) {
 452     _current_pending_monitor_is_from_java = from_java;
 453   }
 454   bool current_pending_monitor_is_from_java() {
 455     return _current_pending_monitor_is_from_java;
 456   }
 457 
 458   // For tracking the ObjectMonitor on which this thread called Object.wait()


 985   void cleanup_failed_attach_current_thread();
 986 
 987   // Testers
 988   virtual bool is_Java_thread() const            { return true;  }
 989 
 990   // Thread chain operations
 991   JavaThread* next() const                       { return _next; }
 992   void set_next(JavaThread* p)                   { _next = p; }
 993 
 994   // Thread oop. threadObj() can be NULL for initial JavaThread
 995   // (or for threads attached via JNI)
 996   oop threadObj() const                          { return _threadObj; }
 997   void set_threadObj(oop p)                      { _threadObj = p; }
 998 
 999   ThreadPriority java_priority() const;          // Read from threadObj()
1000 
1001   // Prepare thread and add to priority queue.  If a priority is
1002   // not specified, use the priority of the thread object. Threads_lock
1003   // must be held while this function is called.
1004   void prepare(jobject jni_thread, ThreadPriority prio=NoPriority);

1005 
1006   void set_saved_exception_pc(address pc)        { _saved_exception_pc = pc; }
1007   address saved_exception_pc()                   { return _saved_exception_pc; }
1008 
1009 
1010   ThreadFunction entry_point() const             { return _entry_point; }
1011 
1012   // Allocates a new Java level thread object for this thread. thread_name may be NULL.
1013   void allocate_threadObj(Handle thread_group, char* thread_name, bool daemon, TRAPS);
1014 
1015   // Last frame anchor routines
1016 
1017   JavaFrameAnchor* frame_anchor(void)            { return &_anchor; }
1018 
1019   // last_Java_sp
1020   bool has_last_Java_frame() const               { return _anchor.has_last_Java_frame(); }
1021   intptr_t* last_Java_sp() const                 { return _anchor.last_Java_sp(); }
1022 
1023   // last_Java_pc
1024 


1938 
1939   // Get Java threads that are waiting to enter a monitor. If doLock
1940   // is true, then Threads_lock is grabbed as needed. Otherwise, the
1941   // VM needs to be at a safepoint.
1942   static GrowableArray<JavaThread*>* get_pending_threads(int count,
1943     address monitor, bool doLock);
1944 
1945   // Get owning Java thread from the monitor's owner field. If doLock
1946   // is true, then Threads_lock is grabbed as needed. Otherwise, the
1947   // VM needs to be at a safepoint.
1948   static JavaThread *owning_thread_from_monitor_owner(address owner,
1949     bool doLock);
1950 
1951   // Number of threads on the active threads list
1952   static int number_of_threads()                 { return _number_of_threads; }
1953   // Number of non-daemon threads on the active threads list
1954   static int number_of_non_daemon_threads()      { return _number_of_non_daemon_threads; }
1955 
1956   // Deoptimizes all frames tied to marked nmethods
1957   static void deoptimized_wrt_marked_nmethods();


1958 
1959 };
1960 
1961 
1962 // Thread iterator
1963 class ThreadClosure: public StackObj {
1964  public:
1965   virtual void do_thread(Thread* thread) = 0;
1966 };
1967 
1968 class SignalHandlerMark: public StackObj {
1969 private:
1970   Thread* _thread;
1971 public:
1972   SignalHandlerMark(Thread* t) {
1973     _thread = t;
1974     if (_thread) _thread->enter_signal_handler();
1975   }
1976   ~SignalHandlerMark() {
1977     if (_thread) _thread->leave_signal_handler();


  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREAD_HPP
  26 #define SHARE_VM_RUNTIME_THREAD_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "memory/threadLocalAllocBuffer.hpp"
  30 #include "oops/oop.hpp"
  31 #include "prims/jni.h"
  32 #include "prims/jvmtiExport.hpp"
  33 #include "runtime/frame.hpp"
  34 #include "runtime/javaFrameAnchor.hpp"
  35 #include "runtime/jniHandles.hpp"
  36 #include "runtime/mutexLocker.hpp"
  37 #include "runtime/os.hpp"
  38 #include "runtime/osThread.hpp"
  39 #include "runtime/park.hpp"
  40 #include "runtime/safepoint.hpp"
  41 #include "runtime/stubRoutines.hpp"
  42 #include "runtime/threadLocalStorage.hpp"
  43 #include "runtime/thread_ext.hpp"
  44 #include "runtime/unhandledOops.hpp"
  45 #include "utilities/macros.hpp"
  46 
  47 #include "trace/traceBackend.hpp"
  48 #include "trace/traceMacros.hpp"
  49 #include "utilities/exceptions.hpp"
  50 #include "utilities/top.hpp"
  51 #if INCLUDE_ALL_GCS
  52 #include "gc_implementation/g1/dirtyCardQueue.hpp"
  53 #include "gc_implementation/g1/satbQueue.hpp"
  54 #endif // INCLUDE_ALL_GCS
  55 #ifdef ZERO
  56 #ifdef TARGET_ARCH_zero
  57 # include "stack_zero.hpp"
  58 #endif
  59 #endif
  60 
  61 class ThreadSafepointState;
  62 class ThreadProfiler;
  63 


 241   // The two classes No_Safepoint_Verifier and No_Allocation_Verifier are used to set these counters.
 242   //
 243   NOT_PRODUCT(int _allow_safepoint_count;)      // If 0, thread allow a safepoint to happen
 244   debug_only (int _allow_allocation_count;)     // If 0, the thread is allowed to allocate oops.
 245 
 246   // Used by SkipGCALot class.
 247   NOT_PRODUCT(bool _skip_gcalot;)               // Should we elide gc-a-lot?
 248 
 249   friend class No_Alloc_Verifier;
 250   friend class No_Safepoint_Verifier;
 251   friend class Pause_No_Safepoint_Verifier;
 252   friend class ThreadLocalStorage;
 253   friend class GC_locker;
 254 
 255   ThreadLocalAllocBuffer _tlab;                 // Thread-local eden
 256   jlong _allocated_bytes;                       // Cumulative number of bytes allocated on
 257                                                 // the Java heap
 258 
 259   TRACE_DATA _trace_data;                       // Thread-local data for tracing
 260 
 261   ThreadExt _ext;
 262 
 263   int   _vm_operation_started_count;            // VM_Operation support
 264   int   _vm_operation_completed_count;          // VM_Operation support
 265 
 266   ObjectMonitor* _current_pending_monitor;      // ObjectMonitor this thread
 267                                                 // is waiting to lock
 268   bool _current_pending_monitor_is_from_java;   // locking is from Java code
 269 
 270   // ObjectMonitor on which this thread called Object.wait()
 271   ObjectMonitor* _current_waiting_monitor;
 272 
 273   // Private thread-local objectmonitor list - a simple cache organized as a SLL.
 274  public:
 275   ObjectMonitor* omFreeList;
 276   int omFreeCount;                              // length of omFreeList
 277   int omFreeProvision;                          // reload chunk size
 278   ObjectMonitor* omInUseList;                   // SLL to track monitors in circulation
 279   int omInUseCount;                             // length of omInUseList
 280 
 281 #ifdef ASSERT
 282  private:


 422   void set_handle_area(HandleArea* area)         { _handle_area = area; }
 423 
 424   GrowableArray<Metadata*>* metadata_handles() const          { return _metadata_handles; }
 425   void set_metadata_handles(GrowableArray<Metadata*>* handles){ _metadata_handles = handles; }
 426 
 427   // Thread-Local Allocation Buffer (TLAB) support
 428   ThreadLocalAllocBuffer& tlab()                 { return _tlab; }
 429   void initialize_tlab() {
 430     if (UseTLAB) {
 431       tlab().initialize();
 432     }
 433   }
 434 
 435   jlong allocated_bytes()               { return _allocated_bytes; }
 436   void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
 437   void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
 438   inline jlong cooked_allocated_bytes();
 439 
 440   TRACE_DATA* trace_data()              { return &_trace_data; }
 441 
 442   const ThreadExt& ext() const          { return _ext; }
 443   ThreadExt& ext()                      { return _ext; }
 444 
 445   // VM operation support
 446   int vm_operation_ticket()                      { return ++_vm_operation_started_count; }
 447   int vm_operation_completed_count()             { return _vm_operation_completed_count; }
 448   void increment_vm_operation_completed_count()  { _vm_operation_completed_count++; }
 449 
 450   // For tracking the heavyweight monitor the thread is pending on.
 451   ObjectMonitor* current_pending_monitor() {
 452     return _current_pending_monitor;
 453   }
 454   void set_current_pending_monitor(ObjectMonitor* monitor) {
 455     _current_pending_monitor = monitor;
 456   }
 457   void set_current_pending_monitor_is_from_java(bool from_java) {
 458     _current_pending_monitor_is_from_java = from_java;
 459   }
 460   bool current_pending_monitor_is_from_java() {
 461     return _current_pending_monitor_is_from_java;
 462   }
 463 
 464   // For tracking the ObjectMonitor on which this thread called Object.wait()


 991   void cleanup_failed_attach_current_thread();
 992 
 993   // Testers
 994   virtual bool is_Java_thread() const            { return true;  }
 995 
 996   // Thread chain operations
 997   JavaThread* next() const                       { return _next; }
 998   void set_next(JavaThread* p)                   { _next = p; }
 999 
1000   // Thread oop. threadObj() can be NULL for initial JavaThread
1001   // (or for threads attached via JNI)
1002   oop threadObj() const                          { return _threadObj; }
1003   void set_threadObj(oop p)                      { _threadObj = p; }
1004 
1005   ThreadPriority java_priority() const;          // Read from threadObj()
1006 
1007   // Prepare thread and add to priority queue.  If a priority is
1008   // not specified, use the priority of the thread object. Threads_lock
1009   // must be held while this function is called.
1010   void prepare(jobject jni_thread, ThreadPriority prio=NoPriority);
1011   void prepare_ext();
1012 
1013   void set_saved_exception_pc(address pc)        { _saved_exception_pc = pc; }
1014   address saved_exception_pc()                   { return _saved_exception_pc; }
1015 
1016 
1017   ThreadFunction entry_point() const             { return _entry_point; }
1018 
1019   // Allocates a new Java level thread object for this thread. thread_name may be NULL.
1020   void allocate_threadObj(Handle thread_group, char* thread_name, bool daemon, TRAPS);
1021 
1022   // Last frame anchor routines
1023 
1024   JavaFrameAnchor* frame_anchor(void)            { return &_anchor; }
1025 
1026   // last_Java_sp
1027   bool has_last_Java_frame() const               { return _anchor.has_last_Java_frame(); }
1028   intptr_t* last_Java_sp() const                 { return _anchor.last_Java_sp(); }
1029 
1030   // last_Java_pc
1031 


1945 
1946   // Get Java threads that are waiting to enter a monitor. If doLock
1947   // is true, then Threads_lock is grabbed as needed. Otherwise, the
1948   // VM needs to be at a safepoint.
1949   static GrowableArray<JavaThread*>* get_pending_threads(int count,
1950     address monitor, bool doLock);
1951 
1952   // Get owning Java thread from the monitor's owner field. If doLock
1953   // is true, then Threads_lock is grabbed as needed. Otherwise, the
1954   // VM needs to be at a safepoint.
1955   static JavaThread *owning_thread_from_monitor_owner(address owner,
1956     bool doLock);
1957 
1958   // Number of threads on the active threads list
1959   static int number_of_threads()                 { return _number_of_threads; }
1960   // Number of non-daemon threads on the active threads list
1961   static int number_of_non_daemon_threads()      { return _number_of_non_daemon_threads; }
1962 
1963   // Deoptimizes all frames tied to marked nmethods
1964   static void deoptimized_wrt_marked_nmethods();
1965 
1966   static JavaThread* find_java_thread_from_java_tid(jlong java_tid);
1967 
1968 };
1969 
1970 
1971 // Thread iterator
1972 class ThreadClosure: public StackObj {
1973  public:
1974   virtual void do_thread(Thread* thread) = 0;
1975 };
1976 
1977 class SignalHandlerMark: public StackObj {
1978 private:
1979   Thread* _thread;
1980 public:
1981   SignalHandlerMark(Thread* t) {
1982     _thread = t;
1983     if (_thread) _thread->enter_signal_handler();
1984   }
1985   ~SignalHandlerMark() {
1986     if (_thread) _thread->leave_signal_handler();