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