author | kbarrett |
Tue, 21 May 2019 19:19:44 -0400 | |
changeset 54970 | 76d3d96a8bc2 |
parent 54810 | 258170da6d3a |
child 55498 | e64383344f14 |
child 58678 | 9cf78a70fa4f |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
53404 | 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:
51332
diff
changeset
|
26 |
#include "gc/shared/ptrQueue.hpp" |
53404 | 27 |
#include "logging/log.hpp" |
7397 | 28 |
#include "memory/allocation.hpp" |
29 |
#include "memory/allocation.inline.hpp" |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
30 |
#include "runtime/atomic.hpp" |
7397 | 31 |
#include "runtime/mutex.hpp" |
32 |
#include "runtime/mutexLocker.hpp" |
|
53404 | 33 |
#include "runtime/orderAccess.hpp" |
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
13963
diff
changeset
|
34 |
#include "runtime/thread.inline.hpp" |
53404 | 35 |
#include "utilities/globalCounter.inline.hpp" |
1374 | 36 |
|
36354 | 37 |
#include <new> |
38 |
||
54255 | 39 |
PtrQueue::PtrQueue(PtrQueueSet* qset, bool active) : |
46443 | 40 |
_qset(qset), |
41 |
_active(active), |
|
42 |
_index(0), |
|
43 |
_capacity_in_bytes(0), |
|
54255 | 44 |
_buf(NULL) |
1374 | 45 |
{} |
46 |
||
28507 | 47 |
PtrQueue::~PtrQueue() { |
54255 | 48 |
assert(_buf == NULL, "queue must be flushed before delete"); |
28507 | 49 |
} |
50 |
||
51 |
void PtrQueue::flush_impl() { |
|
46305
bff6d23aa1e3
8175221: Cleanup DirtyCardQueueSet::concatenate_log
kbarrett
parents:
37065
diff
changeset
|
52 |
if (_buf != NULL) { |
46443 | 53 |
BufferNode* node = BufferNode::make_node_from_buffer(_buf, index()); |
37065 | 54 |
if (is_empty()) { |
1374 | 55 |
// No work to do. |
37065 | 56 |
qset()->deallocate_buffer(node); |
1374 | 57 |
} else { |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
58 |
qset()->enqueue_completed_buffer(node); |
1374 | 59 |
} |
1560
1b328492b7f8
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
1374
diff
changeset
|
60 |
_buf = NULL; |
46443 | 61 |
set_index(0); |
1374 | 62 |
} |
63 |
} |
|
64 |
||
65 |
void PtrQueue::enqueue_known_active(void* ptr) { |
|
66 |
while (_index == 0) { |
|
67 |
handle_zero_index(); |
|
68 |
} |
|
4481 | 69 |
|
46443 | 70 |
assert(_buf != NULL, "postcondition"); |
71 |
assert(index() > 0, "postcondition"); |
|
72 |
assert(index() <= capacity(), "invariant"); |
|
73 |
_index -= _element_size; |
|
74 |
_buf[index()] = ptr; |
|
1374 | 75 |
} |
76 |
||
54970
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
77 |
void PtrQueue::handle_zero_index() { |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
78 |
assert(index() == 0, "precondition"); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
79 |
|
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
80 |
if (_buf != NULL) { |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
81 |
handle_completed_buffer(); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
82 |
} else { |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
83 |
// Bootstrapping kludge; lazily initialize capacity. The initial |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
84 |
// thread's queues are constructed before the second phase of the |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
85 |
// two-phase initialization of the associated qsets. As a result, |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
86 |
// we can't initialize _capacity_in_bytes in the queue constructor. |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
87 |
if (_capacity_in_bytes == 0) { |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
88 |
_capacity_in_bytes = index_to_byte_index(qset()->buffer_size()); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
89 |
} |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
90 |
allocate_buffer(); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
91 |
} |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
92 |
} |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
93 |
|
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
94 |
void PtrQueue::allocate_buffer() { |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
95 |
_buf = qset()->allocate_buffer(); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
96 |
reset(); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
97 |
} |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
98 |
|
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
99 |
void PtrQueue::enqueue_completed_buffer() { |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
100 |
assert(_buf != NULL, "precondition"); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
101 |
BufferNode* node = BufferNode::make_node_from_buffer(_buf, index()); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
102 |
qset()->enqueue_completed_buffer(node); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
103 |
allocate_buffer(); |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
104 |
} |
76d3d96a8bc2
8224167: Refactor PtrQueue completed buffer processing
kbarrett
parents:
54810
diff
changeset
|
105 |
|
46443 | 106 |
BufferNode* BufferNode::allocate(size_t size) { |
107 |
size_t byte_size = size * sizeof(void*); |
|
36354 | 108 |
void* data = NEW_C_HEAP_ARRAY(char, buffer_offset() + byte_size, mtGC); |
109 |
return new (data) BufferNode; |
|
110 |
} |
|
111 |
||
112 |
void BufferNode::deallocate(BufferNode* node) { |
|
113 |
node->~BufferNode(); |
|
114 |
FREE_C_HEAP_ARRAY(char, node); |
|
115 |
} |
|
116 |
||
53404 | 117 |
BufferNode::Allocator::Allocator(const char* name, size_t buffer_size) : |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
118 |
_buffer_size(buffer_size), |
53404 | 119 |
_pending_list(), |
120 |
_free_list(), |
|
121 |
_pending_count(0), |
|
122 |
_free_count(0), |
|
123 |
_transfer_lock(false) |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
124 |
{ |
54810 | 125 |
strncpy(_name, name, sizeof(_name) - 1); |
53404 | 126 |
_name[sizeof(_name) - 1] = '\0'; |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
127 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
128 |
|
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
129 |
BufferNode::Allocator::~Allocator() { |
53404 | 130 |
delete_list(_free_list.pop_all()); |
131 |
delete_list(_pending_list.pop_all()); |
|
132 |
} |
|
133 |
||
134 |
void BufferNode::Allocator::delete_list(BufferNode* list) { |
|
135 |
while (list != NULL) { |
|
136 |
BufferNode* next = list->next(); |
|
137 |
DEBUG_ONLY(list->set_next(NULL);) |
|
138 |
BufferNode::deallocate(list); |
|
139 |
list = next; |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
140 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
141 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
142 |
|
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
143 |
size_t BufferNode::Allocator::free_count() const { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
144 |
return Atomic::load(&_free_count); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
145 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
146 |
|
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
147 |
BufferNode* BufferNode::Allocator::allocate() { |
53404 | 148 |
BufferNode* node; |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
149 |
{ |
53404 | 150 |
// Protect against ABA; see release(). |
151 |
GlobalCounter::CriticalSection cs(Thread::current()); |
|
152 |
node = _free_list.pop(); |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
153 |
} |
53404 | 154 |
if (node == NULL) { |
155 |
node = BufferNode::allocate(_buffer_size); |
|
156 |
} else { |
|
157 |
// Decrement count after getting buffer from free list. This, along |
|
158 |
// with incrementing count before adding to free list, ensures count |
|
159 |
// never underflows. |
|
160 |
size_t count = Atomic::sub(1u, &_free_count); |
|
161 |
assert((count + 1) != 0, "_free_count underflow"); |
|
162 |
} |
|
163 |
return node; |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
164 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
165 |
|
53404 | 166 |
// To solve the ABA problem for lock-free stack pop, allocate does the |
167 |
// pop inside a critical section, and release synchronizes on the |
|
168 |
// critical sections before adding to the _free_list. But we don't |
|
169 |
// want to make every release have to do a synchronize. Instead, we |
|
170 |
// initially place released nodes on the _pending_list, and transfer |
|
171 |
// them to the _free_list in batches. Only one transfer at a time is |
|
172 |
// permitted, with a lock bit to control access to that phase. A |
|
173 |
// transfer takes all the nodes from the _pending_list, synchronizes on |
|
174 |
// the _free_list pops, and then adds the former pending nodes to the |
|
175 |
// _free_list. While that's happening, other threads might be adding |
|
176 |
// other nodes to the _pending_list, to be dealt with by some later |
|
177 |
// transfer. |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
178 |
void BufferNode::Allocator::release(BufferNode* node) { |
53404 | 179 |
assert(node != NULL, "precondition"); |
180 |
assert(node->next() == NULL, "precondition"); |
|
181 |
||
182 |
// Desired minimum transfer batch size. There is relatively little |
|
183 |
// importance to the specific number. It shouldn't be too big, else |
|
184 |
// we're wasting space when the release rate is low. If the release |
|
185 |
// rate is high, we might accumulate more than this before being |
|
186 |
// able to start a new transfer, but that's okay. Also note that |
|
187 |
// the allocation rate and the release rate are going to be fairly |
|
188 |
// similar, due to how the buffers are used. |
|
189 |
const size_t trigger_transfer = 10; |
|
190 |
||
191 |
// Add to pending list. Update count first so no underflow in transfer. |
|
192 |
size_t pending_count = Atomic::add(1u, &_pending_count); |
|
193 |
_pending_list.push(*node); |
|
194 |
if (pending_count > trigger_transfer) { |
|
195 |
try_transfer_pending(); |
|
196 |
} |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
197 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
198 |
|
53404 | 199 |
// Try to transfer nodes from _pending_list to _free_list, with a |
200 |
// synchronization delay for any in-progress pops from the _free_list, |
|
201 |
// to solve ABA there. Return true if performed a (possibly empty) |
|
202 |
// transfer, false if blocked from doing so by some other thread's |
|
203 |
// in-progress transfer. |
|
204 |
bool BufferNode::Allocator::try_transfer_pending() { |
|
205 |
// Attempt to claim the lock. |
|
206 |
if (Atomic::load(&_transfer_lock) || // Skip CAS if likely to fail. |
|
207 |
Atomic::cmpxchg(true, &_transfer_lock, false)) { |
|
208 |
return false; |
|
209 |
} |
|
210 |
// Have the lock; perform the transfer. |
|
211 |
||
212 |
// Claim all the pending nodes. |
|
213 |
BufferNode* first = _pending_list.pop_all(); |
|
214 |
if (first != NULL) { |
|
215 |
// Prepare to add the claimed nodes, and update _pending_count. |
|
216 |
BufferNode* last = first; |
|
217 |
size_t count = 1; |
|
218 |
for (BufferNode* next = first->next(); next != NULL; next = next->next()) { |
|
219 |
last = next; |
|
220 |
++count; |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
221 |
} |
53404 | 222 |
Atomic::sub(count, &_pending_count); |
223 |
||
224 |
// Wait for any in-progress pops, to avoid ABA for them. |
|
225 |
GlobalCounter::write_synchronize(); |
|
226 |
||
227 |
// Add synchronized nodes to _free_list. |
|
228 |
// Update count first so no underflow in allocate(). |
|
229 |
Atomic::add(count, &_free_count); |
|
230 |
_free_list.prepend(*first, *last); |
|
231 |
log_trace(gc, ptrqueue, freelist) |
|
232 |
("Transferred %s pending to free: " SIZE_FORMAT, name(), count); |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
233 |
} |
53404 | 234 |
OrderAccess::release_store(&_transfer_lock, false); |
235 |
return true; |
|
236 |
} |
|
237 |
||
238 |
size_t BufferNode::Allocator::reduce_free_list(size_t remove_goal) { |
|
239 |
try_transfer_pending(); |
|
240 |
size_t removed = 0; |
|
241 |
for ( ; removed < remove_goal; ++removed) { |
|
242 |
BufferNode* node = _free_list.pop(); |
|
243 |
if (node == NULL) break; |
|
244 |
BufferNode::deallocate(node); |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
245 |
} |
53404 | 246 |
size_t new_count = Atomic::sub(removed, &_free_count); |
247 |
log_debug(gc, ptrqueue, freelist) |
|
248 |
("Reduced %s free list by " SIZE_FORMAT " to " SIZE_FORMAT, |
|
249 |
name(), removed, new_count); |
|
250 |
return removed; |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
251 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
252 |
|
1374 | 253 |
PtrQueueSet::PtrQueueSet(bool notify_when_complete) : |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
254 |
_allocator(NULL), |
51332 | 255 |
_cbl_mon(NULL), |
1374 | 256 |
_completed_buffers_head(NULL), |
257 |
_completed_buffers_tail(NULL), |
|
258 |
_n_completed_buffers(0), |
|
52726
9cfa2e273b77
8214278: Cleanup process_completed_threshold and related state
kbarrett
parents:
52684
diff
changeset
|
259 |
_process_completed_buffers_threshold(ProcessCompletedBuffersThresholdNever), |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
260 |
_process_completed_buffers(false), |
51332 | 261 |
_notify_when_complete(notify_when_complete), |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
262 |
_all_active(false) |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
263 |
{} |
1374 | 264 |
|
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
265 |
PtrQueueSet::~PtrQueueSet() { |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
266 |
// There are presently only a couple (derived) instances ever |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
267 |
// created, and they are permanent, so no harm currently done by |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
268 |
// doing nothing here. |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
269 |
} |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
270 |
|
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
271 |
void PtrQueueSet::initialize(Monitor* cbl_mon, |
52726
9cfa2e273b77
8214278: Cleanup process_completed_threshold and related state
kbarrett
parents:
52684
diff
changeset
|
272 |
BufferNode::Allocator* allocator) { |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
273 |
assert(cbl_mon != NULL && allocator != NULL, "Init order issue?"); |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
274 |
_cbl_mon = cbl_mon; |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
275 |
_allocator = allocator; |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
276 |
} |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
277 |
|
1374 | 278 |
void** PtrQueueSet::allocate_buffer() { |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
279 |
BufferNode* node = _allocator->allocate(); |
36354 | 280 |
return BufferNode::make_buffer_from_node(node); |
1374 | 281 |
} |
282 |
||
37065 | 283 |
void PtrQueueSet::deallocate_buffer(BufferNode* node) { |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
284 |
_allocator->release(node); |
1374 | 285 |
} |
286 |
||
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
287 |
void PtrQueueSet::enqueue_completed_buffer(BufferNode* cbn) { |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54255
diff
changeset
|
288 |
MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
36354 | 289 |
cbn->set_next(NULL); |
1374 | 290 |
if (_completed_buffers_tail == NULL) { |
291 |
assert(_completed_buffers_head == NULL, "Well-formedness"); |
|
292 |
_completed_buffers_head = cbn; |
|
293 |
_completed_buffers_tail = cbn; |
|
294 |
} else { |
|
4481 | 295 |
_completed_buffers_tail->set_next(cbn); |
1374 | 296 |
_completed_buffers_tail = cbn; |
297 |
} |
|
298 |
_n_completed_buffers++; |
|
299 |
||
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
300 |
if (!_process_completed_buffers && |
52726
9cfa2e273b77
8214278: Cleanup process_completed_threshold and related state
kbarrett
parents:
52684
diff
changeset
|
301 |
(_n_completed_buffers > _process_completed_buffers_threshold)) { |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
302 |
_process_completed_buffers = true; |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
303 |
if (_notify_when_complete) { |
4481 | 304 |
_cbl_mon->notify(); |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
305 |
} |
1374 | 306 |
} |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
307 |
assert_completed_buffers_list_len_correct_locked(); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
308 |
} |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
309 |
|
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
310 |
BufferNode* PtrQueueSet::get_completed_buffer(size_t stop_at) { |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54255
diff
changeset
|
311 |
MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
312 |
|
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
313 |
if (_n_completed_buffers <= stop_at) { |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
314 |
return NULL; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
315 |
} |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
316 |
|
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
317 |
assert(_n_completed_buffers > 0, "invariant"); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
318 |
assert(_completed_buffers_head != NULL, "invariant"); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
319 |
assert(_completed_buffers_tail != NULL, "invariant"); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
320 |
|
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
321 |
BufferNode* bn = _completed_buffers_head; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
322 |
_n_completed_buffers--; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
323 |
_completed_buffers_head = bn->next(); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
324 |
if (_completed_buffers_head == NULL) { |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
325 |
assert(_n_completed_buffers == 0, "invariant"); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
326 |
_completed_buffers_tail = NULL; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
327 |
_process_completed_buffers = false; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
328 |
} |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
329 |
assert_completed_buffers_list_len_correct_locked(); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
330 |
bn->set_next(NULL); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
331 |
return bn; |
1374 | 332 |
} |
333 |
||
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
334 |
void PtrQueueSet::abandon_completed_buffers() { |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
335 |
BufferNode* buffers_to_delete = NULL; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
336 |
{ |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54255
diff
changeset
|
337 |
MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
338 |
buffers_to_delete = _completed_buffers_head; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
339 |
_completed_buffers_head = NULL; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
340 |
_completed_buffers_tail = NULL; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
341 |
_n_completed_buffers = 0; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
342 |
_process_completed_buffers = false; |
1374 | 343 |
} |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
344 |
while (buffers_to_delete != NULL) { |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
345 |
BufferNode* bn = buffers_to_delete; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
346 |
buffers_to_delete = bn->next(); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
347 |
bn->set_next(NULL); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
348 |
deallocate_buffer(bn); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
349 |
} |
1374 | 350 |
} |
351 |
||
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
352 |
#ifdef ASSERT |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
353 |
|
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
354 |
void PtrQueueSet::assert_completed_buffers_list_len_correct_locked() { |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
355 |
assert_lock_strong(_cbl_mon); |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
356 |
size_t n = 0; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
357 |
for (BufferNode* bn = _completed_buffers_head; bn != NULL; bn = bn->next()) { |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
358 |
++n; |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
359 |
} |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
360 |
assert(n == _n_completed_buffers, |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
361 |
"Completed buffer length is wrong: counted: " SIZE_FORMAT |
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
362 |
", expected: " SIZE_FORMAT, n, _n_completed_buffers); |
1374 | 363 |
} |
364 |
||
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
365 |
#endif // ASSERT |
1374 | 366 |
|
4481 | 367 |
// Merge lists of buffers. Notify the processing threads. |
368 |
// The source queue is emptied as a result. The queues |
|
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
369 |
// must share the monitor. |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
370 |
void PtrQueueSet::merge_bufferlists(PtrQueueSet *src) { |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
371 |
assert(_cbl_mon == src->_cbl_mon, "Should share the same lock"); |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54255
diff
changeset
|
372 |
MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
373 |
if (_completed_buffers_tail == NULL) { |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
374 |
assert(_completed_buffers_head == NULL, "Well-formedness"); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
375 |
_completed_buffers_head = src->_completed_buffers_head; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
376 |
_completed_buffers_tail = src->_completed_buffers_tail; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
377 |
} else { |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
378 |
assert(_completed_buffers_head != NULL, "Well formedness"); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
379 |
if (src->_completed_buffers_head != NULL) { |
4481 | 380 |
_completed_buffers_tail->set_next(src->_completed_buffers_head); |
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
381 |
_completed_buffers_tail = src->_completed_buffers_tail; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
382 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
383 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
384 |
_n_completed_buffers += src->_n_completed_buffers; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
385 |
|
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
386 |
src->_n_completed_buffers = 0; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
387 |
src->_completed_buffers_head = NULL; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
388 |
src->_completed_buffers_tail = NULL; |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
389 |
src->_process_completed_buffers = false; |
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
390 |
|
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
391 |
assert(_completed_buffers_head == NULL && _completed_buffers_tail == NULL || |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
392 |
_completed_buffers_head != NULL && _completed_buffers_tail != NULL, |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
393 |
"Sanity"); |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
394 |
assert_completed_buffers_list_len_correct_locked(); |
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
395 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
396 |
|
4481 | 397 |
void PtrQueueSet::notify_if_necessary() { |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54255
diff
changeset
|
398 |
MutexLocker x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
52726
9cfa2e273b77
8214278: Cleanup process_completed_threshold and related state
kbarrett
parents:
52684
diff
changeset
|
399 |
if (_n_completed_buffers > _process_completed_buffers_threshold) { |
53102
35530ca3e0b2
8214201: Make PtrQueueSet completed buffer list private
kbarrett
parents:
52726
diff
changeset
|
400 |
_process_completed_buffers = true; |
4481 | 401 |
if (_notify_when_complete) |
402 |
_cbl_mon->notify(); |
|
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
403 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
404 |
} |