Skip to content

Commit b3594c9

Browse files
committed
8357481: Excessive CompileTask wait/notify monitor creation
Reviewed-by: vlivanov, kvn
1 parent 83b15da commit b3594c9

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

src/hotspot/share/compiler/compileBroker.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ CompileTaskWrapper::~CompileTaskWrapper() {
231231
if (task->is_blocking()) {
232232
bool free_task = false;
233233
{
234-
MutexLocker notifier(thread, task->lock());
234+
MutexLocker notifier(thread, CompileTaskWait_lock);
235235
task->mark_complete();
236236
#if INCLUDE_JVMCI
237237
if (CompileBroker::compiler(task->comp_level())->is_jvmci()) {
@@ -245,7 +245,7 @@ CompileTaskWrapper::~CompileTaskWrapper() {
245245
if (!free_task) {
246246
// Notify the waiting thread that the compilation has completed
247247
// so that it can free the task.
248-
task->lock()->notify_all();
248+
CompileTaskWait_lock->notify_all();
249249
}
250250
}
251251
if (free_task) {
@@ -375,12 +375,12 @@ void CompileQueue::free_all() {
375375
next = current->next();
376376
bool found_waiter = false;
377377
{
378-
MutexLocker ct_lock(current->lock());
378+
MutexLocker ct_lock(CompileTaskWait_lock);
379379
assert(current->waiting_for_completion_count() <= 1, "more than one thread are waiting for task");
380380
if (current->waiting_for_completion_count() > 0) {
381381
// If another thread waits for this task, we must wake them up
382382
// so they will stop waiting and free the task.
383-
current->lock()->notify();
383+
CompileTaskWait_lock->notify_all();
384384
found_waiter = true;
385385
}
386386
}
@@ -1655,7 +1655,7 @@ static const int JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS = 10;
16551655
*/
16561656
bool CompileBroker::wait_for_jvmci_completion(JVMCICompiler* jvmci, CompileTask* task, JavaThread* thread) {
16571657
assert(UseJVMCICompiler, "sanity");
1658-
MonitorLocker ml(thread, task->lock());
1658+
MonitorLocker ml(thread, CompileTaskWait_lock);
16591659
int progress_wait_attempts = 0;
16601660
jint thread_jvmci_compilation_ticks = 0;
16611661
jint global_jvmci_compilation_ticks = jvmci->global_compilation_ticks();
@@ -1723,7 +1723,7 @@ void CompileBroker::wait_for_completion(CompileTask* task) {
17231723
} else
17241724
#endif
17251725
{
1726-
MonitorLocker ml(thread, task->lock());
1726+
MonitorLocker ml(thread, CompileTaskWait_lock);
17271727
free_task = true;
17281728
task->inc_waiting_for_completion();
17291729
while (!task->is_complete() && !is_compilation_disabled_forever()) {

src/hotspot/share/compiler/compileTask.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ CompileTask* CompileTask::allocate() {
6565
void CompileTask::free(CompileTask* task) {
6666
MutexLocker locker(CompileTaskAlloc_lock);
6767
if (!task->is_free()) {
68-
assert(!task->lock()->is_locked(), "Should not be locked when freed");
6968
if ((task->_method_holder != nullptr && JNIHandles::is_weak_global_handle(task->_method_holder))) {
7069
JNIHandles::destroy_weak_global(task->_method_holder);
7170
} else {
@@ -90,8 +89,6 @@ void CompileTask::initialize(int compile_id,
9089
int hot_count,
9190
CompileTask::CompileReason compile_reason,
9291
bool is_blocking) {
93-
assert(!_lock->is_locked(), "bad locking");
94-
9592
Thread* thread = Thread::current();
9693
_compile_id = compile_id;
9794
_method = method();

src/hotspot/share/compiler/compileTask.hpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "code/nmethod.hpp"
3030
#include "compiler/compileLog.hpp"
3131
#include "memory/allocation.hpp"
32+
#include "runtime/mutexLocker.hpp"
3233
#include "utilities/xmlstream.hpp"
3334

3435
class CompileTrainingData;
@@ -82,7 +83,6 @@ class CompileTask : public CHeapObj<mtCompiler> {
8283

8384
private:
8485
static CompileTask* _task_free_list;
85-
Monitor* _lock;
8686
int _compile_id;
8787
Method* _method;
8888
jobject _method_holder;
@@ -116,11 +116,7 @@ class CompileTask : public CHeapObj<mtCompiler> {
116116
size_t _arena_bytes; // peak size of temporary memory during compilation (e.g. node arenas)
117117

118118
public:
119-
CompileTask() : _failure_reason(nullptr), _failure_reason_on_C_heap(false) {
120-
// May hold MethodCompileQueue_lock
121-
_lock = new Monitor(Mutex::safepoint-1, "CompileTask_lock");
122-
}
123-
119+
CompileTask() : _failure_reason(nullptr), _failure_reason_on_C_heap(false) {}
124120
void initialize(int compile_id, const methodHandle& method, int osr_bci, int comp_level,
125121
int hot_count,
126122
CompileTask::CompileReason compile_reason, bool is_blocking);
@@ -172,21 +168,19 @@ class CompileTask : public CHeapObj<mtCompiler> {
172168
}
173169
#endif
174170

175-
Monitor* lock() const { return _lock; }
176-
177171
// See how many threads are waiting for this task. Must have lock to read this.
178172
int waiting_for_completion_count() {
179-
assert(_lock->owned_by_self(), "must have lock to use waiting_for_completion_count()");
173+
assert(CompileTaskWait_lock->owned_by_self(), "must have lock to use waiting_for_completion_count()");
180174
return _waiting_count;
181175
}
182176
// Indicates that a thread is waiting for this task to complete. Must have lock to use this.
183177
void inc_waiting_for_completion() {
184-
assert(_lock->owned_by_self(), "must have lock to use inc_waiting_for_completion()");
178+
assert(CompileTaskWait_lock->owned_by_self(), "must have lock to use inc_waiting_for_completion()");
185179
_waiting_count++;
186180
}
187181
// Indicates that a thread stopped waiting for this task to complete. Must have lock to use this.
188182
void dec_waiting_for_completion() {
189-
assert(_lock->owned_by_self(), "must have lock to use dec_waiting_for_completion()");
183+
assert(CompileTaskWait_lock->owned_by_self(), "must have lock to use dec_waiting_for_completion()");
190184
assert(_waiting_count > 0, "waiting count is not positive");
191185
_waiting_count--;
192186
}

src/hotspot/share/runtime/mutexLocker.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Mutex* MarkStackChunkList_lock = nullptr;
7979
Mutex* MonitoringSupport_lock = nullptr;
8080
Monitor* ConcurrentGCBreakpoints_lock = nullptr;
8181
Mutex* Compile_lock = nullptr;
82+
Monitor* CompileTaskWait_lock = nullptr;
8283
Monitor* MethodCompileQueue_lock = nullptr;
8384
Monitor* CompileThread_lock = nullptr;
8485
Monitor* Compilation_lock = nullptr;
@@ -342,7 +343,9 @@ void mutex_init() {
342343
MUTEX_DEFL(G1RareEvent_lock , PaddedMutex , Threads_lock, true);
343344
}
344345

345-
MUTEX_DEFL(CompileTaskAlloc_lock , PaddedMutex , MethodCompileQueue_lock);
346+
MUTEX_DEFL(CompileTaskAlloc_lock , PaddedMutex , MethodCompileQueue_lock);
347+
MUTEX_DEFL(CompileTaskWait_lock , PaddedMonitor, MethodCompileQueue_lock);
348+
346349
#if INCLUDE_PARALLELGC
347350
if (UseParallelGC) {
348351
MUTEX_DEFL(PSOldGenExpand_lock , PaddedMutex , Heap_lock, true);

src/hotspot/share/runtime/mutexLocker.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ extern Monitor* Compilation_lock; // a lock used to pause compila
8686
extern Mutex* TrainingData_lock; // a lock used when accessing training records
8787
extern Monitor* TrainingReplayQueue_lock; // a lock held when class are added/removed to the training replay queue
8888
extern Mutex* CompileTaskAlloc_lock; // a lock held when CompileTasks are allocated
89+
extern Monitor* CompileTaskWait_lock; // a lock held when CompileTasks are waited/notified
8990
extern Mutex* CompileStatistics_lock; // a lock held when updating compilation statistics
9091
extern Mutex* DirectivesStack_lock; // a lock held when mutating the dirstack and ref counting directives
9192
extern Monitor* Terminator_lock; // a lock used to guard termination of the vm

0 commit comments

Comments
 (0)