annotate src/share/vm/gc_implementation/g1/dirtyCardQueue.cpp @ 844:bd02caa94611

6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
author xdono
date Tue, 28 Jul 2009 12:12:40 -0700
parents 215f81b4d9b3
children 7f807f55161a
rev   line source
ysr@342 1 /*
xdono@844 2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved.
ysr@342 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@342 4 *
ysr@342 5 * This code is free software; you can redistribute it and/or modify it
ysr@342 6 * under the terms of the GNU General Public License version 2 only, as
ysr@342 7 * published by the Free Software Foundation.
ysr@342 8 *
ysr@342 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@342 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@342 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@342 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@342 13 * accompanied this code).
ysr@342 14 *
ysr@342 15 * You should have received a copy of the GNU General Public License version
ysr@342 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@342 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@342 18 *
ysr@342 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ysr@342 20 * CA 95054 USA or visit www.sun.com if you need additional information or
ysr@342 21 * have any questions.
ysr@342 22 *
ysr@342 23 */
ysr@342 24
ysr@342 25 # include "incls/_precompiled.incl"
ysr@342 26 # include "incls/_dirtyCardQueue.cpp.incl"
ysr@342 27
ysr@342 28 bool DirtyCardQueue::apply_closure(CardTableEntryClosure* cl,
ysr@342 29 bool consume,
ysr@342 30 size_t worker_i) {
ysr@342 31 bool res = true;
ysr@342 32 if (_buf != NULL) {
ysr@342 33 res = apply_closure_to_buffer(cl, _buf, _index, _sz,
ysr@342 34 consume,
ysr@342 35 (int) worker_i);
ysr@342 36 if (res && consume) _index = _sz;
ysr@342 37 }
ysr@342 38 return res;
ysr@342 39 }
ysr@342 40
ysr@342 41 bool DirtyCardQueue::apply_closure_to_buffer(CardTableEntryClosure* cl,
ysr@342 42 void** buf,
ysr@342 43 size_t index, size_t sz,
ysr@342 44 bool consume,
ysr@342 45 int worker_i) {
ysr@342 46 if (cl == NULL) return true;
ysr@342 47 for (size_t i = index; i < sz; i += oopSize) {
ysr@342 48 int ind = byte_index_to_index((int)i);
ysr@342 49 jbyte* card_ptr = (jbyte*)buf[ind];
ysr@342 50 if (card_ptr != NULL) {
ysr@342 51 // Set the entry to null, so we don't do it again (via the test
ysr@342 52 // above) if we reconsider this buffer.
ysr@342 53 if (consume) buf[ind] = NULL;
ysr@342 54 if (!cl->do_card_ptr(card_ptr, worker_i)) return false;
ysr@342 55 }
ysr@342 56 }
ysr@342 57 return true;
ysr@342 58 }
ysr@342 59
ysr@342 60 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
ysr@342 61 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
ysr@342 62 #endif // _MSC_VER
ysr@342 63
ysr@342 64 DirtyCardQueueSet::DirtyCardQueueSet() :
ysr@342 65 PtrQueueSet(true /*notify_when_complete*/),
ysr@342 66 _closure(NULL),
ysr@342 67 _shared_dirty_card_queue(this, true /*perm*/),
ysr@342 68 _free_ids(NULL),
ysr@342 69 _processed_buffers_mut(0), _processed_buffers_rs_thread(0)
ysr@342 70 {
ysr@342 71 _all_active = true;
ysr@342 72 }
ysr@342 73
iveresov@795 74 // Determines how many mutator threads can process the buffers in parallel.
ysr@342 75 size_t DirtyCardQueueSet::num_par_ids() {
iveresov@795 76 return os::processor_count();
ysr@342 77 }
ysr@342 78
ysr@342 79 void DirtyCardQueueSet::initialize(Monitor* cbl_mon, Mutex* fl_lock,
ysr@342 80 int max_completed_queue,
iveresov@616 81 Mutex* lock, PtrQueueSet* fl_owner) {
iveresov@616 82 PtrQueueSet::initialize(cbl_mon, fl_lock, max_completed_queue, fl_owner);
ysr@342 83 set_buffer_size(DCQBarrierQueueBufferSize);
ysr@342 84 set_process_completed_threshold(DCQBarrierProcessCompletedThreshold);
ysr@342 85
ysr@342 86 _shared_dirty_card_queue.set_lock(lock);
ysr@342 87 _free_ids = new FreeIdSet((int) num_par_ids(), _cbl_mon);
ysr@342 88 }
ysr@342 89
ysr@342 90 void DirtyCardQueueSet::handle_zero_index_for_thread(JavaThread* t) {
ysr@342 91 t->dirty_card_queue().handle_zero_index();
ysr@342 92 }
ysr@342 93
ysr@342 94 void DirtyCardQueueSet::set_closure(CardTableEntryClosure* closure) {
ysr@342 95 _closure = closure;
ysr@342 96 }
ysr@342 97
ysr@342 98 void DirtyCardQueueSet::iterate_closure_all_threads(bool consume,
ysr@342 99 size_t worker_i) {
ysr@342 100 assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
ysr@342 101 for(JavaThread* t = Threads::first(); t; t = t->next()) {
ysr@342 102 bool b = t->dirty_card_queue().apply_closure(_closure, consume);
ysr@342 103 guarantee(b, "Should not be interrupted.");
ysr@342 104 }
ysr@342 105 bool b = shared_dirty_card_queue()->apply_closure(_closure,
ysr@342 106 consume,
ysr@342 107 worker_i);
ysr@342 108 guarantee(b, "Should not be interrupted.");
ysr@342 109 }
ysr@342 110
ysr@342 111 bool DirtyCardQueueSet::mut_process_buffer(void** buf) {
ysr@342 112
ysr@342 113 // Used to determine if we had already claimed a par_id
ysr@342 114 // before entering this method.
ysr@342 115 bool already_claimed = false;
ysr@342 116
ysr@342 117 // We grab the current JavaThread.
ysr@342 118 JavaThread* thread = JavaThread::current();
ysr@342 119
ysr@342 120 // We get the the number of any par_id that this thread
ysr@342 121 // might have already claimed.
ysr@342 122 int worker_i = thread->get_claimed_par_id();
ysr@342 123
ysr@342 124 // If worker_i is not -1 then the thread has already claimed
ysr@342 125 // a par_id. We make note of it using the already_claimed value
ysr@342 126 if (worker_i != -1) {
ysr@342 127 already_claimed = true;
ysr@342 128 } else {
ysr@342 129
ysr@342 130 // Otherwise we need to claim a par id
ysr@342 131 worker_i = _free_ids->claim_par_id();
ysr@342 132
ysr@342 133 // And store the par_id value in the thread
ysr@342 134 thread->set_claimed_par_id(worker_i);
ysr@342 135 }
ysr@342 136
ysr@342 137 bool b = false;
ysr@342 138 if (worker_i != -1) {
ysr@342 139 b = DirtyCardQueue::apply_closure_to_buffer(_closure, buf, 0,
ysr@342 140 _sz, true, worker_i);
ysr@342 141 if (b) Atomic::inc(&_processed_buffers_mut);
ysr@342 142
ysr@342 143 // If we had not claimed an id before entering the method
ysr@342 144 // then we must release the id.
ysr@342 145 if (!already_claimed) {
ysr@342 146
ysr@342 147 // we release the id
ysr@342 148 _free_ids->release_par_id(worker_i);
ysr@342 149
ysr@342 150 // and set the claimed_id in the thread to -1
ysr@342 151 thread->set_claimed_par_id(-1);
ysr@342 152 }
ysr@342 153 }
ysr@342 154 return b;
ysr@342 155 }
ysr@342 156
ysr@342 157 DirtyCardQueueSet::CompletedBufferNode*
ysr@342 158 DirtyCardQueueSet::get_completed_buffer_lock(int stop_at) {
ysr@342 159 CompletedBufferNode* nd = NULL;
ysr@342 160 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
ysr@342 161
ysr@342 162 if ((int)_n_completed_buffers <= stop_at) {
ysr@342 163 _process_completed = false;
ysr@342 164 return NULL;
ysr@342 165 }
ysr@342 166
ysr@342 167 if (_completed_buffers_head != NULL) {
ysr@342 168 nd = _completed_buffers_head;
ysr@342 169 _completed_buffers_head = nd->next;
ysr@342 170 if (_completed_buffers_head == NULL)
ysr@342 171 _completed_buffers_tail = NULL;
ysr@342 172 _n_completed_buffers--;
ysr@342 173 }
ysr@342 174 debug_only(assert_completed_buffer_list_len_correct_locked());
ysr@342 175 return nd;
ysr@342 176 }
ysr@342 177
ysr@342 178 // We only do this in contexts where there is no concurrent enqueueing.
ysr@342 179 DirtyCardQueueSet::CompletedBufferNode*
ysr@342 180 DirtyCardQueueSet::get_completed_buffer_CAS() {
ysr@342 181 CompletedBufferNode* nd = _completed_buffers_head;
ysr@342 182
ysr@342 183 while (nd != NULL) {
ysr@342 184 CompletedBufferNode* next = nd->next;
ysr@342 185 CompletedBufferNode* result =
ysr@342 186 (CompletedBufferNode*)Atomic::cmpxchg_ptr(next,
ysr@342 187 &_completed_buffers_head,
ysr@342 188 nd);
ysr@342 189 if (result == nd) {
ysr@342 190 return result;
ysr@342 191 } else {
ysr@342 192 nd = _completed_buffers_head;
ysr@342 193 }
ysr@342 194 }
ysr@342 195 assert(_completed_buffers_head == NULL, "Loop post");
ysr@342 196 _completed_buffers_tail = NULL;
ysr@342 197 return NULL;
ysr@342 198 }
ysr@342 199
ysr@342 200 bool DirtyCardQueueSet::
ysr@342 201 apply_closure_to_completed_buffer_helper(int worker_i,
ysr@342 202 CompletedBufferNode* nd) {
ysr@342 203 if (nd != NULL) {
ysr@342 204 bool b =
ysr@342 205 DirtyCardQueue::apply_closure_to_buffer(_closure, nd->buf,
ysr@342 206 nd->index, _sz,
ysr@342 207 true, worker_i);
ysr@342 208 void** buf = nd->buf;
tonyp@364 209 size_t index = nd->index;
ysr@342 210 delete nd;
ysr@342 211 if (b) {
ysr@342 212 deallocate_buffer(buf);
ysr@342 213 return true; // In normal case, go on to next buffer.
ysr@342 214 } else {
tonyp@364 215 enqueue_complete_buffer(buf, index, true);
ysr@342 216 return false;
ysr@342 217 }
ysr@342 218 } else {
ysr@342 219 return false;
ysr@342 220 }
ysr@342 221 }
ysr@342 222
ysr@342 223 bool DirtyCardQueueSet::apply_closure_to_completed_buffer(int worker_i,
ysr@342 224 int stop_at,
ysr@342 225 bool with_CAS)
ysr@342 226 {
ysr@342 227 CompletedBufferNode* nd = NULL;
ysr@342 228 if (with_CAS) {
ysr@342 229 guarantee(stop_at == 0, "Precondition");
ysr@342 230 nd = get_completed_buffer_CAS();
ysr@342 231 } else {
ysr@342 232 nd = get_completed_buffer_lock(stop_at);
ysr@342 233 }
ysr@342 234 bool res = apply_closure_to_completed_buffer_helper(worker_i, nd);
iveresov@794 235 if (res) Atomic::inc(&_processed_buffers_rs_thread);
ysr@342 236 return res;
ysr@342 237 }
ysr@342 238
ysr@342 239 void DirtyCardQueueSet::apply_closure_to_all_completed_buffers() {
ysr@342 240 CompletedBufferNode* nd = _completed_buffers_head;
ysr@342 241 while (nd != NULL) {
ysr@342 242 bool b =
ysr@342 243 DirtyCardQueue::apply_closure_to_buffer(_closure, nd->buf, 0, _sz,
ysr@342 244 false);
ysr@342 245 guarantee(b, "Should not stop early.");
ysr@342 246 nd = nd->next;
ysr@342 247 }
ysr@342 248 }
ysr@342 249
ysr@342 250 void DirtyCardQueueSet::abandon_logs() {
ysr@342 251 assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
ysr@342 252 CompletedBufferNode* buffers_to_delete = NULL;
ysr@342 253 {
ysr@342 254 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
ysr@342 255 while (_completed_buffers_head != NULL) {
ysr@342 256 CompletedBufferNode* nd = _completed_buffers_head;
ysr@342 257 _completed_buffers_head = nd->next;
ysr@342 258 nd->next = buffers_to_delete;
ysr@342 259 buffers_to_delete = nd;
ysr@342 260 }
ysr@342 261 _n_completed_buffers = 0;
ysr@342 262 _completed_buffers_tail = NULL;
ysr@342 263 debug_only(assert_completed_buffer_list_len_correct_locked());
ysr@342 264 }
ysr@342 265 while (buffers_to_delete != NULL) {
ysr@342 266 CompletedBufferNode* nd = buffers_to_delete;
ysr@342 267 buffers_to_delete = nd->next;
ysr@342 268 deallocate_buffer(nd->buf);
ysr@342 269 delete nd;
ysr@342 270 }
ysr@342 271 // Since abandon is done only at safepoints, we can safely manipulate
ysr@342 272 // these queues.
ysr@342 273 for (JavaThread* t = Threads::first(); t; t = t->next()) {
ysr@342 274 t->dirty_card_queue().reset();
ysr@342 275 }
ysr@342 276 shared_dirty_card_queue()->reset();
ysr@342 277 }
ysr@342 278
ysr@342 279
ysr@342 280 void DirtyCardQueueSet::concatenate_logs() {
ysr@342 281 // Iterate over all the threads, if we find a partial log add it to
ysr@342 282 // the global list of logs. Temporarily turn off the limit on the number
ysr@342 283 // of outstanding buffers.
ysr@342 284 int save_max_completed_queue = _max_completed_queue;
ysr@342 285 _max_completed_queue = max_jint;
ysr@342 286 assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
ysr@342 287 for (JavaThread* t = Threads::first(); t; t = t->next()) {
ysr@342 288 DirtyCardQueue& dcq = t->dirty_card_queue();
ysr@342 289 if (dcq.size() != 0) {
ysr@342 290 void **buf = t->dirty_card_queue().get_buf();
ysr@342 291 // We must NULL out the unused entries, then enqueue.
ysr@342 292 for (size_t i = 0; i < t->dirty_card_queue().get_index(); i += oopSize) {
ysr@342 293 buf[PtrQueue::byte_index_to_index((int)i)] = NULL;
ysr@342 294 }
ysr@342 295 enqueue_complete_buffer(dcq.get_buf(), dcq.get_index());
ysr@342 296 dcq.reinitialize();
ysr@342 297 }
ysr@342 298 }
ysr@342 299 if (_shared_dirty_card_queue.size() != 0) {
ysr@342 300 enqueue_complete_buffer(_shared_dirty_card_queue.get_buf(),
ysr@342 301 _shared_dirty_card_queue.get_index());
ysr@342 302 _shared_dirty_card_queue.reinitialize();
ysr@342 303 }
ysr@342 304 // Restore the completed buffer queue limit.
ysr@342 305 _max_completed_queue = save_max_completed_queue;
ysr@342 306 }