annotate src/share/vm/gc_implementation/g1/ptrQueue.cpp @ 6862:8a5ea0a9ccc4

7127708: G1: change task num types from int to uint in concurrent mark Summary: Change the type of various task num fields, parameters etc to unsigned and rename them to be more consistent with the other collectors. Code changes were also reviewed by Vitaly Davidovich. Reviewed-by: johnc Contributed-by: Kaushik Srenevasan <kaushik@twitter.com>
author johnc
date Sat, 06 Oct 2012 01:17:44 -0700
parents d2a62e0f25eb
children b9a9ed0f8eeb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
1 /*
2149
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
4 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
7 * published by the Free Software Foundation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
8 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
13 * accompanied this code).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
14 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1317
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1317
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1317
diff changeset
21 * questions.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
22 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
23 */
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "gc_implementation/g1/ptrQueue.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "runtime/mutex.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "runtime/mutexLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #ifdef TARGET_OS_FAMILY_linux
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 # include "thread_linux.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #ifdef TARGET_OS_FAMILY_solaris
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 # include "thread_solaris.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
37 #ifdef TARGET_OS_FAMILY_windows
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38 # include "thread_windows.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
39 #endif
3960
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 2149
diff changeset
40 #ifdef TARGET_OS_FAMILY_bsd
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 2149
diff changeset
41 # include "thread_bsd.inline.hpp"
f08d439fab8c 7089790: integrate bsd-port changes
never
parents: 2149
diff changeset
42 #endif
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
43
2149
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
44 PtrQueue::PtrQueue(PtrQueueSet* qset, bool perm, bool active) :
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
45 _qset(qset), _buf(NULL), _index(0), _active(active),
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
46 _perm(perm), _lock(NULL)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
47 {}
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
48
441
da9cb4e97a5f 6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents: 342
diff changeset
49 void PtrQueue::flush() {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
50 if (!_perm && _buf != NULL) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
51 if (_index == _sz) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
52 // No work to do.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
53 qset()->deallocate_buffer(_buf);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
54 } else {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
55 // We must NULL out the unused entries, then enqueue.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
56 for (size_t i = 0; i < _index; i += oopSize) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
57 _buf[byte_index_to_index((int)i)] = NULL;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
58 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
59 qset()->enqueue_complete_buffer(_buf);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
60 }
441
da9cb4e97a5f 6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents: 342
diff changeset
61 _buf = NULL;
da9cb4e97a5f 6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents: 342
diff changeset
62 _index = 0;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
63 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
64 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
65
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
66
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
67 static int byte_index_to_index(int ind) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
68 assert((ind % oopSize) == 0, "Invariant.");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
69 return ind / oopSize;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
70 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
71
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
72 static int index_to_byte_index(int byte_ind) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
73 return byte_ind * oopSize;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
74 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
75
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
76 void PtrQueue::enqueue_known_active(void* ptr) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
77 assert(0 <= _index && _index <= _sz, "Invariant.");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
78 assert(_index == 0 || _buf != NULL, "invariant");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
79
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
80 while (_index == 0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
81 handle_zero_index();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
82 }
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
83
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
84 assert(_index > 0, "postcondition");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
85 _index -= oopSize;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
86 _buf[byte_index_to_index((int)_index)] = ptr;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
87 assert(0 <= _index && _index <= _sz, "Invariant.");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
88 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
89
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
90 void PtrQueue::locking_enqueue_completed_buffer(void** buf) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
91 assert(_lock->owned_by_self(), "Required.");
1169
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
92
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
93 // We have to unlock _lock (which may be Shared_DirtyCardQ_lock) before
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
94 // we acquire DirtyCardQ_CBL_mon inside enqeue_complete_buffer as they
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
95 // have the same rank and we may get the "possible deadlock" message
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
96 _lock->unlock();
1169
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
97
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
98 qset()->enqueue_complete_buffer(buf);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
99 // We must relock only because the caller will unlock, for the normal
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
100 // case.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
101 _lock->lock_without_safepoint_check();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
102 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
103
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
104
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
105 PtrQueueSet::PtrQueueSet(bool notify_when_complete) :
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
106 _max_completed_queue(0),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
107 _cbl_mon(NULL), _fl_lock(NULL),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
108 _notify_when_complete(notify_when_complete),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
109 _sz(0),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
110 _completed_buffers_head(NULL),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
111 _completed_buffers_tail(NULL),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
112 _n_completed_buffers(0),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
113 _process_completed_threshold(0), _process_completed(false),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
114 _buf_free_list(NULL), _buf_free_list_sz(0)
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
115 {
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
116 _fl_owner = this;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
117 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
118
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
119 void** PtrQueueSet::allocate_buffer() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
120 assert(_sz > 0, "Didn't set a buffer size.");
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
121 MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag);
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
122 if (_fl_owner->_buf_free_list != NULL) {
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
123 void** res = BufferNode::make_buffer_from_node(_fl_owner->_buf_free_list);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
124 _fl_owner->_buf_free_list = _fl_owner->_buf_free_list->next();
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
125 _fl_owner->_buf_free_list_sz--;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
126 return res;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
127 } else {
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
128 // Allocate space for the BufferNode in front of the buffer.
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 3960
diff changeset
129 char *b = NEW_C_HEAP_ARRAY(char, _sz + BufferNode::aligned_size(), mtGC);
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
130 return BufferNode::make_buffer_from_block(b);
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
131 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
132 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
133
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
134 void PtrQueueSet::deallocate_buffer(void** buf) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
135 assert(_sz > 0, "Didn't set a buffer size.");
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
136 MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag);
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
137 BufferNode *node = BufferNode::make_node_from_buffer(buf);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
138 node->set_next(_fl_owner->_buf_free_list);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
139 _fl_owner->_buf_free_list = node;
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
140 _fl_owner->_buf_free_list_sz++;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
141 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
142
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
143 void PtrQueueSet::reduce_free_list() {
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
144 assert(_fl_owner == this, "Free list reduction is allowed only for the owner");
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
145 // For now we'll adopt the strategy of deleting half.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
146 MutexLockerEx x(_fl_lock, Mutex::_no_safepoint_check_flag);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
147 size_t n = _buf_free_list_sz / 2;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
148 while (n > 0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
149 assert(_buf_free_list != NULL, "_buf_free_list_sz must be wrong.");
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
150 void* b = BufferNode::make_block_from_node(_buf_free_list);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
151 _buf_free_list = _buf_free_list->next();
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 3960
diff changeset
152 FREE_C_HEAP_ARRAY(char, b, mtGC);
1084
5f932a151fd4 6895788: G1: SATB and update buffer allocation code allocates too much space
johnc
parents: 844
diff changeset
153 _buf_free_list_sz --;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
154 n--;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
155 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
156 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
157
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
158 void PtrQueue::handle_zero_index() {
2149
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
159 assert(_index == 0, "Precondition.");
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
160
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
161 // This thread records the full buffer and allocates a new one (while
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
162 // holding the lock if there is one).
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
163 if (_buf != NULL) {
2149
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
164 if (!should_enqueue_buffer()) {
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
165 assert(_index > 0, "the buffer can only be re-used if it's not full");
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
166 return;
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
167 }
7e37af9d69ef 7011379: G1: overly long concurrent marking cycles
tonyp
parents: 1972
diff changeset
168
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
169 if (_lock) {
1169
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
170 assert(_lock->owned_by_self(), "Required.");
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
171
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
172 // The current PtrQ may be the shared dirty card queue and
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
173 // may be being manipulated by more than one worker thread
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
174 // during a pause. Since the enqueuing of the completed
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
175 // buffer unlocks the Shared_DirtyCardQ_lock more than one
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
176 // worker thread can 'race' on reading the shared queue attributes
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
177 // (_buf and _index) and multiple threads can call into this
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
178 // routine for the same buffer. This will cause the completed
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
179 // buffer to be added to the CBL multiple times.
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
180
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
181 // We "claim" the current buffer by caching value of _buf in
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
182 // a local and clearing the field while holding _lock. When
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
183 // _lock is released (while enqueueing the completed buffer)
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
184 // the thread that acquires _lock will skip this code,
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
185 // preventing the subsequent the multiple enqueue, and
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
186 // install a newly allocated buffer below.
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
187
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
188 void** buf = _buf; // local pointer to completed buffer
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
189 _buf = NULL; // clear shared _buf field
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
190
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
191 locking_enqueue_completed_buffer(buf); // enqueue completed buffer
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
192
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
193 // While the current thread was enqueuing the buffer another thread
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
194 // may have a allocated a new buffer and inserted it into this pointer
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
195 // queue. If that happens then we just return so that the current
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
196 // thread doesn't overwrite the buffer allocated by the other thread
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
197 // and potentially losing some dirtied cards.
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
198
09646c4656ca 6915005: G1: Hang in PtrQueueSet::completed_buffers_list_length with gcl001
johnc
parents: 1111
diff changeset
199 if (_buf != NULL) return;
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
200 } else {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
201 if (qset()->process_or_enqueue_complete_buffer(_buf)) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
202 // Recycle the buffer. No allocation.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
203 _sz = qset()->buffer_size();
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
204 _index = _sz;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
205 return;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
206 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
207 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
208 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
209 // Reallocate the buffer
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
210 _buf = qset()->allocate_buffer();
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
211 _sz = qset()->buffer_size();
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
212 _index = _sz;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
213 assert(0 <= _index && _index <= _sz, "Invariant.");
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
214 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
215
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
216 bool PtrQueueSet::process_or_enqueue_complete_buffer(void** buf) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
217 if (Thread::current()->is_Java_thread()) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
218 // We don't lock. It is fine to be epsilon-precise here.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
219 if (_max_completed_queue == 0 || _max_completed_queue > 0 &&
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
220 _n_completed_buffers >= _max_completed_queue + _completed_queue_padding) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
221 bool b = mut_process_buffer(buf);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
222 if (b) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
223 // True here means that the buffer hasn't been deallocated and the caller may reuse it.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
224 return true;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
225 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
226 }
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
227 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
228 // The buffer will be enqueued. The caller will have to get a new one.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
229 enqueue_complete_buffer(buf);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
230 return false;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
231 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
232
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
233 void PtrQueueSet::enqueue_complete_buffer(void** buf, size_t index) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
234 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
235 BufferNode* cbn = BufferNode::new_from_buffer(buf);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
236 cbn->set_index(index);
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
237 if (_completed_buffers_tail == NULL) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
238 assert(_completed_buffers_head == NULL, "Well-formedness");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
239 _completed_buffers_head = cbn;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
240 _completed_buffers_tail = cbn;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
241 } else {
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
242 _completed_buffers_tail->set_next(cbn);
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
243 _completed_buffers_tail = cbn;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
244 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
245 _n_completed_buffers++;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
246
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
247 if (!_process_completed && _process_completed_threshold >= 0 &&
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 616
diff changeset
248 _n_completed_buffers >= _process_completed_threshold) {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
249 _process_completed = true;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
250 if (_notify_when_complete)
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
251 _cbl_mon->notify();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
252 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
253 debug_only(assert_completed_buffer_list_len_correct_locked());
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
254 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
255
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
256 int PtrQueueSet::completed_buffers_list_length() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
257 int n = 0;
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
258 BufferNode* cbn = _completed_buffers_head;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
259 while (cbn != NULL) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
260 n++;
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
261 cbn = cbn->next();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
262 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
263 return n;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
264 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
265
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
266 void PtrQueueSet::assert_completed_buffer_list_len_correct() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
267 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
268 assert_completed_buffer_list_len_correct_locked();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
269 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
270
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
271 void PtrQueueSet::assert_completed_buffer_list_len_correct_locked() {
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
272 guarantee(completed_buffers_list_length() == _n_completed_buffers,
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
273 "Completed buffer length is wrong.");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
274 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
275
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
276 void PtrQueueSet::set_buffer_size(size_t sz) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
277 assert(_sz == 0 && sz > 0, "Should be called only once.");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
278 _sz = sz * oopSize;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
279 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
280
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
281 // Merge lists of buffers. Notify the processing threads.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
282 // The source queue is emptied as a result. The queues
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
283 // must share the monitor.
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
284 void PtrQueueSet::merge_bufferlists(PtrQueueSet *src) {
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
285 assert(_cbl_mon == src->_cbl_mon, "Should share the same lock");
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
286 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
287 if (_completed_buffers_tail == NULL) {
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
288 assert(_completed_buffers_head == NULL, "Well-formedness");
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
289 _completed_buffers_head = src->_completed_buffers_head;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
290 _completed_buffers_tail = src->_completed_buffers_tail;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
291 } else {
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
292 assert(_completed_buffers_head != NULL, "Well formedness");
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
293 if (src->_completed_buffers_head != NULL) {
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
294 _completed_buffers_tail->set_next(src->_completed_buffers_head);
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
295 _completed_buffers_tail = src->_completed_buffers_tail;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
296 }
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
297 }
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
298 _n_completed_buffers += src->_n_completed_buffers;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
299
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
300 src->_n_completed_buffers = 0;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
301 src->_completed_buffers_head = NULL;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
302 src->_completed_buffers_tail = NULL;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
303
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
304 assert(_completed_buffers_head == NULL && _completed_buffers_tail == NULL ||
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
305 _completed_buffers_head != NULL && _completed_buffers_tail != NULL,
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
306 "Sanity");
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
307 }
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
308
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
309 void PtrQueueSet::notify_if_necessary() {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
310 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
311 if (_n_completed_buffers >= _process_completed_threshold || _max_completed_queue == 0) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
312 _process_completed = true;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
313 if (_notify_when_complete)
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 1084
diff changeset
314 _cbl_mon->notify();
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
315 }
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 470
diff changeset
316 }