Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/g1/ptrQueue.hpp @ 1282:b81f3572f355
6928059: G1: command line parameter renaming
Summary: Rename G1 parameters to make them more consistent.
Reviewed-by: jmasa, johnc
author | tonyp |
---|---|
date | Tue, 23 Feb 2010 23:13:23 -0500 |
parents | 44f61c24ddab |
children | d4197f8d516a |
rev | line source |
---|---|
342 | 1 /* |
579 | 2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. |
342 | 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // There are various techniques that require threads to be able to log | |
26 // addresses. For example, a generational write barrier might log | |
27 // the addresses of modified old-generation objects. This type supports | |
28 // this operation. | |
29 | |
1111 | 30 // The definition of placement operator new(size_t, void*) in the <new>. |
31 #include <new> | |
32 | |
342 | 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 | 35 |
36 protected: | |
37 // The ptr queue set to which this queue belongs. | |
38 PtrQueueSet* _qset; | |
39 | |
40 // Whether updates should be logged. | |
41 bool _active; | |
42 | |
43 // The buffer. | |
44 void** _buf; | |
45 // The index at which an object was last enqueued. Starts at "_sz" | |
46 // (indicating an empty buffer) and goes towards zero. | |
47 size_t _index; | |
48 | |
49 // The size of the buffer. | |
50 size_t _sz; | |
51 | |
52 // If true, the queue is permanent, and doesn't need to deallocate | |
53 // its buffer in the destructor (since that obtains a lock which may not | |
54 // be legally locked by then. | |
55 bool _perm; | |
56 | |
57 // If there is a lock associated with this buffer, this is that lock. | |
58 Mutex* _lock; | |
59 | |
60 PtrQueueSet* qset() { return _qset; } | |
61 | |
62 public: | |
63 // Initialize this queue to contain a null buffer, and be part of the | |
64 // given PtrQueueSet. | |
65 PtrQueue(PtrQueueSet*, bool perm = false); | |
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 | 70 |
71 // Associate a lock with a ptr queue. | |
72 void set_lock(Mutex* lock) { _lock = lock; } | |
73 | |
74 void reset() { if (_buf != NULL) _index = _sz; } | |
75 | |
76 // Enqueues the given "obj". | |
77 void enqueue(void* ptr) { | |
78 if (!_active) return; | |
79 else enqueue_known_active(ptr); | |
80 } | |
81 | |
1111 | 82 void handle_zero_index(); |
342 | 83 void locking_enqueue_completed_buffer(void** buf); |
84 | |
85 void enqueue_known_active(void* ptr); | |
86 | |
87 size_t size() { | |
88 assert(_sz >= _index, "Invariant."); | |
89 return _buf == NULL ? 0 : _sz - _index; | |
90 } | |
91 | |
92 // Set the "active" property of the queue to "b". An enqueue to an | |
93 // inactive thread is a no-op. Setting a queue to inactive resets its | |
94 // log to the empty state. | |
95 void set_active(bool b) { | |
96 _active = b; | |
97 if (!b && _buf != NULL) { | |
98 _index = _sz; | |
99 } else if (b && _buf != NULL) { | |
100 assert(_index == _sz, "invariant: queues are empty when activated."); | |
101 } | |
102 } | |
103 | |
104 static int byte_index_to_index(int ind) { | |
105 assert((ind % oopSize) == 0, "Invariant."); | |
106 return ind / oopSize; | |
107 } | |
108 | |
109 static int index_to_byte_index(int byte_ind) { | |
110 return byte_ind * oopSize; | |
111 } | |
112 | |
113 // To support compiler. | |
114 static ByteSize byte_offset_of_index() { | |
115 return byte_offset_of(PtrQueue, _index); | |
116 } | |
117 static ByteSize byte_width_of_index() { return in_ByteSize(sizeof(size_t)); } | |
118 | |
119 static ByteSize byte_offset_of_buf() { | |
120 return byte_offset_of(PtrQueue, _buf); | |
121 } | |
122 static ByteSize byte_width_of_buf() { return in_ByteSize(sizeof(void*)); } | |
123 | |
124 static ByteSize byte_offset_of_active() { | |
125 return byte_offset_of(PtrQueue, _active); | |
126 } | |
127 static ByteSize byte_width_of_active() { return in_ByteSize(sizeof(bool)); } | |
128 | |
129 }; | |
130 | |
1111 | 131 class BufferNode { |
132 size_t _index; | |
133 BufferNode* _next; | |
134 public: | |
135 BufferNode() : _index(0), _next(NULL) { } | |
136 BufferNode* next() const { return _next; } | |
137 void set_next(BufferNode* n) { _next = n; } | |
138 size_t index() const { return _index; } | |
139 void set_index(size_t i) { _index = i; } | |
140 | |
141 // Align the size of the structure to the size of the pointer | |
142 static size_t aligned_size() { | |
143 static const size_t alignment = round_to(sizeof(BufferNode), sizeof(void*)); | |
144 return alignment; | |
145 } | |
146 | |
147 // BufferNode is allocated before the buffer. | |
148 // The chunk of memory that holds both of them is a block. | |
149 | |
150 // Produce a new BufferNode given a buffer. | |
151 static BufferNode* new_from_buffer(void** buf) { | |
152 return new (make_block_from_buffer(buf)) BufferNode; | |
153 } | |
154 | |
155 // The following are the required conversion routines: | |
156 static BufferNode* make_node_from_buffer(void** buf) { | |
157 return (BufferNode*)make_block_from_buffer(buf); | |
158 } | |
159 static void** make_buffer_from_node(BufferNode *node) { | |
160 return make_buffer_from_block(node); | |
161 } | |
162 static void* make_block_from_node(BufferNode *node) { | |
163 return (void*)node; | |
164 } | |
165 static void** make_buffer_from_block(void* p) { | |
166 return (void**)((char*)p + aligned_size()); | |
167 } | |
168 static void* make_block_from_buffer(void** p) { | |
169 return (void*)((char*)p - aligned_size()); | |
170 } | |
171 }; | |
172 | |
342 | 173 // A PtrQueueSet represents resources common to a set of pointer queues. |
174 // In particular, the individual queues allocate buffers from this shared | |
175 // set, and return completed buffers to the set. | |
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 | 178 protected: |
179 Monitor* _cbl_mon; // Protects the fields below. | |
1111 | 180 BufferNode* _completed_buffers_head; |
181 BufferNode* _completed_buffers_tail; | |
182 int _n_completed_buffers; | |
183 int _process_completed_threshold; | |
342 | 184 volatile bool _process_completed; |
185 | |
186 // This (and the interpretation of the first element as a "next" | |
187 // pointer) are protected by the TLOQ_FL_lock. | |
188 Mutex* _fl_lock; | |
1111 | 189 BufferNode* _buf_free_list; |
342 | 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 | 194 |
195 // The size of all buffers in the set. | |
196 size_t _sz; | |
197 | |
198 bool _all_active; | |
199 | |
200 // If true, notify_all on _cbl_mon when the threshold is reached. | |
201 bool _notify_when_complete; | |
202 | |
203 // Maximum number of elements allowed on completed queue: after that, | |
204 // enqueuer does the work itself. Zero indicates no maximum. | |
205 int _max_completed_queue; | |
1111 | 206 int _completed_queue_padding; |
342 | 207 |
208 int completed_buffers_list_length(); | |
209 void assert_completed_buffer_list_len_correct_locked(); | |
210 void assert_completed_buffer_list_len_correct(); | |
211 | |
212 protected: | |
213 // A mutator thread does the the work of processing a buffer. | |
214 // Returns "true" iff the work is complete (and the buffer may be | |
215 // deallocated). | |
216 virtual bool mut_process_buffer(void** buf) { | |
217 ShouldNotReachHere(); | |
218 return false; | |
219 } | |
220 | |
221 public: | |
222 // Create an empty ptr queue set. | |
223 PtrQueueSet(bool notify_when_complete = false); | |
224 | |
225 // Because of init-order concerns, we can't pass these as constructor | |
226 // arguments. | |
227 void initialize(Monitor* cbl_mon, Mutex* fl_lock, | |
1111 | 228 int process_completed_threshold, |
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 | 231 _max_completed_queue = max_completed_queue; |
1111 | 232 _process_completed_threshold = process_completed_threshold; |
233 _completed_queue_padding = 0; | |
342 | 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 | 238 } |
239 | |
240 // Return an empty oop array of size _sz (required to be non-zero). | |
241 void** allocate_buffer(); | |
242 | |
243 // Return an empty buffer to the free list. The "buf" argument is | |
244 // required to be a pointer to the head of an array of length "_sz". | |
245 void deallocate_buffer(void** buf); | |
246 | |
247 // Declares that "buf" is a complete buffer. | |
1111 | 248 void enqueue_complete_buffer(void** buf, size_t index = 0); |
249 | |
250 // To be invoked by the mutator. | |
251 bool process_or_enqueue_complete_buffer(void** buf); | |
342 | 252 |
253 bool completed_buffers_exist_dirty() { | |
254 return _n_completed_buffers > 0; | |
255 } | |
256 | |
257 bool process_completed_buffers() { return _process_completed; } | |
1111 | 258 void set_process_completed(bool x) { _process_completed = x; } |
342 | 259 |
260 bool active() { return _all_active; } | |
261 | |
262 // Set the buffer size. Should be called before any "enqueue" operation | |
263 // can be called. And should only be called once. | |
264 void set_buffer_size(size_t sz); | |
265 | |
266 // Get the buffer size. | |
267 size_t buffer_size() { return _sz; } | |
268 | |
1111 | 269 // Get/Set the number of completed buffers that triggers log processing. |
270 void set_process_completed_threshold(int sz) { _process_completed_threshold = sz; } | |
271 int process_completed_threshold() const { return _process_completed_threshold; } | |
342 | 272 |
273 // Must only be called at a safe point. Indicates that the buffer free | |
274 // list size may be reduced, if that is deemed desirable. | |
275 void reduce_free_list(); | |
276 | |
1111 | 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 | 280 |
281 void set_max_completed_queue(int m) { _max_completed_queue = m; } | |
282 int max_completed_queue() { return _max_completed_queue; } | |
283 | |
284 void set_completed_queue_padding(int padding) { _completed_queue_padding = padding; } | |
285 int completed_queue_padding() { return _completed_queue_padding; } | |
286 | |
287 // Notify the consumer if the number of buffers crossed the threshold | |
288 void notify_if_necessary(); | |
342 | 289 }; |