author | coleenp |
Wed, 18 Nov 2015 11:47:55 -0500 | |
changeset 34230 | b9c64b7c06c9 |
parent 33608 | 7afc768e4d62 |
child 35061 | be6025ebffea |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
30613
a7815bb05ae2
8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents:
29464
diff
changeset
|
2 |
* Copyright (c) 2001, 2015, 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" |
7397 | 31 |
#include "memory/resourceArea.hpp" |
32 |
#include "runtime/handles.inline.hpp" |
|
33 |
#include "runtime/mutexLocker.hpp" |
|
1374 | 34 |
|
35 |
ConcurrentG1RefineThread:: |
|
2882
d508a8bac491
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
2881
diff
changeset
|
36 |
ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next, |
24104
febf9363fb68
8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents:
24094
diff
changeset
|
37 |
CardTableEntryClosure* refine_closure, |
23855
c4574075402c
8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents:
22551
diff
changeset
|
38 |
uint worker_id_offset, uint worker_id) : |
1374 | 39 |
ConcurrentGCThread(), |
24104
febf9363fb68
8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents:
24094
diff
changeset
|
40 |
_refine_closure(refine_closure), |
2882
d508a8bac491
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
2881
diff
changeset
|
41 |
_worker_id_offset(worker_id_offset), |
2881 | 42 |
_worker_id(worker_id), |
43 |
_active(false), |
|
44 |
_next(next), |
|
4481 | 45 |
_monitor(NULL), |
1374 | 46 |
_cg1r(cg1r), |
4481 | 47 |
_vtime_accum(0.0) |
1374 | 48 |
{ |
4481 | 49 |
|
22551 | 50 |
// Each thread has its own monitor. The i-th thread is responsible for signaling |
51 |
// to thread i+1 if the number of buffers in the queue exceeds a threshold for this |
|
4481 | 52 |
// 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
|
53 |
// 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
|
54 |
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
|
55 |
_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
|
56 |
Monitor::_safepoint_check_never); |
4481 | 57 |
} else { |
58 |
_monitor = DirtyCardQ_CBL_mon; |
|
59 |
} |
|
60 |
initialize(); |
|
1374 | 61 |
create_and_start(); |
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); |
1374 | 65 |
} |
66 |
||
4481 | 67 |
void ConcurrentG1RefineThread::initialize() { |
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
68 |
// Current thread activation threshold |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
69 |
_threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(), |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
70 |
cg1r()->yellow_zone()); |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
71 |
// A thread deactivates once the number of buffer reached a deactivation threshold |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
72 |
_deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone()); |
4481 | 73 |
} |
2881 | 74 |
|
4481 | 75 |
void ConcurrentG1RefineThread::wait_for_completed_buffers() { |
76 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
77 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
|
78 |
while (!_should_terminate && !is_active()) { |
|
79 |
_monitor->wait(Mutex::_no_safepoint_check_flag); |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
bool ConcurrentG1RefineThread::is_active() { |
|
84 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
85 |
return is_primary() ? dcqs.process_completed_buffers() : _active; |
4481 | 86 |
} |
87 |
||
88 |
void ConcurrentG1RefineThread::activate() { |
|
89 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
90 |
if (!is_primary()) { |
5033 | 91 |
if (G1TraceConcRefinement) { |
4481 | 92 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
93 |
gclog_or_tty->print_cr("G1-Refine-activated worker %d, on threshold %d, current %d", |
|
94 |
_worker_id, _threshold, (int)dcqs.completed_buffers_num()); |
|
1374 | 95 |
} |
4481 | 96 |
set_active(true); |
97 |
} else { |
|
98 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
99 |
dcqs.set_process_completed(true); |
|
100 |
} |
|
101 |
_monitor->notify(); |
|
102 |
} |
|
2881 | 103 |
|
4481 | 104 |
void ConcurrentG1RefineThread::deactivate() { |
105 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
106 |
if (!is_primary()) { |
5033 | 107 |
if (G1TraceConcRefinement) { |
4481 | 108 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
109 |
gclog_or_tty->print_cr("G1-Refine-deactivated worker %d, off threshold %d, current %d", |
|
110 |
_worker_id, _deactivation_threshold, (int)dcqs.completed_buffers_num()); |
|
111 |
} |
|
112 |
set_active(false); |
|
113 |
} else { |
|
114 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
|
115 |
dcqs.set_process_completed(false); |
|
116 |
} |
|
117 |
} |
|
118 |
||
119 |
void ConcurrentG1RefineThread::run() { |
|
120 |
initialize_in_thread(); |
|
121 |
wait_for_universe_init(); |
|
2881 | 122 |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
123 |
run_service(); |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
124 |
|
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
125 |
terminate(); |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
126 |
} |
4481 | 127 |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
128 |
void ConcurrentG1RefineThread::run_service() { |
4481 | 129 |
_vtime_start = os::elapsedVTime(); |
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
130 |
|
4481 | 131 |
while (!_should_terminate) { |
132 |
// Wait for work |
|
133 |
wait_for_completed_buffers(); |
|
134 |
if (_should_terminate) { |
|
135 |
break; |
|
136 |
} |
|
137 |
||
24094 | 138 |
{ |
30613
a7815bb05ae2
8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents:
29464
diff
changeset
|
139 |
SuspendibleThreadSetJoiner sts_join; |
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
140 |
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); |
24094 | 141 |
|
142 |
do { |
|
143 |
int curr_buffer_num = (int)dcqs.completed_buffers_num(); |
|
144 |
// If the number of the buffers falls down into the yellow zone, |
|
145 |
// that means that the transition period after the evacuation pause has ended. |
|
146 |
if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) { |
|
147 |
dcqs.set_completed_queue_padding(0); |
|
148 |
} |
|
4481 | 149 |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
150 |
if (!is_primary() && curr_buffer_num <= _deactivation_threshold) { |
24094 | 151 |
// If the number of the buffer has fallen below our threshold |
152 |
// we should deactivate. The predecessor will reactivate this |
|
153 |
// thread should the number of the buffers cross the threshold again. |
|
154 |
deactivate(); |
|
155 |
break; |
|
156 |
} |
|
4481 | 157 |
|
24094 | 158 |
// Check if we need to activate the next thread. |
159 |
if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) { |
|
160 |
_next->activate(); |
|
161 |
} |
|
24104
febf9363fb68
8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents:
24094
diff
changeset
|
162 |
} while (dcqs.apply_closure_to_completed_buffer(_refine_closure, _worker_id + _worker_id_offset, cg1r()->green_zone())); |
24094 | 163 |
|
164 |
// We can exit the loop above while being active if there was a yield request. |
|
165 |
if (is_active()) { |
|
2881 | 166 |
deactivate(); |
167 |
} |
|
168 |
} |
|
4481 | 169 |
|
1374 | 170 |
if (os::supports_vtime()) { |
171 |
_vtime_accum = (os::elapsedVTime() - _vtime_start); |
|
172 |
} else { |
|
173 |
_vtime_accum = 0.0; |
|
174 |
} |
|
175 |
} |
|
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
176 |
|
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
177 |
if (G1TraceConcRefinement) { |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
178 |
gclog_or_tty->print_cr("G1-Refine-stop"); |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
179 |
} |
1374 | 180 |
} |
181 |
||
182 |
void ConcurrentG1RefineThread::stop() { |
|
183 |
// it is ok to take late safepoints here, if needed |
|
184 |
{ |
|
185 |
MutexLockerEx mu(Terminator_lock); |
|
186 |
_should_terminate = true; |
|
187 |
} |
|
188 |
||
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
189 |
stop_service(); |
1374 | 190 |
|
191 |
{ |
|
192 |
MutexLockerEx mu(Terminator_lock); |
|
193 |
while (!_has_terminated) { |
|
194 |
Terminator_lock->wait(); |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
||
33608
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
199 |
void ConcurrentG1RefineThread::stop_service() { |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
200 |
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag); |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
201 |
_monitor->notify(); |
7afc768e4d62
8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
30770
diff
changeset
|
202 |
} |