< prev index next >

src/share/vm/runtime/safepoint.hpp

Print this page
rev 13526 : [mq]: 13512.patch


  34 #include "utilities/ostream.hpp"
  35 
  36 //
  37 // Safepoint synchronization
  38 ////
  39 // The VMThread or CMS_thread uses the SafepointSynchronize::begin/end
  40 // methods to enter/exit a safepoint region. The begin method will roll
  41 // all JavaThreads forward to a safepoint.
  42 //
  43 // JavaThreads must use the ThreadSafepointState abstraction (defined in
  44 // thread.hpp) to indicate that that they are at a safepoint.
  45 //
  46 // The Mutex/Condition variable and ObjectLocker classes calls the enter/
  47 // exit safepoint methods, when a thread is blocked/restarted. Hence, all mutex exter/
  48 // exit points *must* be at a safepoint.
  49 
  50 
  51 class ThreadSafepointState;
  52 class SnippetCache;
  53 class nmethod;
  54 class WorkGang;
  55 class SubTasksDone;
  56 
  57 //
  58 // Implements roll-forward to safepoint (safepoint synchronization)
  59 //
  60 class SafepointSynchronize : AllStatic {
  61  public:
  62   enum SynchronizeState {
  63       _not_synchronized = 0,                   // Threads not synchronized at a safepoint
  64                                                // Keep this value 0. See the comment in do_call_back()
  65       _synchronizing    = 1,                   // Synchronizing in progress
  66       _synchronized     = 2                    // All Java threads are stopped at a safepoint. Only VM thread is running
  67   };
  68 
  69   enum SafepointingThread {
  70       _null_thread  = 0,
  71       _vm_thread    = 1,
  72       _other_thread = 2
  73   };
  74 
  75   enum SafepointTimeoutReason {
  76     _spinning_timeout = 0,
  77     _blocking_timeout = 1
  78   };
  79 
  80   typedef struct {
  81     float  _time_stamp;                        // record when the current safepoint occurs in seconds
  82     int    _vmop_type;                         // type of VM operation triggers the safepoint
  83     int    _nof_total_threads;                 // total number of Java threads
  84     int    _nof_initial_running_threads;       // total number of initially seen running threads
  85     int    _nof_threads_wait_to_block;         // total number of threads waiting for to block
  86     bool   _page_armed;                        // true if polling page is armed, false otherwise
  87     int    _nof_threads_hit_page_trap;         // total number of threads hitting the page trap
  88     jlong  _time_to_spin;                      // total time in millis spent in spinning
  89     jlong  _time_to_wait_to_block;             // total time in millis spent in waiting for to block
  90     jlong  _time_to_do_cleanups;               // total time in millis spent in performing cleanups
  91     jlong  _time_to_sync;                      // total time in millis spent in getting to _synchronized
  92     jlong  _time_to_exec_vmop;                 // total time in millis spent in vm operation itself
  93   } SafepointStats;
  94 
  95   enum SafepointCleanupTasks {
  96     SAFEPOINT_CLEANUP_DEFLATE_MONITORS,
  97     SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES,
  98     SAFEPOINT_CLEANUP_COMPILATION_POLICY,
  99     SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH,
 100     SAFEPOINT_CLEANUP_STRING_TABLE_REHASH,
 101     SAFEPOINT_CLEANUP_CLD_PURGE,
 102     // Leave this one last.
 103     SAFEPOINT_CLEANUP_NUM_TASKS
 104   };
 105 
 106  private:
 107   static volatile SynchronizeState _state;     // Threads might read this flag directly, without acquiring the Threads_lock
 108   static volatile int _waiting_to_block;       // number of threads we are waiting for to block
 109   static int _current_jni_active_count;        // Counts the number of active critical natives during the safepoint
 110 
 111   // This counter is used for fast versions of jni_Get<Primitive>Field.
 112   // An even value means there is no ongoing safepoint operations.
 113   // The counter is incremented ONLY at the beginning and end of each
 114   // safepoint. The fact that Threads_lock is held throughout each pair of
 115   // increments (at the beginning and end of each safepoint) guarantees
 116   // race freedom.
 117 public:
 118   static volatile int _safepoint_counter;
 119 private:
 120   static long       _end_of_last_safepoint;     // Time of last safepoint in milliseconds
 121 
 122   // Statistics
 123   static jlong            _safepoint_begin_time;     // time when safepoint begins
 124   static SafepointStats*  _safepoint_stats;          // array of SafepointStats struct
 125   static int              _cur_stat_index;           // current index to the above array
 126   static julong           _safepoint_reasons[];      // safepoint count for each VM op
 127   static julong           _coalesced_vmop_count;     // coalesced vmop count
 128   static jlong            _max_sync_time;            // maximum sync time in nanos
 129   static jlong            _max_vmop_time;            // maximum vm operation time in nanos
 130   static float            _ts_of_current_safepoint;  // time stamp of current safepoint in seconds
 131 
 132   static void begin_statistics(int nof_threads, int nof_running);
 133   static void update_statistics_on_spin_end();
 134   static void update_statistics_on_sync_end(jlong end_time);
 135   static void update_statistics_on_cleanup_end(jlong end_time);
 136   static void end_statistics(jlong end_time);
 137   static void print_statistics();
 138   inline static void inc_page_trap_count() {
 139     Atomic::inc(&_safepoint_stats[_cur_stat_index]._nof_threads_hit_page_trap);
 140   }
 141 
 142   // For debug long safepoint
 143   static void print_safepoint_timeout(SafepointTimeoutReason timeout_reason);
 144 
 145   // Parallel cleanup
 146   static WorkGang* _cleanup_workers;
 147   static SubTasksDone* _cleanup_subtasks;
 148 
 149 public:
 150 
 151   // Main entry points
 152 
 153   // Roll all threads forward to safepoint. Must be called by the
 154   // VMThread or CMS_thread.
 155   static void begin();
 156   static void end();                    // Start all suspended threads again...
 157 
 158   static bool safepoint_safe(JavaThread *thread, JavaThreadState state);
 159 
 160   static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state);
 161 
 162   // Query
 163   inline static bool is_at_safepoint()   { return _state == _synchronized;  }
 164   inline static bool is_synchronizing()  { return _state == _synchronizing;  }
 165   inline static int safepoint_counter()  { return _safepoint_counter; }
 166 
 167   inline static bool do_call_back() {
 168     return (_state != _not_synchronized);


 173     _current_jni_active_count++;
 174   }
 175 
 176   // Called when a thread voluntarily blocks
 177   static void   block(JavaThread *thread);
 178   static void   signal_thread_at_safepoint()              { _waiting_to_block--; }
 179 
 180   // Exception handling for page polling
 181   static void handle_polling_page_exception(JavaThread *thread);
 182 
 183   // VM Thread interface for determining safepoint rate
 184   static long last_non_safepoint_interval() {
 185     return os::javaTimeMillis() - _end_of_last_safepoint;
 186   }
 187   static long end_of_last_safepoint() {
 188     return _end_of_last_safepoint;
 189   }
 190   static bool is_cleanup_needed();
 191   static void do_cleanup_tasks();
 192 
 193 private:
 194   static void serial_cleanup();
 195   static void parallel_cleanup();
 196 
 197 public:
 198   // Debugging
 199   static void print_state()                                PRODUCT_RETURN;
 200   static void safepoint_msg(const char* format, ...) ATTRIBUTE_PRINTF(1, 2) PRODUCT_RETURN;
 201 
 202   static void deferred_initialize_stat();
 203   static void print_stat_on_exit();
 204   inline static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; }
 205 
 206   static void set_is_at_safepoint()                        { _state = _synchronized; }
 207   static void set_is_not_at_safepoint()                    { _state = _not_synchronized; }
 208 
 209   // Assembly support
 210   static address address_of_state()                        { return (address)&_state; }
 211 
 212   static address safepoint_counter_addr()                  { return (address)&_safepoint_counter; }
 213 };
 214 
 215 // State class for a thread suspended at a safepoint
 216 class ThreadSafepointState: public CHeapObj<mtInternal> {
 217  public:




  34 #include "utilities/ostream.hpp"
  35 
  36 //
  37 // Safepoint synchronization
  38 ////
  39 // The VMThread or CMS_thread uses the SafepointSynchronize::begin/end
  40 // methods to enter/exit a safepoint region. The begin method will roll
  41 // all JavaThreads forward to a safepoint.
  42 //
  43 // JavaThreads must use the ThreadSafepointState abstraction (defined in
  44 // thread.hpp) to indicate that that they are at a safepoint.
  45 //
  46 // The Mutex/Condition variable and ObjectLocker classes calls the enter/
  47 // exit safepoint methods, when a thread is blocked/restarted. Hence, all mutex exter/
  48 // exit points *must* be at a safepoint.
  49 
  50 
  51 class ThreadSafepointState;
  52 class SnippetCache;
  53 class nmethod;


  54 
  55 //
  56 // Implements roll-forward to safepoint (safepoint synchronization)
  57 //
  58 class SafepointSynchronize : AllStatic {
  59  public:
  60   enum SynchronizeState {
  61       _not_synchronized = 0,                   // Threads not synchronized at a safepoint
  62                                                // Keep this value 0. See the comment in do_call_back()
  63       _synchronizing    = 1,                   // Synchronizing in progress
  64       _synchronized     = 2                    // All Java threads are stopped at a safepoint. Only VM thread is running
  65   };
  66 
  67   enum SafepointingThread {
  68       _null_thread  = 0,
  69       _vm_thread    = 1,
  70       _other_thread = 2
  71   };
  72 
  73   enum SafepointTimeoutReason {
  74     _spinning_timeout = 0,
  75     _blocking_timeout = 1
  76   };
  77 
  78   typedef struct {
  79     float  _time_stamp;                        // record when the current safepoint occurs in seconds
  80     int    _vmop_type;                         // type of VM operation triggers the safepoint
  81     int    _nof_total_threads;                 // total number of Java threads
  82     int    _nof_initial_running_threads;       // total number of initially seen running threads
  83     int    _nof_threads_wait_to_block;         // total number of threads waiting for to block
  84     bool   _page_armed;                        // true if polling page is armed, false otherwise
  85     int    _nof_threads_hit_page_trap;         // total number of threads hitting the page trap
  86     jlong  _time_to_spin;                      // total time in millis spent in spinning
  87     jlong  _time_to_wait_to_block;             // total time in millis spent in waiting for to block
  88     jlong  _time_to_do_cleanups;               // total time in millis spent in performing cleanups
  89     jlong  _time_to_sync;                      // total time in millis spent in getting to _synchronized
  90     jlong  _time_to_exec_vmop;                 // total time in millis spent in vm operation itself
  91   } SafepointStats;
  92 











  93  private:
  94   static volatile SynchronizeState _state;     // Threads might read this flag directly, without acquiring the Threads_lock
  95   static volatile int _waiting_to_block;       // number of threads we are waiting for to block
  96   static int _current_jni_active_count;        // Counts the number of active critical natives during the safepoint
  97 
  98   // This counter is used for fast versions of jni_Get<Primitive>Field.
  99   // An even value means there is no ongoing safepoint operations.
 100   // The counter is incremented ONLY at the beginning and end of each
 101   // safepoint. The fact that Threads_lock is held throughout each pair of
 102   // increments (at the beginning and end of each safepoint) guarantees
 103   // race freedom.
 104 public:
 105   static volatile int _safepoint_counter;
 106 private:
 107   static long       _end_of_last_safepoint;     // Time of last safepoint in milliseconds
 108 
 109   // Statistics
 110   static jlong            _safepoint_begin_time;     // time when safepoint begins
 111   static SafepointStats*  _safepoint_stats;          // array of SafepointStats struct
 112   static int              _cur_stat_index;           // current index to the above array
 113   static julong           _safepoint_reasons[];      // safepoint count for each VM op
 114   static julong           _coalesced_vmop_count;     // coalesced vmop count
 115   static jlong            _max_sync_time;            // maximum sync time in nanos
 116   static jlong            _max_vmop_time;            // maximum vm operation time in nanos
 117   static float            _ts_of_current_safepoint;  // time stamp of current safepoint in seconds
 118 
 119   static void begin_statistics(int nof_threads, int nof_running);
 120   static void update_statistics_on_spin_end();
 121   static void update_statistics_on_sync_end(jlong end_time);
 122   static void update_statistics_on_cleanup_end(jlong end_time);
 123   static void end_statistics(jlong end_time);
 124   static void print_statistics();
 125   inline static void inc_page_trap_count() {
 126     Atomic::inc(&_safepoint_stats[_cur_stat_index]._nof_threads_hit_page_trap);
 127   }
 128 
 129   // For debug long safepoint
 130   static void print_safepoint_timeout(SafepointTimeoutReason timeout_reason);
 131 




 132 public:
 133 
 134   // Main entry points
 135 
 136   // Roll all threads forward to safepoint. Must be called by the
 137   // VMThread or CMS_thread.
 138   static void begin();
 139   static void end();                    // Start all suspended threads again...
 140 
 141   static bool safepoint_safe(JavaThread *thread, JavaThreadState state);
 142 
 143   static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state);
 144 
 145   // Query
 146   inline static bool is_at_safepoint()   { return _state == _synchronized;  }
 147   inline static bool is_synchronizing()  { return _state == _synchronizing;  }
 148   inline static int safepoint_counter()  { return _safepoint_counter; }
 149 
 150   inline static bool do_call_back() {
 151     return (_state != _not_synchronized);


 156     _current_jni_active_count++;
 157   }
 158 
 159   // Called when a thread voluntarily blocks
 160   static void   block(JavaThread *thread);
 161   static void   signal_thread_at_safepoint()              { _waiting_to_block--; }
 162 
 163   // Exception handling for page polling
 164   static void handle_polling_page_exception(JavaThread *thread);
 165 
 166   // VM Thread interface for determining safepoint rate
 167   static long last_non_safepoint_interval() {
 168     return os::javaTimeMillis() - _end_of_last_safepoint;
 169   }
 170   static long end_of_last_safepoint() {
 171     return _end_of_last_safepoint;
 172   }
 173   static bool is_cleanup_needed();
 174   static void do_cleanup_tasks();
 175 





 176   // Debugging
 177   static void print_state()                                PRODUCT_RETURN;
 178   static void safepoint_msg(const char* format, ...) ATTRIBUTE_PRINTF(1, 2) PRODUCT_RETURN;
 179 
 180   static void deferred_initialize_stat();
 181   static void print_stat_on_exit();
 182   inline static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; }
 183 
 184   static void set_is_at_safepoint()                        { _state = _synchronized; }
 185   static void set_is_not_at_safepoint()                    { _state = _not_synchronized; }
 186 
 187   // Assembly support
 188   static address address_of_state()                        { return (address)&_state; }
 189 
 190   static address safepoint_counter_addr()                  { return (address)&_safepoint_counter; }
 191 };
 192 
 193 // State class for a thread suspended at a safepoint
 194 class ThreadSafepointState: public CHeapObj<mtInternal> {
 195  public:


< prev index next >