author | kbarrett |
Wed, 21 Nov 2018 09:40:19 -0500 | |
changeset 52637 | 0877040ec224 |
parent 52582 | 6df094be7f58 |
child 52684 | e62fe5079d64 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
51441
2e91d927e00c
8154343: Make SATB related code available to other GCs
kbarrett
parents:
51332
diff
changeset
|
2 |
* Copyright (c) 2001, 2018, 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" |
7397 | 27 |
#include "memory/allocation.hpp" |
28 |
#include "memory/allocation.inline.hpp" |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
29 |
#include "runtime/atomic.hpp" |
7397 | 30 |
#include "runtime/mutex.hpp" |
31 |
#include "runtime/mutexLocker.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
13963
diff
changeset
|
32 |
#include "runtime/thread.inline.hpp" |
1374 | 33 |
|
36354 | 34 |
#include <new> |
35 |
||
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
36 |
PtrQueue::PtrQueue(PtrQueueSet* qset, bool permanent, bool active) : |
46443 | 37 |
_qset(qset), |
38 |
_active(active), |
|
39 |
_permanent(permanent), |
|
40 |
_index(0), |
|
41 |
_capacity_in_bytes(0), |
|
42 |
_buf(NULL), |
|
43 |
_lock(NULL) |
|
1374 | 44 |
{} |
45 |
||
28507 | 46 |
PtrQueue::~PtrQueue() { |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
47 |
assert(_permanent || (_buf == NULL), "queue must be flushed before delete"); |
28507 | 48 |
} |
49 |
||
50 |
void PtrQueue::flush_impl() { |
|
46305
bff6d23aa1e3
8175221: Cleanup DirtyCardQueueSet::concatenate_log
kbarrett
parents:
37065
diff
changeset
|
51 |
if (_buf != NULL) { |
46443 | 52 |
BufferNode* node = BufferNode::make_node_from_buffer(_buf, index()); |
37065 | 53 |
if (is_empty()) { |
1374 | 54 |
// No work to do. |
37065 | 55 |
qset()->deallocate_buffer(node); |
1374 | 56 |
} else { |
37065 | 57 |
qset()->enqueue_complete_buffer(node); |
1374 | 58 |
} |
1560
1b328492b7f8
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
1374
diff
changeset
|
59 |
_buf = NULL; |
46443 | 60 |
set_index(0); |
1374 | 61 |
} |
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 |
||
46443 | 77 |
BufferNode* BufferNode::allocate(size_t size) { |
78 |
size_t byte_size = size * sizeof(void*); |
|
36354 | 79 |
void* data = NEW_C_HEAP_ARRAY(char, buffer_offset() + byte_size, mtGC); |
80 |
return new (data) BufferNode; |
|
81 |
} |
|
82 |
||
83 |
void BufferNode::deallocate(BufferNode* node) { |
|
84 |
node->~BufferNode(); |
|
85 |
FREE_C_HEAP_ARRAY(char, node); |
|
86 |
} |
|
87 |
||
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
88 |
BufferNode::Allocator::Allocator(size_t buffer_size, Mutex* lock) : |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
89 |
_buffer_size(buffer_size), |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
90 |
_lock(lock), |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
91 |
_free_list(NULL), |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
92 |
_free_count(0) |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
93 |
{ |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
94 |
assert(lock != NULL, "precondition"); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
95 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
96 |
|
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
97 |
BufferNode::Allocator::~Allocator() { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
98 |
while (_free_list != NULL) { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
99 |
BufferNode* node = _free_list; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
100 |
_free_list = node->next(); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
101 |
BufferNode::deallocate(node); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
102 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
103 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
104 |
|
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
105 |
size_t BufferNode::Allocator::free_count() const { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
106 |
return Atomic::load(&_free_count); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
107 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
108 |
|
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
109 |
BufferNode* BufferNode::Allocator::allocate() { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
110 |
BufferNode* node = NULL; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
111 |
{ |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
112 |
MutexLockerEx ml(_lock, Mutex::_no_safepoint_check_flag); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
113 |
node = _free_list; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
114 |
if (node != NULL) { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
115 |
_free_list = node->next(); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
116 |
--_free_count; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
117 |
node->set_next(NULL); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
118 |
node->set_index(0); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
119 |
return node; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
120 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
121 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
122 |
return BufferNode::allocate(_buffer_size); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
123 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
124 |
|
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
125 |
void BufferNode::Allocator::release(BufferNode* node) { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
126 |
MutexLockerEx ml(_lock, Mutex::_no_safepoint_check_flag); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
127 |
node->set_next(_free_list); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
128 |
_free_list = node; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
129 |
++_free_count; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
130 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
131 |
|
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
132 |
void BufferNode::Allocator::reduce_free_list() { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
133 |
BufferNode* head = NULL; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
134 |
{ |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
135 |
MutexLockerEx ml(_lock, Mutex::_no_safepoint_check_flag); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
136 |
// For now, delete half. |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
137 |
size_t remove = _free_count / 2; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
138 |
if (remove > 0) { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
139 |
head = _free_list; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
140 |
BufferNode* tail = head; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
141 |
BufferNode* prev = NULL; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
142 |
for (size_t i = 0; i < remove; ++i) { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
143 |
assert(tail != NULL, "free list size is wrong"); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
144 |
prev = tail; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
145 |
tail = tail->next(); |
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 |
assert(prev != NULL, "invariant"); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
148 |
assert(prev->next() == tail, "invariant"); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
149 |
prev->set_next(NULL); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
150 |
_free_list = tail; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
151 |
_free_count -= remove; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
152 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
153 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
154 |
while (head != NULL) { |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
155 |
BufferNode* next = head->next(); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
156 |
BufferNode::deallocate(head); |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
157 |
head = next; |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
158 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
159 |
} |
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
160 |
|
1374 | 161 |
PtrQueueSet::PtrQueueSet(bool notify_when_complete) : |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
162 |
_allocator(NULL), |
51332 | 163 |
_cbl_mon(NULL), |
1374 | 164 |
_completed_buffers_head(NULL), |
165 |
_completed_buffers_tail(NULL), |
|
166 |
_n_completed_buffers(0), |
|
51332 | 167 |
_process_completed_threshold(0), |
168 |
_process_completed(false), |
|
169 |
_all_active(false), |
|
170 |
_notify_when_complete(notify_when_complete), |
|
171 |
_max_completed_queue(0), |
|
172 |
_completed_queue_padding(0) |
|
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
173 |
{} |
1374 | 174 |
|
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
175 |
PtrQueueSet::~PtrQueueSet() { |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
176 |
// 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
|
177 |
// 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
|
178 |
// doing nothing here. |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
179 |
} |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
180 |
|
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
181 |
void PtrQueueSet::initialize(Monitor* cbl_mon, |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
182 |
BufferNode::Allocator* allocator, |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
183 |
int process_completed_threshold, |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
184 |
int max_completed_queue) { |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
185 |
_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
|
186 |
_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
|
187 |
_completed_queue_padding = 0; |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
188 |
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
|
189 |
_cbl_mon = cbl_mon; |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
190 |
_allocator = allocator; |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
191 |
} |
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
192 |
|
1374 | 193 |
void** PtrQueueSet::allocate_buffer() { |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
194 |
BufferNode* node = _allocator->allocate(); |
36354 | 195 |
return BufferNode::make_buffer_from_node(node); |
1374 | 196 |
} |
197 |
||
37065 | 198 |
void PtrQueueSet::deallocate_buffer(BufferNode* node) { |
52582
6df094be7f58
8213352: Separate BufferNode allocation from PtrQueueSet
kbarrett
parents:
51441
diff
changeset
|
199 |
_allocator->release(node); |
1374 | 200 |
} |
201 |
||
4481 | 202 |
void PtrQueue::handle_zero_index() { |
46443 | 203 |
assert(index() == 0, "precondition"); |
7920 | 204 |
|
4481 | 205 |
// This thread records the full buffer and allocates a new one (while |
206 |
// holding the lock if there is one). |
|
207 |
if (_buf != NULL) { |
|
7920 | 208 |
if (!should_enqueue_buffer()) { |
46443 | 209 |
assert(index() > 0, "the buffer can only be re-used if it's not full"); |
7920 | 210 |
return; |
211 |
} |
|
212 |
||
4481 | 213 |
if (_lock) { |
4640
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
214 |
assert(_lock->owned_by_self(), "Required."); |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
215 |
|
46443 | 216 |
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
|
217 |
_buf = NULL; // clear shared _buf field |
b5edb9b319e4
6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents:
4481
diff
changeset
|
218 |
|
52637
0877040ec224
8214144: Remove confusing locking_enqueue_completed_buffer
kbarrett
parents:
52582
diff
changeset
|
219 |
qset()->enqueue_complete_buffer(node); |
46685
b218dfc2853a
8182703: Correct G1 barrier queue lock orderings
eosterlund
parents:
46630
diff
changeset
|
220 |
assert(_buf == NULL, "multiple enqueuers appear to be racing"); |
4481 | 221 |
} else { |
46443 | 222 |
BufferNode* node = BufferNode::make_node_from_buffer(_buf, index()); |
37065 | 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"); |
46443 | 226 |
assert(capacity() == qset()->buffer_size(), "invariant"); |
227 |
reset(); |
|
4481 | 228 |
return; |
229 |
} |
|
230 |
} |
|
231 |
} |
|
46443 | 232 |
// Set capacity in case this is the first allocation. |
233 |
set_capacity(qset()->buffer_size()); |
|
234 |
// Allocate a new buffer. |
|
4481 | 235 |
_buf = qset()->allocate_buffer(); |
46443 | 236 |
reset(); |
4481 | 237 |
} |
1374 | 238 |
|
37065 | 239 |
bool PtrQueueSet::process_or_enqueue_complete_buffer(BufferNode* node) { |
4481 | 240 |
if (Thread::current()->is_Java_thread()) { |
241 |
// We don't lock. It is fine to be epsilon-precise here. |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46443
diff
changeset
|
242 |
if (_max_completed_queue == 0 || |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46443
diff
changeset
|
243 |
(_max_completed_queue > 0 && |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46443
diff
changeset
|
244 |
_n_completed_buffers >= _max_completed_queue + _completed_queue_padding)) { |
37065 | 245 |
bool b = mut_process_buffer(node); |
4481 | 246 |
if (b) { |
247 |
// True here means that the buffer hasn't been deallocated and the caller may reuse it. |
|
248 |
return true; |
|
249 |
} |
|
1374 | 250 |
} |
4481 | 251 |
} |
252 |
// The buffer will be enqueued. The caller will have to get a new one. |
|
37065 | 253 |
enqueue_complete_buffer(node); |
4481 | 254 |
return false; |
255 |
} |
|
1374 | 256 |
|
37065 | 257 |
void PtrQueueSet::enqueue_complete_buffer(BufferNode* cbn) { |
4481 | 258 |
MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
36354 | 259 |
cbn->set_next(NULL); |
1374 | 260 |
if (_completed_buffers_tail == NULL) { |
261 |
assert(_completed_buffers_head == NULL, "Well-formedness"); |
|
262 |
_completed_buffers_head = cbn; |
|
263 |
_completed_buffers_tail = cbn; |
|
264 |
} else { |
|
4481 | 265 |
_completed_buffers_tail->set_next(cbn); |
1374 | 266 |
_completed_buffers_tail = cbn; |
267 |
} |
|
268 |
_n_completed_buffers++; |
|
269 |
||
4481 | 270 |
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
|
271 |
_n_completed_buffers >= (size_t)_process_completed_threshold) { |
1374 | 272 |
_process_completed = true; |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
273 |
if (_notify_when_complete) { |
4481 | 274 |
_cbl_mon->notify(); |
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
275 |
} |
1374 | 276 |
} |
33761
329db4b51480
6899049: G1: Clean up code in ptrQueue.[ch]pp and ptrQueue.inline.hpp
kbarrett
parents:
30764
diff
changeset
|
277 |
DEBUG_ONLY(assert_completed_buffer_list_len_correct_locked()); |
1374 | 278 |
} |
279 |
||
36371
fd81a4f0ea00
8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents:
36354
diff
changeset
|
280 |
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
|
281 |
size_t n = 0; |
4481 | 282 |
BufferNode* cbn = _completed_buffers_head; |
1374 | 283 |
while (cbn != NULL) { |
284 |
n++; |
|
4481 | 285 |
cbn = cbn->next(); |
1374 | 286 |
} |
287 |
return n; |
|
288 |
} |
|
289 |
||
290 |
void PtrQueueSet::assert_completed_buffer_list_len_correct() { |
|
291 |
MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
|
292 |
assert_completed_buffer_list_len_correct_locked(); |
|
293 |
} |
|
294 |
||
295 |
void PtrQueueSet::assert_completed_buffer_list_len_correct_locked() { |
|
4481 | 296 |
guarantee(completed_buffers_list_length() == _n_completed_buffers, |
1374 | 297 |
"Completed buffer length is wrong."); |
298 |
} |
|
299 |
||
4481 | 300 |
// Merge lists of buffers. Notify the processing threads. |
301 |
// 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
|
302 |
// must share the monitor. |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
303 |
void PtrQueueSet::merge_bufferlists(PtrQueueSet *src) { |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
304 |
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
|
305 |
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
|
306 |
if (_completed_buffers_tail == NULL) { |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
307 |
assert(_completed_buffers_head == NULL, "Well-formedness"); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
308 |
_completed_buffers_head = src->_completed_buffers_head; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
309 |
_completed_buffers_tail = src->_completed_buffers_tail; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
310 |
} else { |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
311 |
assert(_completed_buffers_head != NULL, "Well formedness"); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
312 |
if (src->_completed_buffers_head != NULL) { |
4481 | 313 |
_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
|
314 |
_completed_buffers_tail = src->_completed_buffers_tail; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
315 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
316 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
317 |
_n_completed_buffers += src->_n_completed_buffers; |
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 |
src->_n_completed_buffers = 0; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
320 |
src->_completed_buffers_head = NULL; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
321 |
src->_completed_buffers_tail = NULL; |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
322 |
|
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
323 |
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
|
324 |
_completed_buffers_head != NULL && _completed_buffers_tail != NULL, |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
325 |
"Sanity"); |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
326 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
327 |
|
4481 | 328 |
void PtrQueueSet::notify_if_necessary() { |
329 |
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
|
330 |
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
|
331 |
if (_n_completed_buffers >= (size_t)_process_completed_threshold || _max_completed_queue == 0) { |
4481 | 332 |
_process_completed = true; |
333 |
if (_notify_when_complete) |
|
334 |
_cbl_mon->notify(); |
|
2142
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
335 |
} |
032f4652700c
6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents:
1623
diff
changeset
|
336 |
} |