author | kbarrett |
Wed, 26 Jun 2019 13:18:38 -0400 | |
changeset 55498 | e64383344f14 |
parent 54970 | 76d3d96a8bc2 |
child 58059 | baa4dd528de0 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
54006 | 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:
5082
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5082
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:
5082
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
51441
2e91d927e00c
8154343: Make SATB related code available to other GCs
kbarrett
parents:
51403
diff
changeset
|
26 |
#include "gc/shared/satbMarkQueue.hpp" |
30764 | 27 |
#include "gc/shared/collectedHeap.hpp" |
51393
cc8d309cd05a
8209345: Merge SATBMarkQueueFilter into SATBMarkQueueSet
kbarrett
parents:
51368
diff
changeset
|
28 |
#include "logging/log.hpp" |
7397 | 29 |
#include "memory/allocation.inline.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
30 |
#include "oops/oop.inline.hpp" |
55498 | 31 |
#include "runtime/atomic.hpp" |
7397 | 32 |
#include "runtime/mutexLocker.hpp" |
55498 | 33 |
#include "runtime/orderAccess.hpp" |
51403
0f3bfea3acf1
8209347: SATBMarkQueue.cpp should not need jvm.h
kbarrett
parents:
51401
diff
changeset
|
34 |
#include "runtime/os.hpp" |
30577
de9fa7ccc1bc
8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents:
30279
diff
changeset
|
35 |
#include "runtime/safepoint.hpp" |
7397 | 36 |
#include "runtime/thread.hpp" |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47765
diff
changeset
|
37 |
#include "runtime/threadSMR.hpp" |
10670
4ea0e7d2ffbc
6484982: G1: process references during evacuation pauses
johnc
parents:
7920
diff
changeset
|
38 |
#include "runtime/vmThread.hpp" |
55498 | 39 |
#include "utilities/globalCounter.inline.hpp" |
1374 | 40 |
|
54255 | 41 |
SATBMarkQueue::SATBMarkQueue(SATBMarkQueueSet* qset) : |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
33105
diff
changeset
|
42 |
// SATB queues are only active during marking cycles. We create |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
33105
diff
changeset
|
43 |
// them with their active field set to false. If a thread is |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
33105
diff
changeset
|
44 |
// created during a cycle and its SATB queue needs to be activated |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
33105
diff
changeset
|
45 |
// before the thread starts running, we'll need to set its active |
51401
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
46 |
// field to true. This must be done in the collector-specific |
54006 | 47 |
// BarrierSet thread attachment protocol. |
54255 | 48 |
PtrQueue(qset, false /* active */) |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
33105
diff
changeset
|
49 |
{ } |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
33105
diff
changeset
|
50 |
|
33792 | 51 |
void SATBMarkQueue::flush() { |
30255
f43e306ec51e
8075466: SATB queue pre-filter verify found reclaimed humongous object
kbarrett
parents:
30154
diff
changeset
|
52 |
// Filter now to possibly save work later. If filtering empties the |
f43e306ec51e
8075466: SATB queue pre-filter verify found reclaimed humongous object
kbarrett
parents:
30154
diff
changeset
|
53 |
// buffer then flush_impl can deallocate the buffer. |
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
54 |
filter(); |
28507 | 55 |
flush_impl(); |
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
56 |
} |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
57 |
|
51278
d56dd9798d54
8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents:
49752
diff
changeset
|
58 |
// This method will first apply filtering to the buffer. If filtering |
d56dd9798d54
8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents:
49752
diff
changeset
|
59 |
// retains a small enough collection in the buffer, we can continue to |
d56dd9798d54
8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents:
49752
diff
changeset
|
60 |
// use the buffer as-is, instead of enqueueing and replacing it. |
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
61 |
|
54970
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54713
diff
changeset
|
62 |
void SATBMarkQueue::handle_completed_buffer() { |
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
63 |
// This method should only be called if there is a non-NULL buffer |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
64 |
// that is full. |
46443 | 65 |
assert(index() == 0, "pre-condition"); |
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
66 |
assert(_buf != NULL, "pre-condition"); |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
67 |
|
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
68 |
filter(); |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
69 |
|
54970
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54713
diff
changeset
|
70 |
size_t threshold = satb_qset()->buffer_enqueue_threshold(); |
51401
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
71 |
// Ensure we'll enqueue completely full buffers. |
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
72 |
assert(threshold > 0, "enqueue threshold = 0"); |
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
73 |
// Ensure we won't enqueue empty buffers. |
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
74 |
assert(threshold <= capacity(), |
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
75 |
"enqueue threshold " SIZE_FORMAT " exceeds capacity " SIZE_FORMAT, |
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
76 |
threshold, capacity()); |
54970
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54713
diff
changeset
|
77 |
|
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54713
diff
changeset
|
78 |
if (index() < threshold) { |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54713
diff
changeset
|
79 |
// Buffer is sufficiently full; enqueue and allocate a new one. |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54713
diff
changeset
|
80 |
enqueue_completed_buffer(); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54713
diff
changeset
|
81 |
} // Else continue to accumulate in buffer. |
7920 | 82 |
} |
83 |
||
33792 | 84 |
void SATBMarkQueue::apply_closure_and_empty(SATBBufferClosure* cl) { |
30577
de9fa7ccc1bc
8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents:
30279
diff
changeset
|
85 |
assert(SafepointSynchronize::is_at_safepoint(), |
de9fa7ccc1bc
8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents:
30279
diff
changeset
|
86 |
"SATB queues must only be processed at safepoints"); |
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
87 |
if (_buf != NULL) { |
46443 | 88 |
cl->do_buffer(&_buf[index()], size()); |
89 |
reset(); |
|
1374 | 90 |
} |
91 |
} |
|
92 |
||
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
93 |
#ifndef PRODUCT |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
94 |
// Helpful for debugging |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
95 |
|
46443 | 96 |
static void print_satb_buffer(const char* name, |
97 |
void** buf, |
|
98 |
size_t index, |
|
99 |
size_t capacity) { |
|
100 |
tty->print_cr(" SATB BUFFER [%s] buf: " PTR_FORMAT " index: " SIZE_FORMAT |
|
101 |
" capacity: " SIZE_FORMAT, |
|
102 |
name, p2i(buf), index, capacity); |
|
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
103 |
} |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
104 |
|
46443 | 105 |
void SATBMarkQueue::print(const char* name) { |
106 |
print_satb_buffer(name, _buf, index(), capacity()); |
|
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
107 |
} |
46443 | 108 |
|
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
109 |
#endif // PRODUCT |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
110 |
|
1374 | 111 |
SATBMarkQueueSet::SATBMarkQueueSet() : |
30268
d28a9aa10804
8078021: SATB apply_closure_to_completed_buffer should have closure argument
kbarrett
parents:
30255
diff
changeset
|
112 |
PtrQueueSet(), |
55498 | 113 |
_list(), |
114 |
_count_and_process_flag(0), |
|
115 |
_process_completed_buffers_threshold(SIZE_MAX), |
|
51401
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
116 |
_buffer_enqueue_threshold(0) |
51278
d56dd9798d54
8208611: Refactor SATBMarkQueue filtering to allow GC-specific filters
kbarrett
parents:
49752
diff
changeset
|
117 |
{} |
1374 | 118 |
|
55498 | 119 |
SATBMarkQueueSet::~SATBMarkQueueSet() { |
120 |
abandon_completed_buffers(); |
|
121 |
} |
|
122 |
||
123 |
// _count_and_process_flag has flag in least significant bit, count in |
|
124 |
// remaining bits. _process_completed_buffers_threshold is scaled |
|
125 |
// accordingly, with the lsbit set, so a _count_and_process_flag value |
|
126 |
// is directly comparable with the recorded threshold value. The |
|
127 |
// process flag is set whenever the count exceeds the threshold, and |
|
128 |
// remains set until the count is reduced to zero. |
|
129 |
||
130 |
// Increment count. If count > threshold, set flag, else maintain flag. |
|
131 |
static void increment_count(volatile size_t* cfptr, size_t threshold) { |
|
132 |
size_t old; |
|
133 |
size_t value = Atomic::load(cfptr); |
|
134 |
do { |
|
135 |
old = value; |
|
136 |
value += 2; |
|
137 |
assert(value > old, "overflow"); |
|
138 |
if (value > threshold) value |= 1; |
|
139 |
value = Atomic::cmpxchg(value, cfptr, old); |
|
140 |
} while (value != old); |
|
141 |
} |
|
142 |
||
143 |
// Decrement count. If count == 0, clear flag, else maintain flag. |
|
144 |
static void decrement_count(volatile size_t* cfptr) { |
|
145 |
size_t old; |
|
146 |
size_t value = Atomic::load(cfptr); |
|
147 |
do { |
|
148 |
assert((value >> 1) != 0, "underflow"); |
|
149 |
old = value; |
|
150 |
value -= 2; |
|
151 |
if (value <= 1) value = 0; |
|
152 |
value = Atomic::cmpxchg(value, cfptr, old); |
|
153 |
} while (value != old); |
|
154 |
} |
|
155 |
||
156 |
// Scale requested threshold to align with count field. If scaling |
|
157 |
// overflows, just use max value. Set process flag field to make |
|
158 |
// comparison in increment_count exact. |
|
159 |
static size_t scale_threshold(size_t value) { |
|
160 |
size_t scaled_value = value << 1; |
|
161 |
if ((scaled_value >> 1) != value) { |
|
162 |
scaled_value = SIZE_MAX; |
|
163 |
} |
|
164 |
return scaled_value | 1; |
|
165 |
} |
|
166 |
||
167 |
void SATBMarkQueueSet::initialize(BufferNode::Allocator* allocator, |
|
52726
9cfa2e273b77
8214278: Cleanup process_completed_threshold and related state
kbarrett
parents:
52582
diff
changeset
|
168 |
size_t process_completed_buffers_threshold, |
54006 | 169 |
uint buffer_enqueue_threshold_percentage) { |
55498 | 170 |
PtrQueueSet::initialize(allocator); |
171 |
_process_completed_buffers_threshold = |
|
172 |
scale_threshold(process_completed_buffers_threshold); |
|
51401
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
173 |
assert(buffer_size() != 0, "buffer size not initialized"); |
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
174 |
// Minimum threshold of 1 ensures enqueuing of completely full buffers. |
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
175 |
size_t size = buffer_size(); |
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
176 |
size_t enqueue_qty = (size * buffer_enqueue_threshold_percentage) / 100; |
58113ce90caf
8209346: Refactor SATBMarkQueue filter configuration
kbarrett
parents:
51393
diff
changeset
|
177 |
_buffer_enqueue_threshold = MAX2(size - enqueue_qty, (size_t)1); |
1374 | 178 |
} |
179 |
||
5082
19e725a3d2eb
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
4481
diff
changeset
|
180 |
#ifdef ASSERT |
22497 | 181 |
void SATBMarkQueueSet::dump_active_states(bool expected_active) { |
36090
cffc1dd98258
8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents:
35061
diff
changeset
|
182 |
log_error(gc, verify)("Expected SATB active state: %s", expected_active ? "ACTIVE" : "INACTIVE"); |
cffc1dd98258
8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents:
35061
diff
changeset
|
183 |
log_error(gc, verify)("Actual SATB active states:"); |
cffc1dd98258
8149541: Use log_error() instead of log_info() when verification reports a problem
brutisso
parents:
35061
diff
changeset
|
184 |
log_error(gc, verify)(" Queue set: %s", is_active() ? "ACTIVE" : "INACTIVE"); |
54006 | 185 |
|
186 |
class DumpThreadStateClosure : public ThreadClosure { |
|
187 |
SATBMarkQueueSet* _qset; |
|
188 |
public: |
|
189 |
DumpThreadStateClosure(SATBMarkQueueSet* qset) : _qset(qset) {} |
|
190 |
virtual void do_thread(Thread* t) { |
|
191 |
SATBMarkQueue& queue = _qset->satb_queue_for_thread(t); |
|
192 |
log_error(gc, verify)(" Thread \"%s\" queue: %s", |
|
193 |
t->name(), |
|
194 |
queue.is_active() ? "ACTIVE" : "INACTIVE"); |
|
195 |
} |
|
196 |
} closure(this); |
|
197 |
Threads::threads_do(&closure); |
|
22497 | 198 |
} |
199 |
||
200 |
void SATBMarkQueueSet::verify_active_states(bool expected_active) { |
|
201 |
// Verify queue set state |
|
202 |
if (is_active() != expected_active) { |
|
203 |
dump_active_states(expected_active); |
|
54006 | 204 |
fatal("SATB queue set has an unexpected active state"); |
22497 | 205 |
} |
206 |
||
207 |
// Verify thread queue states |
|
54006 | 208 |
class VerifyThreadStatesClosure : public ThreadClosure { |
209 |
SATBMarkQueueSet* _qset; |
|
210 |
bool _expected_active; |
|
211 |
public: |
|
212 |
VerifyThreadStatesClosure(SATBMarkQueueSet* qset, bool expected_active) : |
|
213 |
_qset(qset), _expected_active(expected_active) {} |
|
214 |
virtual void do_thread(Thread* t) { |
|
215 |
if (_qset->satb_queue_for_thread(t).is_active() != _expected_active) { |
|
216 |
_qset->dump_active_states(_expected_active); |
|
217 |
fatal("Thread SATB queue has an unexpected active state"); |
|
218 |
} |
|
22497 | 219 |
} |
54006 | 220 |
} closure(this, expected_active); |
221 |
Threads::threads_do(&closure); |
|
5082
19e725a3d2eb
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
4481
diff
changeset
|
222 |
} |
19e725a3d2eb
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
4481
diff
changeset
|
223 |
#endif // ASSERT |
19e725a3d2eb
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
4481
diff
changeset
|
224 |
|
22497 | 225 |
void SATBMarkQueueSet::set_active_all_threads(bool active, bool expected_active) { |
5082
19e725a3d2eb
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
4481
diff
changeset
|
226 |
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint."); |
19e725a3d2eb
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
4481
diff
changeset
|
227 |
#ifdef ASSERT |
22497 | 228 |
verify_active_states(expected_active); |
5082
19e725a3d2eb
6935821: G1: threads created during marking do not active their SATB queues
tonyp
parents:
4481
diff
changeset
|
229 |
#endif // ASSERT |
54366
2b48cedce327
8220671: Initialization race for non-JavaThread PtrQueues
kbarrett
parents:
54255
diff
changeset
|
230 |
// Update the global state, synchronized with threads list management. |
2b48cedce327
8220671: Initialization race for non-JavaThread PtrQueues
kbarrett
parents:
54255
diff
changeset
|
231 |
{ |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54366
diff
changeset
|
232 |
MutexLocker ml(NonJavaThreadsList_lock, Mutex::_no_safepoint_check_flag); |
54366
2b48cedce327
8220671: Initialization race for non-JavaThread PtrQueues
kbarrett
parents:
54255
diff
changeset
|
233 |
_all_active = active; |
2b48cedce327
8220671: Initialization race for non-JavaThread PtrQueues
kbarrett
parents:
54255
diff
changeset
|
234 |
} |
54006 | 235 |
|
236 |
class SetThreadActiveClosure : public ThreadClosure { |
|
237 |
SATBMarkQueueSet* _qset; |
|
238 |
bool _active; |
|
239 |
public: |
|
240 |
SetThreadActiveClosure(SATBMarkQueueSet* qset, bool active) : |
|
241 |
_qset(qset), _active(active) {} |
|
242 |
virtual void do_thread(Thread* t) { |
|
243 |
_qset->satb_queue_for_thread(t).set_active(_active); |
|
244 |
} |
|
245 |
} closure(this, active); |
|
246 |
Threads::threads_do(&closure); |
|
1374 | 247 |
} |
248 |
||
30577
de9fa7ccc1bc
8075215: SATB buffer processing found reclaimed humongous object
kbarrett
parents:
30279
diff
changeset
|
249 |
bool SATBMarkQueueSet::apply_closure_to_completed_buffer(SATBBufferClosure* cl) { |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
250 |
BufferNode* nd = get_completed_buffer(); |
1374 | 251 |
if (nd != NULL) { |
4481 | 252 |
void **buf = BufferNode::make_buffer_from_node(nd); |
46443 | 253 |
size_t index = nd->index(); |
254 |
size_t size = buffer_size(); |
|
37065 | 255 |
assert(index <= size, "invariant"); |
256 |
cl->do_buffer(buf + index, size - index); |
|
257 |
deallocate_buffer(nd); |
|
1374 | 258 |
return true; |
259 |
} else { |
|
260 |
return false; |
|
261 |
} |
|
262 |
} |
|
263 |
||
55498 | 264 |
// SATB buffer life-cycle - Per-thread queues obtain buffers from the |
265 |
// qset's buffer allocator, fill them, and push them onto the qset's |
|
266 |
// list. The GC concurrently pops buffers from the qset, processes |
|
267 |
// them, and returns them to the buffer allocator for re-use. Both |
|
268 |
// the allocator and the qset use lock-free stacks. The ABA problem |
|
269 |
// is solved by having both allocation pops and GC pops performed |
|
270 |
// within GlobalCounter critical sections, while the return of buffers |
|
271 |
// to the allocator performs a GlobalCounter synchronize before |
|
272 |
// pushing onto the allocator's list. |
|
273 |
||
274 |
void SATBMarkQueueSet::enqueue_completed_buffer(BufferNode* node) { |
|
275 |
assert(node != NULL, "precondition"); |
|
276 |
// Increment count and update flag appropriately. Done before |
|
277 |
// pushing buffer so count is always at least the actual number in |
|
278 |
// the list, and decrement never underflows. |
|
279 |
increment_count(&_count_and_process_flag, _process_completed_buffers_threshold); |
|
280 |
_list.push(*node); |
|
281 |
} |
|
282 |
||
283 |
BufferNode* SATBMarkQueueSet::get_completed_buffer() { |
|
284 |
BufferNode* node; |
|
285 |
{ |
|
286 |
GlobalCounter::CriticalSection cs(Thread::current()); |
|
287 |
node = _list.pop(); |
|
288 |
} |
|
289 |
if (node != NULL) { |
|
290 |
// Got a buffer so decrement count and update flag appropriately. |
|
291 |
decrement_count(&_count_and_process_flag); |
|
292 |
} |
|
293 |
return node; |
|
294 |
} |
|
295 |
||
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
296 |
#ifndef PRODUCT |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
297 |
// Helpful for debugging |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
298 |
|
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
299 |
#define SATB_PRINTER_BUFFER_SIZE 256 |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
300 |
|
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
301 |
void SATBMarkQueueSet::print_all(const char* msg) { |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
302 |
char buffer[SATB_PRINTER_BUFFER_SIZE]; |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
303 |
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint."); |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
304 |
|
35061 | 305 |
tty->cr(); |
306 |
tty->print_cr("SATB BUFFERS [%s]", msg); |
|
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
307 |
|
55498 | 308 |
BufferNode* nd = _list.top(); |
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
309 |
int i = 0; |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
310 |
while (nd != NULL) { |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
311 |
void** buf = BufferNode::make_buffer_from_node(nd); |
51403
0f3bfea3acf1
8209347: SATBMarkQueue.cpp should not need jvm.h
kbarrett
parents:
51401
diff
changeset
|
312 |
os::snprintf(buffer, SATB_PRINTER_BUFFER_SIZE, "Enqueued: %d", i); |
46443 | 313 |
print_satb_buffer(buffer, buf, nd->index(), buffer_size()); |
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
314 |
nd = nd->next(); |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
315 |
i += 1; |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
316 |
} |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
317 |
|
54006 | 318 |
class PrintThreadClosure : public ThreadClosure { |
319 |
SATBMarkQueueSet* _qset; |
|
320 |
char* _buffer; |
|
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
321 |
|
54006 | 322 |
public: |
323 |
PrintThreadClosure(SATBMarkQueueSet* qset, char* buffer) : |
|
324 |
_qset(qset), _buffer(buffer) {} |
|
325 |
||
326 |
virtual void do_thread(Thread* t) { |
|
327 |
os::snprintf(_buffer, SATB_PRINTER_BUFFER_SIZE, "Thread: %s", t->name()); |
|
328 |
_qset->satb_queue_for_thread(t).print(_buffer); |
|
329 |
} |
|
330 |
} closure(this, buffer); |
|
331 |
Threads::threads_do(&closure); |
|
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
332 |
|
35061 | 333 |
tty->cr(); |
11455
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
334 |
} |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
335 |
#endif // PRODUCT |
a6ab3d8b9a4c
6888336: G1: avoid explicitly marking and pushing objects in survivor spaces
tonyp
parents:
10670
diff
changeset
|
336 |
|
55498 | 337 |
void SATBMarkQueueSet::abandon_completed_buffers() { |
338 |
Atomic::store(size_t(0), &_count_and_process_flag); |
|
339 |
BufferNode* buffers_to_delete = _list.pop_all(); |
|
340 |
while (buffers_to_delete != NULL) { |
|
341 |
BufferNode* bn = buffers_to_delete; |
|
342 |
buffers_to_delete = bn->next(); |
|
343 |
bn->set_next(NULL); |
|
344 |
deallocate_buffer(bn); |
|
345 |
} |
|
346 |
} |
|
347 |
||
1374 | 348 |
void SATBMarkQueueSet::abandon_partial_marking() { |
54006 | 349 |
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint."); |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
350 |
abandon_completed_buffers(); |
54006 | 351 |
|
352 |
class AbandonThreadQueueClosure : public ThreadClosure { |
|
353 |
SATBMarkQueueSet* _qset; |
|
354 |
public: |
|
355 |
AbandonThreadQueueClosure(SATBMarkQueueSet* qset) : _qset(qset) {} |
|
356 |
virtual void do_thread(Thread* t) { |
|
357 |
_qset->satb_queue_for_thread(t).reset(); |
|
358 |
} |
|
359 |
} closure(this); |
|
360 |
Threads::threads_do(&closure); |
|
1374 | 361 |
} |