< prev index next >

src/hotspot/share/runtime/thread.hpp

Print this page

  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 class SafeThreadsListPtr;
  58 class ThreadSafepointState;

1622   inline void set_done_attaching_via_jni();
1623 
1624   // Stack dump assistance:
1625   // Track the class we want to initialize but for which we have to wait
1626   // on its init_lock() because it is already being initialized.
1627   void set_class_to_be_initialized(InstanceKlass* k);
1628   InstanceKlass* class_to_be_initialized() const;
1629 
1630 private:
1631   InstanceKlass* _class_to_be_initialized;
1632 
1633   // java.lang.Thread.sleep support
1634   ParkEvent * _SleepEvent;
1635 public:
1636   bool sleep(jlong millis);
1637 
1638   // java.lang.Thread interruption support
1639   void interrupt();
1640   bool is_interrupted(bool clear_interrupted);
1641 













1642   static OopStorage* thread_oop_storage();
1643 
1644   static void verify_cross_modify_fence_failure(JavaThread *thread) PRODUCT_RETURN;
1645 
1646   // Helper function to start a VM-internal daemon thread.
1647   // E.g. ServiceThread, NotificationThread, CompilerThread etc.
1648   static void start_internal_daemon(JavaThread* current, JavaThread* target,
1649                                     Handle thread_oop, ThreadPriority prio);
1650 
1651   // Helper function to do vm_exit_on_initialization for osthread
1652   // resource allocation failure.
1653   static void vm_exit_on_osthread_failure(JavaThread* thread);
1654 
1655   // AsyncGetCallTrace support
1656   inline bool in_asgct(void) {return _in_asgct;}
1657   inline void set_in_asgct(bool value) {_in_asgct = value;}
1658 };
1659 
1660 // Inline implementation of JavaThread::current
1661 inline JavaThread* JavaThread::current() {

1754   // Verification
1755   static void verify();
1756   static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks, bool print_extended_info);
1757   static void print(bool print_stacks, bool internal_format) {
1758     // this function is only used by debug.cpp
1759     print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */, false /* simple format */);
1760   }
1761   static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
1762   static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
1763                              int buflen, bool* found_current);
1764   static void print_threads_compiling(outputStream* st, char* buf, int buflen, bool short_form = false);
1765 
1766   // Get Java threads that are waiting to enter a monitor.
1767   static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
1768                                                          int count, address monitor);
1769 
1770   // Get owning Java thread from the monitor's owner field.
1771   static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
1772                                                       address owner);
1773 



1774   // Number of threads on the active threads list
1775   static int number_of_threads()                 { return _number_of_threads; }
1776   // Number of non-daemon threads on the active threads list
1777   static int number_of_non_daemon_threads()      { return _number_of_non_daemon_threads; }
1778 
1779   // Deoptimizes all frames tied to marked nmethods
1780   static void deoptimized_wrt_marked_nmethods();
1781 
1782   struct Test;                  // For private gtest access.
1783 };
1784 
1785 class UnlockFlagSaver {
1786   private:
1787     JavaThread* _thread;
1788     bool _do_not_unlock;
1789   public:
1790     UnlockFlagSaver(JavaThread* t) {
1791       _thread = t;
1792       _do_not_unlock = t->do_not_unlock_if_synchronized();
1793       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 class SafeThreadsListPtr;
  59 class ThreadSafepointState;

1623   inline void set_done_attaching_via_jni();
1624 
1625   // Stack dump assistance:
1626   // Track the class we want to initialize but for which we have to wait
1627   // on its init_lock() because it is already being initialized.
1628   void set_class_to_be_initialized(InstanceKlass* k);
1629   InstanceKlass* class_to_be_initialized() const;
1630 
1631 private:
1632   InstanceKlass* _class_to_be_initialized;
1633 
1634   // java.lang.Thread.sleep support
1635   ParkEvent * _SleepEvent;
1636 public:
1637   bool sleep(jlong millis);
1638 
1639   // java.lang.Thread interruption support
1640   void interrupt();
1641   bool is_interrupted(bool clear_interrupted);
1642 
1643 private:
1644   LockStack _lock_stack;
1645 
1646 public:
1647   LockStack& lock_stack() { return _lock_stack; }
1648 
1649   static ByteSize lock_stack_offset()      { return byte_offset_of(JavaThread, _lock_stack); }
1650   // Those offsets are used in code generators to access the LockStack that is embedded in this
1651   // JavaThread structure. Those accesses are relative to the current thread, which
1652   // is typically in a dedicated register.
1653   static ByteSize lock_stack_top_offset()  { return lock_stack_offset() + LockStack::top_offset(); }
1654   static ByteSize lock_stack_base_offset() { return lock_stack_offset() + LockStack::base_offset(); }
1655 
1656   static OopStorage* thread_oop_storage();
1657 
1658   static void verify_cross_modify_fence_failure(JavaThread *thread) PRODUCT_RETURN;
1659 
1660   // Helper function to start a VM-internal daemon thread.
1661   // E.g. ServiceThread, NotificationThread, CompilerThread etc.
1662   static void start_internal_daemon(JavaThread* current, JavaThread* target,
1663                                     Handle thread_oop, ThreadPriority prio);
1664 
1665   // Helper function to do vm_exit_on_initialization for osthread
1666   // resource allocation failure.
1667   static void vm_exit_on_osthread_failure(JavaThread* thread);
1668 
1669   // AsyncGetCallTrace support
1670   inline bool in_asgct(void) {return _in_asgct;}
1671   inline void set_in_asgct(bool value) {_in_asgct = value;}
1672 };
1673 
1674 // Inline implementation of JavaThread::current
1675 inline JavaThread* JavaThread::current() {

1768   // Verification
1769   static void verify();
1770   static void print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks, bool print_extended_info);
1771   static void print(bool print_stacks, bool internal_format) {
1772     // this function is only used by debug.cpp
1773     print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */, false /* simple format */);
1774   }
1775   static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
1776   static void print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
1777                              int buflen, bool* found_current);
1778   static void print_threads_compiling(outputStream* st, char* buf, int buflen, bool short_form = false);
1779 
1780   // Get Java threads that are waiting to enter a monitor.
1781   static GrowableArray<JavaThread*>* get_pending_threads(ThreadsList * t_list,
1782                                                          int count, address monitor);
1783 
1784   // Get owning Java thread from the monitor's owner field.
1785   static JavaThread *owning_thread_from_monitor_owner(ThreadsList * t_list,
1786                                                       address owner);
1787 
1788   static JavaThread* owning_thread_from_object(ThreadsList* t_list, oop obj);
1789   static JavaThread* owning_thread_from_monitor(ThreadsList* t_list, ObjectMonitor* owner);
1790 
1791   // Number of threads on the active threads list
1792   static int number_of_threads()                 { return _number_of_threads; }
1793   // Number of non-daemon threads on the active threads list
1794   static int number_of_non_daemon_threads()      { return _number_of_non_daemon_threads; }
1795 
1796   // Deoptimizes all frames tied to marked nmethods
1797   static void deoptimized_wrt_marked_nmethods();
1798 
1799   struct Test;                  // For private gtest access.
1800 };
1801 
1802 class UnlockFlagSaver {
1803   private:
1804     JavaThread* _thread;
1805     bool _do_not_unlock;
1806   public:
1807     UnlockFlagSaver(JavaThread* t) {
1808       _thread = t;
1809       _do_not_unlock = t->do_not_unlock_if_synchronized();
1810       t->set_do_not_unlock_if_synchronized(false);
< prev index next >