diff -r 13588c901957 -r 9cf78a70fa4f src/hotspot/share/runtime/safepoint.hpp --- a/src/hotspot/share/runtime/safepoint.hpp Thu Oct 17 20:27:44 2019 +0100 +++ b/src/hotspot/share/runtime/safepoint.hpp Thu Oct 17 20:53:35 2019 +0100 @@ -48,6 +48,14 @@ class ThreadSafepointState; +class SafepointStateTracker { + uint64_t _safepoint_id; + bool _at_safepoint; +public: + SafepointStateTracker(uint64_t safepoint_id, bool at_safepoint); + bool safepoint_state_changed(); +}; + // // Implements roll-forward to safepoint (safepoint synchronization) // @@ -69,6 +77,7 @@ SAFEPOINT_CLEANUP_STRING_TABLE_REHASH, SAFEPOINT_CLEANUP_CLD_PURGE, SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE, + SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP, // Leave this one last. SAFEPOINT_CLEANUP_NUM_TASKS }; @@ -77,6 +86,7 @@ friend class SafepointMechanism; friend class ThreadSafepointState; friend class HandshakeState; + friend class SafepointStateTracker; // Threads might read this flag directly, without acquiring the Threads_lock: static volatile SynchronizeState _state; @@ -91,20 +101,17 @@ // safepoint. static volatile uint64_t _safepoint_counter; + // A change in this counter or a change in the result of + // is_at_safepoint() are used by SafepointStateTracker:: + // safepoint_state_changed() to determine its answer. + static uint64_t _safepoint_id; + // JavaThreads that need to block for the safepoint will stop on the // _wait_barrier, where they can quickly be started again. static WaitBarrier* _wait_barrier; static long _end_of_last_safepoint; // Time of last safepoint in milliseconds static julong _coalesced_vmop_count; // coalesced vmop count - // Statistics - static void begin_statistics(int nof_threads, int nof_running); - static void update_statistics_on_spin_end(); - static void update_statistics_on_sync_end(jlong end_time); - static void update_statistics_on_cleanup_end(jlong end_time); - static void end_statistics(jlong end_time); - static void print_statistics(); - // For debug long safepoint static void print_safepoint_timeout(); @@ -114,6 +121,7 @@ static void disarm_safepoint(); static void increment_jni_active_count(); static void decrement_waiting_to_block(); + static bool thread_not_running(ThreadSafepointState *cur_state); // Used in safepoint_safe to do a stable load of the thread state. static bool try_stable_load_state(JavaThreadState *state, @@ -127,6 +135,8 @@ // If true the VMThread may safely process the handshake operation for the JavaThread. static bool handshake_safe(JavaThread *thread); + static uint64_t safepoint_counter() { return _safepoint_counter; } + public: static void init(Thread* vmthread); @@ -141,8 +151,15 @@ // Query static bool is_at_safepoint() { return _state == _synchronized; } static bool is_synchronizing() { return _state == _synchronizing; } - static uint64_t safepoint_counter() { return _safepoint_counter; } - static bool is_same_safepoint(uint64_t counter) { return (SafepointSynchronize::safepoint_counter() - counter) < 2; } + + static uint64_t safepoint_id() { + return _safepoint_id; + } + + static SafepointStateTracker safepoint_state_tracker() { + return SafepointStateTracker(safepoint_id(), is_at_safepoint()); + } + // Exception handling for page polling static void handle_polling_page_exception(JavaThread *thread); @@ -190,7 +207,6 @@ JavaThread* _thread; bool _safepoint_safe; volatile uint64_t _safepoint_id; - JavaThreadState _orig_thread_state; ThreadSafepointState* _next; @@ -216,8 +232,6 @@ void reset_safepoint_id(); void set_safepoint_id(uint64_t sid); - JavaThreadState orig_thread_state() const { return _orig_thread_state; } - // Support for safepoint timeout (debugging) bool is_at_poll_safepoint() { return _at_poll_safepoint; } void set_at_poll_safepoint(bool val) { _at_poll_safepoint = val; } @@ -226,7 +240,6 @@ // debugging void print_on(outputStream* st) const; - void print() const; // Initialize static void create(JavaThread *thread);