19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef SHARE_RUNTIME_THREAD_HPP
27 #define SHARE_RUNTIME_THREAD_HPP
28
29 #include "jni.h"
30 #include "gc/shared/gcThreadLocalData.hpp"
31 #include "gc/shared/threadLocalAllocBuffer.hpp"
32 #include "memory/allocation.hpp"
33 #include "oops/oop.hpp"
34 #include "oops/oopHandle.hpp"
35 #include "runtime/frame.hpp"
36 #include "runtime/globals.hpp"
37 #include "runtime/handshake.hpp"
38 #include "runtime/javaFrameAnchor.hpp"
39 #include "runtime/mutexLocker.hpp"
40 #include "runtime/os.hpp"
41 #include "runtime/park.hpp"
42 #include "runtime/safepointMechanism.hpp"
43 #include "runtime/stackWatermarkSet.hpp"
44 #include "runtime/stackOverflow.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/globalDefinitions.hpp"
52 #include "utilities/macros.hpp"
53 #if INCLUDE_JFR
54 #include "jfr/support/jfrThreadExtension.hpp"
55 #endif
56
57
58 class SafeThreadsListPtr;
1594 inline void set_done_attaching_via_jni();
1595
1596 // Stack dump assistance:
1597 // Track the class we want to initialize but for which we have to wait
1598 // on its init_lock() because it is already being initialized.
1599 void set_class_to_be_initialized(InstanceKlass* k);
1600 InstanceKlass* class_to_be_initialized() const;
1601
1602 private:
1603 InstanceKlass* _class_to_be_initialized;
1604
1605 // java.lang.Thread.sleep support
1606 ParkEvent * _SleepEvent;
1607 public:
1608 bool sleep(jlong millis);
1609
1610 // java.lang.Thread interruption support
1611 void interrupt();
1612 bool is_interrupted(bool clear_interrupted);
1613
1614 static OopStorage* thread_oop_storage();
1615
1616 static void verify_cross_modify_fence_failure(JavaThread *thread) PRODUCT_RETURN;
1617
1618 // AsyncGetCallTrace support
1619 inline bool in_asgct(void) {return _in_asgct;}
1620 inline void set_in_asgct(bool value) {_in_asgct = value;}
1621 };
1622
1623 // Inline implementation of JavaThread::current
1624 inline JavaThread* JavaThread::current() {
1625 return Thread::current()->as_Java_thread();
1626 }
1627
1628 inline JavaThread* JavaThread::current_or_null() {
1629 Thread* current = Thread::current_or_null();
1630 return current != nullptr ? current->as_Java_thread() : nullptr;
1631 }
1632
1633 inline JavaThread* Thread::as_Java_thread() {
1717 // Verification
1718 static void verify();
1719 static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks, bool print_extended_info);
1720 static void print(bool print_stacks, bool internal_format) {
1721 // this function is only used by debug.cpp
1722 print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */, false /* simple format */);
1723 }
1724 static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
1725 static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
1726 int buflen, bool* found_current);
1727 static void print_threads_compiling(outputStream* st, char* buf, int buflen, bool short_form = false);
1728
1729 // Get Java threads that are waiting to enter a monitor.
1730 static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
1731 int count, address monitor);
1732
1733 // Get owning Java thread from the monitor's owner field.
1734 static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
1735 address owner);
1736
1737 // Number of threads on the active threads list
1738 static int number_of_threads() { return _number_of_threads; }
1739 // Number of non-daemon threads on the active threads list
1740 static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; }
1741
1742 // Deoptimizes all frames tied to marked nmethods
1743 static void deoptimized_wrt_marked_nmethods();
1744
1745 struct Test; // For private gtest access.
1746 };
1747
1748 class UnlockFlagSaver {
1749 private:
1750 JavaThread* _thread;
1751 bool _do_not_unlock;
1752 public:
1753 UnlockFlagSaver(JavaThread* t) {
1754 _thread = t;
1755 _do_not_unlock = t->do_not_unlock_if_synchronized();
1756 t->set_do_not_unlock_if_synchronized(false);
|
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef SHARE_RUNTIME_THREAD_HPP
27 #define SHARE_RUNTIME_THREAD_HPP
28
29 #include "jni.h"
30 #include "gc/shared/gcThreadLocalData.hpp"
31 #include "gc/shared/threadLocalAllocBuffer.hpp"
32 #include "memory/allocation.hpp"
33 #include "oops/oop.hpp"
34 #include "oops/oopHandle.hpp"
35 #include "runtime/frame.hpp"
36 #include "runtime/globals.hpp"
37 #include "runtime/handshake.hpp"
38 #include "runtime/javaFrameAnchor.hpp"
39 #include "runtime/lockStack.hpp"
40 #include "runtime/mutexLocker.hpp"
41 #include "runtime/os.hpp"
42 #include "runtime/park.hpp"
43 #include "runtime/safepointMechanism.hpp"
44 #include "runtime/stackWatermarkSet.hpp"
45 #include "runtime/stackOverflow.hpp"
46 #include "runtime/threadHeapSampler.hpp"
47 #include "runtime/threadLocalStorage.hpp"
48 #include "runtime/threadStatisticalInfo.hpp"
49 #include "runtime/unhandledOops.hpp"
50 #include "utilities/align.hpp"
51 #include "utilities/exceptions.hpp"
52 #include "utilities/globalDefinitions.hpp"
53 #include "utilities/macros.hpp"
54 #if INCLUDE_JFR
55 #include "jfr/support/jfrThreadExtension.hpp"
56 #endif
57
58
59 class SafeThreadsListPtr;
1595 inline void set_done_attaching_via_jni();
1596
1597 // Stack dump assistance:
1598 // Track the class we want to initialize but for which we have to wait
1599 // on its init_lock() because it is already being initialized.
1600 void set_class_to_be_initialized(InstanceKlass* k);
1601 InstanceKlass* class_to_be_initialized() const;
1602
1603 private:
1604 InstanceKlass* _class_to_be_initialized;
1605
1606 // java.lang.Thread.sleep support
1607 ParkEvent * _SleepEvent;
1608 public:
1609 bool sleep(jlong millis);
1610
1611 // java.lang.Thread interruption support
1612 void interrupt();
1613 bool is_interrupted(bool clear_interrupted);
1614
1615 private:
1616 LockStack _lock_stack;
1617
1618 public:
1619 LockStack& lock_stack() { return _lock_stack; }
1620
1621 static ByteSize lock_stack_offset() { return byte_offset_of(JavaThread, _lock_stack); }
1622 // Those offsets are used in code generators to access the LockStack that is embedded in this
1623 // JavaThread structure. Those accesses are relative to the current thread, which
1624 // is typically in a dedicated register.
1625 static ByteSize lock_stack_top_offset() { return lock_stack_offset() + LockStack::top_offset(); }
1626 static ByteSize lock_stack_base_offset() { return lock_stack_offset() + LockStack::base_offset(); }
1627
1628 static OopStorage* thread_oop_storage();
1629
1630 static void verify_cross_modify_fence_failure(JavaThread *thread) PRODUCT_RETURN;
1631
1632 // AsyncGetCallTrace support
1633 inline bool in_asgct(void) {return _in_asgct;}
1634 inline void set_in_asgct(bool value) {_in_asgct = value;}
1635 };
1636
1637 // Inline implementation of JavaThread::current
1638 inline JavaThread* JavaThread::current() {
1639 return Thread::current()->as_Java_thread();
1640 }
1641
1642 inline JavaThread* JavaThread::current_or_null() {
1643 Thread* current = Thread::current_or_null();
1644 return current != nullptr ? current->as_Java_thread() : nullptr;
1645 }
1646
1647 inline JavaThread* Thread::as_Java_thread() {
1731 // Verification
1732 static void verify();
1733 static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks, bool print_extended_info);
1734 static void print(bool print_stacks, bool internal_format) {
1735 // this function is only used by debug.cpp
1736 print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */, false /* simple format */);
1737 }
1738 static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
1739 static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
1740 int buflen, bool* found_current);
1741 static void print_threads_compiling(outputStream* st, char* buf, int buflen, bool short_form = false);
1742
1743 // Get Java threads that are waiting to enter a monitor.
1744 static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
1745 int count, address monitor);
1746
1747 // Get owning Java thread from the monitor's owner field.
1748 static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
1749 address owner);
1750
1751 static JavaThread* owning_thread_from_object(ThreadsList* t_list, oop obj);
1752 static JavaThread* owning_thread_from_monitor(ThreadsList* t_list, ObjectMonitor* owner);
1753
1754 // Number of threads on the active threads list
1755 static int number_of_threads() { return _number_of_threads; }
1756 // Number of non-daemon threads on the active threads list
1757 static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; }
1758
1759 // Deoptimizes all frames tied to marked nmethods
1760 static void deoptimized_wrt_marked_nmethods();
1761
1762 struct Test; // For private gtest access.
1763 };
1764
1765 class UnlockFlagSaver {
1766 private:
1767 JavaThread* _thread;
1768 bool _do_not_unlock;
1769 public:
1770 UnlockFlagSaver(JavaThread* t) {
1771 _thread = t;
1772 _do_not_unlock = t->do_not_unlock_if_synchronized();
1773 t->set_do_not_unlock_if_synchronized(false);
|