author | kbarrett |
Fri, 25 Mar 2016 15:50:31 -0400 | |
changeset 37197 | 282fa21230c3 |
parent 37081 | 7656f5356a5d |
child 37510 | cf066fe4531b |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
35916
23189249c2c1
8147884: Names of GC threads should be set before the threads start
asmotrak
parents:
35061
diff
changeset
|
2 |
* Copyright (c) 2001, 2016, 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:
5350
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5350
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:
5350
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/g1/concurrentG1Refine.hpp" |
27 |
#include "gc/g1/concurrentG1RefineThread.hpp" |
|
28 |
#include "gc/g1/g1CollectedHeap.inline.hpp" |
|
29 |
#include "gc/g1/g1CollectorPolicy.hpp" |
|
30770
5ba2d9f2084d
8080585: concurrentGCThread.hpp should not include suspendibleThreadSet.hpp
pliden
parents:
30764
diff
changeset
|
30 |
#include "gc/g1/suspendibleThreadSet.hpp" |
35061 | 31 |
#include "logging/log.hpp" |
7397 | 32 |
#include "memory/resourceArea.hpp" |
33 |
#include "runtime/handles.inline.hpp" |
|
34 |
#include "runtime/mutexLocker.hpp" |
|
1374 | 35 |
|
36 |
ConcurrentG1RefineThread:: |
|
2882
d508a8bac491
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
2881
diff
changeset
|
37 |
ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next, |
24104
febf9363fb68
8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents:
24094
diff
changeset
|
38 |
CardTableEntryClosure* refine_closure, |
23855
c4574075402c
8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents:
22551
diff
changeset
|
39 |
uint worker_id_offset, uint worker_id) : |
1374 | 40 |
ConcurrentGCThread(), |
24104
febf9363fb68
8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents:
24094
diff
changeset
|
41 |
_refine_closure(refine_closure), |
2882
d508a8bac491
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
2881
diff
changeset
|
42 |
_worker_id_offset(worker_id_offset), |
2881 | 43 |
_worker_id(worker_id), |
44 |
_active(false), |
|
45 |
_next(next), |
|
4481 | 46 |
_monitor(NULL), |
1374 | 47 |
_cg1r(cg1r), |
4481 | 48 |
_vtime_accum(0.0) |
1374 | 49 |
{ |
4481 | 50 |
|
22551 | 51 |
// Each thread has its own monitor. The i-th thread is responsible for signaling |
52 |
// to thread i+1 if the number of buffers in the queue exceeds a threshold for this |
|
4481 | 53 |
// thread. Monitors are also used to wake up the threads during termination. |
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
54 |
// The 0th (primary) worker is notified by mutator threads and has a special monitor. |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
55 |
if (!is_primary()) { |
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
24331
diff
changeset
|
56 |
_monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true, |
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
24331
diff
changeset
|
57 |
Monitor::_safepoint_check_never); |
4481 | 58 |
} else { |
59 |
_monitor = DirtyCardQ_CBL_mon; |
|
60 |
} |
|
61 |
initialize(); |
|
24331
c0bc7e5653fb
6885993: Named Thread: introduce print() and print_on(outputStream* st) methods
zgu
parents:
24104
diff
changeset
|
62 |
|
c0bc7e5653fb
6885993: Named Thread: introduce print() and print_on(outputStream* st) methods
zgu
parents:
24104
diff
changeset
|
63 |
// set name |
29464
02c245ad3ec9
8073545: Use shorter and more descriptive names for GC worker threads
david
parents:
28163
diff
changeset
|
64 |
set_name("G1 Refine#%d", worker_id); |
35916
23189249c2c1
8147884: Names of GC threads should be set before the threads start
asmotrak
parents:
35061
diff
changeset
|
65 |
create_and_start(); |
1374 | 66 |
} |
67 |
||
4481 | 68 |
void ConcurrentG1RefineThread::initialize() { |
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
69 |
// Current thread activation threshold |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36196
diff
changeset
|
70 |
_threshold = MIN2(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(), |
36402
7c20aae43c41
8150984: Invalid VM argument causes crash -XX:G1ConcRefinementServiceIntervalMillis=2147483648
jprovino
parents:
36371
diff
changeset
|
71 |
cg1r()->yellow_zone()); |
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
72 |
// A thread deactivates once the number of buffer reached a deactivation threshold |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36196
diff
changeset
|
73 |
_deactivation_threshold = |
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36196
diff
changeset
|
74 |
MAX2(_threshold - MIN2(_threshold, cg1r()->thread_threshold_step()), |
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36196
diff
changeset
|
75 |
cg1r()->green_zone()); |
4481 | 76 |
} |
2881 | 77 |
|
4481 | 78 |
void ConcurrentG1RefineThread::wait_for_completed_buffers() { |
79 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36402
diff
changeset
|
80 |
while (!should_terminate() && !is_active()) { |
4481 | 81 |
_monitor->wait(Mutex::_no_safepoint_check_flag); |
82 |
} |
|
83 |
} |
|
84 |
||
85 |
bool ConcurrentG1RefineThread::is_active() { |
|
86 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
87 |
return is_primary() ? dcqs.process_completed_buffers() : _active; |
4481 | 88 |
} |
89 |
||
90 |
void ConcurrentG1RefineThread::activate() { |
|
91 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
92 |
if (!is_primary()) { |
4481 | 93 |
set_active(true); |
94 |
} else { |
|
95 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
96 |
dcqs.set_process_completed(true); |
|
97 |
} |
|
98 |
_monitor->notify(); |
|
99 |
} |
|
2881 | 100 |
|
4481 | 101 |
void ConcurrentG1RefineThread::deactivate() { |
102 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
103 |
if (!is_primary()) { |
4481 | 104 |
set_active(false); |
105 |
} else { |
|
106 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
107 |
dcqs.set_process_completed(false); |
|
108 |
} |
|
109 |
} |
|
110 |
||
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
111 |
void ConcurrentG1RefineThread::run_service() { |
4481 | 112 |
_vtime_start = os::elapsedVTime(); |
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
113 |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36402
diff
changeset
|
114 |
while (!should_terminate()) { |
4481 | 115 |
// Wait for work |
116 |
wait_for_completed_buffers(); |
|
37081
7656f5356a5d
8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents:
36402
diff
changeset
|
117 |
if (should_terminate()) { |
4481 | 118 |
break; |
119 |
} |
|
120 |
||
36196
5128f617b0c6
8150134: Simplify concurrent refinement thread deactivation
kbarrett
parents:
36179
diff
changeset
|
121 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36196
diff
changeset
|
122 |
log_debug(gc, refine)("Activated %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT, |
36196
5128f617b0c6
8150134: Simplify concurrent refinement thread deactivation
kbarrett
parents:
36179
diff
changeset
|
123 |
_worker_id, _threshold, dcqs.completed_buffers_num()); |
5128f617b0c6
8150134: Simplify concurrent refinement thread deactivation
kbarrett
parents:
36179
diff
changeset
|
124 |
|
24094 | 125 |
{ |
30613
a7815bb05ae2
8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents:
29464
diff
changeset
|
126 |
SuspendibleThreadSetJoiner sts_join; |
24094 | 127 |
|
37197
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
128 |
while (!should_terminate()) { |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
129 |
if (sts_join.should_yield()) { |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
130 |
sts_join.yield(); |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
131 |
continue; // Re-check for termination after yield delay. |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
132 |
} |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
133 |
|
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36196
diff
changeset
|
134 |
size_t curr_buffer_num = dcqs.completed_buffers_num(); |
24094 | 135 |
// If the number of the buffers falls down into the yellow zone, |
136 |
// that means that the transition period after the evacuation pause has ended. |
|
137 |
if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { |
|
138 |
dcqs.set_completed_queue_padding(0); |
|
139 |
} |
|
4481 | 140 |
|
24094 | 141 |
// Check if we need to activate the next thread. |
142 |
if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { |
|
143 |
_next->activate(); |
|
144 |
} |
|
145 |
||
37197
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
146 |
// Process the next buffer, if there are enough left. |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
147 |
if (!dcqs.apply_closure_to_completed_buffer(_refine_closure, |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
148 |
_worker_id + _worker_id_offset, |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
149 |
_deactivation_threshold, |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
150 |
false /* during_pause */)) { |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
151 |
break; // Deactivate, number of buffers fell below threshold. |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
152 |
} |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
153 |
} |
2881 | 154 |
} |
4481 | 155 |
|
37197
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
156 |
deactivate(); |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
157 |
log_debug(gc, refine)("Deactivated %d, off threshold: " SIZE_FORMAT |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
158 |
", current: " SIZE_FORMAT, |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
159 |
_worker_id, _deactivation_threshold, |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
160 |
dcqs.completed_buffers_num()); |
282fa21230c3
8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents:
37081
diff
changeset
|
161 |
|
1374 | 162 |
if (os::supports_vtime()) { |
163 |
_vtime_accum = (os::elapsedVTime() - _vtime_start); |
|
164 |
} else { |
|
165 |
_vtime_accum = 0.0; |
|
166 |
} |
|
167 |
} |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
168 |
|
36196
5128f617b0c6
8150134: Simplify concurrent refinement thread deactivation
kbarrett
parents:
36179
diff
changeset
|
169 |
log_debug(gc, refine)("Stopping %d", _worker_id); |
1374 | 170 |
} |
171 |
||
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
172 |
void ConcurrentG1RefineThread::stop_service() { |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
173 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
174 |
_monitor->notify(); |
35061 | 175 |
} |