src/share/vm/gc_implementation/g1/satbQueue.cpp

Thu, 05 Jun 2008 15:57:56 -0700

author
ysr
date
Thu, 05 Jun 2008 15:57:56 -0700
changeset 777
37f87013dfd8
child 1280
df6caf649ff7
permissions
-rw-r--r--

6711316: Open source the Garbage-First garbage collector
Summary: First mercurial integration of the code for the Garbage-First garbage collector.
Reviewed-by: apetrusenko, iveresov, jmasa, sgoldman, tonyp, ysr

ysr@777 1 /*
ysr@777 2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
ysr@777 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ysr@777 20 * CA 95054 USA or visit www.sun.com if you need additional information or
ysr@777 21 * have any questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
ysr@777 25 # include "incls/_precompiled.incl"
ysr@777 26 # include "incls/_satbQueue.cpp.incl"
ysr@777 27
ysr@777 28 void ObjPtrQueue::apply_closure(ObjectClosure* cl) {
ysr@777 29 if (_buf != NULL) {
ysr@777 30 apply_closure_to_buffer(cl, _buf, _index, _sz);
ysr@777 31 _index = _sz;
ysr@777 32 }
ysr@777 33 }
ysr@777 34
ysr@777 35 void ObjPtrQueue::apply_closure_to_buffer(ObjectClosure* cl,
ysr@777 36 void** buf, size_t index, size_t sz) {
ysr@777 37 if (cl == NULL) return;
ysr@777 38 for (size_t i = index; i < sz; i += oopSize) {
ysr@777 39 oop obj = (oop)buf[byte_index_to_index((int)i)];
ysr@777 40 // There can be NULL entries because of destructors.
ysr@777 41 if (obj != NULL) {
ysr@777 42 cl->do_object(obj);
ysr@777 43 }
ysr@777 44 }
ysr@777 45 }
ysr@777 46 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
ysr@777 47 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
ysr@777 48 #endif // _MSC_VER
ysr@777 49
ysr@777 50
ysr@777 51 SATBMarkQueueSet::SATBMarkQueueSet() :
ysr@777 52 PtrQueueSet(),
ysr@777 53 _closure(NULL), _par_closures(NULL),
ysr@777 54 _shared_satb_queue(this, true /*perm*/)
ysr@777 55 {}
ysr@777 56
ysr@777 57 void SATBMarkQueueSet::initialize(Monitor* cbl_mon, Mutex* fl_lock,
ysr@777 58 int max_completed_queue,
ysr@777 59 Mutex* lock) {
ysr@777 60 PtrQueueSet::initialize(cbl_mon, fl_lock, max_completed_queue);
ysr@777 61 _shared_satb_queue.set_lock(lock);
ysr@777 62 if (ParallelGCThreads > 0) {
ysr@777 63 _par_closures = NEW_C_HEAP_ARRAY(ObjectClosure*, ParallelGCThreads);
ysr@777 64 }
ysr@777 65 }
ysr@777 66
ysr@777 67
ysr@777 68 void SATBMarkQueueSet::handle_zero_index_for_thread(JavaThread* t) {
ysr@777 69 t->satb_mark_queue().handle_zero_index();
ysr@777 70 }
ysr@777 71
ysr@777 72 void SATBMarkQueueSet::set_active_all_threads(bool b) {
ysr@777 73 _all_active = b;
ysr@777 74 for(JavaThread* t = Threads::first(); t; t = t->next()) {
ysr@777 75 t->satb_mark_queue().set_active(b);
ysr@777 76 }
ysr@777 77 }
ysr@777 78
ysr@777 79 void SATBMarkQueueSet::set_closure(ObjectClosure* closure) {
ysr@777 80 _closure = closure;
ysr@777 81 }
ysr@777 82
ysr@777 83 void SATBMarkQueueSet::set_par_closure(int i, ObjectClosure* par_closure) {
ysr@777 84 assert(ParallelGCThreads > 0 && _par_closures != NULL, "Precondition");
ysr@777 85 _par_closures[i] = par_closure;
ysr@777 86 }
ysr@777 87
ysr@777 88 void SATBMarkQueueSet::iterate_closure_all_threads() {
ysr@777 89 for(JavaThread* t = Threads::first(); t; t = t->next()) {
ysr@777 90 t->satb_mark_queue().apply_closure(_closure);
ysr@777 91 }
ysr@777 92 shared_satb_queue()->apply_closure(_closure);
ysr@777 93 }
ysr@777 94
ysr@777 95 void SATBMarkQueueSet::par_iterate_closure_all_threads(int worker) {
ysr@777 96 SharedHeap* sh = SharedHeap::heap();
ysr@777 97 int parity = sh->strong_roots_parity();
ysr@777 98
ysr@777 99 for(JavaThread* t = Threads::first(); t; t = t->next()) {
ysr@777 100 if (t->claim_oops_do(true, parity)) {
ysr@777 101 t->satb_mark_queue().apply_closure(_par_closures[worker]);
ysr@777 102 }
ysr@777 103 }
ysr@777 104 // We'll have worker 0 do this one.
ysr@777 105 if (worker == 0) {
ysr@777 106 shared_satb_queue()->apply_closure(_par_closures[0]);
ysr@777 107 }
ysr@777 108 }
ysr@777 109
ysr@777 110 bool SATBMarkQueueSet::apply_closure_to_completed_buffer_work(bool par,
ysr@777 111 int worker) {
ysr@777 112 CompletedBufferNode* nd = NULL;
ysr@777 113 {
ysr@777 114 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
ysr@777 115 if (_completed_buffers_head != NULL) {
ysr@777 116 nd = _completed_buffers_head;
ysr@777 117 _completed_buffers_head = nd->next;
ysr@777 118 if (_completed_buffers_head == NULL) _completed_buffers_tail = NULL;
ysr@777 119 _n_completed_buffers--;
ysr@777 120 if (_n_completed_buffers == 0) _process_completed = false;
ysr@777 121 }
ysr@777 122 }
ysr@777 123 ObjectClosure* cl = (par ? _par_closures[worker] : _closure);
ysr@777 124 if (nd != NULL) {
ysr@777 125 ObjPtrQueue::apply_closure_to_buffer(cl, nd->buf, 0, _sz);
ysr@777 126 deallocate_buffer(nd->buf);
ysr@777 127 delete nd;
ysr@777 128 return true;
ysr@777 129 } else {
ysr@777 130 return false;
ysr@777 131 }
ysr@777 132 }
ysr@777 133
ysr@777 134 void SATBMarkQueueSet::abandon_partial_marking() {
ysr@777 135 CompletedBufferNode* buffers_to_delete = NULL;
ysr@777 136 {
ysr@777 137 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
ysr@777 138 while (_completed_buffers_head != NULL) {
ysr@777 139 CompletedBufferNode* nd = _completed_buffers_head;
ysr@777 140 _completed_buffers_head = nd->next;
ysr@777 141 nd->next = buffers_to_delete;
ysr@777 142 buffers_to_delete = nd;
ysr@777 143 }
ysr@777 144 _completed_buffers_tail = NULL;
ysr@777 145 _n_completed_buffers = 0;
ysr@777 146 debug_only(assert_completed_buffer_list_len_correct_locked());
ysr@777 147 }
ysr@777 148 while (buffers_to_delete != NULL) {
ysr@777 149 CompletedBufferNode* nd = buffers_to_delete;
ysr@777 150 buffers_to_delete = nd->next;
ysr@777 151 deallocate_buffer(nd->buf);
ysr@777 152 delete nd;
ysr@777 153 }
ysr@777 154 assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
ysr@777 155 // So we can safely manipulate these queues.
ysr@777 156 for (JavaThread* t = Threads::first(); t; t = t->next()) {
ysr@777 157 t->satb_mark_queue().reset();
ysr@777 158 }
ysr@777 159 shared_satb_queue()->reset();
ysr@777 160 }

mercurial