Skip to content

Commit 7946c94

Browse files
committed
8257082: ZGC: Clean up ZRuntimeWorkers and ZWorkers
Reviewed-by: stefank
1 parent f6d6a07 commit 7946c94

File tree

5 files changed

+23
-51
lines changed

5 files changed

+23
-51
lines changed

src/hotspot/share/gc/z/zRuntimeWorkers.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,34 @@
2323

2424
#include "precompiled.hpp"
2525
#include "gc/shared/gcLogPrecious.hpp"
26+
#include "gc/z/zLock.inline.hpp"
2627
#include "gc/z/zRuntimeWorkers.hpp"
28+
#include "gc/z/zTask.hpp"
2729
#include "gc/z/zThread.hpp"
2830
#include "runtime/java.hpp"
29-
#include "runtime/mutex.hpp"
30-
#include "runtime/mutexLocker.hpp"
3131

3232
class ZRuntimeWorkersInitializeTask : public AbstractGangTask {
3333
private:
34-
const uint _nworkers;
35-
uint _started;
36-
Monitor _monitor;
34+
const uint _nworkers;
35+
uint _started;
36+
ZConditionLock _lock;
3737

3838
public:
3939
ZRuntimeWorkersInitializeTask(uint nworkers) :
4040
AbstractGangTask("ZRuntimeWorkersInitializeTask"),
4141
_nworkers(nworkers),
4242
_started(0),
43-
_monitor(Monitor::leaf,
44-
"ZRuntimeWorkersInitialize",
45-
false /* allow_vm_block */,
46-
Monitor::_safepoint_check_never) {}
43+
_lock() {}
4744

4845
virtual void work(uint worker_id) {
49-
// Register as runtime worker
50-
ZThread::set_runtime_worker();
51-
5246
// Wait for all threads to start
53-
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
47+
ZLocker<ZConditionLock> locker(&_lock);
5448
if (++_started == _nworkers) {
5549
// All threads started
56-
ml.notify_all();
50+
_lock.notify_all();
5751
} else {
5852
while (_started != _nworkers) {
59-
ml.wait();
53+
_lock.wait();
6054
}
6155
}
6256
}
@@ -77,9 +71,8 @@ ZRuntimeWorkers::ZRuntimeWorkers() :
7771
vm_exit_during_initialization("Failed to create ZRuntimeWorkers");
7872
}
7973

80-
// Execute task to register threads as runtime workers. This also
81-
// helps reduce latency in early safepoints, which otherwise would
82-
// have to take on any warmup costs.
74+
// Execute task to reduce latency in early safepoints,
75+
// which otherwise would have to take on any warmup costs.
8376
ZRuntimeWorkersInitializeTask task(nworkers());
8477
_workers.run_task(&task);
8578
}

src/hotspot/share/gc/z/zThread.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, 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
@@ -31,7 +31,6 @@ THREAD_LOCAL uintptr_t ZThread::_id;
3131
THREAD_LOCAL bool ZThread::_is_vm;
3232
THREAD_LOCAL bool ZThread::_is_java;
3333
THREAD_LOCAL bool ZThread::_is_worker;
34-
THREAD_LOCAL bool ZThread::_is_runtime_worker;
3534
THREAD_LOCAL uint ZThread::_worker_id;
3635

3736
void ZThread::initialize() {
@@ -42,7 +41,6 @@ void ZThread::initialize() {
4241
_is_vm = thread->is_VM_thread();
4342
_is_java = thread->is_Java_thread();
4443
_is_worker = false;
45-
_is_runtime_worker = false;
4644
_worker_id = (uint)-1;
4745
}
4846

@@ -63,11 +61,6 @@ void ZThread::set_worker() {
6361
_is_worker = true;
6462
}
6563

66-
void ZThread::set_runtime_worker() {
67-
ensure_initialized();
68-
_is_runtime_worker = true;
69-
}
70-
7164
bool ZThread::has_worker_id() {
7265
return _initialized &&
7366
_is_worker &&

src/hotspot/share/gc/z/zThread.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, 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
@@ -38,14 +38,12 @@ class ZThread : public AllStatic {
3838
static THREAD_LOCAL bool _is_vm;
3939
static THREAD_LOCAL bool _is_java;
4040
static THREAD_LOCAL bool _is_worker;
41-
static THREAD_LOCAL bool _is_runtime_worker;
4241
static THREAD_LOCAL uint _worker_id;
4342

4443
static void initialize();
4544
static void ensure_initialized();
4645

4746
static void set_worker();
48-
static void set_runtime_worker();
4947

5048
static bool has_worker_id();
5149
static void set_worker_id(uint worker_id);
@@ -57,7 +55,6 @@ class ZThread : public AllStatic {
5755
static bool is_vm();
5856
static bool is_java();
5957
static bool is_worker();
60-
static bool is_runtime_worker();
6158
static uint worker_id();
6259
};
6360

src/hotspot/share/gc/z/zThread.inline.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, 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
@@ -53,11 +53,6 @@ inline bool ZThread::is_worker() {
5353
return _is_worker;
5454
}
5555

56-
inline bool ZThread::is_runtime_worker() {
57-
ensure_initialized();
58-
return _is_runtime_worker;
59-
}
60-
6156
inline uint ZThread::worker_id() {
6257
assert(has_worker_id(), "Worker id not initialized");
6358
return _worker_id;

src/hotspot/share/gc/z/zWorkers.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,37 @@
2323

2424
#include "precompiled.hpp"
2525
#include "gc/shared/gcLogPrecious.hpp"
26+
#include "gc/z/zLock.inline.hpp"
2627
#include "gc/z/zTask.hpp"
2728
#include "gc/z/zThread.hpp"
2829
#include "gc/z/zWorkers.inline.hpp"
2930
#include "runtime/java.hpp"
30-
#include "runtime/mutex.hpp"
31-
#include "runtime/mutexLocker.hpp"
3231

3332
class ZWorkersInitializeTask : public ZTask {
3433
private:
35-
const uint _nworkers;
36-
uint _started;
37-
Monitor _monitor;
34+
const uint _nworkers;
35+
uint _started;
36+
ZConditionLock _lock;
3837

3938
public:
4039
ZWorkersInitializeTask(uint nworkers) :
4140
ZTask("ZWorkersInitializeTask"),
4241
_nworkers(nworkers),
4342
_started(0),
44-
_monitor(Monitor::leaf,
45-
"ZWorkersInitialize",
46-
false /* allow_vm_block */,
47-
Monitor::_safepoint_check_never) {}
43+
_lock() {}
4844

4945
virtual void work() {
5046
// Register as worker
5147
ZThread::set_worker();
5248

5349
// Wait for all threads to start
54-
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
50+
ZLocker<ZConditionLock> locker(&_lock);
5551
if (++_started == _nworkers) {
5652
// All threads started
57-
ml.notify_all();
53+
_lock.notify_all();
5854
} else {
5955
while (_started != _nworkers) {
60-
ml.wait();
56+
_lock.wait();
6157
}
6258
}
6359
}
@@ -79,9 +75,7 @@ ZWorkers::ZWorkers() :
7975
vm_exit_during_initialization("Failed to create ZWorkers");
8076
}
8177

82-
// Execute task to register threads as workers. This also helps
83-
// reduce latency in early GC pauses, which otherwise would have
84-
// to take on any warmup costs.
78+
// Execute task to register threads as workers
8579
ZWorkersInitializeTask task(nworkers());
8680
run(&task, nworkers());
8781
}

0 commit comments

Comments
 (0)