< prev index next >

src/hotspot/share/runtime/safepoint.hpp

Print this page

 60 // Implements roll-forward to safepoint (safepoint synchronization)
 61 //
 62 class SafepointSynchronize : AllStatic {
 63  public:
 64   enum SynchronizeState {
 65       _not_synchronized = 0,                   // Threads not synchronized at a safepoint. Keep this value 0.
 66       _synchronizing    = 1,                   // Synchronizing in progress
 67       _synchronized     = 2                    // All Java threads are running in native, blocked in OS or stopped at safepoint.
 68                                                // VM thread and any NonJavaThread may be running.
 69   };
 70 
 71   // The enums are listed in the order of the tasks when done serially.
 72   enum SafepointCleanupTasks {
 73     SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING,
 74     SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES,
 75     SAFEPOINT_CLEANUP_COMPILATION_POLICY,
 76     SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH,
 77     SAFEPOINT_CLEANUP_STRING_TABLE_REHASH,
 78     SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE,
 79     SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP,

 80     // Leave this one last.
 81     SAFEPOINT_CLEANUP_NUM_TASKS
 82   };
 83 
 84  private:
 85   friend class SafepointMechanism;
 86   friend class ThreadSafepointState;
 87   friend class HandshakeState;
 88   friend class SafepointStateTracker;
 89 
 90   // Threads might read this flag directly, without acquiring the Threads_lock:
 91   static volatile SynchronizeState _state;
 92   // Number of threads we are waiting for to block:
 93   static int              _waiting_to_block;
 94   // Counts the number of active critical natives during the safepoint:
 95   static int              _current_jni_active_count;
 96 
 97   // This counter is used for fast versions of jni_Get<Primitive>Field.
 98   // An even value means there are no ongoing safepoint operations.
 99   // The counter is incremented ONLY at the beginning and end of each

116   // Helper methods for safepoint procedure:
117   static void arm_safepoint();
118   static int synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running);
119   static void disarm_safepoint();
120   static void increment_jni_active_count();
121   static void decrement_waiting_to_block();
122   static bool thread_not_running(ThreadSafepointState *cur_state);
123 
124   // Used in safepoint_safe to do a stable load of the thread state.
125   static bool try_stable_load_state(JavaThreadState *state,
126                                     JavaThread *thread,
127                                     uint64_t safepoint_count);
128 
129   // Called when a thread voluntarily blocks
130   static void block(JavaThread *thread);
131 
132   // Called from VMThread during handshakes.
133   // If true the VMThread may safely process the handshake operation for the JavaThread.
134   static bool handshake_safe(JavaThread *thread);
135 
136   static uint64_t safepoint_counter()             { return _safepoint_counter; }
137 
138 public:
139 


140   static void init(Thread* vmthread);
141 
142   // Roll all threads forward to safepoint. Must be called by the VMThread.
143   static void begin();
144   static void end();                    // Start all suspended threads again...
145 
146   // The value for a not set safepoint id.
147   static const uint64_t InactiveSafepointCounter;
148 
149   // Query
150   static bool is_at_safepoint()                   { return _state == _synchronized; }
151   static bool is_synchronizing()                  { return _state == _synchronizing; }
152 
153   static uint64_t safepoint_id() {
154     return _safepoint_id;
155   }
156 
157   static SafepointStateTracker safepoint_state_tracker() {
158     return SafepointStateTracker(safepoint_id(), is_at_safepoint());
159   }

 60 // Implements roll-forward to safepoint (safepoint synchronization)
 61 //
 62 class SafepointSynchronize : AllStatic {
 63  public:
 64   enum SynchronizeState {
 65       _not_synchronized = 0,                   // Threads not synchronized at a safepoint. Keep this value 0.
 66       _synchronizing    = 1,                   // Synchronizing in progress
 67       _synchronized     = 2                    // All Java threads are running in native, blocked in OS or stopped at safepoint.
 68                                                // VM thread and any NonJavaThread may be running.
 69   };
 70 
 71   // The enums are listed in the order of the tasks when done serially.
 72   enum SafepointCleanupTasks {
 73     SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING,
 74     SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES,
 75     SAFEPOINT_CLEANUP_COMPILATION_POLICY,
 76     SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH,
 77     SAFEPOINT_CLEANUP_STRING_TABLE_REHASH,
 78     SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE,
 79     SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP,
 80     SAFEPOINT_CLEANUP_KEEPALIVES,
 81     // Leave this one last.
 82     SAFEPOINT_CLEANUP_NUM_TASKS
 83   };
 84 
 85  private:
 86   friend class SafepointMechanism;
 87   friend class ThreadSafepointState;
 88   friend class HandshakeState;
 89   friend class SafepointStateTracker;
 90 
 91   // Threads might read this flag directly, without acquiring the Threads_lock:
 92   static volatile SynchronizeState _state;
 93   // Number of threads we are waiting for to block:
 94   static int              _waiting_to_block;
 95   // Counts the number of active critical natives during the safepoint:
 96   static int              _current_jni_active_count;
 97 
 98   // This counter is used for fast versions of jni_Get<Primitive>Field.
 99   // An even value means there are no ongoing safepoint operations.
100   // The counter is incremented ONLY at the beginning and end of each

117   // Helper methods for safepoint procedure:
118   static void arm_safepoint();
119   static int synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running);
120   static void disarm_safepoint();
121   static void increment_jni_active_count();
122   static void decrement_waiting_to_block();
123   static bool thread_not_running(ThreadSafepointState *cur_state);
124 
125   // Used in safepoint_safe to do a stable load of the thread state.
126   static bool try_stable_load_state(JavaThreadState *state,
127                                     JavaThread *thread,
128                                     uint64_t safepoint_count);
129 
130   // Called when a thread voluntarily blocks
131   static void block(JavaThread *thread);
132 
133   // Called from VMThread during handshakes.
134   // If true the VMThread may safely process the handshake operation for the JavaThread.
135   static bool handshake_safe(JavaThread *thread);
136 


137 public:
138 
139   static uint64_t safepoint_counter()             { return _safepoint_counter; }
140 
141   static void init(Thread* vmthread);
142 
143   // Roll all threads forward to safepoint. Must be called by the VMThread.
144   static void begin();
145   static void end();                    // Start all suspended threads again...
146 
147   // The value for a not set safepoint id.
148   static const uint64_t InactiveSafepointCounter;
149 
150   // Query
151   static bool is_at_safepoint()                   { return _state == _synchronized; }
152   static bool is_synchronizing()                  { return _state == _synchronizing; }
153 
154   static uint64_t safepoint_id() {
155     return _safepoint_id;
156   }
157 
158   static SafepointStateTracker safepoint_state_tracker() {
159     return SafepointStateTracker(safepoint_id(), is_at_safepoint());
160   }
< prev index next >