< prev index next >

src/hotspot/share/runtime/thread.hpp

Print this page

 669   }
 670   return NULL;
 671 #endif
 672 }
 673 
 674 inline Thread* Thread::current_or_null_safe() {
 675   if (ThreadLocalStorage::is_initialized()) {
 676     return ThreadLocalStorage::thread();
 677   }
 678   return NULL;
 679 }
 680 
 681 class CompilerThread;
 682 
 683 typedef void (*ThreadFunction)(JavaThread*, TRAPS);
 684 
 685 class JavaThread: public Thread {
 686   friend class VMStructs;
 687   friend class JVMCIVMStructs;
 688   friend class WhiteBox;

 689   friend class ThreadsSMRSupport; // to access _threadObj for exiting_threads_oops_do
 690   friend class HandshakeState;
 691  private:
 692   bool           _on_thread_list;                // Is set when this JavaThread is added to the Threads list
 693   OopHandle      _threadObj;                     // The Java level thread object
 694 
 695 #ifdef ASSERT
 696  private:
 697   int _java_call_counter;
 698 
 699  public:
 700   int  java_call_counter()                       { return _java_call_counter; }
 701   void inc_java_call_counter()                   { _java_call_counter++; }
 702   void dec_java_call_counter() {
 703     assert(_java_call_counter > 0, "Invalid nesting of JavaCallWrapper");
 704     _java_call_counter--;
 705   }
 706  private:  // restore original namespace restriction
 707 #endif  // ifdef ASSERT
 708 

 719   vframeArray*  _vframe_array_head;              // Holds the heap of the active vframeArrays
 720   vframeArray*  _vframe_array_last;              // Holds last vFrameArray we popped
 721   // Holds updates by JVMTI agents for compiled frames that cannot be performed immediately. They
 722   // will be carried out as soon as possible which, in most cases, is just before deoptimization of
 723   // the frame, when control returns to it.
 724   JvmtiDeferredUpdates* _jvmti_deferred_updates;
 725 
 726   // Handshake value for fixing 6243940. We need a place for the i2c
 727   // adapter to store the callee Method*. This value is NEVER live
 728   // across a gc point so it does NOT have to be gc'd
 729   // The handshake is open ended since we can't be certain that it will
 730   // be NULLed. This is because we rarely ever see the race and end up
 731   // in handle_wrong_method which is the backend of the handshake. See
 732   // code in i2c adapters and handle_wrong_method.
 733 
 734   Method*       _callee_target;
 735 
 736   // Used to pass back results to the interpreter or generated code running Java code.
 737   oop           _vm_result;    // oop result is GC-preserved
 738   Metadata*     _vm_result_2;  // non-oop result

 739 
 740   // See ReduceInitialCardMarks: this holds the precise space interval of
 741   // the most recent slow path allocation for which compiled code has
 742   // elided card-marks for performance along the fast-path.
 743   MemRegion     _deferred_card_mark;
 744 
 745   ObjectMonitor* volatile _current_pending_monitor;     // ObjectMonitor this thread is waiting to lock
 746   bool           _current_pending_monitor_is_from_java; // locking is from Java code
 747   ObjectMonitor* volatile _current_waiting_monitor;     // ObjectMonitor on which this thread called Object.wait()
 748  public:
 749   volatile intptr_t _Stalled;
 750 
 751   // For tracking the heavyweight monitor the thread is pending on.
 752   ObjectMonitor* current_pending_monitor() {
 753     // Use Atomic::load() to prevent data race between concurrent modification and
 754     // concurrent readers, e.g. ThreadService::get_current_contended_monitor().
 755     // Especially, reloading pointer from thread after NULL check must be prevented.
 756     return Atomic::load(&_current_pending_monitor);
 757   }
 758   void set_current_pending_monitor(ObjectMonitor* monitor) {

1200   vframeArray* vframe_array_last() const         { return _vframe_array_last;  }
1201 
1202   // The special resourceMark used during deoptimization
1203 
1204   void set_deopt_mark(DeoptResourceMark* value)  { _deopt_mark = value; }
1205   DeoptResourceMark* deopt_mark(void)            { return _deopt_mark; }
1206 
1207   void set_deopt_compiled_method(CompiledMethod* nm)  { _deopt_nmethod = nm; }
1208   CompiledMethod* deopt_compiled_method()        { return _deopt_nmethod; }
1209 
1210   Method*    callee_target() const               { return _callee_target; }
1211   void set_callee_target  (Method* x)          { _callee_target   = x; }
1212 
1213   // Oop results of vm runtime calls
1214   oop  vm_result() const                         { return _vm_result; }
1215   void set_vm_result  (oop x)                    { _vm_result   = x; }
1216 
1217   Metadata*    vm_result_2() const               { return _vm_result_2; }
1218   void set_vm_result_2  (Metadata* x)          { _vm_result_2   = x; }
1219 



1220   MemRegion deferred_card_mark() const           { return _deferred_card_mark; }
1221   void set_deferred_card_mark(MemRegion mr)      { _deferred_card_mark = mr;   }
1222 
1223 #if INCLUDE_JVMCI
1224   int  pending_deoptimization() const             { return _pending_deoptimization; }
1225   jlong pending_failed_speculation() const        { return _pending_failed_speculation; }
1226   bool has_pending_monitorenter() const           { return _pending_monitorenter; }
1227   void set_pending_monitorenter(bool b)           { _pending_monitorenter = b; }
1228   void set_pending_deoptimization(int reason)     { _pending_deoptimization = reason; }
1229   void set_pending_failed_speculation(jlong failed_speculation) { _pending_failed_speculation = failed_speculation; }
1230   void set_pending_transfer_to_interpreter(bool b) { _pending_transfer_to_interpreter = b; }
1231   void set_jvmci_alternate_call_target(address a) { assert(_jvmci._alternate_call_target == NULL, "must be"); _jvmci._alternate_call_target = a; }
1232   void set_jvmci_implicit_exception_pc(address a) { assert(_jvmci._implicit_exception_pc == NULL, "must be"); _jvmci._implicit_exception_pc = a; }
1233 
1234   virtual bool in_retryable_allocation() const    { return _in_retryable_allocation; }
1235   void set_in_retryable_allocation(bool b)        { _in_retryable_allocation = b; }
1236 #endif // INCLUDE_JVMCI
1237 
1238   // Exception handling for compiled methods
1239   oop      exception_oop() const;

1264   bool do_not_unlock(void)                       { return _do_not_unlock_if_synchronized; }
1265 
1266   // For assembly stub generation
1267   static ByteSize threadObj_offset()             { return byte_offset_of(JavaThread, _threadObj); }
1268   static ByteSize jni_environment_offset()       { return byte_offset_of(JavaThread, _jni_environment); }
1269   static ByteSize pending_jni_exception_check_fn_offset() {
1270     return byte_offset_of(JavaThread, _pending_jni_exception_check_fn);
1271   }
1272   static ByteSize last_Java_sp_offset() {
1273     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1274   }
1275   static ByteSize last_Java_pc_offset() {
1276     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1277   }
1278   static ByteSize frame_anchor_offset() {
1279     return byte_offset_of(JavaThread, _anchor);
1280   }
1281   static ByteSize callee_target_offset()         { return byte_offset_of(JavaThread, _callee_target); }
1282   static ByteSize vm_result_offset()             { return byte_offset_of(JavaThread, _vm_result); }
1283   static ByteSize vm_result_2_offset()           { return byte_offset_of(JavaThread, _vm_result_2); }

1284   static ByteSize thread_state_offset()          { return byte_offset_of(JavaThread, _thread_state); }
1285   static ByteSize polling_word_offset()          { return byte_offset_of(JavaThread, _poll_data) + byte_offset_of(SafepointMechanism::ThreadData, _polling_word);}
1286   static ByteSize polling_page_offset()          { return byte_offset_of(JavaThread, _poll_data) + byte_offset_of(SafepointMechanism::ThreadData, _polling_page);}
1287   static ByteSize saved_exception_pc_offset()    { return byte_offset_of(JavaThread, _saved_exception_pc); }
1288   static ByteSize osthread_offset()              { return byte_offset_of(JavaThread, _osthread); }
1289 #if INCLUDE_JVMCI
1290   static ByteSize pending_deoptimization_offset() { return byte_offset_of(JavaThread, _pending_deoptimization); }
1291   static ByteSize pending_monitorenter_offset()  { return byte_offset_of(JavaThread, _pending_monitorenter); }
1292   static ByteSize pending_failed_speculation_offset() { return byte_offset_of(JavaThread, _pending_failed_speculation); }
1293   static ByteSize jvmci_alternate_call_target_offset() { return byte_offset_of(JavaThread, _jvmci._alternate_call_target); }
1294   static ByteSize jvmci_implicit_exception_pc_offset() { return byte_offset_of(JavaThread, _jvmci._implicit_exception_pc); }
1295   static ByteSize jvmci_counters_offset()        { return byte_offset_of(JavaThread, _jvmci_counters); }
1296 #endif // INCLUDE_JVMCI
1297   static ByteSize exception_oop_offset()         { return byte_offset_of(JavaThread, _exception_oop); }
1298   static ByteSize exception_pc_offset()          { return byte_offset_of(JavaThread, _exception_pc); }
1299   static ByteSize exception_handler_pc_offset()  { return byte_offset_of(JavaThread, _exception_handler_pc); }
1300   static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
1301 
1302   // StackOverflow offsets
1303   static ByteSize stack_overflow_limit_offset()  {

 669   }
 670   return NULL;
 671 #endif
 672 }
 673 
 674 inline Thread* Thread::current_or_null_safe() {
 675   if (ThreadLocalStorage::is_initialized()) {
 676     return ThreadLocalStorage::thread();
 677   }
 678   return NULL;
 679 }
 680 
 681 class CompilerThread;
 682 
 683 typedef void (*ThreadFunction)(JavaThread*, TRAPS);
 684 
 685 class JavaThread: public Thread {
 686   friend class VMStructs;
 687   friend class JVMCIVMStructs;
 688   friend class WhiteBox;
 689   friend class VTBuffer;
 690   friend class ThreadsSMRSupport; // to access _threadObj for exiting_threads_oops_do
 691   friend class HandshakeState;
 692  private:
 693   bool           _on_thread_list;                // Is set when this JavaThread is added to the Threads list
 694   OopHandle      _threadObj;                     // The Java level thread object
 695 
 696 #ifdef ASSERT
 697  private:
 698   int _java_call_counter;
 699 
 700  public:
 701   int  java_call_counter()                       { return _java_call_counter; }
 702   void inc_java_call_counter()                   { _java_call_counter++; }
 703   void dec_java_call_counter() {
 704     assert(_java_call_counter > 0, "Invalid nesting of JavaCallWrapper");
 705     _java_call_counter--;
 706   }
 707  private:  // restore original namespace restriction
 708 #endif  // ifdef ASSERT
 709 

 720   vframeArray*  _vframe_array_head;              // Holds the heap of the active vframeArrays
 721   vframeArray*  _vframe_array_last;              // Holds last vFrameArray we popped
 722   // Holds updates by JVMTI agents for compiled frames that cannot be performed immediately. They
 723   // will be carried out as soon as possible which, in most cases, is just before deoptimization of
 724   // the frame, when control returns to it.
 725   JvmtiDeferredUpdates* _jvmti_deferred_updates;
 726 
 727   // Handshake value for fixing 6243940. We need a place for the i2c
 728   // adapter to store the callee Method*. This value is NEVER live
 729   // across a gc point so it does NOT have to be gc'd
 730   // The handshake is open ended since we can't be certain that it will
 731   // be NULLed. This is because we rarely ever see the race and end up
 732   // in handle_wrong_method which is the backend of the handshake. See
 733   // code in i2c adapters and handle_wrong_method.
 734 
 735   Method*       _callee_target;
 736 
 737   // Used to pass back results to the interpreter or generated code running Java code.
 738   oop           _vm_result;    // oop result is GC-preserved
 739   Metadata*     _vm_result_2;  // non-oop result
 740   oop           _return_buffered_value; // buffered value being returned
 741 
 742   // See ReduceInitialCardMarks: this holds the precise space interval of
 743   // the most recent slow path allocation for which compiled code has
 744   // elided card-marks for performance along the fast-path.
 745   MemRegion     _deferred_card_mark;
 746 
 747   ObjectMonitor* volatile _current_pending_monitor;     // ObjectMonitor this thread is waiting to lock
 748   bool           _current_pending_monitor_is_from_java; // locking is from Java code
 749   ObjectMonitor* volatile _current_waiting_monitor;     // ObjectMonitor on which this thread called Object.wait()
 750  public:
 751   volatile intptr_t _Stalled;
 752 
 753   // For tracking the heavyweight monitor the thread is pending on.
 754   ObjectMonitor* current_pending_monitor() {
 755     // Use Atomic::load() to prevent data race between concurrent modification and
 756     // concurrent readers, e.g. ThreadService::get_current_contended_monitor().
 757     // Especially, reloading pointer from thread after NULL check must be prevented.
 758     return Atomic::load(&_current_pending_monitor);
 759   }
 760   void set_current_pending_monitor(ObjectMonitor* monitor) {

1202   vframeArray* vframe_array_last() const         { return _vframe_array_last;  }
1203 
1204   // The special resourceMark used during deoptimization
1205 
1206   void set_deopt_mark(DeoptResourceMark* value)  { _deopt_mark = value; }
1207   DeoptResourceMark* deopt_mark(void)            { return _deopt_mark; }
1208 
1209   void set_deopt_compiled_method(CompiledMethod* nm)  { _deopt_nmethod = nm; }
1210   CompiledMethod* deopt_compiled_method()        { return _deopt_nmethod; }
1211 
1212   Method*    callee_target() const               { return _callee_target; }
1213   void set_callee_target  (Method* x)          { _callee_target   = x; }
1214 
1215   // Oop results of vm runtime calls
1216   oop  vm_result() const                         { return _vm_result; }
1217   void set_vm_result  (oop x)                    { _vm_result   = x; }
1218 
1219   Metadata*    vm_result_2() const               { return _vm_result_2; }
1220   void set_vm_result_2  (Metadata* x)          { _vm_result_2   = x; }
1221 
1222   oop return_buffered_value() const              { return _return_buffered_value; }
1223   void set_return_buffered_value(oop val)        { _return_buffered_value = val; }
1224 
1225   MemRegion deferred_card_mark() const           { return _deferred_card_mark; }
1226   void set_deferred_card_mark(MemRegion mr)      { _deferred_card_mark = mr;   }
1227 
1228 #if INCLUDE_JVMCI
1229   int  pending_deoptimization() const             { return _pending_deoptimization; }
1230   jlong pending_failed_speculation() const        { return _pending_failed_speculation; }
1231   bool has_pending_monitorenter() const           { return _pending_monitorenter; }
1232   void set_pending_monitorenter(bool b)           { _pending_monitorenter = b; }
1233   void set_pending_deoptimization(int reason)     { _pending_deoptimization = reason; }
1234   void set_pending_failed_speculation(jlong failed_speculation) { _pending_failed_speculation = failed_speculation; }
1235   void set_pending_transfer_to_interpreter(bool b) { _pending_transfer_to_interpreter = b; }
1236   void set_jvmci_alternate_call_target(address a) { assert(_jvmci._alternate_call_target == NULL, "must be"); _jvmci._alternate_call_target = a; }
1237   void set_jvmci_implicit_exception_pc(address a) { assert(_jvmci._implicit_exception_pc == NULL, "must be"); _jvmci._implicit_exception_pc = a; }
1238 
1239   virtual bool in_retryable_allocation() const    { return _in_retryable_allocation; }
1240   void set_in_retryable_allocation(bool b)        { _in_retryable_allocation = b; }
1241 #endif // INCLUDE_JVMCI
1242 
1243   // Exception handling for compiled methods
1244   oop      exception_oop() const;

1269   bool do_not_unlock(void)                       { return _do_not_unlock_if_synchronized; }
1270 
1271   // For assembly stub generation
1272   static ByteSize threadObj_offset()             { return byte_offset_of(JavaThread, _threadObj); }
1273   static ByteSize jni_environment_offset()       { return byte_offset_of(JavaThread, _jni_environment); }
1274   static ByteSize pending_jni_exception_check_fn_offset() {
1275     return byte_offset_of(JavaThread, _pending_jni_exception_check_fn);
1276   }
1277   static ByteSize last_Java_sp_offset() {
1278     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1279   }
1280   static ByteSize last_Java_pc_offset() {
1281     return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1282   }
1283   static ByteSize frame_anchor_offset() {
1284     return byte_offset_of(JavaThread, _anchor);
1285   }
1286   static ByteSize callee_target_offset()         { return byte_offset_of(JavaThread, _callee_target); }
1287   static ByteSize vm_result_offset()             { return byte_offset_of(JavaThread, _vm_result); }
1288   static ByteSize vm_result_2_offset()           { return byte_offset_of(JavaThread, _vm_result_2); }
1289   static ByteSize return_buffered_value_offset() { return byte_offset_of(JavaThread, _return_buffered_value); }
1290   static ByteSize thread_state_offset()          { return byte_offset_of(JavaThread, _thread_state); }
1291   static ByteSize polling_word_offset()          { return byte_offset_of(JavaThread, _poll_data) + byte_offset_of(SafepointMechanism::ThreadData, _polling_word);}
1292   static ByteSize polling_page_offset()          { return byte_offset_of(JavaThread, _poll_data) + byte_offset_of(SafepointMechanism::ThreadData, _polling_page);}
1293   static ByteSize saved_exception_pc_offset()    { return byte_offset_of(JavaThread, _saved_exception_pc); }
1294   static ByteSize osthread_offset()              { return byte_offset_of(JavaThread, _osthread); }
1295 #if INCLUDE_JVMCI
1296   static ByteSize pending_deoptimization_offset() { return byte_offset_of(JavaThread, _pending_deoptimization); }
1297   static ByteSize pending_monitorenter_offset()  { return byte_offset_of(JavaThread, _pending_monitorenter); }
1298   static ByteSize pending_failed_speculation_offset() { return byte_offset_of(JavaThread, _pending_failed_speculation); }
1299   static ByteSize jvmci_alternate_call_target_offset() { return byte_offset_of(JavaThread, _jvmci._alternate_call_target); }
1300   static ByteSize jvmci_implicit_exception_pc_offset() { return byte_offset_of(JavaThread, _jvmci._implicit_exception_pc); }
1301   static ByteSize jvmci_counters_offset()        { return byte_offset_of(JavaThread, _jvmci_counters); }
1302 #endif // INCLUDE_JVMCI
1303   static ByteSize exception_oop_offset()         { return byte_offset_of(JavaThread, _exception_oop); }
1304   static ByteSize exception_pc_offset()          { return byte_offset_of(JavaThread, _exception_pc); }
1305   static ByteSize exception_handler_pc_offset()  { return byte_offset_of(JavaThread, _exception_handler_pc); }
1306   static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
1307 
1308   // StackOverflow offsets
1309   static ByteSize stack_overflow_limit_offset()  {
< prev index next >