< prev index next >

src/hotspot/share/runtime/thread.hpp

Print this page
rev 47591 : Add Thread Local handshakes and thread local polling
rev 47592 : imported patch Atomic-Update-Rebase-3


  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREAD_HPP
  26 #define SHARE_VM_RUNTIME_THREAD_HPP
  27 
  28 #include "jni.h"
  29 #include "gc/shared/threadLocalAllocBuffer.hpp"
  30 #include "memory/allocation.hpp"
  31 #include "oops/oop.hpp"
  32 #include "prims/jvmtiExport.hpp"
  33 #include "runtime/frame.hpp"

  34 #include "runtime/javaFrameAnchor.hpp"
  35 #include "runtime/jniHandles.hpp"
  36 #include "runtime/mutexLocker.hpp"
  37 #include "runtime/os.hpp"
  38 #include "runtime/osThread.hpp"
  39 #include "runtime/park.hpp"
  40 #include "runtime/safepoint.hpp"
  41 #include "runtime/stubRoutines.hpp"
  42 #include "runtime/threadLocalStorage.hpp"
  43 #include "runtime/thread_ext.hpp"
  44 #include "runtime/unhandledOops.hpp"
  45 #include "trace/traceBackend.hpp"
  46 #include "trace/traceMacros.hpp"
  47 #include "utilities/align.hpp"
  48 #include "utilities/exceptions.hpp"
  49 #include "utilities/macros.hpp"
  50 #if INCLUDE_ALL_GCS
  51 #include "gc/g1/dirtyCardQueue.hpp"
  52 #include "gc/g1/satbMarkQueue.hpp"
  53 #endif // INCLUDE_ALL_GCS


 254   // debug support for checking if code does allow safepoints or not
 255   // GC points in the VM can happen because of allocation, invoking a VM operation, or blocking on
 256   // mutex, or blocking on an object synchronizer (Java locking).
 257   // If !allow_safepoint(), then an assertion failure will happen in any of the above cases
 258   // If !allow_allocation(), then an assertion failure will happen during allocation
 259   // (Hence, !allow_safepoint() => !allow_allocation()).
 260   //
 261   // The two classes NoSafepointVerifier and No_Allocation_Verifier are used to set these counters.
 262   //
 263   NOT_PRODUCT(int _allow_safepoint_count;)      // If 0, thread allow a safepoint to happen
 264   debug_only(int _allow_allocation_count;)     // If 0, the thread is allowed to allocate oops.
 265 
 266   // Used by SkipGCALot class.
 267   NOT_PRODUCT(bool _skip_gcalot;)               // Should we elide gc-a-lot?
 268 
 269   friend class NoAllocVerifier;
 270   friend class NoSafepointVerifier;
 271   friend class PauseNoSafepointVerifier;
 272   friend class GCLocker;
 273 


 274   ThreadLocalAllocBuffer _tlab;                 // Thread-local eden
 275   jlong _allocated_bytes;                       // Cumulative number of bytes allocated on
 276                                                 // the Java heap
 277 
 278   mutable TRACE_DATA _trace_data;               // Thread-local data for tracing
 279 
 280   ThreadExt _ext;
 281 
 282   int   _vm_operation_started_count;            // VM_Operation support
 283   int   _vm_operation_completed_count;          // VM_Operation support
 284 
 285   ObjectMonitor* _current_pending_monitor;      // ObjectMonitor this thread
 286                                                 // is waiting to lock
 287   bool _current_pending_monitor_is_from_java;   // locking is from Java code
 288 
 289   // ObjectMonitor on which this thread called Object.wait()
 290   ObjectMonitor* _current_waiting_monitor;
 291 
 292   // Private thread-local objectmonitor list - a simple cache organized as a SLL.
 293  public:


 532 
 533 protected:
 534   // OS data associated with the thread
 535   OSThread* _osthread;  // Platform-specific thread information
 536 
 537   // Thread local resource area for temporary allocation within the VM
 538   ResourceArea* _resource_area;
 539 
 540   DEBUG_ONLY(ResourceMark* _current_resource_mark;)
 541 
 542   // Thread local handle area for allocation of handles within the VM
 543   HandleArea* _handle_area;
 544   GrowableArray<Metadata*>* _metadata_handles;
 545 
 546   // Support for stack overflow handling, get_thread, etc.
 547   address          _stack_base;
 548   size_t           _stack_size;
 549   uintptr_t        _self_raw_id;      // used by get_thread (mutable)
 550   int              _lgrp_id;
 551 


 552  public:
 553   // Stack overflow support
 554   address stack_base() const           { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
 555   void    set_stack_base(address base) { _stack_base = base; }
 556   size_t  stack_size() const           { return _stack_size; }
 557   void    set_stack_size(size_t size)  { _stack_size = size; }
 558   address stack_end()  const           { return stack_base() - stack_size(); }
 559   void    record_stack_base_and_size();
 560 
 561   bool    on_local_stack(address adr) const {
 562     // QQQ this has knowledge of direction, ought to be a stack method
 563     return (_stack_base >= adr && adr >= stack_end());
 564   }
 565 
 566   uintptr_t self_raw_id()                    { return _self_raw_id; }
 567   void      set_self_raw_id(uintptr_t value) { _self_raw_id = value; }
 568 
 569   int     lgrp_id() const        { return _lgrp_id; }
 570   void    set_lgrp_id(int value) { _lgrp_id = value; }
 571 


 600 #endif
 601 
 602   void check_for_valid_safepoint_state(bool potential_vm_operation) PRODUCT_RETURN;
 603 
 604  private:
 605   volatile int _jvmti_env_iteration_count;
 606 
 607  public:
 608   void entering_jvmti_env_iteration()            { ++_jvmti_env_iteration_count; }
 609   void leaving_jvmti_env_iteration()             { --_jvmti_env_iteration_count; }
 610   bool is_inside_jvmti_env_iteration()           { return _jvmti_env_iteration_count > 0; }
 611 
 612   // Code generation
 613   static ByteSize exception_file_offset()        { return byte_offset_of(Thread, _exception_file); }
 614   static ByteSize exception_line_offset()        { return byte_offset_of(Thread, _exception_line); }
 615   static ByteSize active_handles_offset()        { return byte_offset_of(Thread, _active_handles); }
 616 
 617   static ByteSize stack_base_offset()            { return byte_offset_of(Thread, _stack_base); }
 618   static ByteSize stack_size_offset()            { return byte_offset_of(Thread, _stack_size); }
 619 


 620 #define TLAB_FIELD_OFFSET(name) \
 621   static ByteSize tlab_##name##_offset()         { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
 622 
 623   TLAB_FIELD_OFFSET(start)
 624   TLAB_FIELD_OFFSET(end)
 625   TLAB_FIELD_OFFSET(top)
 626   TLAB_FIELD_OFFSET(pf_top)
 627   TLAB_FIELD_OFFSET(size)                   // desired_size
 628   TLAB_FIELD_OFFSET(refill_waste_limit)
 629   TLAB_FIELD_OFFSET(number_of_refills)
 630   TLAB_FIELD_OFFSET(fast_refill_waste)
 631   TLAB_FIELD_OFFSET(slow_allocations)
 632 
 633 #undef TLAB_FIELD_OFFSET
 634 
 635   static ByteSize allocated_bytes_offset()       { return byte_offset_of(Thread, _allocated_bytes); }
 636 
 637  public:
 638   volatile intptr_t _Stalled;
 639   volatile int _TypeTag;


1117   ThreadSafepointState *safepoint_state() const  { return _safepoint_state; }
1118   void set_safepoint_state(ThreadSafepointState *state) { _safepoint_state = state; }
1119   bool is_at_poll_safepoint()                    { return _safepoint_state->is_at_poll_safepoint(); }
1120 
1121   // thread has called JavaThread::exit() or is terminated
1122   bool is_exiting()                              { return _terminated == _thread_exiting || is_terminated(); }
1123   // thread is terminated (no longer on the threads list); we compare
1124   // against the two non-terminated values so that a freed JavaThread
1125   // will also be considered terminated.
1126   bool is_terminated()                           { return _terminated != _not_terminated && _terminated != _thread_exiting; }
1127   void set_terminated(TerminatedTypes t)         { _terminated = t; }
1128   // special for Threads::remove() which is static:
1129   void set_terminated_value()                    { _terminated = _thread_terminated; }
1130   void block_if_vm_exited();
1131 
1132   bool doing_unsafe_access()                     { return _doing_unsafe_access; }
1133   void set_doing_unsafe_access(bool val)         { _doing_unsafe_access = val; }
1134 
1135   bool do_not_unlock_if_synchronized()             { return _do_not_unlock_if_synchronized; }
1136   void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; }



























1137 
1138   // Suspend/resume support for JavaThread
1139  private:
1140   inline void set_ext_suspended();
1141   inline void clear_ext_suspended();
1142 
1143  public:
1144   void java_suspend();
1145   void java_resume();
1146   int  java_suspend_self();
1147 
1148   void check_and_wait_while_suspended() {
1149     assert(JavaThread::current() == this, "sanity check");
1150 
1151     bool do_self_suspend;
1152     do {
1153       // were we externally suspended while we were waiting?
1154       do_self_suspend = handle_special_suspend_equivalent_condition();
1155       if (do_self_suspend) {
1156         // don't surprise the thread that suspended us by returning




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_THREAD_HPP
  26 #define SHARE_VM_RUNTIME_THREAD_HPP
  27 
  28 #include "jni.h"
  29 #include "gc/shared/threadLocalAllocBuffer.hpp"
  30 #include "memory/allocation.hpp"
  31 #include "oops/oop.hpp"
  32 #include "prims/jvmtiExport.hpp"
  33 #include "runtime/frame.hpp"
  34 #include "runtime/handshake.hpp"
  35 #include "runtime/javaFrameAnchor.hpp"
  36 #include "runtime/jniHandles.hpp"
  37 #include "runtime/mutexLocker.hpp"
  38 #include "runtime/os.hpp"
  39 #include "runtime/osThread.hpp"
  40 #include "runtime/park.hpp"
  41 #include "runtime/safepoint.hpp"
  42 #include "runtime/stubRoutines.hpp"
  43 #include "runtime/threadLocalStorage.hpp"
  44 #include "runtime/thread_ext.hpp"
  45 #include "runtime/unhandledOops.hpp"
  46 #include "trace/traceBackend.hpp"
  47 #include "trace/traceMacros.hpp"
  48 #include "utilities/align.hpp"
  49 #include "utilities/exceptions.hpp"
  50 #include "utilities/macros.hpp"
  51 #if INCLUDE_ALL_GCS
  52 #include "gc/g1/dirtyCardQueue.hpp"
  53 #include "gc/g1/satbMarkQueue.hpp"
  54 #endif // INCLUDE_ALL_GCS


 255   // debug support for checking if code does allow safepoints or not
 256   // GC points in the VM can happen because of allocation, invoking a VM operation, or blocking on
 257   // mutex, or blocking on an object synchronizer (Java locking).
 258   // If !allow_safepoint(), then an assertion failure will happen in any of the above cases
 259   // If !allow_allocation(), then an assertion failure will happen during allocation
 260   // (Hence, !allow_safepoint() => !allow_allocation()).
 261   //
 262   // The two classes NoSafepointVerifier and No_Allocation_Verifier are used to set these counters.
 263   //
 264   NOT_PRODUCT(int _allow_safepoint_count;)      // If 0, thread allow a safepoint to happen
 265   debug_only(int _allow_allocation_count;)     // If 0, the thread is allowed to allocate oops.
 266 
 267   // Used by SkipGCALot class.
 268   NOT_PRODUCT(bool _skip_gcalot;)               // Should we elide gc-a-lot?
 269 
 270   friend class NoAllocVerifier;
 271   friend class NoSafepointVerifier;
 272   friend class PauseNoSafepointVerifier;
 273   friend class GCLocker;
 274 
 275   volatile void* _polling_page;                 // Thread local polling page
 276 
 277   ThreadLocalAllocBuffer _tlab;                 // Thread-local eden
 278   jlong _allocated_bytes;                       // Cumulative number of bytes allocated on
 279                                                 // the Java heap
 280 
 281   mutable TRACE_DATA _trace_data;               // Thread-local data for tracing
 282 
 283   ThreadExt _ext;
 284 
 285   int   _vm_operation_started_count;            // VM_Operation support
 286   int   _vm_operation_completed_count;          // VM_Operation support
 287 
 288   ObjectMonitor* _current_pending_monitor;      // ObjectMonitor this thread
 289                                                 // is waiting to lock
 290   bool _current_pending_monitor_is_from_java;   // locking is from Java code
 291 
 292   // ObjectMonitor on which this thread called Object.wait()
 293   ObjectMonitor* _current_waiting_monitor;
 294 
 295   // Private thread-local objectmonitor list - a simple cache organized as a SLL.
 296  public:


 535 
 536 protected:
 537   // OS data associated with the thread
 538   OSThread* _osthread;  // Platform-specific thread information
 539 
 540   // Thread local resource area for temporary allocation within the VM
 541   ResourceArea* _resource_area;
 542 
 543   DEBUG_ONLY(ResourceMark* _current_resource_mark;)
 544 
 545   // Thread local handle area for allocation of handles within the VM
 546   HandleArea* _handle_area;
 547   GrowableArray<Metadata*>* _metadata_handles;
 548 
 549   // Support for stack overflow handling, get_thread, etc.
 550   address          _stack_base;
 551   size_t           _stack_size;
 552   uintptr_t        _self_raw_id;      // used by get_thread (mutable)
 553   int              _lgrp_id;
 554 
 555   volatile void** polling_page_addr() { return &_polling_page; }
 556 
 557  public:
 558   // Stack overflow support
 559   address stack_base() const           { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
 560   void    set_stack_base(address base) { _stack_base = base; }
 561   size_t  stack_size() const           { return _stack_size; }
 562   void    set_stack_size(size_t size)  { _stack_size = size; }
 563   address stack_end()  const           { return stack_base() - stack_size(); }
 564   void    record_stack_base_and_size();
 565 
 566   bool    on_local_stack(address adr) const {
 567     // QQQ this has knowledge of direction, ought to be a stack method
 568     return (_stack_base >= adr && adr >= stack_end());
 569   }
 570 
 571   uintptr_t self_raw_id()                    { return _self_raw_id; }
 572   void      set_self_raw_id(uintptr_t value) { _self_raw_id = value; }
 573 
 574   int     lgrp_id() const        { return _lgrp_id; }
 575   void    set_lgrp_id(int value) { _lgrp_id = value; }
 576 


 605 #endif
 606 
 607   void check_for_valid_safepoint_state(bool potential_vm_operation) PRODUCT_RETURN;
 608 
 609  private:
 610   volatile int _jvmti_env_iteration_count;
 611 
 612  public:
 613   void entering_jvmti_env_iteration()            { ++_jvmti_env_iteration_count; }
 614   void leaving_jvmti_env_iteration()             { --_jvmti_env_iteration_count; }
 615   bool is_inside_jvmti_env_iteration()           { return _jvmti_env_iteration_count > 0; }
 616 
 617   // Code generation
 618   static ByteSize exception_file_offset()        { return byte_offset_of(Thread, _exception_file); }
 619   static ByteSize exception_line_offset()        { return byte_offset_of(Thread, _exception_line); }
 620   static ByteSize active_handles_offset()        { return byte_offset_of(Thread, _active_handles); }
 621 
 622   static ByteSize stack_base_offset()            { return byte_offset_of(Thread, _stack_base); }
 623   static ByteSize stack_size_offset()            { return byte_offset_of(Thread, _stack_size); }
 624 
 625   static ByteSize polling_page_offset()          { return byte_offset_of(Thread, _polling_page); }
 626 
 627 #define TLAB_FIELD_OFFSET(name) \
 628   static ByteSize tlab_##name##_offset()         { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
 629 
 630   TLAB_FIELD_OFFSET(start)
 631   TLAB_FIELD_OFFSET(end)
 632   TLAB_FIELD_OFFSET(top)
 633   TLAB_FIELD_OFFSET(pf_top)
 634   TLAB_FIELD_OFFSET(size)                   // desired_size
 635   TLAB_FIELD_OFFSET(refill_waste_limit)
 636   TLAB_FIELD_OFFSET(number_of_refills)
 637   TLAB_FIELD_OFFSET(fast_refill_waste)
 638   TLAB_FIELD_OFFSET(slow_allocations)
 639 
 640 #undef TLAB_FIELD_OFFSET
 641 
 642   static ByteSize allocated_bytes_offset()       { return byte_offset_of(Thread, _allocated_bytes); }
 643 
 644  public:
 645   volatile intptr_t _Stalled;
 646   volatile int _TypeTag;


1124   ThreadSafepointState *safepoint_state() const  { return _safepoint_state; }
1125   void set_safepoint_state(ThreadSafepointState *state) { _safepoint_state = state; }
1126   bool is_at_poll_safepoint()                    { return _safepoint_state->is_at_poll_safepoint(); }
1127 
1128   // thread has called JavaThread::exit() or is terminated
1129   bool is_exiting()                              { return _terminated == _thread_exiting || is_terminated(); }
1130   // thread is terminated (no longer on the threads list); we compare
1131   // against the two non-terminated values so that a freed JavaThread
1132   // will also be considered terminated.
1133   bool is_terminated()                           { return _terminated != _not_terminated && _terminated != _thread_exiting; }
1134   void set_terminated(TerminatedTypes t)         { _terminated = t; }
1135   // special for Threads::remove() which is static:
1136   void set_terminated_value()                    { _terminated = _thread_terminated; }
1137   void block_if_vm_exited();
1138 
1139   bool doing_unsafe_access()                     { return _doing_unsafe_access; }
1140   void set_doing_unsafe_access(bool val)         { _doing_unsafe_access = val; }
1141 
1142   bool do_not_unlock_if_synchronized()             { return _do_not_unlock_if_synchronized; }
1143   void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; }
1144 
1145   inline void set_polling_page(void* poll_value);
1146   inline volatile void* get_polling_page();
1147 
1148  private:
1149   // Support for thread handshake operations
1150   HandshakeState _handshake;
1151  public:
1152   void set_handshake_operation(HandshakeOperation* op) {
1153     _handshake.set_operation(this, op);
1154   }
1155 
1156   bool has_handshake() const {
1157     return _handshake.has_operation();
1158   }
1159 
1160   void cancel_handshake() {
1161     _handshake.cancel(this);
1162   }
1163 
1164   void handshake_process_by_self() {
1165     _handshake.process_by_self(this);
1166   }
1167 
1168   void handshake_process_by_vmthread() {
1169     _handshake.process_by_vmthread(this);
1170   }
1171 
1172   // Suspend/resume support for JavaThread
1173  private:
1174   inline void set_ext_suspended();
1175   inline void clear_ext_suspended();
1176 
1177  public:
1178   void java_suspend();
1179   void java_resume();
1180   int  java_suspend_self();
1181 
1182   void check_and_wait_while_suspended() {
1183     assert(JavaThread::current() == this, "sanity check");
1184 
1185     bool do_self_suspend;
1186     do {
1187       // were we externally suspended while we were waiting?
1188       do_self_suspend = handle_special_suspend_equivalent_condition();
1189       if (do_self_suspend) {
1190         // don't surprise the thread that suspended us by returning


< prev index next >