74 class CompileTask;
75 class CompileQueue;
76 class CompilerCounters;
77 class vframeArray;
78
79 class DeoptResourceMark;
80 class jvmtiDeferredLocalVariableSet;
81
82 class GCTaskQueue;
83 class ThreadClosure;
84 class IdealGraphPrinter;
85
86 class Metadata;
87 template <class T, MEMFLAGS F> class ChunkedList;
88 typedef ChunkedList<Metadata*, mtInternal> MetadataOnStackBuffer;
89
90 DEBUG_ONLY(class ResourceMark;)
91
92 class WorkerThread;
93
94 // Class hierarchy
95 // - Thread
96 // - NamedThread
97 // - VMThread
98 // - ConcurrentGCThread
99 // - WorkerThread
100 // - GangWorker
101 // - GCTaskThread
102 // - JavaThread
103 // - various subclasses eg CompilerThread, ServiceThread
104 // - WatcherThread
105
106 class Thread: public ThreadShadow {
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;
304 // If !allow_safepoint(), then an assertion failure will happen in any of the above cases
305 // If !allow_allocation(), then an assertion failure will happen during allocation
306 // (Hence, !allow_safepoint() => !allow_allocation()).
307 //
308 // The two classes NoSafepointVerifier and No_Allocation_Verifier are used to set these counters.
309 //
310 NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen
311 debug_only(int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops.
312
313 // Used by SkipGCALot class.
314 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot?
315
316 friend class NoAllocVerifier;
317 friend class NoSafepointVerifier;
318 friend class PauseNoSafepointVerifier;
319 friend class GCLocker;
320
321 volatile void* _polling_page; // Thread local polling page
322
323 ThreadLocalAllocBuffer _tlab; // Thread-local eden
324 ThreadLocalAllocBuffer _gclab; // Thread-local allocation buffer for GC (e.g. evacuation)
325 jlong _allocated_bytes; // Cumulative number of bytes allocated on
326 // the Java heap
327 jlong _allocated_bytes_gclab; // Cumulative number of bytes allocated on
328 // the Java heap, in GCLABs
329
330 mutable TRACE_DATA _trace_data; // Thread-local data for tracing
331
332 ThreadExt _ext;
333
334 int _vm_operation_started_count; // VM_Operation support
335 int _vm_operation_completed_count; // VM_Operation support
336
337 char _oom_during_evac;
338
339 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
340 // is waiting to lock
341 bool _current_pending_monitor_is_from_java; // locking is from Java code
342
343 // ObjectMonitor on which this thread called Object.wait()
344 ObjectMonitor* _current_waiting_monitor;
345
346 // Private thread-local objectmonitor list - a simple cache organized as a SLL.
347 public:
348 ObjectMonitor* omFreeList;
349 int omFreeCount; // length of omFreeList
491 OSThread* osthread() const { return _osthread; }
492 void set_osthread(OSThread* thread) { _osthread = thread; }
493
494 // JNI handle support
495 JNIHandleBlock* active_handles() const { return _active_handles; }
496 void set_active_handles(JNIHandleBlock* block) { _active_handles = block; }
497 JNIHandleBlock* free_handle_block() const { return _free_handle_block; }
498 void set_free_handle_block(JNIHandleBlock* block) { _free_handle_block = block; }
499
500 // Internal handle support
501 HandleArea* handle_area() const { return _handle_area; }
502 void set_handle_area(HandleArea* area) { _handle_area = area; }
503
504 GrowableArray<Metadata*>* metadata_handles() const { return _metadata_handles; }
505 void set_metadata_handles(GrowableArray<Metadata*>* handles){ _metadata_handles = handles; }
506
507 // Thread-Local Allocation Buffer (TLAB) support
508 ThreadLocalAllocBuffer& tlab() { return _tlab; }
509 void initialize_tlab() {
510 if (UseTLAB) {
511 tlab().initialize(false);
512 gclab().initialize(true);
513 }
514 }
515
516 // Thread-Local GC Allocation Buffer (GCLAB) support
517 ThreadLocalAllocBuffer& gclab() { return _gclab; }
518
519 jlong allocated_bytes() { return _allocated_bytes; }
520 void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
521 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
522 inline jlong cooked_allocated_bytes();
523
524 jlong allocated_bytes_gclab() { return _allocated_bytes_gclab; }
525 void set_allocated_bytes_gclab(jlong value) { _allocated_bytes_gclab = value; }
526 void incr_allocated_bytes_gclab(jlong size) { _allocated_bytes_gclab += size; }
527
528 TRACE_DEFINE_THREAD_TRACE_DATA_OFFSET;
529 TRACE_DATA* trace_data() const { return &_trace_data; }
530 bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; }
531
532 const ThreadExt& ext() const { return _ext; }
533 ThreadExt& ext() { return _ext; }
534
535 // VM operation support
536 int vm_operation_ticket() { return ++_vm_operation_started_count; }
537 int vm_operation_completed_count() { return _vm_operation_completed_count; }
538 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
539
540 // For tracking the heavyweight monitor the thread is pending on.
541 ObjectMonitor* current_pending_monitor() {
542 return _current_pending_monitor;
543 }
544 void set_current_pending_monitor(ObjectMonitor* monitor) {
545 _current_pending_monitor = monitor;
546 }
547 void set_current_pending_monitor_is_from_java(bool from_java) {
692
693 static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base); }
694 static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size); }
695
696 static ByteSize polling_page_offset() { return byte_offset_of(Thread, _polling_page); }
697
698 #define TLAB_FIELD_OFFSET(name) \
699 static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
700
701 TLAB_FIELD_OFFSET(start)
702 TLAB_FIELD_OFFSET(end)
703 TLAB_FIELD_OFFSET(top)
704 TLAB_FIELD_OFFSET(pf_top)
705 TLAB_FIELD_OFFSET(size) // desired_size
706 TLAB_FIELD_OFFSET(refill_waste_limit)
707 TLAB_FIELD_OFFSET(number_of_refills)
708 TLAB_FIELD_OFFSET(fast_refill_waste)
709 TLAB_FIELD_OFFSET(slow_allocations)
710
711 #undef TLAB_FIELD_OFFSET
712
713 static ByteSize gclab_start_offset() { return byte_offset_of(Thread, _gclab) + ThreadLocalAllocBuffer::start_offset(); }
714 static ByteSize gclab_top_offset() { return byte_offset_of(Thread, _gclab) + ThreadLocalAllocBuffer::top_offset(); }
715 static ByteSize gclab_end_offset() { return byte_offset_of(Thread, _gclab) + ThreadLocalAllocBuffer::end_offset(); }
716
717 static ByteSize allocated_bytes_offset() { return byte_offset_of(Thread, _allocated_bytes); }
718
719 public:
720 volatile intptr_t _Stalled;
721 volatile int _TypeTag;
722 ParkEvent * _ParkEvent; // for synchronized()
723 ParkEvent * _SleepEvent; // for Thread.sleep
724 ParkEvent * _MutexEvent; // for native internal Mutex/Monitor
725 ParkEvent * _MuxEvent; // for low-level muxAcquire-muxRelease
726 int NativeSyncRecursion; // diagnostic
727
728 volatile int _OnTrap; // Resume-at IP delta
729 jint _hashStateW; // Marsaglia Shift-XOR thread-local RNG
730 jint _hashStateX; // thread-specific hashCode generator state
731 jint _hashStateY;
732 jint _hashStateZ;
733 void * _schedctl;
734
735
|
74 class CompileTask;
75 class CompileQueue;
76 class CompilerCounters;
77 class vframeArray;
78
79 class DeoptResourceMark;
80 class jvmtiDeferredLocalVariableSet;
81
82 class GCTaskQueue;
83 class ThreadClosure;
84 class IdealGraphPrinter;
85
86 class Metadata;
87 template <class T, MEMFLAGS F> class ChunkedList;
88 typedef ChunkedList<Metadata*, mtInternal> MetadataOnStackBuffer;
89
90 DEBUG_ONLY(class ResourceMark;)
91
92 class WorkerThread;
93
94 #ifdef INCLUDE_ALL_GCS
95 class PLAB;
96 #endif
97
98 // Class hierarchy
99 // - Thread
100 // - NamedThread
101 // - VMThread
102 // - ConcurrentGCThread
103 // - WorkerThread
104 // - GangWorker
105 // - GCTaskThread
106 // - JavaThread
107 // - various subclasses eg CompilerThread, ServiceThread
108 // - WatcherThread
109
110 class Thread: public ThreadShadow {
111 friend class VMStructs;
112 friend class JVMCIVMStructs;
113 private:
114
115 #ifndef USE_LIBRARY_BASED_TLS_ONLY
116 // Current thread is maintained as a thread-local variable
117 static THREAD_LOCAL_DECL Thread* _thr_current;
308 // If !allow_safepoint(), then an assertion failure will happen in any of the above cases
309 // If !allow_allocation(), then an assertion failure will happen during allocation
310 // (Hence, !allow_safepoint() => !allow_allocation()).
311 //
312 // The two classes NoSafepointVerifier and No_Allocation_Verifier are used to set these counters.
313 //
314 NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen
315 debug_only(int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops.
316
317 // Used by SkipGCALot class.
318 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot?
319
320 friend class NoAllocVerifier;
321 friend class NoSafepointVerifier;
322 friend class PauseNoSafepointVerifier;
323 friend class GCLocker;
324
325 volatile void* _polling_page; // Thread local polling page
326
327 ThreadLocalAllocBuffer _tlab; // Thread-local eden
328 #ifdef INCLUDE_ALL_GCS
329 PLAB* _gclab; // Thread-local allocation buffer for GC (e.g. evacuation)
330 #endif
331 jlong _allocated_bytes; // Cumulative number of bytes allocated on
332 // the Java heap
333 mutable TRACE_DATA _trace_data; // Thread-local data for tracing
334
335 ThreadExt _ext;
336
337 int _vm_operation_started_count; // VM_Operation support
338 int _vm_operation_completed_count; // VM_Operation support
339
340 char _oom_during_evac;
341
342 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
343 // is waiting to lock
344 bool _current_pending_monitor_is_from_java; // locking is from Java code
345
346 // ObjectMonitor on which this thread called Object.wait()
347 ObjectMonitor* _current_waiting_monitor;
348
349 // Private thread-local objectmonitor list - a simple cache organized as a SLL.
350 public:
351 ObjectMonitor* omFreeList;
352 int omFreeCount; // length of omFreeList
494 OSThread* osthread() const { return _osthread; }
495 void set_osthread(OSThread* thread) { _osthread = thread; }
496
497 // JNI handle support
498 JNIHandleBlock* active_handles() const { return _active_handles; }
499 void set_active_handles(JNIHandleBlock* block) { _active_handles = block; }
500 JNIHandleBlock* free_handle_block() const { return _free_handle_block; }
501 void set_free_handle_block(JNIHandleBlock* block) { _free_handle_block = block; }
502
503 // Internal handle support
504 HandleArea* handle_area() const { return _handle_area; }
505 void set_handle_area(HandleArea* area) { _handle_area = area; }
506
507 GrowableArray<Metadata*>* metadata_handles() const { return _metadata_handles; }
508 void set_metadata_handles(GrowableArray<Metadata*>* handles){ _metadata_handles = handles; }
509
510 // Thread-Local Allocation Buffer (TLAB) support
511 ThreadLocalAllocBuffer& tlab() { return _tlab; }
512 void initialize_tlab() {
513 if (UseTLAB) {
514 tlab().initialize();
515 }
516 }
517
518 // Thread-Local GC Allocation Buffer (GCLAB) support
519 #ifdef INCLUDE_ALL_GCS
520 PLAB* gclab() { return _gclab; }
521 void set_gclab(PLAB* gclab) { _gclab = gclab; }
522 #endif
523 jlong allocated_bytes() { return _allocated_bytes; }
524 void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
525 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
526 inline jlong cooked_allocated_bytes();
527
528 TRACE_DEFINE_THREAD_TRACE_DATA_OFFSET;
529 TRACE_DATA* trace_data() const { return &_trace_data; }
530 bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; }
531
532 const ThreadExt& ext() const { return _ext; }
533 ThreadExt& ext() { return _ext; }
534
535 // VM operation support
536 int vm_operation_ticket() { return ++_vm_operation_started_count; }
537 int vm_operation_completed_count() { return _vm_operation_completed_count; }
538 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
539
540 // For tracking the heavyweight monitor the thread is pending on.
541 ObjectMonitor* current_pending_monitor() {
542 return _current_pending_monitor;
543 }
544 void set_current_pending_monitor(ObjectMonitor* monitor) {
545 _current_pending_monitor = monitor;
546 }
547 void set_current_pending_monitor_is_from_java(bool from_java) {
692
693 static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base); }
694 static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size); }
695
696 static ByteSize polling_page_offset() { return byte_offset_of(Thread, _polling_page); }
697
698 #define TLAB_FIELD_OFFSET(name) \
699 static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
700
701 TLAB_FIELD_OFFSET(start)
702 TLAB_FIELD_OFFSET(end)
703 TLAB_FIELD_OFFSET(top)
704 TLAB_FIELD_OFFSET(pf_top)
705 TLAB_FIELD_OFFSET(size) // desired_size
706 TLAB_FIELD_OFFSET(refill_waste_limit)
707 TLAB_FIELD_OFFSET(number_of_refills)
708 TLAB_FIELD_OFFSET(fast_refill_waste)
709 TLAB_FIELD_OFFSET(slow_allocations)
710
711 #undef TLAB_FIELD_OFFSET
712
713 static ByteSize allocated_bytes_offset() { return byte_offset_of(Thread, _allocated_bytes); }
714
715 public:
716 volatile intptr_t _Stalled;
717 volatile int _TypeTag;
718 ParkEvent * _ParkEvent; // for synchronized()
719 ParkEvent * _SleepEvent; // for Thread.sleep
720 ParkEvent * _MutexEvent; // for native internal Mutex/Monitor
721 ParkEvent * _MuxEvent; // for low-level muxAcquire-muxRelease
722 int NativeSyncRecursion; // diagnostic
723
724 volatile int _OnTrap; // Resume-at IP delta
725 jint _hashStateW; // Marsaglia Shift-XOR thread-local RNG
726 jint _hashStateX; // thread-specific hashCode generator state
727 jint _hashStateY;
728 jint _hashStateZ;
729 void * _schedctl;
730
731
|