src/hotspot/share/runtime/safepoint.hpp
changeset 53895 b22d8ae270a2
parent 53847 74b616640b00
child 54009 13acb4339895
equal deleted inserted replaced
53894:bf1133e7dfba 53895:b22d8ae270a2
    26 #define SHARE_RUNTIME_SAFEPOINT_HPP
    26 #define SHARE_RUNTIME_SAFEPOINT_HPP
    27 
    27 
    28 #include "memory/allocation.hpp"
    28 #include "memory/allocation.hpp"
    29 #include "runtime/os.hpp"
    29 #include "runtime/os.hpp"
    30 #include "runtime/thread.hpp"
    30 #include "runtime/thread.hpp"
       
    31 #include "runtime/vmOperations.hpp"
    31 #include "utilities/ostream.hpp"
    32 #include "utilities/ostream.hpp"
    32 #include "utilities/waitBarrier.hpp"
    33 #include "utilities/waitBarrier.hpp"
    33 
    34 
    34 //
    35 //
    35 // Safepoint synchronization
    36 // Safepoint synchronization
    75  private:
    76  private:
    76   friend class SafepointMechanism;
    77   friend class SafepointMechanism;
    77   friend class ThreadSafepointState;
    78   friend class ThreadSafepointState;
    78   friend class HandshakeState;
    79   friend class HandshakeState;
    79 
    80 
    80   enum SafepointTimeoutReason {
       
    81     _spinning_timeout = 0,
       
    82     _blocking_timeout = 1
       
    83   };
       
    84 
       
    85   // Threads might read this flag directly, without acquiring the Threads_lock:
    81   // Threads might read this flag directly, without acquiring the Threads_lock:
    86   static volatile SynchronizeState _state;
    82   static volatile SynchronizeState _state;
    87   // Number of threads we are waiting for to block:
    83   // Number of threads we are waiting for to block:
    88   static int              _waiting_to_block;
    84   static int              _waiting_to_block;
    89   // Counts the number of active critical natives during the safepoint:
    85   // Counts the number of active critical natives during the safepoint:
   108   static void update_statistics_on_cleanup_end(jlong end_time);
   104   static void update_statistics_on_cleanup_end(jlong end_time);
   109   static void end_statistics(jlong end_time);
   105   static void end_statistics(jlong end_time);
   110   static void print_statistics();
   106   static void print_statistics();
   111 
   107 
   112   // For debug long safepoint
   108   // For debug long safepoint
   113   static void print_safepoint_timeout(SafepointTimeoutReason timeout_reason);
   109   static void print_safepoint_timeout();
   114 
   110 
   115   // Helper methods for safepoint procedure:
   111   // Helper methods for safepoint procedure:
   116   static void arm_safepoint();
   112   static void arm_safepoint();
   117   static int synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running);
   113   static int synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running);
   118   static void disarm_safepoint();
   114   static void disarm_safepoint();
   148   static uint64_t safepoint_counter()             { return _safepoint_counter; }
   144   static uint64_t safepoint_counter()             { return _safepoint_counter; }
   149   static bool is_same_safepoint(uint64_t counter) { return (SafepointSynchronize::safepoint_counter() - counter) < 2; }
   145   static bool is_same_safepoint(uint64_t counter) { return (SafepointSynchronize::safepoint_counter() - counter) < 2; }
   150   // Exception handling for page polling
   146   // Exception handling for page polling
   151   static void handle_polling_page_exception(JavaThread *thread);
   147   static void handle_polling_page_exception(JavaThread *thread);
   152 
   148 
   153   // VM Thread interface for determining safepoint rate
       
   154   static long last_non_safepoint_interval() {
       
   155     return os::javaTimeMillis() - _end_of_last_safepoint;
       
   156   }
       
   157   static long end_of_last_safepoint() {
       
   158     return _end_of_last_safepoint;
       
   159   }
       
   160   static bool is_cleanup_needed();
   149   static bool is_cleanup_needed();
   161   static void do_cleanup_tasks();
   150   static void do_cleanup_tasks();
   162 
       
   163   static void print_stat_on_exit();
       
   164   static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; }
       
   165 
   151 
   166   static void set_is_at_safepoint()             { _state = _synchronized; }
   152   static void set_is_at_safepoint()             { _state = _synchronized; }
   167   static void set_is_not_at_safepoint()         { _state = _not_synchronized; }
   153   static void set_is_not_at_safepoint()         { _state = _not_synchronized; }
   168 
   154 
   169   // Assembly support
   155   // Assembly support
   245   // Initialize
   231   // Initialize
   246   static void create(JavaThread *thread);
   232   static void create(JavaThread *thread);
   247   static void destroy(JavaThread *thread);
   233   static void destroy(JavaThread *thread);
   248 };
   234 };
   249 
   235 
   250 
   236 class SafepointTracing : public AllStatic {
       
   237 private:
       
   238   // Absolute
       
   239   static jlong _last_safepoint_begin_time_ns;
       
   240   static jlong _last_safepoint_sync_time_ns;
       
   241   static jlong _last_safepoint_cleanup_time_ns;
       
   242   static jlong _last_safepoint_end_time_ns;
       
   243   // Relative
       
   244   static jlong _last_app_time_ns;
       
   245 
       
   246   static int _nof_threads;
       
   247   static int _nof_running;
       
   248   static int _page_trap;
       
   249 
       
   250   static VM_Operation::VMOp_Type _current_type;
       
   251   static jlong     _max_sync_time;
       
   252   static jlong     _max_vmop_time;
       
   253   static uint64_t  _op_count[VM_Operation::VMOp_Terminating];
       
   254 
       
   255   static void statistics_log();
       
   256 
       
   257 public:
       
   258   static void init();
       
   259 
       
   260   static void begin(VM_Operation::VMOp_Type type);
       
   261   static void synchronized(int nof_threads, int nof_running, int traps);
       
   262   static void cleanup();
       
   263   static void end();
       
   264 
       
   265   static void statistics_exit_log();
       
   266 
       
   267   static jlong time_since_last_safepoint_ms() {
       
   268     return (os::javaTimeNanos() - _last_safepoint_end_time_ns) / (NANOUNITS / MILLIUNITS);
       
   269   }
       
   270 
       
   271   static jlong end_of_last_safepoint_ms() {
       
   272     return _last_safepoint_end_time_ns / (NANOUNITS / MILLIUNITS);
       
   273   }
       
   274 
       
   275   static jlong start_of_safepoint() {
       
   276     return _last_safepoint_begin_time_ns;
       
   277   }
       
   278 };
   251 
   279 
   252 #endif // SHARE_RUNTIME_SAFEPOINT_HPP
   280 #endif // SHARE_RUNTIME_SAFEPOINT_HPP