mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-17 17:44:40 +02:00
8225702: Safepoint counter can't be used for safepoint detection
Reviewed-by: dcubed, dholmes
This commit is contained in:
parent
1a72f29e35
commit
8b067a95ed
6 changed files with 56 additions and 20 deletions
|
@ -118,12 +118,22 @@ static void post_safepoint_end_event(EventSafepointEnd& event, uint64_t safepoin
|
|||
}
|
||||
}
|
||||
|
||||
// SafepointCheck
|
||||
SafepointStateTracker::SafepointStateTracker(uint64_t safepoint_id, bool at_safepoint)
|
||||
: _safepoint_id(safepoint_id), _at_safepoint(at_safepoint) {}
|
||||
|
||||
bool SafepointStateTracker::safepoint_state_changed() {
|
||||
return _safepoint_id != SafepointSynchronize::safepoint_id() ||
|
||||
_at_safepoint != SafepointSynchronize::is_at_safepoint();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------
|
||||
// Implementation of Safepoint begin/end
|
||||
|
||||
SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized;
|
||||
int SafepointSynchronize::_waiting_to_block = 0;
|
||||
volatile uint64_t SafepointSynchronize::_safepoint_counter = 0;
|
||||
uint64_t SafepointSynchronize::_safepoint_id = 0;
|
||||
const uint64_t SafepointSynchronize::InactiveSafepointCounter = 0;
|
||||
int SafepointSynchronize::_current_jni_active_count = 0;
|
||||
|
||||
|
@ -154,7 +164,7 @@ void SafepointSynchronize::decrement_waiting_to_block() {
|
|||
--_waiting_to_block;
|
||||
}
|
||||
|
||||
static bool thread_not_running(ThreadSafepointState *cur_state) {
|
||||
bool SafepointSynchronize::thread_not_running(ThreadSafepointState *cur_state) {
|
||||
if (!cur_state->is_running()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -408,6 +418,9 @@ void SafepointSynchronize::begin() {
|
|||
|
||||
OrderAccess::fence();
|
||||
|
||||
// Set the new id
|
||||
++_safepoint_id;
|
||||
|
||||
#ifdef ASSERT
|
||||
// Make sure all the threads were visited.
|
||||
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur = jtiwh.next(); ) {
|
||||
|
@ -419,7 +432,7 @@ void SafepointSynchronize::begin() {
|
|||
GCLocker::set_jni_lock_count(_current_jni_active_count);
|
||||
|
||||
post_safepoint_synchronize_event(sync_event,
|
||||
_safepoint_counter,
|
||||
_safepoint_id,
|
||||
initial_running,
|
||||
_waiting_to_block, iterations);
|
||||
|
||||
|
@ -429,14 +442,14 @@ void SafepointSynchronize::begin() {
|
|||
// needs cleanup to be completed before running the GC op.
|
||||
EventSafepointCleanup cleanup_event;
|
||||
do_cleanup_tasks();
|
||||
post_safepoint_cleanup_event(cleanup_event, _safepoint_counter);
|
||||
post_safepoint_cleanup_event(cleanup_event, _safepoint_id);
|
||||
|
||||
post_safepoint_begin_event(begin_event, _safepoint_counter, nof_threads, _current_jni_active_count);
|
||||
post_safepoint_begin_event(begin_event, _safepoint_id, nof_threads, _current_jni_active_count);
|
||||
SafepointTracing::cleanup();
|
||||
}
|
||||
|
||||
void SafepointSynchronize::disarm_safepoint() {
|
||||
uint64_t safepoint_id = _safepoint_counter;
|
||||
uint64_t active_safepoint_counter = _safepoint_counter;
|
||||
{
|
||||
JavaThreadIteratorWithHandle jtiwh;
|
||||
#ifdef ASSERT
|
||||
|
@ -475,7 +488,7 @@ void SafepointSynchronize::disarm_safepoint() {
|
|||
jtiwh.rewind();
|
||||
for (; JavaThread *current = jtiwh.next(); ) {
|
||||
// Clear the visited flag to ensure that the critical counts are collected properly.
|
||||
DEBUG_ONLY(current->reset_visited_for_critical_count(safepoint_id);)
|
||||
DEBUG_ONLY(current->reset_visited_for_critical_count(active_safepoint_counter);)
|
||||
ThreadSafepointState* cur_state = current->safepoint_state();
|
||||
assert(!cur_state->is_running(), "Thread not suspended at safepoint");
|
||||
cur_state->restart(); // TSS _running
|
||||
|
@ -497,7 +510,6 @@ void SafepointSynchronize::disarm_safepoint() {
|
|||
void SafepointSynchronize::end() {
|
||||
assert(Threads_lock->owned_by_self(), "must hold Threads_lock");
|
||||
EventSafepointEnd event;
|
||||
uint64_t safepoint_id = _safepoint_counter;
|
||||
assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint");
|
||||
|
||||
disarm_safepoint();
|
||||
|
@ -506,7 +518,7 @@ void SafepointSynchronize::end() {
|
|||
|
||||
SafepointTracing::end();
|
||||
|
||||
post_safepoint_end_event(event, safepoint_id);
|
||||
post_safepoint_end_event(event, safepoint_id());
|
||||
}
|
||||
|
||||
bool SafepointSynchronize::is_cleanup_needed() {
|
||||
|
@ -554,7 +566,7 @@ public:
|
|||
_counters(counters) {}
|
||||
|
||||
void work(uint worker_id) {
|
||||
uint64_t safepoint_id = SafepointSynchronize::safepoint_counter();
|
||||
uint64_t safepoint_id = SafepointSynchronize::safepoint_id();
|
||||
// All threads deflate monitors and mark nmethods (if necessary).
|
||||
Threads::possibly_parallel_threads_do(true, &_cleanup_threads_cl);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue