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/threadLocalStorage.hpp"
46 #include "runtime/unhandledOops.hpp"
47 #include "utilities/align.hpp"
48 #include "utilities/exceptions.hpp"
49 #include "utilities/macros.hpp"
50 #ifdef ZERO
51 # include "stack_zero.hpp"
52 #endif
53 #if INCLUDE_JFR
54 #include "jfr/support/jfrThreadExtension.hpp"
55 #endif
56
57
58 class SafeThreadsListPtr;
59 class ThreadSafepointState;
60 class ThreadsList;
61 class ThreadsSMRSupport;
62
63 class JvmtiThreadState;
64 class JvmtiGetLoadedClassesClosure;
65 class ThreadStatistics;
66 class ConcurrentLocksDump;
67 class ParkEvent;
68 class Parker;
69
70 class ciEnv;
71 class CompileThread;
72 class CompileLog;
73 class CompileTask;
74 class CompileQueue;
75 class CompilerCounters;
322 //
323 // The two classes NoSafepointVerifier and No_Allocation_Verifier are used to set these counters.
324 //
325 NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen
326 debug_only(int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops.
327
328 // Used by SkipGCALot class.
329 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot?
330
331 friend class NoAllocVerifier;
332 friend class NoSafepointVerifier;
333 friend class PauseNoSafepointVerifier;
334 friend class GCLocker;
335
336 volatile void* _polling_page; // Thread local polling page
337
338 ThreadLocalAllocBuffer _tlab; // Thread-local eden
339 jlong _allocated_bytes; // Cumulative number of bytes allocated on
340 // the Java heap
341
342 JFR_ONLY(DEFINE_THREAD_LOCAL_FIELD_JFR;) // Thread-local data for jfr
343
344 int _vm_operation_started_count; // VM_Operation support
345 int _vm_operation_completed_count; // VM_Operation support
346
347 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
348 // is waiting to lock
349 bool _current_pending_monitor_is_from_java; // locking is from Java code
350
351 // ObjectMonitor on which this thread called Object.wait()
352 ObjectMonitor* _current_waiting_monitor;
353
354 // Private thread-local objectmonitor list - a simple cache organized as a SLL.
355 public:
356 ObjectMonitor* omFreeList;
357 int omFreeCount; // length of omFreeList
358 int omFreeProvision; // reload chunk size
359 ObjectMonitor* omInUseList; // SLL to track monitors in circulation
360 int omInUseCount; // length of omInUseList
361
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();
512 }
513 }
514
515 jlong allocated_bytes() { return _allocated_bytes; }
516 void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
517 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
518 inline jlong cooked_allocated_bytes();
519
520 JFR_ONLY(DEFINE_THREAD_LOCAL_ACCESSOR_JFR;)
521
522 bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; }
523
524 // VM operation support
525 int vm_operation_ticket() { return ++_vm_operation_started_count; }
526 int vm_operation_completed_count() { return _vm_operation_completed_count; }
527 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
528
529 // For tracking the heavyweight monitor the thread is pending on.
530 ObjectMonitor* current_pending_monitor() {
531 return _current_pending_monitor;
532 }
533 void set_current_pending_monitor(ObjectMonitor* monitor) {
534 _current_pending_monitor = monitor;
535 }
536 void set_current_pending_monitor_is_from_java(bool from_java) {
537 _current_pending_monitor_is_from_java = from_java;
538 }
539 bool current_pending_monitor_is_from_java() {
617 // Stack overflow support
618 address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
619 void set_stack_base(address base) { _stack_base = base; }
620 size_t stack_size() const { return _stack_size; }
621 void set_stack_size(size_t size) { _stack_size = size; }
622 address stack_end() const { return stack_base() - stack_size(); }
623 void record_stack_base_and_size();
624
625 bool on_local_stack(address adr) const {
626 // QQQ this has knowledge of direction, ought to be a stack method
627 return (_stack_base >= adr && adr >= stack_end());
628 }
629
630 uintptr_t self_raw_id() { return _self_raw_id; }
631 void set_self_raw_id(uintptr_t value) { _self_raw_id = value; }
632
633 int lgrp_id() const { return _lgrp_id; }
634 void set_lgrp_id(int value) { _lgrp_id = value; }
635
636 // Printing
637 virtual void print_on(outputStream* st) const;
638 void print() const { print_on(tty); }
639 virtual void print_on_error(outputStream* st, char* buf, int buflen) const;
640 void print_value_on(outputStream* st) const;
641
642 // Debug-only code
643 #ifdef ASSERT
644 private:
645 // Deadlock detection support for Mutex locks. List of locks own by thread.
646 Monitor* _owned_locks;
647 // Mutex::set_owner_implementation is the only place where _owned_locks is modified,
648 // thus the friendship
649 friend class Mutex;
650 friend class Monitor;
651
652 public:
653 void print_owned_locks_on(outputStream* st) const;
654 void print_owned_locks() const { print_owned_locks_on(tty); }
655 Monitor* owned_locks() const { return _owned_locks; }
656 bool owns_locks() const { return owned_locks() != NULL; }
657 bool owns_locks_but_compiled_lock() const;
1738
1739 private:
1740 void set_entry_point(ThreadFunction entry_point) { _entry_point = entry_point; }
1741
1742 public:
1743
1744 // Frame iteration; calls the function f for all frames on the stack
1745 void frames_do(void f(frame*, const RegisterMap*));
1746
1747 // Memory operations
1748 void oops_do(OopClosure* f, CodeBlobClosure* cf);
1749
1750 // Sweeper operations
1751 virtual void nmethods_do(CodeBlobClosure* cf);
1752
1753 // RedefineClasses Support
1754 void metadata_do(void f(Metadata*));
1755
1756 // Misc. operations
1757 char* name() const { return (char*)get_thread_name(); }
1758 void print_on(outputStream* st) const;
1759 void print_value();
1760 void print_thread_state_on(outputStream*) const PRODUCT_RETURN;
1761 void print_thread_state() const PRODUCT_RETURN;
1762 void print_on_error(outputStream* st, char* buf, int buflen) const;
1763 void print_name_on_error(outputStream* st, char* buf, int buflen) const;
1764 void verify();
1765 const char* get_thread_name() const;
1766 private:
1767 // factor out low-level mechanics for use in both normal and error cases
1768 const char* get_thread_name_string(char* buf = NULL, int buflen = 0) const;
1769 public:
1770 const char* get_threadgroup_name() const;
1771 const char* get_parent_name() const;
1772
1773 // Accessing frames
1774 frame last_frame() {
1775 _anchor.make_walkable(this);
1776 return pd_last_frame();
1777 }
1778 javaVFrame* last_java_vframe(RegisterMap* reg_map);
2152 // Apply "f->do_oop" to roots in all threads that
2153 // are part of compiled frames
2154 static void compiled_frame_oops_do(OopClosure* f, CodeBlobClosure* cf);
2155
2156 static void convert_hcode_pointers();
2157 static void restore_hcode_pointers();
2158
2159 // Sweeper
2160 static void nmethods_do(CodeBlobClosure* cf);
2161
2162 // RedefineClasses support
2163 static void metadata_do(void f(Metadata*));
2164 static void metadata_handles_do(void f(Metadata*));
2165
2166 #ifdef ASSERT
2167 static bool is_vm_complete() { return _vm_complete; }
2168 #endif
2169
2170 // Verification
2171 static void verify();
2172 static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks);
2173 static void print(bool print_stacks, bool internal_format) {
2174 // this function is only used by debug.cpp
2175 print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */);
2176 }
2177 static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
2178 static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
2179 int buflen, bool* found_current);
2180 static void print_threads_compiling(outputStream* st, char* buf, int buflen);
2181
2182 // Get Java threads that are waiting to enter a monitor.
2183 static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
2184 int count, address monitor);
2185
2186 // Get owning Java thread from the monitor's owner field.
2187 static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
2188 address owner);
2189
2190 // Number of threads on the active threads list
2191 static int number_of_threads() { return _number_of_threads; }
2192 // Number of non-daemon threads on the active threads list
2193 static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; }
2194
2195 // Deoptimizes all frames tied to marked nmethods
|
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/threadLocalStorage.hpp"
46 #include "runtime/unhandledOops.hpp"
47 #include "utilities/align.hpp"
48 #include "utilities/exceptions.hpp"
49 #include "utilities/macros.hpp"
50 #ifdef ZERO
51 # include "stack_zero.hpp"
52 #endif
53 #if INCLUDE_JFR
54 #include "jfr/support/jfrThreadExtension.hpp"
55 #endif
56 #include "runtime/threadStatisticInfo.hpp"
57
58
59 class SafeThreadsListPtr;
60 class ThreadSafepointState;
61 class ThreadsList;
62 class ThreadsSMRSupport;
63
64 class JvmtiThreadState;
65 class JvmtiGetLoadedClassesClosure;
66 class ThreadStatistics;
67 class ConcurrentLocksDump;
68 class ParkEvent;
69 class Parker;
70
71 class ciEnv;
72 class CompileThread;
73 class CompileLog;
74 class CompileTask;
75 class CompileQueue;
76 class CompilerCounters;
323 //
324 // The two classes NoSafepointVerifier and No_Allocation_Verifier are used to set these counters.
325 //
326 NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen
327 debug_only(int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops.
328
329 // Used by SkipGCALot class.
330 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot?
331
332 friend class NoAllocVerifier;
333 friend class NoSafepointVerifier;
334 friend class PauseNoSafepointVerifier;
335 friend class GCLocker;
336
337 volatile void* _polling_page; // Thread local polling page
338
339 ThreadLocalAllocBuffer _tlab; // Thread-local eden
340 jlong _allocated_bytes; // Cumulative number of bytes allocated on
341 // the Java heap
342
343 ThreadStatisticInfo _statistic_info; // Statistic info about the thread
344
345 JFR_ONLY(DEFINE_THREAD_LOCAL_FIELD_JFR;) // Thread-local data for jfr
346
347 int _vm_operation_started_count; // VM_Operation support
348 int _vm_operation_completed_count; // VM_Operation support
349
350 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
351 // is waiting to lock
352 bool _current_pending_monitor_is_from_java; // locking is from Java code
353
354 // ObjectMonitor on which this thread called Object.wait()
355 ObjectMonitor* _current_waiting_monitor;
356
357 // Private thread-local objectmonitor list - a simple cache organized as a SLL.
358 public:
359 ObjectMonitor* omFreeList;
360 int omFreeCount; // length of omFreeList
361 int omFreeProvision; // reload chunk size
362 ObjectMonitor* omInUseList; // SLL to track monitors in circulation
363 int omInUseCount; // length of omInUseList
364
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 jlong allocated_bytes() { return _allocated_bytes; }
519 void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
520 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
521 inline jlong cooked_allocated_bytes();
522
523 ThreadStatisticInfo& statistic_info() { return _statistic_info; }
524
525 JFR_ONLY(DEFINE_THREAD_LOCAL_ACCESSOR_JFR;)
526
527 bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; }
528
529 // VM operation support
530 int vm_operation_ticket() { return ++_vm_operation_started_count; }
531 int vm_operation_completed_count() { return _vm_operation_completed_count; }
532 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
533
534 // For tracking the heavyweight monitor the thread is pending on.
535 ObjectMonitor* current_pending_monitor() {
536 return _current_pending_monitor;
537 }
538 void set_current_pending_monitor(ObjectMonitor* monitor) {
539 _current_pending_monitor = monitor;
540 }
541 void set_current_pending_monitor_is_from_java(bool from_java) {
542 _current_pending_monitor_is_from_java = from_java;
543 }
544 bool current_pending_monitor_is_from_java() {
622 // Stack overflow support
623 address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
624 void set_stack_base(address base) { _stack_base = base; }
625 size_t stack_size() const { return _stack_size; }
626 void set_stack_size(size_t size) { _stack_size = size; }
627 address stack_end() const { return stack_base() - stack_size(); }
628 void record_stack_base_and_size();
629
630 bool on_local_stack(address adr) const {
631 // QQQ this has knowledge of direction, ought to be a stack method
632 return (_stack_base >= adr && adr >= stack_end());
633 }
634
635 uintptr_t self_raw_id() { return _self_raw_id; }
636 void set_self_raw_id(uintptr_t value) { _self_raw_id = value; }
637
638 int lgrp_id() const { return _lgrp_id; }
639 void set_lgrp_id(int value) { _lgrp_id = value; }
640
641 // Printing
642 void print_on(outputStream* st, bool extended_thread_info) const;
643 virtual void print_on(outputStream* st) const { print_on(st, false); }
644 void print() const { print_on(tty); }
645 virtual void print_on_error(outputStream* st, char* buf, int buflen) const;
646 void print_value_on(outputStream* st) const;
647
648 // Debug-only code
649 #ifdef ASSERT
650 private:
651 // Deadlock detection support for Mutex locks. List of locks own by thread.
652 Monitor* _owned_locks;
653 // Mutex::set_owner_implementation is the only place where _owned_locks is modified,
654 // thus the friendship
655 friend class Mutex;
656 friend class Monitor;
657
658 public:
659 void print_owned_locks_on(outputStream* st) const;
660 void print_owned_locks() const { print_owned_locks_on(tty); }
661 Monitor* owned_locks() const { return _owned_locks; }
662 bool owns_locks() const { return owned_locks() != NULL; }
663 bool owns_locks_but_compiled_lock() const;
1744
1745 private:
1746 void set_entry_point(ThreadFunction entry_point) { _entry_point = entry_point; }
1747
1748 public:
1749
1750 // Frame iteration; calls the function f for all frames on the stack
1751 void frames_do(void f(frame*, const RegisterMap*));
1752
1753 // Memory operations
1754 void oops_do(OopClosure* f, CodeBlobClosure* cf);
1755
1756 // Sweeper operations
1757 virtual void nmethods_do(CodeBlobClosure* cf);
1758
1759 // RedefineClasses Support
1760 void metadata_do(void f(Metadata*));
1761
1762 // Misc. operations
1763 char* name() const { return (char*)get_thread_name(); }
1764 void print_on(outputStream* st, bool extended_thread_info) const;
1765 void print_on(outputStream* st) const { print_on(st, false); }
1766 void print_value();
1767 void print_thread_state_on(outputStream*) const PRODUCT_RETURN;
1768 void print_thread_state() const PRODUCT_RETURN;
1769 void print_on_error(outputStream* st, char* buf, int buflen) const;
1770 void print_name_on_error(outputStream* st, char* buf, int buflen) const;
1771 void verify();
1772 const char* get_thread_name() const;
1773 private:
1774 // factor out low-level mechanics for use in both normal and error cases
1775 const char* get_thread_name_string(char* buf = NULL, int buflen = 0) const;
1776 public:
1777 const char* get_threadgroup_name() const;
1778 const char* get_parent_name() const;
1779
1780 // Accessing frames
1781 frame last_frame() {
1782 _anchor.make_walkable(this);
1783 return pd_last_frame();
1784 }
1785 javaVFrame* last_java_vframe(RegisterMap* reg_map);
2159 // Apply "f->do_oop" to roots in all threads that
2160 // are part of compiled frames
2161 static void compiled_frame_oops_do(OopClosure* f, CodeBlobClosure* cf);
2162
2163 static void convert_hcode_pointers();
2164 static void restore_hcode_pointers();
2165
2166 // Sweeper
2167 static void nmethods_do(CodeBlobClosure* cf);
2168
2169 // RedefineClasses support
2170 static void metadata_do(void f(Metadata*));
2171 static void metadata_handles_do(void f(Metadata*));
2172
2173 #ifdef ASSERT
2174 static bool is_vm_complete() { return _vm_complete; }
2175 #endif
2176
2177 // Verification
2178 static void verify();
2179 static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks, bool extended_thread_info);
2180 static void print(bool print_stacks, bool internal_format) {
2181 // this function is only used by debug.cpp
2182 print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */, false /* simple format */);
2183 }
2184 static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
2185 static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
2186 int buflen, bool* found_current);
2187 static void print_threads_compiling(outputStream* st, char* buf, int buflen);
2188
2189 // Get Java threads that are waiting to enter a monitor.
2190 static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
2191 int count, address monitor);
2192
2193 // Get owning Java thread from the monitor's owner field.
2194 static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
2195 address owner);
2196
2197 // Number of threads on the active threads list
2198 static int number_of_threads() { return _number_of_threads; }
2199 // Number of non-daemon threads on the active threads list
2200 static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; }
2201
2202 // Deoptimizes all frames tied to marked nmethods
|