annotate src/share/vm/gc_implementation/g1/ptrQueue.hpp @ 1111:44f61c24ddab

6862387: tune concurrent refinement further Summary: Reworked the concurrent refinement: threads activation, feedback-based threshold adjustment, other miscellaneous fixes. Reviewed-by: apetrusenko, tonyp
author iveresov
date Wed, 16 Dec 2009 15:12:51 -0800
parents 7bb995fbd3c0
children d4197f8d516a
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 /*
579
0fbdb4381b99 6814575: Update copyright year
xdono
parents: 549
diff changeset
2 * Copyright 2001-2009 Sun Microsystems, Inc. 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 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
21 * have any questions.
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
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
25 // There are various techniques that require threads to be able to log
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
26 // addresses. For example, a generational write barrier might log
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
27 // the addresses of modified old-generation objects. This type supports
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
28 // this operation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
29
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
30 // The definition of placement operator new(size_t, void*) in the <new>.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
31 #include <new>
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
32
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
33 class PtrQueueSet;
549
fe3d7c11b4b7 6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents: 470
diff changeset
34 class PtrQueue VALUE_OBJ_CLASS_SPEC {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
35
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
36 protected:
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
37 // The ptr queue set to which this queue belongs.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
38 PtrQueueSet* _qset;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
39
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
40 // Whether updates should be logged.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
41 bool _active;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
42
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
43 // The buffer.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
44 void** _buf;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
45 // The index at which an object was last enqueued. Starts at "_sz"
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
46 // (indicating an empty buffer) and goes towards zero.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
47 size_t _index;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
48
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
49 // The size of the buffer.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
50 size_t _sz;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
51
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
52 // If true, the queue is permanent, and doesn't need to deallocate
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
53 // its buffer in the destructor (since that obtains a lock which may not
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
54 // be legally locked by then.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
55 bool _perm;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
56
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
57 // If there is a lock associated with this buffer, this is that lock.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
58 Mutex* _lock;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
59
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
60 PtrQueueSet* qset() { return _qset; }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
61
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
62 public:
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
63 // Initialize this queue to contain a null buffer, and be part of the
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
64 // given PtrQueueSet.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
65 PtrQueue(PtrQueueSet*, bool perm = false);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
66 // Release any contained resources.
441
da9cb4e97a5f 6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents: 342
diff changeset
67 void flush();
da9cb4e97a5f 6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents: 342
diff changeset
68 // Calls flush() when destroyed.
da9cb4e97a5f 6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents: 342
diff changeset
69 ~PtrQueue() { flush(); }
342
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 // Associate a lock with a ptr queue.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
72 void set_lock(Mutex* lock) { _lock = lock; }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
73
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
74 void reset() { if (_buf != NULL) _index = _sz; }
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 // Enqueues the given "obj".
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
77 void enqueue(void* ptr) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
78 if (!_active) return;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
79 else enqueue_known_active(ptr);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
80 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
81
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
82 void handle_zero_index();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
83 void locking_enqueue_completed_buffer(void** buf);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
84
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
85 void enqueue_known_active(void* ptr);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
86
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
87 size_t size() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
88 assert(_sz >= _index, "Invariant.");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
89 return _buf == NULL ? 0 : _sz - _index;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
90 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
91
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
92 // Set the "active" property of the queue to "b". An enqueue to an
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
93 // inactive thread is a no-op. Setting a queue to inactive resets its
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
94 // log to the empty state.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
95 void set_active(bool b) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
96 _active = b;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
97 if (!b && _buf != NULL) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
98 _index = _sz;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
99 } else if (b && _buf != NULL) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
100 assert(_index == _sz, "invariant: queues are empty when activated.");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
101 }
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 static int byte_index_to_index(int ind) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
105 assert((ind % oopSize) == 0, "Invariant.");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
106 return ind / oopSize;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
107 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
108
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
109 static int index_to_byte_index(int byte_ind) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
110 return byte_ind * oopSize;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
111 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
112
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
113 // To support compiler.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
114 static ByteSize byte_offset_of_index() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
115 return byte_offset_of(PtrQueue, _index);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
116 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
117 static ByteSize byte_width_of_index() { return in_ByteSize(sizeof(size_t)); }
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 static ByteSize byte_offset_of_buf() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
120 return byte_offset_of(PtrQueue, _buf);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
121 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
122 static ByteSize byte_width_of_buf() { return in_ByteSize(sizeof(void*)); }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
123
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
124 static ByteSize byte_offset_of_active() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
125 return byte_offset_of(PtrQueue, _active);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
126 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
127 static ByteSize byte_width_of_active() { return in_ByteSize(sizeof(bool)); }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
128
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
129 };
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
130
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
131 class BufferNode {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
132 size_t _index;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
133 BufferNode* _next;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
134 public:
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
135 BufferNode() : _index(0), _next(NULL) { }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
136 BufferNode* next() const { return _next; }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
137 void set_next(BufferNode* n) { _next = n; }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
138 size_t index() const { return _index; }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
139 void set_index(size_t i) { _index = i; }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
140
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
141 // Align the size of the structure to the size of the pointer
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
142 static size_t aligned_size() {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
143 static const size_t alignment = round_to(sizeof(BufferNode), sizeof(void*));
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
144 return alignment;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
145 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
146
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
147 // BufferNode is allocated before the buffer.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
148 // The chunk of memory that holds both of them is a block.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
149
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
150 // Produce a new BufferNode given a buffer.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
151 static BufferNode* new_from_buffer(void** buf) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
152 return new (make_block_from_buffer(buf)) BufferNode;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
153 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
154
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
155 // The following are the required conversion routines:
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
156 static BufferNode* make_node_from_buffer(void** buf) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
157 return (BufferNode*)make_block_from_buffer(buf);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
158 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
159 static void** make_buffer_from_node(BufferNode *node) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
160 return make_buffer_from_block(node);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
161 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
162 static void* make_block_from_node(BufferNode *node) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
163 return (void*)node;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
164 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
165 static void** make_buffer_from_block(void* p) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
166 return (void**)((char*)p + aligned_size());
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
167 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
168 static void* make_block_from_buffer(void** p) {
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
169 return (void*)((char*)p - aligned_size());
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
170 }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
171 };
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
172
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
173 // A PtrQueueSet represents resources common to a set of pointer queues.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
174 // In particular, the individual queues allocate buffers from this shared
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
175 // set, and return completed buffers to the set.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
176 // All these variables are are protected by the TLOQ_CBL_mon. XXX ???
549
fe3d7c11b4b7 6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents: 470
diff changeset
177 class PtrQueueSet VALUE_OBJ_CLASS_SPEC {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
178 protected:
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
179 Monitor* _cbl_mon; // Protects the fields below.
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
180 BufferNode* _completed_buffers_head;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
181 BufferNode* _completed_buffers_tail;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
182 int _n_completed_buffers;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
183 int _process_completed_threshold;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
184 volatile bool _process_completed;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
185
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
186 // This (and the interpretation of the first element as a "next"
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
187 // pointer) are protected by the TLOQ_FL_lock.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
188 Mutex* _fl_lock;
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
189 BufferNode* _buf_free_list;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
190 size_t _buf_free_list_sz;
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 549
diff changeset
191 // Queue set can share a freelist. The _fl_owner variable
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 549
diff changeset
192 // specifies the owner. It is set to "this" by default.
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 549
diff changeset
193 PtrQueueSet* _fl_owner;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
194
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
195 // The size of all buffers in the set.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
196 size_t _sz;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
197
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
198 bool _all_active;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
199
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
200 // If true, notify_all on _cbl_mon when the threshold is reached.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
201 bool _notify_when_complete;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
202
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
203 // Maximum number of elements allowed on completed queue: after that,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
204 // enqueuer does the work itself. Zero indicates no maximum.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
205 int _max_completed_queue;
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
206 int _completed_queue_padding;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
207
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
208 int completed_buffers_list_length();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
209 void assert_completed_buffer_list_len_correct_locked();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
210 void assert_completed_buffer_list_len_correct();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
211
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
212 protected:
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
213 // A mutator thread does the the work of processing a buffer.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
214 // Returns "true" iff the work is complete (and the buffer may be
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
215 // deallocated).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
216 virtual bool mut_process_buffer(void** buf) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
217 ShouldNotReachHere();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
218 return false;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
219 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
220
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
221 public:
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
222 // Create an empty ptr queue set.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
223 PtrQueueSet(bool notify_when_complete = false);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
224
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
225 // Because of init-order concerns, we can't pass these as constructor
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
226 // arguments.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
227 void initialize(Monitor* cbl_mon, Mutex* fl_lock,
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
228 int process_completed_threshold,
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
229 int max_completed_queue,
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 549
diff changeset
230 PtrQueueSet *fl_owner = NULL) {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
231 _max_completed_queue = max_completed_queue;
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
232 _process_completed_threshold = process_completed_threshold;
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
233 _completed_queue_padding = 0;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
234 assert(cbl_mon != NULL && fl_lock != NULL, "Init order issue?");
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 549
diff changeset
235 _cbl_mon = cbl_mon;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 549
diff changeset
236 _fl_lock = fl_lock;
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 549
diff changeset
237 _fl_owner = (fl_owner != NULL) ? fl_owner : this;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
238 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
239
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
240 // Return an empty oop array of size _sz (required to be non-zero).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
241 void** allocate_buffer();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
242
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
243 // Return an empty buffer to the free list. The "buf" argument is
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
244 // required to be a pointer to the head of an array of length "_sz".
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
245 void deallocate_buffer(void** buf);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
246
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
247 // Declares that "buf" is a complete buffer.
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
248 void enqueue_complete_buffer(void** buf, size_t index = 0);
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
249
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
250 // To be invoked by the mutator.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
251 bool process_or_enqueue_complete_buffer(void** buf);
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 bool completed_buffers_exist_dirty() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
254 return _n_completed_buffers > 0;
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
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
257 bool process_completed_buffers() { return _process_completed; }
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
258 void set_process_completed(bool x) { _process_completed = x; }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
259
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
260 bool active() { return _all_active; }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
261
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
262 // Set the buffer size. Should be called before any "enqueue" operation
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
263 // can be called. And should only be called once.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
264 void set_buffer_size(size_t sz);
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 // Get the buffer size.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
267 size_t buffer_size() { return _sz; }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
268
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
269 // Get/Set the number of completed buffers that triggers log processing.
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
270 void set_process_completed_threshold(int sz) { _process_completed_threshold = sz; }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
271 int process_completed_threshold() const { return _process_completed_threshold; }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
272
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
273 // Must only be called at a safe point. Indicates that the buffer free
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
274 // list size may be reduced, if that is deemed desirable.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
275 void reduce_free_list();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
276
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
277 int completed_buffers_num() { return _n_completed_buffers; }
616
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 549
diff changeset
278
4f360ec815ba 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 549
diff changeset
279 void merge_bufferlists(PtrQueueSet* src);
1111
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
280
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
281 void set_max_completed_queue(int m) { _max_completed_queue = m; }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
282 int max_completed_queue() { return _max_completed_queue; }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
283
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
284 void set_completed_queue_padding(int padding) { _completed_queue_padding = padding; }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
285 int completed_queue_padding() { return _completed_queue_padding; }
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
286
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
287 // Notify the consumer if the number of buffers crossed the threshold
44f61c24ddab 6862387: tune concurrent refinement further
iveresov
parents: 628
diff changeset
288 void notify_if_necessary();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
289 };