173 };
174
175 size_t _max_chunk_capacity; // Maximum number of OopChunk elements on the stack.
176
177 OopChunk* _base; // Bottom address of allocated memory area.
178 size_t _chunk_capacity; // Current maximum number of OopChunk elements.
179
180 char _pad0[DEFAULT_CACHE_LINE_SIZE];
181 OopChunk* volatile _free_list; // Linked list of free chunks that can be allocated by users.
182 char _pad1[DEFAULT_CACHE_LINE_SIZE - sizeof(OopChunk*)];
183 OopChunk* volatile _chunk_list; // List of chunks currently containing data.
184 char _pad2[DEFAULT_CACHE_LINE_SIZE - sizeof(OopChunk*)];
185
186 volatile size_t _hwm; // High water mark within the reserved space.
187 char _pad4[DEFAULT_CACHE_LINE_SIZE - sizeof(size_t)];
188
189 // Allocate a new chunk from the reserved memory, using the high water mark. Returns
190 // NULL if out of memory.
191 OopChunk* allocate_new_chunk();
192
193 size_t volatile _chunks_in_chunk_list;
194
195 volatile bool _out_of_memory;
196
197 // Atomically add the given chunk to the list.
198 void add_chunk_to_list(OopChunk* volatile* list, OopChunk* elem);
199 // Atomically remove and return a chunk from the given list. Returns NULL if the
200 // list is empty.
201 OopChunk* remove_chunk_from_list(OopChunk* volatile* list);
202
203 bool _should_expand;
204
205 // Resizes the mark stack to the given new capacity. Releases any previous
206 // memory if successful.
207 bool resize(size_t new_capacity);
208
209 public:
210 G1CMMarkStack();
211 ~G1CMMarkStack();
212
213 // Alignment and minimum capacity of this mark stack in number of oops.
214 static size_t capacity_alignment();
215
216 // Allocate and initialize the mark stack with the given number of oops.
217 bool initialize(size_t initial_capacity, size_t max_capacity);
218
219 // Pushes the given buffer containing at most OopsPerChunk elements on the mark
220 // stack. If less than OopsPerChunk elements are to be pushed, the array must
221 // be terminated with a NULL.
222 // Returns whether the buffer contents were successfully pushed to the global mark
223 // stack.
224 bool par_push_chunk(oop* buffer);
225
226 // Pops a chunk from this mark stack, copying them into the given buffer. This
227 // chunk may contain up to OopsPerChunk elements. If there are less, the last
228 // element in the array is a NULL pointer.
229 bool par_pop_chunk(oop* buffer);
230
231 // Return whether the chunk list is empty. Racy due to unsynchronized access to
232 // _chunks_in_chunk_list.
233 bool is_empty() const { return _chunks_in_chunk_list == 0; }
234
235 size_t capacity() const { return _chunk_capacity; }
236
237 bool is_out_of_memory() const { return _out_of_memory; }
238 void clear_out_of_memory() { _out_of_memory = false; }
239
240 bool should_expand() const { return _should_expand; }
241 void set_should_expand(bool value) { _should_expand = value; }
242
243 // Expand the stack, typically in response to an overflow condition
244 void expand();
245
246 // Return the approximate number of oops on this mark stack. Racy due to
247 // unsynchronized access to _chunks_in_chunk_list.
248 size_t size() const { return _chunks_in_chunk_list * OopsPerChunk; }
249
250 void set_empty();
251
252 // Apply Fn to every oop on the mark stack. The mark stack must not
253 // be modified while iterating.
|
173 };
174
175 size_t _max_chunk_capacity; // Maximum number of OopChunk elements on the stack.
176
177 OopChunk* _base; // Bottom address of allocated memory area.
178 size_t _chunk_capacity; // Current maximum number of OopChunk elements.
179
180 char _pad0[DEFAULT_CACHE_LINE_SIZE];
181 OopChunk* volatile _free_list; // Linked list of free chunks that can be allocated by users.
182 char _pad1[DEFAULT_CACHE_LINE_SIZE - sizeof(OopChunk*)];
183 OopChunk* volatile _chunk_list; // List of chunks currently containing data.
184 char _pad2[DEFAULT_CACHE_LINE_SIZE - sizeof(OopChunk*)];
185
186 volatile size_t _hwm; // High water mark within the reserved space.
187 char _pad4[DEFAULT_CACHE_LINE_SIZE - sizeof(size_t)];
188
189 // Allocate a new chunk from the reserved memory, using the high water mark. Returns
190 // NULL if out of memory.
191 OopChunk* allocate_new_chunk();
192
193 volatile size_t _chunks_in_chunk_list;
194
195 volatile bool _out_of_memory;
196
197 // Atomically add the given chunk to the list.
198 void add_chunk_to_list(OopChunk* volatile* list, OopChunk* elem);
199 // Atomically remove and return a chunk from the given list. Returns NULL if the
200 // list is empty.
201 OopChunk* remove_chunk_from_list(OopChunk* volatile* list);
202
203 void add_chunk_to_chunk_list(OopChunk* elem);
204 void add_chunk_to_free_list(OopChunk* elem);
205
206 OopChunk* remove_chunk_from_chunk_list();
207 OopChunk* remove_chunk_from_free_list();
208
209 bool _should_expand;
210
211 // Resizes the mark stack to the given new capacity. Releases any previous
212 // memory if successful.
213 bool resize(size_t new_capacity);
214
215 public:
216 G1CMMarkStack();
217 ~G1CMMarkStack();
218
219 // Alignment and minimum capacity of this mark stack in number of oops.
220 static size_t capacity_alignment();
221
222 // Allocate and initialize the mark stack with the given number of oops.
223 bool initialize(size_t initial_capacity, size_t max_capacity);
224
225 // Pushes the given buffer containing at most OopsPerChunk elements on the mark
226 // stack. If less than OopsPerChunk elements are to be pushed, the array must
227 // be terminated with a NULL.
228 // Returns whether the buffer contents were successfully pushed to the global mark
229 // stack.
230 bool par_push_chunk(oop* buffer);
231
232 // Pops a chunk from this mark stack, copying them into the given buffer. This
233 // chunk may contain up to OopsPerChunk elements. If there are less, the last
234 // element in the array is a NULL pointer.
235 bool par_pop_chunk(oop* buffer);
236
237 // Return whether the chunk list is empty. Racy due to unsynchronized access to
238 // _chunk_list.
239 bool is_empty() const { return _chunk_list == NULL; }
240
241 size_t capacity() const { return _chunk_capacity; }
242
243 bool is_out_of_memory() const { return _out_of_memory; }
244 void clear_out_of_memory() { _out_of_memory = false; }
245
246 bool should_expand() const { return _should_expand; }
247 void set_should_expand(bool value) { _should_expand = value; }
248
249 // Expand the stack, typically in response to an overflow condition
250 void expand();
251
252 // Return the approximate number of oops on this mark stack. Racy due to
253 // unsynchronized access to _chunks_in_chunk_list.
254 size_t size() const { return _chunks_in_chunk_list * OopsPerChunk; }
255
256 void set_empty();
257
258 // Apply Fn to every oop on the mark stack. The mark stack must not
259 // be modified while iterating.
|