< prev index next >

src/hotspot/share/runtime/thread.hpp

Print this page




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

 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,


 964 
 965   // Create and start the single instance of WatcherThread, or stop it on shutdown
 966   static void start();
 967   static void stop();
 968   // Only allow start once the VM is sufficiently initialized
 969   // Otherwise the first task to enroll will trigger the start
 970   static void make_startable();
 971  private:
 972   int sleep() const;
 973 };
 974 
 975 
 976 class CompilerThread;
 977 
 978 typedef void (*ThreadFunction)(JavaThread*, TRAPS);
 979 
 980 class JavaThread: public Thread {
 981   friend class VMStructs;
 982   friend class JVMCIVMStructs;
 983   friend class WhiteBox;

 984  private:
 985   JavaThread*    _next;                          // The next thread in the Threads list
 986   bool           _on_thread_list;                // Is set when this JavaThread is added to the Threads list
 987   oop            _threadObj;                     // The Java level thread object
 988 
 989 #ifdef ASSERT
 990  private:
 991   int _java_call_counter;
 992 
 993  public:
 994   int  java_call_counter()                       { return _java_call_counter; }
 995   void inc_java_call_counter()                   { _java_call_counter++; }
 996   void dec_java_call_counter() {
 997     assert(_java_call_counter > 0, "Invalid nesting of JavaCallWrapper");
 998     _java_call_counter--;
 999   }
1000  private:  // restore original namespace restriction
1001 #endif  // ifdef ASSERT
1002 
1003 #ifndef PRODUCT


1024   vframeArray*  _vframe_array_last;              // Holds last vFrameArray we popped
1025   // Because deoptimization is lazy we must save jvmti requests to set locals
1026   // in compiled frames until we deoptimize and we have an interpreter frame.
1027   // This holds the pointer to array (yeah like there might be more than one) of
1028   // description of compiled vframes that have locals that need to be updated.
1029   GrowableArray<jvmtiDeferredLocalVariableSet*>* _deferred_locals_updates;
1030 
1031   // Handshake value for fixing 6243940. We need a place for the i2c
1032   // adapter to store the callee Method*. This value is NEVER live
1033   // across a gc point so it does NOT have to be gc'd
1034   // The handshake is open ended since we can't be certain that it will
1035   // be NULLed. This is because we rarely ever see the race and end up
1036   // in handle_wrong_method which is the backend of the handshake. See
1037   // code in i2c adapters and handle_wrong_method.
1038 
1039   Method*       _callee_target;
1040 
1041   // Used to pass back results to the interpreter or generated code running Java code.
1042   oop           _vm_result;    // oop result is GC-preserved
1043   Metadata*     _vm_result_2;  // non-oop result

1044 
1045   // See ReduceInitialCardMarks: this holds the precise space interval of
1046   // the most recent slow path allocation for which compiled code has
1047   // elided card-marks for performance along the fast-path.
1048   MemRegion     _deferred_card_mark;
1049 
1050   MonitorChunk* _monitor_chunks;                 // Contains the off stack monitors
1051                                                  // allocated during deoptimization
1052                                                  // and by JNI_MonitorEnter/Exit
1053 
1054   // Async. requests support
1055   enum AsyncRequests {
1056     _no_async_condition = 0,
1057     _async_exception,
1058     _async_unsafe_access_error
1059   };
1060   AsyncRequests _special_runtime_exit_condition; // Enum indicating pending async. request
1061   oop           _pending_async_exception;
1062 
1063   // Safepoint support


1512   void set_deopt_mark(DeoptResourceMark* value)  { _deopt_mark = value; }
1513   DeoptResourceMark* deopt_mark(void)            { return _deopt_mark; }
1514 
1515   intptr_t* must_deopt_id()                      { return _must_deopt_id; }
1516   void     set_must_deopt_id(intptr_t* id)       { _must_deopt_id = id; }
1517   void     clear_must_deopt_id()                 { _must_deopt_id = NULL; }
1518 
1519   void set_deopt_compiled_method(CompiledMethod* nm)  { _deopt_nmethod = nm; }
1520   CompiledMethod* deopt_compiled_method()        { return _deopt_nmethod; }
1521 
1522   Method*    callee_target() const               { return _callee_target; }
1523   void set_callee_target  (Method* x)          { _callee_target   = x; }
1524 
1525   // Oop results of vm runtime calls
1526   oop  vm_result() const                         { return _vm_result; }
1527   void set_vm_result  (oop x)                    { _vm_result   = x; }
1528 
1529   Metadata*    vm_result_2() const               { return _vm_result_2; }
1530   void set_vm_result_2  (Metadata* x)          { _vm_result_2   = x; }
1531 



1532   MemRegion deferred_card_mark() const           { return _deferred_card_mark; }
1533   void set_deferred_card_mark(MemRegion mr)      { _deferred_card_mark = mr;   }
1534 
1535 #if INCLUDE_JVMCI
1536   int  pending_deoptimization() const             { return _pending_deoptimization; }
1537   long pending_failed_speculation() const         { return _pending_failed_speculation; }
1538   bool adjusting_comp_level() const               { return _adjusting_comp_level; }
1539   void set_adjusting_comp_level(bool b)           { _adjusting_comp_level = b; }
1540   bool has_pending_monitorenter() const           { return _pending_monitorenter; }
1541   void set_pending_monitorenter(bool b)           { _pending_monitorenter = b; }
1542   void set_pending_deoptimization(int reason)     { _pending_deoptimization = reason; }
1543   void set_pending_failed_speculation(long failed_speculation) { _pending_failed_speculation = failed_speculation; }
1544   void set_pending_transfer_to_interpreter(bool b) { _pending_transfer_to_interpreter = b; }
1545   void set_jvmci_alternate_call_target(address a) { assert(_jvmci._alternate_call_target == NULL, "must be"); _jvmci._alternate_call_target = a; }
1546   void set_jvmci_implicit_exception_pc(address a) { assert(_jvmci._implicit_exception_pc == NULL, "must be"); _jvmci._implicit_exception_pc = a; }
1547 
1548   virtual bool in_retryable_allocation() const    { return _in_retryable_allocation; }
1549   void set_in_retryable_allocation(bool b)        { _in_retryable_allocation = b; }
1550 #endif // INCLUDE_JVMCI
1551 


1754 #ifndef PRODUCT
1755   static ByteSize jmp_ring_index_offset()        { return byte_offset_of(JavaThread, _jmp_ring_index); }
1756   static ByteSize jmp_ring_offset()              { return byte_offset_of(JavaThread, _jmp_ring); }
1757 #endif // PRODUCT
1758   static ByteSize jni_environment_offset()       { return byte_offset_of(JavaThread, _jni_environment); }
1759   static ByteSize pending_jni_exception_check_fn_offset() {
1760     return byte_offset_of(JavaThread, _pending_jni_exception_check_fn);
1761   }
1762   static ByteSize last_Java_sp_offset() {
1763     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1764   }
1765   static ByteSize last_Java_pc_offset() {
1766     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1767   }
1768   static ByteSize frame_anchor_offset() {
1769     return byte_offset_of(JavaThread, _anchor);
1770   }
1771   static ByteSize callee_target_offset()         { return byte_offset_of(JavaThread, _callee_target); }
1772   static ByteSize vm_result_offset()             { return byte_offset_of(JavaThread, _vm_result); }
1773   static ByteSize vm_result_2_offset()           { return byte_offset_of(JavaThread, _vm_result_2); }

1774   static ByteSize thread_state_offset()          { return byte_offset_of(JavaThread, _thread_state); }
1775   static ByteSize saved_exception_pc_offset()    { return byte_offset_of(JavaThread, _saved_exception_pc); }
1776   static ByteSize osthread_offset()              { return byte_offset_of(JavaThread, _osthread); }
1777 #if INCLUDE_JVMCI
1778   static ByteSize pending_deoptimization_offset() { return byte_offset_of(JavaThread, _pending_deoptimization); }
1779   static ByteSize pending_monitorenter_offset()  { return byte_offset_of(JavaThread, _pending_monitorenter); }
1780   static ByteSize pending_failed_speculation_offset() { return byte_offset_of(JavaThread, _pending_failed_speculation); }
1781   static ByteSize jvmci_alternate_call_target_offset() { return byte_offset_of(JavaThread, _jvmci._alternate_call_target); }
1782   static ByteSize jvmci_implicit_exception_pc_offset() { return byte_offset_of(JavaThread, _jvmci._implicit_exception_pc); }
1783   static ByteSize jvmci_counters_offset()        { return byte_offset_of(JavaThread, _jvmci_counters); }
1784 #endif // INCLUDE_JVMCI
1785   static ByteSize exception_oop_offset()         { return byte_offset_of(JavaThread, _exception_oop); }
1786   static ByteSize exception_pc_offset()          { return byte_offset_of(JavaThread, _exception_pc); }
1787   static ByteSize exception_handler_pc_offset()  { return byte_offset_of(JavaThread, _exception_handler_pc); }
1788   static ByteSize stack_overflow_limit_offset()  { return byte_offset_of(JavaThread, _stack_overflow_limit); }
1789   static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
1790   static ByteSize stack_guard_state_offset()     { return byte_offset_of(JavaThread, _stack_guard_state); }
1791   static ByteSize reserved_stack_activation_offset() { return byte_offset_of(JavaThread, _reserved_stack_activation); }
1792   static ByteSize suspend_flags_offset()         { return byte_offset_of(JavaThread, _suspend_flags); }
1793 




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


 965 
 966   // Create and start the single instance of WatcherThread, or stop it on shutdown
 967   static void start();
 968   static void stop();
 969   // Only allow start once the VM is sufficiently initialized
 970   // Otherwise the first task to enroll will trigger the start
 971   static void make_startable();
 972  private:
 973   int sleep() const;
 974 };
 975 
 976 
 977 class CompilerThread;
 978 
 979 typedef void (*ThreadFunction)(JavaThread*, TRAPS);
 980 
 981 class JavaThread: public Thread {
 982   friend class VMStructs;
 983   friend class JVMCIVMStructs;
 984   friend class WhiteBox;
 985   friend class VTBuffer;
 986  private:
 987   JavaThread*    _next;                          // The next thread in the Threads list
 988   bool           _on_thread_list;                // Is set when this JavaThread is added to the Threads list
 989   oop            _threadObj;                     // The Java level thread object
 990 
 991 #ifdef ASSERT
 992  private:
 993   int _java_call_counter;
 994 
 995  public:
 996   int  java_call_counter()                       { return _java_call_counter; }
 997   void inc_java_call_counter()                   { _java_call_counter++; }
 998   void dec_java_call_counter() {
 999     assert(_java_call_counter > 0, "Invalid nesting of JavaCallWrapper");
1000     _java_call_counter--;
1001   }
1002  private:  // restore original namespace restriction
1003 #endif  // ifdef ASSERT
1004 
1005 #ifndef PRODUCT


1026   vframeArray*  _vframe_array_last;              // Holds last vFrameArray we popped
1027   // Because deoptimization is lazy we must save jvmti requests to set locals
1028   // in compiled frames until we deoptimize and we have an interpreter frame.
1029   // This holds the pointer to array (yeah like there might be more than one) of
1030   // description of compiled vframes that have locals that need to be updated.
1031   GrowableArray<jvmtiDeferredLocalVariableSet*>* _deferred_locals_updates;
1032 
1033   // Handshake value for fixing 6243940. We need a place for the i2c
1034   // adapter to store the callee Method*. This value is NEVER live
1035   // across a gc point so it does NOT have to be gc'd
1036   // The handshake is open ended since we can't be certain that it will
1037   // be NULLed. This is because we rarely ever see the race and end up
1038   // in handle_wrong_method which is the backend of the handshake. See
1039   // code in i2c adapters and handle_wrong_method.
1040 
1041   Method*       _callee_target;
1042 
1043   // Used to pass back results to the interpreter or generated code running Java code.
1044   oop           _vm_result;    // oop result is GC-preserved
1045   Metadata*     _vm_result_2;  // non-oop result
1046   oop           _return_buffered_value; // buffered value being returned
1047 
1048   // See ReduceInitialCardMarks: this holds the precise space interval of
1049   // the most recent slow path allocation for which compiled code has
1050   // elided card-marks for performance along the fast-path.
1051   MemRegion     _deferred_card_mark;
1052 
1053   MonitorChunk* _monitor_chunks;                 // Contains the off stack monitors
1054                                                  // allocated during deoptimization
1055                                                  // and by JNI_MonitorEnter/Exit
1056 
1057   // Async. requests support
1058   enum AsyncRequests {
1059     _no_async_condition = 0,
1060     _async_exception,
1061     _async_unsafe_access_error
1062   };
1063   AsyncRequests _special_runtime_exit_condition; // Enum indicating pending async. request
1064   oop           _pending_async_exception;
1065 
1066   // Safepoint support


1515   void set_deopt_mark(DeoptResourceMark* value)  { _deopt_mark = value; }
1516   DeoptResourceMark* deopt_mark(void)            { return _deopt_mark; }
1517 
1518   intptr_t* must_deopt_id()                      { return _must_deopt_id; }
1519   void     set_must_deopt_id(intptr_t* id)       { _must_deopt_id = id; }
1520   void     clear_must_deopt_id()                 { _must_deopt_id = NULL; }
1521 
1522   void set_deopt_compiled_method(CompiledMethod* nm)  { _deopt_nmethod = nm; }
1523   CompiledMethod* deopt_compiled_method()        { return _deopt_nmethod; }
1524 
1525   Method*    callee_target() const               { return _callee_target; }
1526   void set_callee_target  (Method* x)          { _callee_target   = x; }
1527 
1528   // Oop results of vm runtime calls
1529   oop  vm_result() const                         { return _vm_result; }
1530   void set_vm_result  (oop x)                    { _vm_result   = x; }
1531 
1532   Metadata*    vm_result_2() const               { return _vm_result_2; }
1533   void set_vm_result_2  (Metadata* x)          { _vm_result_2   = x; }
1534 
1535   oop return_buffered_value() const              { return _return_buffered_value; }
1536   void set_return_buffered_value(oop val)        { _return_buffered_value = val; }
1537 
1538   MemRegion deferred_card_mark() const           { return _deferred_card_mark; }
1539   void set_deferred_card_mark(MemRegion mr)      { _deferred_card_mark = mr;   }
1540 
1541 #if INCLUDE_JVMCI
1542   int  pending_deoptimization() const             { return _pending_deoptimization; }
1543   long pending_failed_speculation() const         { return _pending_failed_speculation; }
1544   bool adjusting_comp_level() const               { return _adjusting_comp_level; }
1545   void set_adjusting_comp_level(bool b)           { _adjusting_comp_level = b; }
1546   bool has_pending_monitorenter() const           { return _pending_monitorenter; }
1547   void set_pending_monitorenter(bool b)           { _pending_monitorenter = b; }
1548   void set_pending_deoptimization(int reason)     { _pending_deoptimization = reason; }
1549   void set_pending_failed_speculation(long failed_speculation) { _pending_failed_speculation = failed_speculation; }
1550   void set_pending_transfer_to_interpreter(bool b) { _pending_transfer_to_interpreter = b; }
1551   void set_jvmci_alternate_call_target(address a) { assert(_jvmci._alternate_call_target == NULL, "must be"); _jvmci._alternate_call_target = a; }
1552   void set_jvmci_implicit_exception_pc(address a) { assert(_jvmci._implicit_exception_pc == NULL, "must be"); _jvmci._implicit_exception_pc = a; }
1553 
1554   virtual bool in_retryable_allocation() const    { return _in_retryable_allocation; }
1555   void set_in_retryable_allocation(bool b)        { _in_retryable_allocation = b; }
1556 #endif // INCLUDE_JVMCI
1557 


1760 #ifndef PRODUCT
1761   static ByteSize jmp_ring_index_offset()        { return byte_offset_of(JavaThread, _jmp_ring_index); }
1762   static ByteSize jmp_ring_offset()              { return byte_offset_of(JavaThread, _jmp_ring); }
1763 #endif // PRODUCT
1764   static ByteSize jni_environment_offset()       { return byte_offset_of(JavaThread, _jni_environment); }
1765   static ByteSize pending_jni_exception_check_fn_offset() {
1766     return byte_offset_of(JavaThread, _pending_jni_exception_check_fn);
1767   }
1768   static ByteSize last_Java_sp_offset() {
1769     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1770   }
1771   static ByteSize last_Java_pc_offset() {
1772     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1773   }
1774   static ByteSize frame_anchor_offset() {
1775     return byte_offset_of(JavaThread, _anchor);
1776   }
1777   static ByteSize callee_target_offset()         { return byte_offset_of(JavaThread, _callee_target); }
1778   static ByteSize vm_result_offset()             { return byte_offset_of(JavaThread, _vm_result); }
1779   static ByteSize vm_result_2_offset()           { return byte_offset_of(JavaThread, _vm_result_2); }
1780   static ByteSize return_buffered_value_offset() { return byte_offset_of(JavaThread, _return_buffered_value); }
1781   static ByteSize thread_state_offset()          { return byte_offset_of(JavaThread, _thread_state); }
1782   static ByteSize saved_exception_pc_offset()    { return byte_offset_of(JavaThread, _saved_exception_pc); }
1783   static ByteSize osthread_offset()              { return byte_offset_of(JavaThread, _osthread); }
1784 #if INCLUDE_JVMCI
1785   static ByteSize pending_deoptimization_offset() { return byte_offset_of(JavaThread, _pending_deoptimization); }
1786   static ByteSize pending_monitorenter_offset()  { return byte_offset_of(JavaThread, _pending_monitorenter); }
1787   static ByteSize pending_failed_speculation_offset() { return byte_offset_of(JavaThread, _pending_failed_speculation); }
1788   static ByteSize jvmci_alternate_call_target_offset() { return byte_offset_of(JavaThread, _jvmci._alternate_call_target); }
1789   static ByteSize jvmci_implicit_exception_pc_offset() { return byte_offset_of(JavaThread, _jvmci._implicit_exception_pc); }
1790   static ByteSize jvmci_counters_offset()        { return byte_offset_of(JavaThread, _jvmci_counters); }
1791 #endif // INCLUDE_JVMCI
1792   static ByteSize exception_oop_offset()         { return byte_offset_of(JavaThread, _exception_oop); }
1793   static ByteSize exception_pc_offset()          { return byte_offset_of(JavaThread, _exception_pc); }
1794   static ByteSize exception_handler_pc_offset()  { return byte_offset_of(JavaThread, _exception_handler_pc); }
1795   static ByteSize stack_overflow_limit_offset()  { return byte_offset_of(JavaThread, _stack_overflow_limit); }
1796   static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
1797   static ByteSize stack_guard_state_offset()     { return byte_offset_of(JavaThread, _stack_guard_state); }
1798   static ByteSize reserved_stack_activation_offset() { return byte_offset_of(JavaThread, _reserved_stack_activation); }
1799   static ByteSize suspend_flags_offset()         { return byte_offset_of(JavaThread, _suspend_flags); }
1800 


< prev index next >