author | pliden |
Wed, 27 Mar 2019 10:38:49 +0100 | |
changeset 54301 | 2f522c487791 |
parent 53103 | 67e3a8b3449c |
child 54329 | ddd60ad787d4 |
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" |
26 |
#include "classfile/systemDictionary.hpp" |
|
30764 | 27 |
#include "gc/shared/concurrentGCThread.hpp" |
7397 | 28 |
#include "oops/instanceRefKlass.hpp" |
29 |
#include "oops/oop.inline.hpp" |
|
30 |
#include "runtime/init.hpp" |
|
31 |
#include "runtime/java.hpp" |
|
32 |
#include "runtime/javaCalls.hpp" |
|
22758
c6b6abb73544
7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents:
22551
diff
changeset
|
33 |
#include "runtime/os.hpp" |
1374 | 34 |
|
2881 | 35 |
ConcurrentGCThread::ConcurrentGCThread() : |
36 |
_should_terminate(false), _has_terminated(false) { |
|
1374 | 37 |
}; |
38 |
||
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
39 |
void ConcurrentGCThread::create_and_start(ThreadPriority prio) { |
1374 | 40 |
if (os::create_thread(this, os::cgc_thread)) { |
41 |
// XXX: need to set this to low priority |
|
22551 | 42 |
// unless "aggressive mode" set; priority |
1374 | 43 |
// should be just less than that of VMThread. |
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
44 |
os::set_priority(this, prio); |
39984
8ecc78131588
8155263: DisableStartThread should not be applied to GC worker threads
jmasa
parents:
37129
diff
changeset
|
45 |
if (!_should_terminate) { |
1374 | 46 |
os::start_thread(this); |
47 |
} |
|
48 |
} |
|
49 |
} |
|
50 |
||
51 |
void ConcurrentGCThread::initialize_in_thread() { |
|
52 |
this->set_active_handles(JNIHandleBlock::allocate_block()); |
|
53 |
// From this time Thread::current() should be working. |
|
54 |
assert(this == Thread::current(), "just checking"); |
|
55 |
} |
|
56 |
||
57 |
void ConcurrentGCThread::terminate() { |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
33123
diff
changeset
|
58 |
assert(_should_terminate, "Should only be called on terminate request."); |
1374 | 59 |
// Signal that it is terminated |
60 |
{ |
|
61 |
MutexLockerEx mu(Terminator_lock, |
|
62 |
Mutex::_no_safepoint_check_flag); |
|
63 |
_has_terminated = true; |
|
64 |
Terminator_lock->notify(); |
|
65 |
} |
|
66 |
} |
|
67 |
||
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
68 |
void ConcurrentGCThread::run() { |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
69 |
initialize_in_thread(); |
54301
2f522c487791
8221392: Reduce ConcurrentGCThreads spinning during start up
pliden
parents:
53103
diff
changeset
|
70 |
wait_init_completed(); |
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 |
run_service(); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
73 |
|
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
74 |
terminate(); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
75 |
} |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
76 |
|
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
77 |
void ConcurrentGCThread::stop() { |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
78 |
// it is ok to take late safepoints here, if needed |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
79 |
{ |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
80 |
MutexLockerEx mu(Terminator_lock); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
81 |
assert(!_has_terminated, "stop should only be called once"); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
82 |
assert(!_should_terminate, "stop should only be called once"); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
83 |
_should_terminate = true; |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
84 |
} |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
85 |
|
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
86 |
stop_service(); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
87 |
|
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
88 |
{ |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
89 |
MutexLockerEx mu(Terminator_lock); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
90 |
while (!_has_terminated) { |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
91 |
Terminator_lock->wait(); |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
92 |
} |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
93 |
} |
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36082
diff
changeset
|
94 |
} |