8187040: ThreadCritical crashes on Solaris if used between os::init and os::init_2
Reviewed-by: dholmes, stuefe
--- a/src/hotspot/os/aix/os_aix.cpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/aix/os_aix.cpp Mon Sep 25 21:25:46 2017 -0400
@@ -3443,8 +3443,6 @@
init_random(1234567);
- ThreadCritical::initialize();
-
// Main_thread points to the aboriginal thread.
Aix::_main_thread = pthread_self();
--- a/src/hotspot/os/aix/threadCritical_aix.cpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/aix/threadCritical_aix.cpp Mon Sep 25 21:25:46 2017 -0400
@@ -38,12 +38,6 @@
static pthread_mutex_t tc_mutex = PTHREAD_MUTEX_INITIALIZER;
static int tc_count = 0;
-void ThreadCritical::initialize() {
-}
-
-void ThreadCritical::release() {
-}
-
ThreadCritical::ThreadCritical() {
pthread_t self = pthread_self();
if (self != tc_owner) {
--- a/src/hotspot/os/bsd/os_bsd.cpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/bsd/os_bsd.cpp Mon Sep 25 21:25:46 2017 -0400
@@ -3353,8 +3353,6 @@
init_random(1234567);
- ThreadCritical::initialize();
-
Bsd::set_page_size(getpagesize());
if (Bsd::page_size() == -1) {
fatal("os_bsd.cpp: os::init: sysconf failed (%s)", os::strerror(errno));
--- a/src/hotspot/os/bsd/threadCritical_bsd.cpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/bsd/threadCritical_bsd.cpp Mon Sep 25 21:25:46 2017 -0400
@@ -37,12 +37,6 @@
static pthread_mutex_t tc_mutex = PTHREAD_MUTEX_INITIALIZER;
static int tc_count = 0;
-void ThreadCritical::initialize() {
-}
-
-void ThreadCritical::release() {
-}
-
ThreadCritical::ThreadCritical() {
pthread_t self = pthread_self();
if (self != tc_owner) {
--- a/src/hotspot/os/linux/os_linux.cpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/linux/os_linux.cpp Mon Sep 25 21:25:46 2017 -0400
@@ -4768,8 +4768,6 @@
init_random(1234567);
- ThreadCritical::initialize();
-
Linux::set_page_size(sysconf(_SC_PAGESIZE));
if (Linux::page_size() == -1) {
fatal("os_linux.cpp: os::init: sysconf failed (%s)",
--- a/src/hotspot/os/linux/threadCritical_linux.cpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/linux/threadCritical_linux.cpp Mon Sep 25 21:25:46 2017 -0400
@@ -37,12 +37,6 @@
static pthread_mutex_t tc_mutex = PTHREAD_MUTEX_INITIALIZER;
static int tc_count = 0;
-void ThreadCritical::initialize() {
-}
-
-void ThreadCritical::release() {
-}
-
ThreadCritical::ThreadCritical() {
pthread_t self = pthread_self();
if (self != tc_owner) {
--- a/src/hotspot/os/solaris/os_solaris.cpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/solaris/os_solaris.cpp Mon Sep 25 21:25:46 2017 -0400
@@ -4076,6 +4076,7 @@
int_fnP_cond_tP_i_vP os::Solaris::_cond_init;
int_fnP_cond_tP os::Solaris::_cond_destroy;
int os::Solaris::_cond_scope = USYNC_THREAD;
+bool os::Solaris::_synchronization_initialized;
void os::Solaris::synchronization_init() {
if (UseLWPSynchronization) {
@@ -4125,6 +4126,7 @@
os::Solaris::set_cond_destroy(::cond_destroy);
}
}
+ _synchronization_initialized = true;
}
bool os::Solaris::liblgrp_init() {
@@ -4198,9 +4200,6 @@
dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1"));
}
- // (Solaris only) this switches to calls that actually do locking.
- ThreadCritical::initialize();
-
main_thread = thr_self();
// dynamic lookup of functions that may not be available in our lowest
--- a/src/hotspot/os/solaris/os_solaris.hpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/solaris/os_solaris.hpp Mon Sep 25 21:25:46 2017 -0400
@@ -65,6 +65,8 @@
static int_fnP_cond_tP _cond_destroy;
static int _cond_scope;
+ static bool _synchronization_initialized;
+
typedef uintptr_t lgrp_cookie_t;
typedef id_t lgrp_id_t;
typedef int lgrp_rsrc_t;
@@ -227,6 +229,8 @@
static void set_cond_destroy(int_fnP_cond_tP func) { _cond_destroy = func; }
static void set_cond_scope(int scope) { _cond_scope = scope; }
+ static bool synchronization_initialized() { return _synchronization_initialized; }
+
static void set_lgrp_home(lgrp_home_func_t func) { _lgrp_home = func; }
static void set_lgrp_init(lgrp_init_func_t func) { _lgrp_init = func; }
static void set_lgrp_fini(lgrp_fini_func_t func) { _lgrp_fini = func; }
--- a/src/hotspot/os/solaris/threadCritical_solaris.cpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/solaris/threadCritical_solaris.cpp Mon Sep 25 21:25:46 2017 -0400
@@ -42,10 +42,9 @@
static mutex_t global_mut;
static thread_t global_mut_owner = -1;
static int global_mut_count = 0;
-static bool initialized = false;
ThreadCritical::ThreadCritical() {
- if (initialized) {
+ if (os::Solaris::synchronization_initialized()) {
thread_t owner = thr_self();
if (global_mut_owner != owner) {
if (os::Solaris::mutex_lock(&global_mut))
@@ -62,7 +61,7 @@
}
ThreadCritical::~ThreadCritical() {
- if (initialized) {
+ if (os::Solaris::synchronization_initialized()) {
assert(global_mut_owner == thr_self(), "must have correct owner");
assert(global_mut_count > 0, "must have correct count");
--global_mut_count;
@@ -75,12 +74,3 @@
assert (Threads::number_of_threads() == 0, "valid only during initialization");
}
}
-
-void ThreadCritical::initialize() {
- // This method is called at the end of os::init(). Until
- // then, we don't do real locking.
- initialized = true;
-}
-
-void ThreadCritical::release() {
-}
--- a/src/hotspot/os/windows/threadCritical_windows.cpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/os/windows/threadCritical_windows.cpp Mon Sep 25 21:25:46 2017 -0400
@@ -51,16 +51,6 @@
// and found them ~30 times slower than the critical region code.
//
-void ThreadCritical::initialize() {
-}
-
-void ThreadCritical::release() {
- assert(lock_owner == -1, "Mutex being deleted while owned.");
- assert(lock_count == -1, "Mutex being deleted while recursively locked");
- assert(lock_event != NULL, "Sanity check");
- CloseHandle(lock_event);
-}
-
ThreadCritical::ThreadCritical() {
DWORD current_thread = GetCurrentThreadId();
--- a/src/hotspot/share/runtime/threadCritical.hpp Mon Sep 25 14:23:18 2017 -0700
+++ b/src/hotspot/share/runtime/threadCritical.hpp Mon Sep 25 21:25:46 2017 -0400
@@ -47,11 +47,6 @@
// or CHeapObj, due to initialization issues.
class ThreadCritical : public StackObj {
- friend class os;
- private:
- static void initialize();
- static void release();
-
public:
ThreadCritical();
~ThreadCritical();