author | jprovino |
Tue, 02 Aug 2016 16:39:33 -0400 | |
changeset 40328 | a2851f5f1cf6 |
parent 37065 | c00d1c2ffb7c |
child 46305 | bff6d23aa1e3 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
36354 | 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:
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" |
30764 | 26 |
#include "gc/g1/ptrQueue.hpp" |
7397 | 27 |
#include "memory/allocation.hpp" |
28 |
#include "memory/allocation.inline.hpp" |
|
29 |
#include "runtime/mutex.hpp" |
|
30 |
#include "runtime/mutexLocker.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
13963
diff
changeset
|
31 |
#include "runtime/thread.inline.hpp" |
1374 | 32 |
|
36354 | 33 |
#include <new> |
34 |
||
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
35 |
PtrQueue::PtrQueue(PtrQueueSet* qset, bool permanent, bool active) : |
28507 | 36 |
_qset(qset), _buf(NULL), _index(0), _sz(0), _active(active), |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
37 |
_permanent(permanent), _lock(NULL) |
1374 | 38 |
{} |
39 |
||
28507 | 40 |
PtrQueue::~PtrQueue() { |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
41 |
assert(_permanent || (_buf == NULL), "queue must be flushed before delete"); |
28507 | 42 |
} |
43 |
||
44 |
void PtrQueue::flush_impl() { |
|
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
45 |
if (!_permanent && _buf != NULL) { |
37065 | 46 |
BufferNode* node = BufferNode::make_node_from_buffer(_buf, _index); |
47 |
if (is_empty()) { |
|
1374 | 48 |
// No work to do. |
37065 | 49 |
qset()->deallocate_buffer(node); |
1374 | 50 |
} else { |
37065 | 51 |
qset()->enqueue_complete_buffer(node); |
1374 | 52 |
} |
1560
1b328492b7f8
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
1374
diff
changeset
|
53 |
_buf = NULL; |
1b328492b7f8
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
1374
diff
changeset
|
54 |
_index = 0; |
1374 | 55 |
} |
56 |
} |
|
57 |
||
58 |
||
59 |
void PtrQueue::enqueue_known_active(void* ptr) { |
|
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
28507
diff
changeset
|
60 |
assert(_index <= _sz, "Invariant."); |
1374 | 61 |
assert(_index == 0 || _buf != NULL, "invariant"); |
62 |
||
63 |
while (_index == 0) { |
|
64 |
handle_zero_index(); |
|
65 |
} |
|
4481 | 66 |
|
1374 | 67 |
assert(_index > 0, "postcondition"); |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
68 |
_index -= sizeof(void*); |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
69 |
_buf[byte_index_to_index(_index)] = ptr; |
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
28507
diff
changeset
|
70 |
assert(_index <= _sz, "Invariant."); |
1374 | 71 |
} |
72 |
||
37065 | 73 |
void PtrQueue::locking_enqueue_completed_buffer(BufferNode* node) { |
1374 | 74 |
assert(_lock->owned_by_self(), "Required."); |
4640
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
75 |
|
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
76 |
// We have to unlock _lock (which may be Shared_DirtyCardQ_lock) before |
22551 | 77 |
// we acquire DirtyCardQ_CBL_mon inside enqueue_complete_buffer as they |
4640
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
78 |
// have the same rank and we may get the "possible deadlock" message |
1374 | 79 |
_lock->unlock(); |
4640
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
80 |
|
37065 | 81 |
qset()->enqueue_complete_buffer(node); |
1374 | 82 |
// We must relock only because the caller will unlock, for the normal |
83 |
// case. |
|
84 |
_lock->lock_without_safepoint_check(); |
|
85 |
} |
|
86 |
||
87 |
||
36354 | 88 |
BufferNode* BufferNode::allocate(size_t byte_size) { |
89 |
assert(byte_size > 0, "precondition"); |
|
90 |
assert(is_size_aligned(byte_size, sizeof(void**)), |
|
91 |
"Invalid buffer size " SIZE_FORMAT, byte_size); |
|
92 |
void* data = NEW_C_HEAP_ARRAY(char, buffer_offset() + byte_size, mtGC); |
|
93 |
return new (data) BufferNode; |
|
94 |
} |
|
95 |
||
96 |
void BufferNode::deallocate(BufferNode* node) { |
|
97 |
node->~BufferNode(); |
|
98 |
FREE_C_HEAP_ARRAY(char, node); |
|
99 |
} |
|
100 |
||
1374 | 101 |
PtrQueueSet::PtrQueueSet(bool notify_when_complete) : |
102 |
_max_completed_queue(0), |
|
103 |
_cbl_mon(NULL), _fl_lock(NULL), |
|
104 |
_notify_when_complete(notify_when_complete), |
|
105 |
_sz(0), |
|
106 |
_completed_buffers_head(NULL), |
|
107 |
_completed_buffers_tail(NULL), |
|
108 |
_n_completed_buffers(0), |
|
109 |
_process_completed_threshold(0), _process_completed(false), |
|
110 |
_buf_free_list(NULL), _buf_free_list_sz(0) |
|
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
111 |
{ |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
112 |
_fl_owner = this; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
113 |
} |
1374 | 114 |
|
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
115 |
PtrQueueSet::~PtrQueueSet() { |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
116 |
// 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
|
117 |
// 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
|
118 |
// doing nothing here. |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
119 |
} |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
120 |
|
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
121 |
void PtrQueueSet::initialize(Monitor* cbl_mon, |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
122 |
Mutex* fl_lock, |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
123 |
int process_completed_threshold, |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
124 |
int max_completed_queue, |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
125 |
PtrQueueSet *fl_owner) { |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
126 |
_max_completed_queue = max_completed_queue; |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
127 |
_process_completed_threshold = process_completed_threshold; |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
128 |
_completed_queue_padding = 0; |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
129 |
assert(cbl_mon != NULL && fl_lock != NULL, "Init order issue?"); |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
130 |
_cbl_mon = cbl_mon; |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
131 |
_fl_lock = fl_lock; |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
132 |
_fl_owner = (fl_owner != NULL) ? fl_owner : this; |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
133 |
} |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
134 |
|
1374 | 135 |
void** PtrQueueSet::allocate_buffer() { |
136 |
assert(_sz > 0, "Didn't set a buffer size."); |
|
36354 | 137 |
BufferNode* node = NULL; |
138 |
{ |
|
139 |
MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag); |
|
140 |
node = _fl_owner->_buf_free_list; |
|
141 |
if (node != NULL) { |
|
142 |
_fl_owner->_buf_free_list = node->next(); |
|
143 |
_fl_owner->_buf_free_list_sz--; |
|
144 |
} |
|
145 |
} |
|
146 |
if (node == NULL) { |
|
147 |
node = BufferNode::allocate(_sz); |
|
1374 | 148 |
} else { |
36354 | 149 |
// Reinitialize buffer obtained from free list. |
150 |
node->set_index(0); |
|
151 |
node->set_next(NULL); |
|
1374 | 152 |
} |
36354 | 153 |
return BufferNode::make_buffer_from_node(node); |
1374 | 154 |
} |
155 |
||
37065 | 156 |
void PtrQueueSet::deallocate_buffer(BufferNode* node) { |
1374 | 157 |
assert(_sz > 0, "Didn't set a buffer size."); |
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
158 |
MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag); |
4481 | 159 |
node->set_next(_fl_owner->_buf_free_list); |
160 |
_fl_owner->_buf_free_list = node; |
|
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
161 |
_fl_owner->_buf_free_list_sz++; |
1374 | 162 |
} |
163 |
||
164 |
void PtrQueueSet::reduce_free_list() { |
|
4481 | 165 |
assert(_fl_owner == this, "Free list reduction is allowed only for the owner"); |
1374 | 166 |
// For now we'll adopt the strategy of deleting half. |
167 |
MutexLockerEx x(_fl_lock, Mutex::_no_safepoint_check_flag); |
|
168 |
size_t n = _buf_free_list_sz / 2; |
|
36354 | 169 |
for (size_t i = 0; i < n; ++i) { |
170 |
assert(_buf_free_list != NULL, |
|
171 |
"_buf_free_list_sz is wrong: " SIZE_FORMAT, _buf_free_list_sz); |
|
172 |
BufferNode* node = _buf_free_list; |
|
173 |
_buf_free_list = node->next(); |
|
174 |
_buf_free_list_sz--; |
|
175 |
BufferNode::deallocate(node); |
|
1374 | 176 |
} |
177 |
} |
|
178 |
||
4481 | 179 |
void PtrQueue::handle_zero_index() { |
7920 | 180 |
assert(_index == 0, "Precondition."); |
181 |
||
4481 | 182 |
// This thread records the full buffer and allocates a new one (while |
183 |
// holding the lock if there is one). |
|
184 |
if (_buf != NULL) { |
|
7920 | 185 |
if (!should_enqueue_buffer()) { |
186 |
assert(_index > 0, "the buffer can only be re-used if it's not full"); |
|
187 |
return; |
|
188 |
} |
|
189 |
||
4481 | 190 |
if (_lock) { |
4640
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
191 |
assert(_lock->owned_by_self(), "Required."); |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
192 |
|
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
193 |
// The current PtrQ may be the shared dirty card queue and |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
194 |
// may be being manipulated by more than one worker thread |
22551 | 195 |
// during a pause. Since the enqueueing of the completed |
4640
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
196 |
// buffer unlocks the Shared_DirtyCardQ_lock more than one |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
197 |
// worker thread can 'race' on reading the shared queue attributes |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
198 |
// (_buf and _index) and multiple threads can call into this |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
199 |
// routine for the same buffer. This will cause the completed |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
200 |
// buffer to be added to the CBL multiple times. |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
201 |
|
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
202 |
// We "claim" the current buffer by caching value of _buf in |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
203 |
// a local and clearing the field while holding _lock. When |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
204 |
// _lock is released (while enqueueing the completed buffer) |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
205 |
// the thread that acquires _lock will skip this code, |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
206 |
// preventing the subsequent the multiple enqueue, and |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
207 |
// install a newly allocated buffer below. |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
208 |
|
37065 | 209 |
BufferNode* node = BufferNode::make_node_from_buffer(_buf, _index); |
4640
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
210 |
_buf = NULL; // clear shared _buf field |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
211 |
|
37065 | 212 |
locking_enqueue_completed_buffer(node); // enqueue completed buffer |
4640
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
213 |
|
22551 | 214 |
// While the current thread was enqueueing the buffer another thread |
4640
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
215 |
// may have a allocated a new buffer and inserted it into this pointer |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
216 |
// queue. If that happens then we just return so that the current |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
217 |
// thread doesn't overwrite the buffer allocated by the other thread |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
218 |
// and potentially losing some dirtied cards. |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
219 |
|
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
220 |
if (_buf != NULL) return; |
4481 | 221 |
} else { |
37065 | 222 |
BufferNode* node = BufferNode::make_node_from_buffer(_buf, _index); |
223 |
if (qset()->process_or_enqueue_complete_buffer(node)) { |
|
4481 | 224 |
// Recycle the buffer. No allocation. |
37065 | 225 |
assert(_buf == BufferNode::make_buffer_from_node(node), "invariant"); |
226 |
assert(_sz == qset()->buffer_size(), "invariant"); |
|
4481 | 227 |
_index = _sz; |
228 |
return; |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
// Reallocate the buffer |
|
233 |
_buf = qset()->allocate_buffer(); |
|
234 |
_sz = qset()->buffer_size(); |
|
235 |
_index = _sz; |
|
236 |
} |
|
1374 | 237 |
|
37065 | 238 |
bool PtrQueueSet::process_or_enqueue_complete_buffer(BufferNode* node) { |
4481 | 239 |
if (Thread::current()->is_Java_thread()) { |
240 |
// We don't lock. It is fine to be epsilon-precise here. |
|
241 |
if (_max_completed_queue == 0 || _max_completed_queue > 0 && |
|
242 |
_n_completed_buffers >= _max_completed_queue + _completed_queue_padding) { |
|
37065 | 243 |
bool b = mut_process_buffer(node); |
4481 | 244 |
if (b) { |
245 |
// True here means that the buffer hasn't been deallocated and the caller may reuse it. |
|
246 |
return true; |
|
247 |
} |
|
1374 | 248 |
} |
4481 | 249 |
} |
250 |
// The buffer will be enqueued. The caller will have to get a new one. |
|
37065 | 251 |
enqueue_complete_buffer(node); |
4481 | 252 |
return false; |
253 |
} |
|
1374 | 254 |
|
37065 | 255 |
void PtrQueueSet::enqueue_complete_buffer(BufferNode* cbn) { |
4481 | 256 |
MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
36354 | 257 |
cbn->set_next(NULL); |
1374 | 258 |
if (_completed_buffers_tail == NULL) { |
259 |
assert(_completed_buffers_head == NULL, "Well-formedness"); |
|
260 |
_completed_buffers_head = cbn; |
|
261 |
_completed_buffers_tail = cbn; |
|
262 |
} else { |
|
4481 | 263 |
_completed_buffers_tail->set_next(cbn); |
1374 | 264 |
_completed_buffers_tail = cbn; |
265 |
} |
|
266 |
_n_completed_buffers++; |
|
267 |
||
4481 | 268 |
if (!_process_completed && _process_completed_threshold >= 0 && |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
269 |
_n_completed_buffers >= (size_t)_process_completed_threshold) { |
1374 | 270 |
_process_completed = true; |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
271 |
if (_notify_when_complete) { |
4481 | 272 |
_cbl_mon->notify(); |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
273 |
} |
1374 | 274 |
} |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
275 |
DEBUG_ONLY(assert_completed_buffer_list_len_correct_locked()); |
1374 | 276 |
} |
277 |
||
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
278 |
size_t PtrQueueSet::completed_buffers_list_length() { |
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
279 |
size_t n = 0; |
4481 | 280 |
BufferNode* cbn = _completed_buffers_head; |
1374 | 281 |
while (cbn != NULL) { |
282 |
n++; |
|
4481 | 283 |
cbn = cbn->next(); |
1374 | 284 |
} |
285 |
return n; |
|
286 |
} |
|
287 |
||
288 |
void PtrQueueSet::assert_completed_buffer_list_len_correct() { |
|
289 |
MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
|
290 |
assert_completed_buffer_list_len_correct_locked(); |
|
291 |
} |
|
292 |
||
293 |
void PtrQueueSet::assert_completed_buffer_list_len_correct_locked() { |
|
4481 | 294 |
guarantee(completed_buffers_list_length() == _n_completed_buffers, |
1374 | 295 |
"Completed buffer length is wrong."); |
296 |
} |
|
297 |
||
298 |
void PtrQueueSet::set_buffer_size(size_t sz) { |
|
299 |
assert(_sz == 0 && sz > 0, "Should be called only once."); |
|
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
300 |
_sz = sz * sizeof(void*); |
1374 | 301 |
} |
302 |
||
4481 | 303 |
// Merge lists of buffers. Notify the processing threads. |
304 |
// 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
|
305 |
// must share the monitor. |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
306 |
void PtrQueueSet::merge_bufferlists(PtrQueueSet *src) { |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
307 |
assert(_cbl_mon == src->_cbl_mon, "Should share the same lock"); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
308 |
MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
309 |
if (_completed_buffers_tail == NULL) { |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
310 |
assert(_completed_buffers_head == NULL, "Well-formedness"); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
311 |
_completed_buffers_head = src->_completed_buffers_head; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
312 |
_completed_buffers_tail = src->_completed_buffers_tail; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
313 |
} else { |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
314 |
assert(_completed_buffers_head != NULL, "Well formedness"); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
315 |
if (src->_completed_buffers_head != NULL) { |
4481 | 316 |
_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
|
317 |
_completed_buffers_tail = src->_completed_buffers_tail; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
318 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
319 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
320 |
_n_completed_buffers += src->_n_completed_buffers; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
321 |
|
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
322 |
src->_n_completed_buffers = 0; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
323 |
src->_completed_buffers_head = NULL; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
324 |
src->_completed_buffers_tail = NULL; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
325 |
|
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
326 |
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
|
327 |
_completed_buffers_head != NULL && _completed_buffers_tail != NULL, |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
328 |
"Sanity"); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
329 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
330 |
|
4481 | 331 |
void PtrQueueSet::notify_if_necessary() { |
332 |
MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
|
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
333 |
assert(_process_completed_threshold >= 0, "_process_completed is negative"); |
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
334 |
if (_n_completed_buffers >= (size_t)_process_completed_threshold || _max_completed_queue == 0) { |
4481 | 335 |
_process_completed = true; |
336 |
if (_notify_when_complete) |
|
337 |
_cbl_mon->notify(); |
|
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
338 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
339 |
} |