8209139: globalCounter bootstrap issue

Reviewed-by: dcubed, dholmes
This commit is contained in:
Robbin Ehn 2018-11-08 15:31:23 +01:00
parent 1117fcb339
commit 1ce3770481
3 changed files with 28 additions and 7 deletions

View File

@ -70,7 +70,16 @@ volatile uint ThreadsSMRSupport::_deleted_thread_time_max = 0;
// isn't available everywhere (or is it?).
volatile uint ThreadsSMRSupport::_deleted_thread_times = 0;
ThreadsList* volatile ThreadsSMRSupport::_java_thread_list = new ThreadsList(0);
// The bootstrap list is empty and cannot be freed.
ThreadsList ThreadsSMRSupport::_bootstrap_list = ThreadsList(0);
// This is the VM's current "threads list" and it contains all of
// the JavaThreads the VM considers to be alive at this moment in
// time. The other ThreadsList objects in the VM contain past
// snapshots of the "threads list". _java_thread_list is initially
// set to _bootstrap_list so that we can detect when we have a very
// early use of a ThreadsListHandle.
ThreadsList* volatile ThreadsSMRSupport::_java_thread_list = &_bootstrap_list;
// # of ThreadsLists allocated over VM lifetime.
// Impl note: We allocate a new ThreadsList for every thread create and
@ -135,6 +144,10 @@ inline void ThreadsSMRSupport::inc_java_thread_list_alloc_cnt() {
_java_thread_list_alloc_cnt++;
}
inline bool ThreadsSMRSupport::is_bootstrap_list(ThreadsList* list) {
return list == &_bootstrap_list;
}
inline void ThreadsSMRSupport::update_deleted_thread_time_max(uint new_value) {
while (true) {
uint cur_value = _deleted_thread_time_max;
@ -159,7 +172,6 @@ inline ThreadsList* ThreadsSMRSupport::xchg_java_thread_list(ThreadsList* new_li
return (ThreadsList*)Atomic::xchg(new_list, &_java_thread_list);
}
// Hash table of pointers found by a scan. Used for collecting hazard
// pointers (ThreadsList references). Also used for collecting JavaThreads
// that are indirectly referenced by hazard ptrs. An instance of this
@ -510,6 +522,11 @@ void SafeThreadsListPtr::verify_hazard_ptr_scanned() {
#ifdef ASSERT
assert(_list != NULL, "_list must not be NULL");
if (ThreadsSMRSupport::is_bootstrap_list(_list)) {
// We are early in VM bootstrapping so nothing to do here.
return;
}
// The closure will attempt to verify that the calling thread can
// be found by threads_do() on the specified ThreadsList. If it
// is successful, then the specified ThreadsList was acquired as
@ -762,6 +779,13 @@ bool ThreadsSMRSupport::delete_notify() {
void ThreadsSMRSupport::free_list(ThreadsList* threads) {
assert_locked_or_safepoint(Threads_lock);
if (is_bootstrap_list(threads)) {
// The bootstrap list cannot be freed and is empty so
// it does not need to be scanned. Nothing to do here.
log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::free_list: bootstrap ThreadsList=" INTPTR_FORMAT " is no longer in use.", os::current_thread_id(), p2i(threads));
return;
}
threads->set_next_list(_to_delete_list);
_to_delete_list = threads;
if (EnableThreadSMRStatistics) {

View File

@ -105,6 +105,7 @@ class ThreadsSMRSupport : AllStatic {
static volatile uint _deleted_thread_cnt;
static volatile uint _deleted_thread_time_max;
static volatile uint _deleted_thread_times;
static ThreadsList _bootstrap_list;
static ThreadsList* volatile _java_thread_list;
static uint64_t _java_thread_list_alloc_cnt;
static uint64_t _java_thread_list_free_cnt;
@ -142,6 +143,7 @@ class ThreadsSMRSupport : AllStatic {
static void add_thread(JavaThread *thread);
static ThreadsList* get_java_thread_list();
static bool is_a_protected_JavaThread_with_lock(JavaThread *thread);
static bool is_bootstrap_list(ThreadsList* list);
static void remove_thread(JavaThread *thread);
static void smr_delete(JavaThread *thread);
static void update_tlh_stats(uint millis);

View File

@ -61,11 +61,6 @@ void GlobalCounter::write_synchronize() {
// Atomic::add must provide fence since we have storeload dependency.
uintx gbl_cnt = Atomic::add(COUNTER_INCREMENT, &_global_counter._counter);
// Handle bootstrap
if (Threads::number_of_threads() == 0) {
return;
}
// Do all RCU threads.
CounterThreadCheck ctc(gbl_cnt);
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {