165 // Even if G1SATBBufferEnqueueingThresholdPercent == 0 we have to
166 // filter the buffer given that this will remove any references into
167 // the CSet as we currently assume that no such refs will appear in
168 // enqueued buffers.
169
170 // This method should only be called if there is a non-NULL buffer
171 // that is full.
172 assert(_index == 0, "pre-condition");
173 assert(_buf != NULL, "pre-condition");
174
175 filter();
176
177 size_t sz = _sz;
178 size_t all_entries = sz / oopSize;
179 size_t retained_entries = (sz - _index) / oopSize;
180 size_t perc = retained_entries * 100 / all_entries;
181 bool should_enqueue = perc > (size_t) G1SATBBufferEnqueueingThresholdPercent;
182 return should_enqueue;
183 }
184
185 void ObjPtrQueue::apply_closure(ObjectClosure* cl) {
186 if (_buf != NULL) {
187 apply_closure_to_buffer(cl, _buf, _index, _sz);
188 }
189 }
190
191 void ObjPtrQueue::apply_closure_and_empty(ObjectClosure* cl) {
192 if (_buf != NULL) {
193 apply_closure_to_buffer(cl, _buf, _index, _sz);
194 _index = _sz;
195 }
196 }
197
198 void ObjPtrQueue::apply_closure_to_buffer(ObjectClosure* cl,
199 void** buf, size_t index, size_t sz) {
200 if (cl == NULL) return;
201 for (size_t i = index; i < sz; i += oopSize) {
202 oop obj = (oop)buf[byte_index_to_index((int)i)];
203 // There can be NULL entries because of destructors.
204 if (obj != NULL) {
205 cl->do_object(obj);
206 }
207 }
208 }
209
210 #ifndef PRODUCT
300 bool SATBMarkQueueSet::apply_closure_to_completed_buffer(ObjectClosure* cl) {
301 BufferNode* nd = NULL;
302 {
303 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
304 if (_completed_buffers_head != NULL) {
305 nd = _completed_buffers_head;
306 _completed_buffers_head = nd->next();
307 if (_completed_buffers_head == NULL) _completed_buffers_tail = NULL;
308 _n_completed_buffers--;
309 if (_n_completed_buffers == 0) _process_completed = false;
310 }
311 }
312 if (nd != NULL) {
313 void **buf = BufferNode::make_buffer_from_node(nd);
314 ObjPtrQueue::apply_closure_to_buffer(cl, buf, 0, _sz);
315 deallocate_buffer(buf);
316 return true;
317 } else {
318 return false;
319 }
320 }
321
322 void SATBMarkQueueSet::iterate_completed_buffers_read_only(ObjectClosure* cl) {
323 assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
324 assert(cl != NULL, "pre-condition");
325
326 BufferNode* nd = _completed_buffers_head;
327 while (nd != NULL) {
328 void** buf = BufferNode::make_buffer_from_node(nd);
329 ObjPtrQueue::apply_closure_to_buffer(cl, buf, 0, _sz);
330 nd = nd->next();
331 }
332 }
333
334 void SATBMarkQueueSet::iterate_thread_buffers_read_only(ObjectClosure* cl) {
335 assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
336 assert(cl != NULL, "pre-condition");
337
338 for (JavaThread* t = Threads::first(); t; t = t->next()) {
339 t->satb_mark_queue().apply_closure(cl);
340 }
341 shared_satb_queue()->apply_closure(cl);
342 }
343
344 #ifndef PRODUCT
345 // Helpful for debugging
346
347 #define SATB_PRINTER_BUFFER_SIZE 256
348
349 void SATBMarkQueueSet::print_all(const char* msg) {
350 char buffer[SATB_PRINTER_BUFFER_SIZE];
351 assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
352
353 gclog_or_tty->cr();
354 gclog_or_tty->print_cr("SATB BUFFERS [%s]", msg);
355
356 BufferNode* nd = _completed_buffers_head;
357 int i = 0;
358 while (nd != NULL) {
359 void** buf = BufferNode::make_buffer_from_node(nd);
360 jio_snprintf(buffer, SATB_PRINTER_BUFFER_SIZE, "Enqueued: %d", i);
361 ObjPtrQueue::print(buffer, buf, 0, _sz);
|
165 // Even if G1SATBBufferEnqueueingThresholdPercent == 0 we have to
166 // filter the buffer given that this will remove any references into
167 // the CSet as we currently assume that no such refs will appear in
168 // enqueued buffers.
169
170 // This method should only be called if there is a non-NULL buffer
171 // that is full.
172 assert(_index == 0, "pre-condition");
173 assert(_buf != NULL, "pre-condition");
174
175 filter();
176
177 size_t sz = _sz;
178 size_t all_entries = sz / oopSize;
179 size_t retained_entries = (sz - _index) / oopSize;
180 size_t perc = retained_entries * 100 / all_entries;
181 bool should_enqueue = perc > (size_t) G1SATBBufferEnqueueingThresholdPercent;
182 return should_enqueue;
183 }
184
185 void ObjPtrQueue::apply_closure_and_empty(ObjectClosure* cl) {
186 if (_buf != NULL) {
187 apply_closure_to_buffer(cl, _buf, _index, _sz);
188 _index = _sz;
189 }
190 }
191
192 void ObjPtrQueue::apply_closure_to_buffer(ObjectClosure* cl,
193 void** buf, size_t index, size_t sz) {
194 if (cl == NULL) return;
195 for (size_t i = index; i < sz; i += oopSize) {
196 oop obj = (oop)buf[byte_index_to_index((int)i)];
197 // There can be NULL entries because of destructors.
198 if (obj != NULL) {
199 cl->do_object(obj);
200 }
201 }
202 }
203
204 #ifndef PRODUCT
294 bool SATBMarkQueueSet::apply_closure_to_completed_buffer(ObjectClosure* cl) {
295 BufferNode* nd = NULL;
296 {
297 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
298 if (_completed_buffers_head != NULL) {
299 nd = _completed_buffers_head;
300 _completed_buffers_head = nd->next();
301 if (_completed_buffers_head == NULL) _completed_buffers_tail = NULL;
302 _n_completed_buffers--;
303 if (_n_completed_buffers == 0) _process_completed = false;
304 }
305 }
306 if (nd != NULL) {
307 void **buf = BufferNode::make_buffer_from_node(nd);
308 ObjPtrQueue::apply_closure_to_buffer(cl, buf, 0, _sz);
309 deallocate_buffer(buf);
310 return true;
311 } else {
312 return false;
313 }
314 }
315
316 #ifndef PRODUCT
317 // Helpful for debugging
318
319 #define SATB_PRINTER_BUFFER_SIZE 256
320
321 void SATBMarkQueueSet::print_all(const char* msg) {
322 char buffer[SATB_PRINTER_BUFFER_SIZE];
323 assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
324
325 gclog_or_tty->cr();
326 gclog_or_tty->print_cr("SATB BUFFERS [%s]", msg);
327
328 BufferNode* nd = _completed_buffers_head;
329 int i = 0;
330 while (nd != NULL) {
331 void** buf = BufferNode::make_buffer_from_node(nd);
332 jio_snprintf(buffer, SATB_PRINTER_BUFFER_SIZE, "Enqueued: %d", i);
333 ObjPtrQueue::print(buffer, buf, 0, _sz);
|