ysr@777: /* ysr@777: * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. ysr@777: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ysr@777: * ysr@777: * This code is free software; you can redistribute it and/or modify it ysr@777: * under the terms of the GNU General Public License version 2 only, as ysr@777: * published by the Free Software Foundation. ysr@777: * ysr@777: * This code is distributed in the hope that it will be useful, but WITHOUT ysr@777: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ysr@777: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ysr@777: * version 2 for more details (a copy is included in the LICENSE file that ysr@777: * accompanied this code). ysr@777: * ysr@777: * You should have received a copy of the GNU General Public License version ysr@777: * 2 along with this work; if not, write to the Free Software Foundation, ysr@777: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ysr@777: * ysr@777: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, ysr@777: * CA 95054 USA or visit www.sun.com if you need additional information or ysr@777: * have any questions. ysr@777: * ysr@777: */ ysr@777: ysr@777: # include "incls/_precompiled.incl" ysr@777: # include "incls/_satbQueue.cpp.incl" ysr@777: ysr@777: void ObjPtrQueue::apply_closure(ObjectClosure* cl) { ysr@777: if (_buf != NULL) { ysr@777: apply_closure_to_buffer(cl, _buf, _index, _sz); ysr@777: _index = _sz; ysr@777: } ysr@777: } ysr@777: ysr@777: void ObjPtrQueue::apply_closure_to_buffer(ObjectClosure* cl, ysr@777: void** buf, size_t index, size_t sz) { ysr@777: if (cl == NULL) return; ysr@777: for (size_t i = index; i < sz; i += oopSize) { ysr@777: oop obj = (oop)buf[byte_index_to_index((int)i)]; ysr@777: // There can be NULL entries because of destructors. ysr@777: if (obj != NULL) { ysr@777: cl->do_object(obj); ysr@777: } ysr@777: } ysr@777: } ysr@777: #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away ysr@777: #pragma warning( disable:4355 ) // 'this' : used in base member initializer list ysr@777: #endif // _MSC_VER ysr@777: ysr@777: ysr@777: SATBMarkQueueSet::SATBMarkQueueSet() : ysr@777: PtrQueueSet(), ysr@777: _closure(NULL), _par_closures(NULL), ysr@777: _shared_satb_queue(this, true /*perm*/) ysr@777: {} ysr@777: ysr@777: void SATBMarkQueueSet::initialize(Monitor* cbl_mon, Mutex* fl_lock, ysr@777: int max_completed_queue, ysr@777: Mutex* lock) { ysr@777: PtrQueueSet::initialize(cbl_mon, fl_lock, max_completed_queue); ysr@777: _shared_satb_queue.set_lock(lock); ysr@777: if (ParallelGCThreads > 0) { ysr@777: _par_closures = NEW_C_HEAP_ARRAY(ObjectClosure*, ParallelGCThreads); ysr@777: } ysr@777: } ysr@777: ysr@777: ysr@777: void SATBMarkQueueSet::handle_zero_index_for_thread(JavaThread* t) { ysr@777: t->satb_mark_queue().handle_zero_index(); ysr@777: } ysr@777: ysr@777: void SATBMarkQueueSet::set_active_all_threads(bool b) { ysr@777: _all_active = b; ysr@777: for(JavaThread* t = Threads::first(); t; t = t->next()) { ysr@777: t->satb_mark_queue().set_active(b); ysr@777: } ysr@777: } ysr@777: ysr@777: void SATBMarkQueueSet::set_closure(ObjectClosure* closure) { ysr@777: _closure = closure; ysr@777: } ysr@777: ysr@777: void SATBMarkQueueSet::set_par_closure(int i, ObjectClosure* par_closure) { ysr@777: assert(ParallelGCThreads > 0 && _par_closures != NULL, "Precondition"); ysr@777: _par_closures[i] = par_closure; ysr@777: } ysr@777: ysr@777: void SATBMarkQueueSet::iterate_closure_all_threads() { ysr@777: for(JavaThread* t = Threads::first(); t; t = t->next()) { ysr@777: t->satb_mark_queue().apply_closure(_closure); ysr@777: } ysr@777: shared_satb_queue()->apply_closure(_closure); ysr@777: } ysr@777: ysr@777: void SATBMarkQueueSet::par_iterate_closure_all_threads(int worker) { ysr@777: SharedHeap* sh = SharedHeap::heap(); ysr@777: int parity = sh->strong_roots_parity(); ysr@777: ysr@777: for(JavaThread* t = Threads::first(); t; t = t->next()) { ysr@777: if (t->claim_oops_do(true, parity)) { ysr@777: t->satb_mark_queue().apply_closure(_par_closures[worker]); ysr@777: } ysr@777: } ysr@777: // We'll have worker 0 do this one. ysr@777: if (worker == 0) { ysr@777: shared_satb_queue()->apply_closure(_par_closures[0]); ysr@777: } ysr@777: } ysr@777: ysr@777: bool SATBMarkQueueSet::apply_closure_to_completed_buffer_work(bool par, ysr@777: int worker) { ysr@777: CompletedBufferNode* nd = NULL; ysr@777: { ysr@777: MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); ysr@777: if (_completed_buffers_head != NULL) { ysr@777: nd = _completed_buffers_head; ysr@777: _completed_buffers_head = nd->next; ysr@777: if (_completed_buffers_head == NULL) _completed_buffers_tail = NULL; ysr@777: _n_completed_buffers--; ysr@777: if (_n_completed_buffers == 0) _process_completed = false; ysr@777: } ysr@777: } ysr@777: ObjectClosure* cl = (par ? _par_closures[worker] : _closure); ysr@777: if (nd != NULL) { ysr@777: ObjPtrQueue::apply_closure_to_buffer(cl, nd->buf, 0, _sz); ysr@777: deallocate_buffer(nd->buf); ysr@777: delete nd; ysr@777: return true; ysr@777: } else { ysr@777: return false; ysr@777: } ysr@777: } ysr@777: ysr@777: void SATBMarkQueueSet::abandon_partial_marking() { ysr@777: CompletedBufferNode* buffers_to_delete = NULL; ysr@777: { ysr@777: MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); ysr@777: while (_completed_buffers_head != NULL) { ysr@777: CompletedBufferNode* nd = _completed_buffers_head; ysr@777: _completed_buffers_head = nd->next; ysr@777: nd->next = buffers_to_delete; ysr@777: buffers_to_delete = nd; ysr@777: } ysr@777: _completed_buffers_tail = NULL; ysr@777: _n_completed_buffers = 0; ysr@777: debug_only(assert_completed_buffer_list_len_correct_locked()); ysr@777: } ysr@777: while (buffers_to_delete != NULL) { ysr@777: CompletedBufferNode* nd = buffers_to_delete; ysr@777: buffers_to_delete = nd->next; ysr@777: deallocate_buffer(nd->buf); ysr@777: delete nd; ysr@777: } ysr@777: assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint."); ysr@777: // So we can safely manipulate these queues. ysr@777: for (JavaThread* t = Threads::first(); t; t = t->next()) { ysr@777: t->satb_mark_queue().reset(); ysr@777: } ysr@777: shared_satb_queue()->reset(); ysr@777: }