Skip to content

Commit cbe9c1b

Browse files
eastigPaul Hohensee
authored andcommitted
8213137: Remove static initialization of monitor/mutex instances
Moved to the global mutex list in mutexLocker Reviewed-by: phh, simonis Backport-of: eac28d7
1 parent e44258c commit cbe9c1b

File tree

11 files changed

+37
-40
lines changed

11 files changed

+37
-40
lines changed

src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ class JfrThreadSampler : public NonJavaThread {
321321
int _cur_index;
322322
const u4 _max_frames;
323323
volatile bool _disenrolled;
324-
static Monitor* _transition_block_lock;
325324

326325
JavaThread* next_thread(ThreadsList* t_list, JavaThread* first_sampled, JavaThread* current);
327326
void task_stacktrace(JfrSampleType type, JavaThread** last_thread);
@@ -339,12 +338,10 @@ class JfrThreadSampler : public NonJavaThread {
339338

340339
public:
341340
void run();
342-
static Monitor* transition_block() { return _transition_block_lock; }
341+
static Monitor* transition_block() { return JfrThreadSampler_lock; }
343342
static void on_javathread_suspend(JavaThread* thread);
344343
};
345344

346-
Monitor* JfrThreadSampler::_transition_block_lock = new Monitor(Mutex::leaf, "Trace block", true, Monitor::_safepoint_check_never);
347-
348345
static void clear_transition_block(JavaThread* jt) {
349346
jt->clear_trace_flag();
350347
JfrThreadLocal* const tl = jt->jfr_thread_local();

src/hotspot/share/runtime/mutexLocker.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Monitor* Notify_lock = NULL;
105105
Mutex* ProfilePrint_lock = NULL;
106106
Mutex* ExceptionCache_lock = NULL;
107107
Mutex* OsrList_lock = NULL;
108-
108+
Mutex* NMethodSweeperStats_lock = NULL;
109109
#ifndef PRODUCT
110110
Mutex* FullGCALot_lock = NULL;
111111
#endif
@@ -139,6 +139,7 @@ Mutex* JfrStacktrace_lock = NULL;
139139
Monitor* JfrMsg_lock = NULL;
140140
Mutex* JfrBuffer_lock = NULL;
141141
Mutex* JfrStream_lock = NULL;
142+
Monitor* JfrThreadSampler_lock = NULL;
142143
#endif
143144

144145
#ifndef SUPPORTS_NATIVE_CX8
@@ -148,6 +149,9 @@ Monitor* CodeHeapStateAnalytics_lock = NULL;
148149

149150
Mutex* MetaspaceExpand_lock = NULL;
150151
Mutex* ThreadIdTableCreate_lock = NULL;
152+
Monitor* ThreadsSMRDelete_lock = NULL;
153+
Mutex* SharedDecoder_lock = NULL;
154+
Mutex* DCmdFactory_lock = NULL;
151155

152156
#define MAX_NUM_MUTEX 128
153157
static Monitor * _mutex_array[MAX_NUM_MUTEX];
@@ -241,7 +245,7 @@ void mutex_init() {
241245
def(JmethodIdCreation_lock , PaddedMutex , leaf, true, Monitor::_safepoint_check_never); // used for creating jmethodIDs.
242246

243247
def(SystemDictionary_lock , PaddedMonitor, leaf, true, Monitor::_safepoint_check_always); // lookups done by VM thread
244-
def(SharedDictionary_lock , PaddedMutex, leaf, true, Monitor::_safepoint_check_always); // lookups done by VM thread
248+
def(SharedDictionary_lock , PaddedMutex , leaf, true, Monitor::_safepoint_check_always); // lookups done by VM thread
245249
def(Module_lock , PaddedMutex , leaf+2, true, Monitor::_safepoint_check_always);
246250
def(InlineCacheBuffer_lock , PaddedMutex , leaf, true, Monitor::_safepoint_check_always);
247251
def(VMStatistic_lock , PaddedMutex , leaf, false, Monitor::_safepoint_check_always);
@@ -323,6 +327,7 @@ void mutex_init() {
323327
def(JfrBuffer_lock , PaddedMutex , leaf, true, Monitor::_safepoint_check_never);
324328
def(JfrStream_lock , PaddedMutex , leaf+1, true, Monitor::_safepoint_check_never); // ensure to rank lower than 'safepoint'
325329
def(JfrStacktrace_lock , PaddedMutex , special, true, Monitor::_safepoint_check_sometimes);
330+
def(JfrThreadSampler_lock , PaddedMonitor, leaf, true, Monitor::_safepoint_check_never);
326331
#endif
327332

328333
#ifndef SUPPORTS_NATIVE_CX8
@@ -331,6 +336,11 @@ void mutex_init() {
331336

332337
def(CodeHeapStateAnalytics_lock , PaddedMutex , nonleaf+6, false, Monitor::_safepoint_check_always);
333338
def(ThreadIdTableCreate_lock , PaddedMutex , leaf, false, Monitor::_safepoint_check_always);
339+
340+
def(NMethodSweeperStats_lock , PaddedMutex , special, true, Monitor::_safepoint_check_sometimes);
341+
def(ThreadsSMRDelete_lock , PaddedMonitor, special, false, Monitor::_safepoint_check_never);
342+
def(SharedDecoder_lock , PaddedMutex , native, false, Monitor::_safepoint_check_never);
343+
def(DCmdFactory_lock , PaddedMutex , leaf, true, Monitor::_safepoint_check_never);
334344
}
335345

336346
GCMutexLocker::GCMutexLocker(Monitor * mutex) {

src/hotspot/share/runtime/mutexLocker.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ extern Monitor* Notify_lock; // a lock used to synchronize t
109109
extern Mutex* ProfilePrint_lock; // a lock used to serialize the printing of profiles
110110
extern Mutex* ExceptionCache_lock; // a lock used to synchronize exception cache updates
111111
extern Mutex* OsrList_lock; // a lock used to serialize access to OSR queues
112+
extern Mutex* NMethodSweeperStats_lock; // a lock used to serialize access to sweeper statistics
112113

113114
#ifndef PRODUCT
114115
extern Mutex* FullGCALot_lock; // a lock to make FullGCALot MT safe
@@ -134,11 +135,15 @@ extern Mutex* ThreadIdTableCreate_lock; // Used by ThreadIdTable to laz
134135
extern Monitor* RedefineClasses_lock; // locks classes from parallel redefinition
135136
extern Mutex* ThreadHeapSampler_lock; // protects the static data for initialization.
136137

138+
extern Monitor* ThreadsSMRDelete_lock; // Used by ThreadsSMRSupport to take pressure off the Threads_lock
139+
extern Mutex* SharedDecoder_lock; // serializes access to the decoder during normal (not error reporting) use
140+
extern Mutex* DCmdFactory_lock; // serialize access to DCmdFactory information
137141
#if INCLUDE_JFR
138142
extern Mutex* JfrStacktrace_lock; // used to guard access to the JFR stacktrace table
139143
extern Monitor* JfrMsg_lock; // protects JFR messaging
140144
extern Mutex* JfrBuffer_lock; // protects JFR buffer operations
141145
extern Mutex* JfrStream_lock; // protects JFR stream access
146+
extern Monitor* JfrThreadSampler_lock; // used to suspend/resume JFR thread sampler
142147
#endif
143148

144149
#ifndef SUPPORTS_NATIVE_CX8

src/hotspot/share/runtime/sweeper.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ Tickspan NMethodSweeper::_total_time_this_sweep; // Total time thi
160160
Tickspan NMethodSweeper::_peak_sweep_time; // Peak time for a full sweep
161161
Tickspan NMethodSweeper::_peak_sweep_fraction_time; // Peak time sweeping one fraction
162162

163-
Monitor* NMethodSweeper::_stat_lock = new Monitor(Mutex::special, "Sweeper::Statistics", true, Monitor::_safepoint_check_sometimes);
164-
165163
class MarkActivationClosure: public CodeBlobClosure {
166164
public:
167165
virtual void do_code_blob(CodeBlob* cb) {
@@ -505,7 +503,7 @@ void NMethodSweeper::sweep_code_cache() {
505503
const Ticks sweep_end_counter = Ticks::now();
506504
const Tickspan sweep_time = sweep_end_counter - sweep_start_counter;
507505
{
508-
MutexLockerEx mu(_stat_lock, Mutex::_no_safepoint_check_flag);
506+
MutexLockerEx mu(NMethodSweeperStats_lock, Mutex::_no_safepoint_check_flag);
509507
_total_time_sweeping += sweep_time;
510508
_total_time_this_sweep += sweep_time;
511509
_peak_sweep_fraction_time = MAX2(sweep_time, _peak_sweep_fraction_time);

src/hotspot/share/runtime/sweeper.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ class NMethodSweeper : public AllStatic {
8888
static Tickspan _peak_sweep_time; // Peak time for a full sweep
8989
static Tickspan _peak_sweep_fraction_time; // Peak time sweeping one fraction
9090

91-
static Monitor* _stat_lock;
92-
9391
static MethodStateChange process_compiled_method(CompiledMethod *nm);
9492

9593
static void init_sweeper_log() NOT_DEBUG_RETURN;

src/hotspot/share/runtime/threadSMR.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
#include "utilities/resourceHash.hpp"
3939
#include "utilities/vmError.hpp"
4040

41-
Monitor* ThreadsSMRSupport::_delete_lock =
42-
new Monitor(Monitor::special, "Thread_SMR_delete_lock",
43-
false /* allow_vm_block */,
44-
Monitor::_safepoint_check_never);
4541
// The '_cnt', '_max' and '_times" fields are enabled via
4642
// -XX:+EnableThreadSMRStatistics:
4743

src/hotspot/share/runtime/threadSMR.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class ThreadsSMRSupport : AllStatic {
9191
// The coordination between ThreadsSMRSupport::release_stable_list() and
9292
// ThreadsSMRSupport::smr_delete() uses the delete_lock in order to
9393
// reduce the traffic on the Threads_lock.
94-
static Monitor* _delete_lock;
94+
static Monitor* delete_lock() { return ThreadsSMRDelete_lock; }
95+
9596
// The '_cnt', '_max' and '_times" fields are enabled via
9697
// -XX:+EnableThreadSMRStatistics (see thread.cpp for a
9798
// description about each field):
@@ -121,7 +122,6 @@ class ThreadsSMRSupport : AllStatic {
121122
static void add_deleted_thread_times(uint add_value);
122123
static void add_tlh_times(uint add_value);
123124
static void clear_delete_notify();
124-
static Monitor* delete_lock() { return _delete_lock; }
125125
static bool delete_notify();
126126
static void free_list(ThreadsList* threads);
127127
static void inc_deleted_thread_cnt();

src/hotspot/share/services/diagnosticFramework.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,10 @@ void DCmdFactory::send_notification_internal(TRAPS) {
491491
}
492492
}
493493

494-
Mutex* DCmdFactory::_dcmdFactory_lock = new Mutex(Mutex::leaf, "DCmdFactory", true, Monitor::_safepoint_check_never);
495494
bool DCmdFactory::_send_jmx_notification = false;
496495

497496
DCmdFactory* DCmdFactory::factory(DCmdSource source, const char* name, size_t len) {
498-
MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
497+
MutexLockerEx ml(DCmdFactory_lock, Mutex::_no_safepoint_check_flag);
499498
DCmdFactory* factory = _DCmdFactoryList;
500499
while (factory != NULL) {
501500
if (strlen(factory->name()) == len &&
@@ -512,7 +511,7 @@ DCmdFactory* DCmdFactory::factory(DCmdSource source, const char* name, size_t le
512511
}
513512

514513
int DCmdFactory::register_DCmdFactory(DCmdFactory* factory) {
515-
MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
514+
MutexLockerEx ml(DCmdFactory_lock, Mutex::_no_safepoint_check_flag);
516515
factory->_next = _DCmdFactoryList;
517516
_DCmdFactoryList = factory;
518517
if (_send_jmx_notification && !factory->_hidden
@@ -537,7 +536,7 @@ DCmd* DCmdFactory::create_local_DCmd(DCmdSource source, CmdLine &line,
537536
}
538537

539538
GrowableArray<const char*>* DCmdFactory::DCmd_list(DCmdSource source) {
540-
MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
539+
MutexLockerEx ml(DCmdFactory_lock, Mutex::_no_safepoint_check_flag);
541540
GrowableArray<const char*>* array = new GrowableArray<const char*>();
542541
DCmdFactory* factory = _DCmdFactoryList;
543542
while (factory != NULL) {
@@ -550,7 +549,7 @@ GrowableArray<const char*>* DCmdFactory::DCmd_list(DCmdSource source) {
550549
}
551550

552551
GrowableArray<DCmdInfo*>* DCmdFactory::DCmdInfo_list(DCmdSource source ) {
553-
MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
552+
MutexLockerEx ml(DCmdFactory_lock, Mutex::_no_safepoint_check_flag);
554553
GrowableArray<DCmdInfo*>* array = new GrowableArray<DCmdInfo*>();
555554
DCmdFactory* factory = _DCmdFactoryList;
556555
while (factory != NULL) {

src/hotspot/share/services/diagnosticFramework.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ class DCmdMark : public StackObj {
344344
// management.cpp)
345345
class DCmdFactory: public CHeapObj<mtInternal> {
346346
private:
347-
static Mutex* _dcmdFactory_lock;
348347
static bool _send_jmx_notification;
349348
static bool _has_pending_jmx_notification;
350349
static DCmdFactory* _DCmdFactoryList;

src/hotspot/share/utilities/decoder.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,14 +41,9 @@
4141
AbstractDecoder* Decoder::_shared_decoder = NULL;
4242
AbstractDecoder* Decoder::_error_handler_decoder = NULL;
4343
NullDecoder Decoder::_do_nothing_decoder;
44-
Mutex* Decoder::_shared_decoder_lock = new Mutex(Mutex::native,
45-
"SharedDecoderLock",
46-
false,
47-
Monitor::_safepoint_check_never);
4844

4945
AbstractDecoder* Decoder::get_shared_instance() {
50-
assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),
51-
"Require DecoderLock to enter");
46+
assert(shared_decoder_lock()->owned_by_self(), "Require DecoderLock to enter");
5247

5348
if (_shared_decoder == NULL) {
5449
_shared_decoder = create_decoder();
@@ -89,21 +84,22 @@ inline bool DecoderLocker::is_first_error_thread() {
8984

9085
DecoderLocker::DecoderLocker() :
9186
MutexLockerEx(DecoderLocker::is_first_error_thread() ?
92-
NULL : Decoder::shared_decoder_lock(), true) {
87+
NULL : Decoder::shared_decoder_lock(),
88+
Mutex::_no_safepoint_check_flag) {
9389
_decoder = is_first_error_thread() ?
9490
Decoder::get_error_handler_instance() : Decoder::get_shared_instance();
9591
assert(_decoder != NULL, "null decoder");
9692
}
9793

9894
Mutex* Decoder::shared_decoder_lock() {
99-
assert(_shared_decoder_lock != NULL, "Just check");
100-
return _shared_decoder_lock;
95+
assert(SharedDecoder_lock != NULL, "Just check");
96+
return SharedDecoder_lock;
10197
}
10298

10399
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {
104-
assert(_shared_decoder_lock != NULL, "Just check");
105100
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
106-
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
101+
MutexLockerEx locker(error_handling_thread ? NULL : shared_decoder_lock(),
102+
Mutex::_no_safepoint_check_flag);
107103
AbstractDecoder* decoder = error_handling_thread ?
108104
get_error_handler_instance(): get_shared_instance();
109105
assert(decoder != NULL, "null decoder");
@@ -112,9 +108,9 @@ bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const cha
112108
}
113109

114110
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
115-
assert(_shared_decoder_lock != NULL, "Just check");
116111
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
117-
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
112+
MutexLockerEx locker(error_handling_thread ? NULL : shared_decoder_lock(),
113+
Mutex::_no_safepoint_check_flag);
118114
AbstractDecoder* decoder = error_handling_thread ?
119115
get_error_handler_instance(): get_shared_instance();
120116
assert(decoder != NULL, "null decoder");
@@ -124,9 +120,9 @@ bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const voi
124120

125121

126122
bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
127-
assert(_shared_decoder_lock != NULL, "Just check");
128123
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
129-
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
124+
MutexLockerEx locker(error_handling_thread ? NULL : shared_decoder_lock(),
125+
Mutex::_no_safepoint_check_flag);
130126
AbstractDecoder* decoder = error_handling_thread ?
131127
get_error_handler_instance(): get_shared_instance();
132128
assert(decoder != NULL, "null decoder");

0 commit comments

Comments
 (0)