src/share/vm/runtime/thread.hpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>


  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 #if INCLUDE_NMT
  47 #include "services/memRecorder.hpp"
  48 #endif // INCLUDE_NMT
  49 
  50 #include "trace/tracing.hpp"

  51 #include "utilities/exceptions.hpp"
  52 #include "utilities/top.hpp"
  53 #if INCLUDE_ALL_GCS
  54 #include "gc_implementation/g1/dirtyCardQueue.hpp"
  55 #include "gc_implementation/g1/satbQueue.hpp"
  56 #endif // INCLUDE_ALL_GCS
  57 #ifdef ZERO
  58 #ifdef TARGET_ARCH_zero
  59 # include "stack_zero.hpp"
  60 #endif
  61 #endif
  62 
  63 class ThreadSafepointState;
  64 class ThreadProfiler;
  65 
  66 class JvmtiThreadState;
  67 class JvmtiGetLoadedClassesClosure;
  68 class ThreadStatistics;
  69 class ConcurrentLocksDump;
  70 class ParkEvent;


 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   // Record when GC is locked out via the GC_locker mechanism
 249   CHECK_UNHANDLED_OOPS_ONLY(int _gc_locked_out_count;)
 250 
 251   friend class No_Alloc_Verifier;
 252   friend class No_Safepoint_Verifier;
 253   friend class Pause_No_Safepoint_Verifier;
 254   friend class ThreadLocalStorage;
 255   friend class GC_locker;
 256 
 257   ThreadLocalAllocBuffer _tlab;                 // Thread-local eden
 258   jlong _allocated_bytes;                       // Cumulative number of bytes allocated on
 259                                                 // the Java heap
 260 
 261   TRACE_BUFFER _trace_buffer;                   // Thread-local buffer for tracing
 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


 432       tlab().initialize();
 433     }
 434   }
 435 
 436   jlong allocated_bytes()               { return _allocated_bytes; }
 437   void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
 438   void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
 439   jlong cooked_allocated_bytes() {
 440     jlong allocated_bytes = OrderAccess::load_acquire(&_allocated_bytes);
 441     if (UseTLAB) {
 442       size_t used_bytes = tlab().used_bytes();
 443       if ((ssize_t)used_bytes > 0) {
 444         // More-or-less valid tlab.  The load_acquire above should ensure
 445         // that the result of the add is <= the instantaneous value
 446         return allocated_bytes + used_bytes;
 447       }
 448     }
 449     return allocated_bytes;
 450   }
 451 
 452   TRACE_BUFFER trace_buffer()              { return _trace_buffer; }
 453   void set_trace_buffer(TRACE_BUFFER buf)  { _trace_buffer = buf; }
 454 
 455   // VM operation support
 456   int vm_operation_ticket()                      { return ++_vm_operation_started_count; }
 457   int vm_operation_completed_count()             { return _vm_operation_completed_count; }
 458   void increment_vm_operation_completed_count()  { _vm_operation_completed_count++; }
 459 
 460   // For tracking the heavyweight monitor the thread is pending on.
 461   ObjectMonitor* current_pending_monitor() {
 462     return _current_pending_monitor;
 463   }
 464   void set_current_pending_monitor(ObjectMonitor* monitor) {
 465     _current_pending_monitor = monitor;
 466   }
 467   void set_current_pending_monitor_is_from_java(bool from_java) {
 468     _current_pending_monitor_is_from_java = from_java;
 469   }
 470   bool current_pending_monitor_is_from_java() {
 471     return _current_pending_monitor_is_from_java;
 472   }
 473 




  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 #if INCLUDE_NMT
  47 #include "services/memRecorder.hpp"
  48 #endif // INCLUDE_NMT
  49 
  50 #include "trace/traceBackend.hpp"
  51 #include "trace/traceMacros.hpp"
  52 #include "utilities/exceptions.hpp"
  53 #include "utilities/top.hpp"
  54 #if INCLUDE_ALL_GCS
  55 #include "gc_implementation/g1/dirtyCardQueue.hpp"
  56 #include "gc_implementation/g1/satbQueue.hpp"
  57 #endif // INCLUDE_ALL_GCS
  58 #ifdef ZERO
  59 #ifdef TARGET_ARCH_zero
  60 # include "stack_zero.hpp"
  61 #endif
  62 #endif
  63 
  64 class ThreadSafepointState;
  65 class ThreadProfiler;
  66 
  67 class JvmtiThreadState;
  68 class JvmtiGetLoadedClassesClosure;
  69 class ThreadStatistics;
  70 class ConcurrentLocksDump;
  71 class ParkEvent;


 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   // Record when GC is locked out via the GC_locker mechanism
 250   CHECK_UNHANDLED_OOPS_ONLY(int _gc_locked_out_count;)
 251 
 252   friend class No_Alloc_Verifier;
 253   friend class No_Safepoint_Verifier;
 254   friend class Pause_No_Safepoint_Verifier;
 255   friend class ThreadLocalStorage;
 256   friend class GC_locker;
 257 
 258   ThreadLocalAllocBuffer _tlab;                 // Thread-local eden
 259   jlong _allocated_bytes;                       // Cumulative number of bytes allocated on
 260                                                 // the Java heap
 261 
 262   TRACE_DATA _trace_data;                       // Thread-local data for tracing
 263 
 264   int   _vm_operation_started_count;            // VM_Operation support
 265   int   _vm_operation_completed_count;          // VM_Operation support
 266 
 267   ObjectMonitor* _current_pending_monitor;      // ObjectMonitor this thread
 268                                                 // is waiting to lock
 269   bool _current_pending_monitor_is_from_java;   // locking is from Java code
 270 
 271   // ObjectMonitor on which this thread called Object.wait()
 272   ObjectMonitor* _current_waiting_monitor;
 273 
 274   // Private thread-local objectmonitor list - a simple cache organized as a SLL.
 275  public:
 276   ObjectMonitor* omFreeList;
 277   int omFreeCount;                              // length of omFreeList
 278   int omFreeProvision;                          // reload chunk size
 279   ObjectMonitor* omInUseList;                   // SLL to track monitors in circulation
 280   int omInUseCount;                             // length of omInUseList
 281 
 282 #ifdef ASSERT


 433       tlab().initialize();
 434     }
 435   }
 436 
 437   jlong allocated_bytes()               { return _allocated_bytes; }
 438   void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
 439   void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
 440   jlong cooked_allocated_bytes() {
 441     jlong allocated_bytes = OrderAccess::load_acquire(&_allocated_bytes);
 442     if (UseTLAB) {
 443       size_t used_bytes = tlab().used_bytes();
 444       if ((ssize_t)used_bytes > 0) {
 445         // More-or-less valid tlab.  The load_acquire above should ensure
 446         // that the result of the add is <= the instantaneous value
 447         return allocated_bytes + used_bytes;
 448       }
 449     }
 450     return allocated_bytes;
 451   }
 452 
 453   TRACE_DATA* trace_data()              { return &_trace_data; }

 454 
 455   // VM operation support
 456   int vm_operation_ticket()                      { return ++_vm_operation_started_count; }
 457   int vm_operation_completed_count()             { return _vm_operation_completed_count; }
 458   void increment_vm_operation_completed_count()  { _vm_operation_completed_count++; }
 459 
 460   // For tracking the heavyweight monitor the thread is pending on.
 461   ObjectMonitor* current_pending_monitor() {
 462     return _current_pending_monitor;
 463   }
 464   void set_current_pending_monitor(ObjectMonitor* monitor) {
 465     _current_pending_monitor = monitor;
 466   }
 467   void set_current_pending_monitor_is_from_java(bool from_java) {
 468     _current_pending_monitor_is_from_java = from_java;
 469   }
 470   bool current_pending_monitor_is_from_java() {
 471     return _current_pending_monitor_is_from_java;
 472   }
 473