< prev index next >

src/hotspot/share/runtime/thread.hpp

Print this page

 425  public:
 426   void set_visited_for_critical_count(uint64_t safepoint_id) {
 427     assert(_visited_for_critical_count == 0, "Must be reset before set");
 428     assert((safepoint_id & 0x1) == 1, "Must be odd");
 429     _visited_for_critical_count = safepoint_id;
 430   }
 431   void reset_visited_for_critical_count(uint64_t safepoint_id) {
 432     assert(_visited_for_critical_count == safepoint_id, "Was not visited");
 433     _visited_for_critical_count = 0;
 434   }
 435   bool was_visited_for_critical_count(uint64_t safepoint_id) const {
 436     return _visited_for_critical_count == safepoint_id;
 437   }
 438 #endif
 439 
 440  public:
 441   enum {
 442     is_definitely_current_thread = true
 443   };
 444 

 445   // Constructor
 446   Thread();
 447   virtual ~Thread() = 0;        // Thread is abstract.
 448 
 449   // Manage Thread::current()
 450   void initialize_thread_current();
 451   static void clear_thread_current(); // TLS cleanup needed before threads terminate
 452 
 453  protected:
 454   // To be implemented by children.
 455   virtual void run() = 0;
 456   virtual void pre_run() = 0;
 457   virtual void post_run() = 0;  // Note: Thread must not be deleted prior to calling this!
 458 
 459 #ifdef ASSERT
 460   enum RunState {
 461     PRE_CALL_RUN,
 462     CALL_RUN,
 463     PRE_RUN,
 464     RUN,

 997 
 998   // Create and start the single instance of WatcherThread, or stop it on shutdown
 999   static void start();
1000   static void stop();
1001   // Only allow start once the VM is sufficiently initialized
1002   // Otherwise the first task to enroll will trigger the start
1003   static void make_startable();
1004  private:
1005   int sleep() const;
1006 };
1007 
1008 
1009 class CompilerThread;
1010 
1011 typedef void (*ThreadFunction)(JavaThread*, TRAPS);
1012 
1013 class JavaThread: public Thread {
1014   friend class VMStructs;
1015   friend class JVMCIVMStructs;
1016   friend class WhiteBox;

1017   friend class ThreadsSMRSupport; // to access _threadObj for exiting_threads_oops_do
1018  private:
1019   bool           _on_thread_list;                // Is set when this JavaThread is added to the Threads list
1020   oop            _threadObj;                     // The Java level thread object
1021 
1022 #ifdef ASSERT
1023  private:
1024   int _java_call_counter;
1025 
1026  public:
1027   int  java_call_counter()                       { return _java_call_counter; }
1028   void inc_java_call_counter()                   { _java_call_counter++; }
1029   void dec_java_call_counter() {
1030     assert(_java_call_counter > 0, "Invalid nesting of JavaCallWrapper");
1031     _java_call_counter--;
1032   }
1033  private:  // restore original namespace restriction
1034 #endif  // ifdef ASSERT
1035 
1036 #ifndef PRODUCT

1055   vframeArray*  _vframe_array_last;              // Holds last vFrameArray we popped
1056   // Because deoptimization is lazy we must save jvmti requests to set locals
1057   // in compiled frames until we deoptimize and we have an interpreter frame.
1058   // This holds the pointer to array (yeah like there might be more than one) of
1059   // description of compiled vframes that have locals that need to be updated.
1060   GrowableArray<jvmtiDeferredLocalVariableSet*>* _deferred_locals_updates;
1061 
1062   // Handshake value for fixing 6243940. We need a place for the i2c
1063   // adapter to store the callee Method*. This value is NEVER live
1064   // across a gc point so it does NOT have to be gc'd
1065   // The handshake is open ended since we can't be certain that it will
1066   // be NULLed. This is because we rarely ever see the race and end up
1067   // in handle_wrong_method which is the backend of the handshake. See
1068   // code in i2c adapters and handle_wrong_method.
1069 
1070   Method*       _callee_target;
1071 
1072   // Used to pass back results to the interpreter or generated code running Java code.
1073   oop           _vm_result;    // oop result is GC-preserved
1074   Metadata*     _vm_result_2;  // non-oop result

1075 
1076   // See ReduceInitialCardMarks: this holds the precise space interval of
1077   // the most recent slow path allocation for which compiled code has
1078   // elided card-marks for performance along the fast-path.
1079   MemRegion     _deferred_card_mark;
1080 
1081   MonitorChunk* _monitor_chunks;                 // Contains the off stack monitors
1082                                                  // allocated during deoptimization
1083                                                  // and by JNI_MonitorEnter/Exit
1084 
1085   // Async. requests support
1086   enum AsyncRequests {
1087     _no_async_condition = 0,
1088     _async_exception,
1089     _async_unsafe_access_error
1090   };
1091   AsyncRequests _special_runtime_exit_condition; // Enum indicating pending async. request
1092   oop           _pending_async_exception;
1093 
1094   // Safepoint support

1535   vframeArray* vframe_array_last() const         { return _vframe_array_last;  }
1536 
1537   // The special resourceMark used during deoptimization
1538 
1539   void set_deopt_mark(DeoptResourceMark* value)  { _deopt_mark = value; }
1540   DeoptResourceMark* deopt_mark(void)            { return _deopt_mark; }
1541 
1542   void set_deopt_compiled_method(CompiledMethod* nm)  { _deopt_nmethod = nm; }
1543   CompiledMethod* deopt_compiled_method()        { return _deopt_nmethod; }
1544 
1545   Method*    callee_target() const               { return _callee_target; }
1546   void set_callee_target  (Method* x)          { _callee_target   = x; }
1547 
1548   // Oop results of vm runtime calls
1549   oop  vm_result() const                         { return _vm_result; }
1550   void set_vm_result  (oop x)                    { _vm_result   = x; }
1551 
1552   Metadata*    vm_result_2() const               { return _vm_result_2; }
1553   void set_vm_result_2  (Metadata* x)          { _vm_result_2   = x; }
1554 



1555   MemRegion deferred_card_mark() const           { return _deferred_card_mark; }
1556   void set_deferred_card_mark(MemRegion mr)      { _deferred_card_mark = mr;   }
1557 
1558 #if INCLUDE_JVMCI
1559   int  pending_deoptimization() const             { return _pending_deoptimization; }
1560   jlong pending_failed_speculation() const        { return _pending_failed_speculation; }
1561   bool has_pending_monitorenter() const           { return _pending_monitorenter; }
1562   void set_pending_monitorenter(bool b)           { _pending_monitorenter = b; }
1563   void set_pending_deoptimization(int reason)     { _pending_deoptimization = reason; }
1564   void set_pending_failed_speculation(jlong failed_speculation) { _pending_failed_speculation = failed_speculation; }
1565   void set_pending_transfer_to_interpreter(bool b) { _pending_transfer_to_interpreter = b; }
1566   void set_jvmci_alternate_call_target(address a) { assert(_jvmci._alternate_call_target == NULL, "must be"); _jvmci._alternate_call_target = a; }
1567   void set_jvmci_implicit_exception_pc(address a) { assert(_jvmci._implicit_exception_pc == NULL, "must be"); _jvmci._implicit_exception_pc = a; }
1568 
1569   virtual bool in_retryable_allocation() const    { return _in_retryable_allocation; }
1570   void set_in_retryable_allocation(bool b)        { _in_retryable_allocation = b; }
1571 #endif // INCLUDE_JVMCI
1572 
1573   // Exception handling for compiled methods
1574   oop      exception_oop() const;

1774   bool do_not_unlock(void)                       { return _do_not_unlock_if_synchronized; }
1775 
1776   // For assembly stub generation
1777   static ByteSize threadObj_offset()             { return byte_offset_of(JavaThread, _threadObj); }
1778   static ByteSize jni_environment_offset()       { return byte_offset_of(JavaThread, _jni_environment); }
1779   static ByteSize pending_jni_exception_check_fn_offset() {
1780     return byte_offset_of(JavaThread, _pending_jni_exception_check_fn);
1781   }
1782   static ByteSize last_Java_sp_offset() {
1783     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1784   }
1785   static ByteSize last_Java_pc_offset() {
1786     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1787   }
1788   static ByteSize frame_anchor_offset() {
1789     return byte_offset_of(JavaThread, _anchor);
1790   }
1791   static ByteSize callee_target_offset()         { return byte_offset_of(JavaThread, _callee_target); }
1792   static ByteSize vm_result_offset()             { return byte_offset_of(JavaThread, _vm_result); }
1793   static ByteSize vm_result_2_offset()           { return byte_offset_of(JavaThread, _vm_result_2); }

1794   static ByteSize thread_state_offset()          { return byte_offset_of(JavaThread, _thread_state); }
1795   static ByteSize saved_exception_pc_offset()    { return byte_offset_of(JavaThread, _saved_exception_pc); }
1796   static ByteSize osthread_offset()              { return byte_offset_of(JavaThread, _osthread); }
1797 #if INCLUDE_JVMCI
1798   static ByteSize pending_deoptimization_offset() { return byte_offset_of(JavaThread, _pending_deoptimization); }
1799   static ByteSize pending_monitorenter_offset()  { return byte_offset_of(JavaThread, _pending_monitorenter); }
1800   static ByteSize pending_failed_speculation_offset() { return byte_offset_of(JavaThread, _pending_failed_speculation); }
1801   static ByteSize jvmci_alternate_call_target_offset() { return byte_offset_of(JavaThread, _jvmci._alternate_call_target); }
1802   static ByteSize jvmci_implicit_exception_pc_offset() { return byte_offset_of(JavaThread, _jvmci._implicit_exception_pc); }
1803   static ByteSize jvmci_counters_offset()        { return byte_offset_of(JavaThread, _jvmci_counters); }
1804 #endif // INCLUDE_JVMCI
1805   static ByteSize exception_oop_offset()         { return byte_offset_of(JavaThread, _exception_oop); }
1806   static ByteSize exception_pc_offset()          { return byte_offset_of(JavaThread, _exception_pc); }
1807   static ByteSize exception_handler_pc_offset()  { return byte_offset_of(JavaThread, _exception_handler_pc); }
1808   static ByteSize stack_overflow_limit_offset()  { return byte_offset_of(JavaThread, _stack_overflow_limit); }
1809   static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
1810   static ByteSize stack_guard_state_offset()     { return byte_offset_of(JavaThread, _stack_guard_state); }
1811   static ByteSize reserved_stack_activation_offset() { return byte_offset_of(JavaThread, _reserved_stack_activation); }
1812   static ByteSize suspend_flags_offset()         { return byte_offset_of(JavaThread, _suspend_flags); }
1813 

 425  public:
 426   void set_visited_for_critical_count(uint64_t safepoint_id) {
 427     assert(_visited_for_critical_count == 0, "Must be reset before set");
 428     assert((safepoint_id & 0x1) == 1, "Must be odd");
 429     _visited_for_critical_count = safepoint_id;
 430   }
 431   void reset_visited_for_critical_count(uint64_t safepoint_id) {
 432     assert(_visited_for_critical_count == safepoint_id, "Was not visited");
 433     _visited_for_critical_count = 0;
 434   }
 435   bool was_visited_for_critical_count(uint64_t safepoint_id) const {
 436     return _visited_for_critical_count == safepoint_id;
 437   }
 438 #endif
 439 
 440  public:
 441   enum {
 442     is_definitely_current_thread = true
 443   };
 444 
 445  public:
 446   // Constructor
 447   Thread();
 448   virtual ~Thread() = 0;        // Thread is abstract.
 449 
 450   // Manage Thread::current()
 451   void initialize_thread_current();
 452   static void clear_thread_current(); // TLS cleanup needed before threads terminate
 453 
 454  protected:
 455   // To be implemented by children.
 456   virtual void run() = 0;
 457   virtual void pre_run() = 0;
 458   virtual void post_run() = 0;  // Note: Thread must not be deleted prior to calling this!
 459 
 460 #ifdef ASSERT
 461   enum RunState {
 462     PRE_CALL_RUN,
 463     CALL_RUN,
 464     PRE_RUN,
 465     RUN,

 998 
 999   // Create and start the single instance of WatcherThread, or stop it on shutdown
1000   static void start();
1001   static void stop();
1002   // Only allow start once the VM is sufficiently initialized
1003   // Otherwise the first task to enroll will trigger the start
1004   static void make_startable();
1005  private:
1006   int sleep() const;
1007 };
1008 
1009 
1010 class CompilerThread;
1011 
1012 typedef void (*ThreadFunction)(JavaThread*, TRAPS);
1013 
1014 class JavaThread: public Thread {
1015   friend class VMStructs;
1016   friend class JVMCIVMStructs;
1017   friend class WhiteBox;
1018   friend class VTBuffer;
1019   friend class ThreadsSMRSupport; // to access _threadObj for exiting_threads_oops_do
1020  private:
1021   bool           _on_thread_list;                // Is set when this JavaThread is added to the Threads list
1022   oop            _threadObj;                     // The Java level thread object
1023 
1024 #ifdef ASSERT
1025  private:
1026   int _java_call_counter;
1027 
1028  public:
1029   int  java_call_counter()                       { return _java_call_counter; }
1030   void inc_java_call_counter()                   { _java_call_counter++; }
1031   void dec_java_call_counter() {
1032     assert(_java_call_counter > 0, "Invalid nesting of JavaCallWrapper");
1033     _java_call_counter--;
1034   }
1035  private:  // restore original namespace restriction
1036 #endif  // ifdef ASSERT
1037 
1038 #ifndef PRODUCT

1057   vframeArray*  _vframe_array_last;              // Holds last vFrameArray we popped
1058   // Because deoptimization is lazy we must save jvmti requests to set locals
1059   // in compiled frames until we deoptimize and we have an interpreter frame.
1060   // This holds the pointer to array (yeah like there might be more than one) of
1061   // description of compiled vframes that have locals that need to be updated.
1062   GrowableArray<jvmtiDeferredLocalVariableSet*>* _deferred_locals_updates;
1063 
1064   // Handshake value for fixing 6243940. We need a place for the i2c
1065   // adapter to store the callee Method*. This value is NEVER live
1066   // across a gc point so it does NOT have to be gc'd
1067   // The handshake is open ended since we can't be certain that it will
1068   // be NULLed. This is because we rarely ever see the race and end up
1069   // in handle_wrong_method which is the backend of the handshake. See
1070   // code in i2c adapters and handle_wrong_method.
1071 
1072   Method*       _callee_target;
1073 
1074   // Used to pass back results to the interpreter or generated code running Java code.
1075   oop           _vm_result;    // oop result is GC-preserved
1076   Metadata*     _vm_result_2;  // non-oop result
1077   oop           _return_buffered_value; // buffered value being returned
1078 
1079   // See ReduceInitialCardMarks: this holds the precise space interval of
1080   // the most recent slow path allocation for which compiled code has
1081   // elided card-marks for performance along the fast-path.
1082   MemRegion     _deferred_card_mark;
1083 
1084   MonitorChunk* _monitor_chunks;                 // Contains the off stack monitors
1085                                                  // allocated during deoptimization
1086                                                  // and by JNI_MonitorEnter/Exit
1087 
1088   // Async. requests support
1089   enum AsyncRequests {
1090     _no_async_condition = 0,
1091     _async_exception,
1092     _async_unsafe_access_error
1093   };
1094   AsyncRequests _special_runtime_exit_condition; // Enum indicating pending async. request
1095   oop           _pending_async_exception;
1096 
1097   // Safepoint support

1538   vframeArray* vframe_array_last() const         { return _vframe_array_last;  }
1539 
1540   // The special resourceMark used during deoptimization
1541 
1542   void set_deopt_mark(DeoptResourceMark* value)  { _deopt_mark = value; }
1543   DeoptResourceMark* deopt_mark(void)            { return _deopt_mark; }
1544 
1545   void set_deopt_compiled_method(CompiledMethod* nm)  { _deopt_nmethod = nm; }
1546   CompiledMethod* deopt_compiled_method()        { return _deopt_nmethod; }
1547 
1548   Method*    callee_target() const               { return _callee_target; }
1549   void set_callee_target  (Method* x)          { _callee_target   = x; }
1550 
1551   // Oop results of vm runtime calls
1552   oop  vm_result() const                         { return _vm_result; }
1553   void set_vm_result  (oop x)                    { _vm_result   = x; }
1554 
1555   Metadata*    vm_result_2() const               { return _vm_result_2; }
1556   void set_vm_result_2  (Metadata* x)          { _vm_result_2   = x; }
1557 
1558   oop return_buffered_value() const              { return _return_buffered_value; }
1559   void set_return_buffered_value(oop val)        { _return_buffered_value = val; }
1560 
1561   MemRegion deferred_card_mark() const           { return _deferred_card_mark; }
1562   void set_deferred_card_mark(MemRegion mr)      { _deferred_card_mark = mr;   }
1563 
1564 #if INCLUDE_JVMCI
1565   int  pending_deoptimization() const             { return _pending_deoptimization; }
1566   jlong pending_failed_speculation() const        { return _pending_failed_speculation; }
1567   bool has_pending_monitorenter() const           { return _pending_monitorenter; }
1568   void set_pending_monitorenter(bool b)           { _pending_monitorenter = b; }
1569   void set_pending_deoptimization(int reason)     { _pending_deoptimization = reason; }
1570   void set_pending_failed_speculation(jlong failed_speculation) { _pending_failed_speculation = failed_speculation; }
1571   void set_pending_transfer_to_interpreter(bool b) { _pending_transfer_to_interpreter = b; }
1572   void set_jvmci_alternate_call_target(address a) { assert(_jvmci._alternate_call_target == NULL, "must be"); _jvmci._alternate_call_target = a; }
1573   void set_jvmci_implicit_exception_pc(address a) { assert(_jvmci._implicit_exception_pc == NULL, "must be"); _jvmci._implicit_exception_pc = a; }
1574 
1575   virtual bool in_retryable_allocation() const    { return _in_retryable_allocation; }
1576   void set_in_retryable_allocation(bool b)        { _in_retryable_allocation = b; }
1577 #endif // INCLUDE_JVMCI
1578 
1579   // Exception handling for compiled methods
1580   oop      exception_oop() const;

1780   bool do_not_unlock(void)                       { return _do_not_unlock_if_synchronized; }
1781 
1782   // For assembly stub generation
1783   static ByteSize threadObj_offset()             { return byte_offset_of(JavaThread, _threadObj); }
1784   static ByteSize jni_environment_offset()       { return byte_offset_of(JavaThread, _jni_environment); }
1785   static ByteSize pending_jni_exception_check_fn_offset() {
1786     return byte_offset_of(JavaThread, _pending_jni_exception_check_fn);
1787   }
1788   static ByteSize last_Java_sp_offset() {
1789     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1790   }
1791   static ByteSize last_Java_pc_offset() {
1792     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1793   }
1794   static ByteSize frame_anchor_offset() {
1795     return byte_offset_of(JavaThread, _anchor);
1796   }
1797   static ByteSize callee_target_offset()         { return byte_offset_of(JavaThread, _callee_target); }
1798   static ByteSize vm_result_offset()             { return byte_offset_of(JavaThread, _vm_result); }
1799   static ByteSize vm_result_2_offset()           { return byte_offset_of(JavaThread, _vm_result_2); }
1800   static ByteSize return_buffered_value_offset() { return byte_offset_of(JavaThread, _return_buffered_value); }
1801   static ByteSize thread_state_offset()          { return byte_offset_of(JavaThread, _thread_state); }
1802   static ByteSize saved_exception_pc_offset()    { return byte_offset_of(JavaThread, _saved_exception_pc); }
1803   static ByteSize osthread_offset()              { return byte_offset_of(JavaThread, _osthread); }
1804 #if INCLUDE_JVMCI
1805   static ByteSize pending_deoptimization_offset() { return byte_offset_of(JavaThread, _pending_deoptimization); }
1806   static ByteSize pending_monitorenter_offset()  { return byte_offset_of(JavaThread, _pending_monitorenter); }
1807   static ByteSize pending_failed_speculation_offset() { return byte_offset_of(JavaThread, _pending_failed_speculation); }
1808   static ByteSize jvmci_alternate_call_target_offset() { return byte_offset_of(JavaThread, _jvmci._alternate_call_target); }
1809   static ByteSize jvmci_implicit_exception_pc_offset() { return byte_offset_of(JavaThread, _jvmci._implicit_exception_pc); }
1810   static ByteSize jvmci_counters_offset()        { return byte_offset_of(JavaThread, _jvmci_counters); }
1811 #endif // INCLUDE_JVMCI
1812   static ByteSize exception_oop_offset()         { return byte_offset_of(JavaThread, _exception_oop); }
1813   static ByteSize exception_pc_offset()          { return byte_offset_of(JavaThread, _exception_pc); }
1814   static ByteSize exception_handler_pc_offset()  { return byte_offset_of(JavaThread, _exception_handler_pc); }
1815   static ByteSize stack_overflow_limit_offset()  { return byte_offset_of(JavaThread, _stack_overflow_limit); }
1816   static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
1817   static ByteSize stack_guard_state_offset()     { return byte_offset_of(JavaThread, _stack_guard_state); }
1818   static ByteSize reserved_stack_activation_offset() { return byte_offset_of(JavaThread, _reserved_stack_activation); }
1819   static ByteSize suspend_flags_offset()         { return byte_offset_of(JavaThread, _suspend_flags); }
1820 
< prev index next >