author | stefank |
Mon, 25 Nov 2019 12:22:13 +0100 | |
changeset 59247 | 56bf71d64d51 |
parent 54623 | 1126f0607c70 |
child 59290 | 97d13893ec3c |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
54301
2f522c487791
8221392: Reduce ConcurrentGCThreads spinning during start up
pliden
parents:
53103
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
1374 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/shared/concurrentGCThread.hpp" |
7397 | 27 |
#include "runtime/init.hpp" |
54329 | 28 |
#include "runtime/mutexLocker.hpp" |
29 |
#include "runtime/orderAccess.hpp" |
|
22758
c6b6abb73544
7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents:
22551
diff
changeset
|
30 |
#include "runtime/os.hpp" |
1374 | 31 |
|
2881 | 32 |
ConcurrentGCThread::ConcurrentGCThread() : |
54329 | 33 |
_should_terminate(false), |
34 |
_has_terminated(false) {} |
|
1374 | 35 |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
36 |
void ConcurrentGCThread::create_and_start(ThreadPriority prio) { |
1374 | 37 |
if (os::create_thread(this, os::cgc_thread)) { |
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
38 |
os::set_priority(this, prio); |
54329 | 39 |
os::start_thread(this); |
1374 | 40 |
} |
41 |
} |
|
42 |
||
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
43 |
void ConcurrentGCThread::run() { |
54329 | 44 |
// Setup handle area |
45 |
set_active_handles(JNIHandleBlock::allocate_block()); |
|
46 |
||
47 |
// Wait for initialization to complete |
|
54301
2f522c487791
8221392: Reduce ConcurrentGCThreads spinning during start up
pliden
parents:
53103
diff
changeset
|
48 |
wait_init_completed(); |
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
49 |
|
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
50 |
run_service(); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
51 |
|
54329 | 52 |
// Signal thread has terminated |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54329
diff
changeset
|
53 |
MonitorLocker ml(Terminator_lock); |
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
54623
diff
changeset
|
54 |
Atomic::release_store(&_has_terminated, true); |
54329 | 55 |
ml.notify_all(); |
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
56 |
} |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
57 |
|
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
58 |
void ConcurrentGCThread::stop() { |
54329 | 59 |
assert(!should_terminate(), "Invalid state"); |
60 |
assert(!has_terminated(), "Invalid state"); |
|
61 |
||
62 |
// Signal thread to terminate |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
54623
diff
changeset
|
63 |
Atomic::release_store_fence(&_should_terminate, true); |
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
64 |
|
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
65 |
stop_service(); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
66 |
|
54329 | 67 |
// Wait for thread to terminate |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54329
diff
changeset
|
68 |
MonitorLocker ml(Terminator_lock); |
54329 | 69 |
while (!_has_terminated) { |
70 |
ml.wait(); |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
71 |
} |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
72 |
} |
54329 | 73 |
|
74 |
bool ConcurrentGCThread::should_terminate() const { |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
54623
diff
changeset
|
75 |
return Atomic::load_acquire(&_should_terminate); |
54329 | 76 |
} |
77 |
||
78 |
bool ConcurrentGCThread::has_terminated() const { |
|
59247
56bf71d64d51
8234562: Move OrderAccess::release_store*/load_acquire to Atomic
stefank
parents:
54623
diff
changeset
|
79 |
return Atomic::load_acquire(&_has_terminated); |
54329 | 80 |
} |