ysr@777: /* trims@1907: * Copyright (c) 2001, 2007, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * 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@1280: ysr@1280: #ifdef ASSERT ysr@1280: void ObjPtrQueue::verify_oops_in_buffer() { ysr@1280: if (_buf == NULL) return; ysr@1280: for (size_t i = _index; i < _sz; i += oopSize) { ysr@1280: oop obj = (oop)_buf[byte_index_to_index((int)i)]; ysr@1280: assert(obj != NULL && obj->is_oop(true /* ignore mark word */), ysr@1280: "Not an oop"); ysr@1280: } ysr@1280: } ysr@1280: #endif ysr@1280: 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, iveresov@1546: int process_completed_threshold, ysr@777: Mutex* lock) { iveresov@1546: PtrQueueSet::initialize(cbl_mon, fl_lock, process_completed_threshold, -1); 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@1280: DEBUG_ONLY(t->satb_mark_queue().verify_oops_in_buffer();) ysr@777: t->satb_mark_queue().handle_zero_index(); ysr@777: } ysr@777: tonyp@1752: #ifdef ASSERT tonyp@1752: void SATBMarkQueueSet::dump_active_values(JavaThread* first, tonyp@1752: bool expected_active) { tonyp@1752: gclog_or_tty->print_cr("SATB queue active values for Java Threads"); tonyp@1752: gclog_or_tty->print_cr(" SATB queue set: active is %s", tonyp@1752: (is_active()) ? "TRUE" : "FALSE"); tonyp@1752: gclog_or_tty->print_cr(" expected_active is %s", tonyp@1752: (expected_active) ? "TRUE" : "FALSE"); tonyp@1752: for (JavaThread* t = first; t; t = t->next()) { tonyp@1752: bool active = t->satb_mark_queue().is_active(); tonyp@1752: gclog_or_tty->print_cr(" thread %s, active is %s", tonyp@1752: t->name(), (active) ? "TRUE" : "FALSE"); tonyp@1752: } tonyp@1752: } tonyp@1752: #endif // ASSERT tonyp@1752: tonyp@1752: void SATBMarkQueueSet::set_active_all_threads(bool b, tonyp@1752: bool expected_active) { tonyp@1752: assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint."); tonyp@1752: JavaThread* first = Threads::first(); tonyp@1752: tonyp@1752: #ifdef ASSERT tonyp@1752: if (_all_active != expected_active) { tonyp@1752: dump_active_values(first, expected_active); tonyp@1752: tonyp@1752: // I leave this here as a guarantee, instead of an assert, so tonyp@1752: // that it will still be compiled in if we choose to uncomment tonyp@1752: // the #ifdef ASSERT in a product build. The whole block is tonyp@1752: // within an #ifdef ASSERT so the guarantee will not be compiled tonyp@1752: // in a product build anyway. tonyp@1752: guarantee(false, tonyp@1752: "SATB queue set has an unexpected active value"); tonyp@1752: } tonyp@1752: #endif // ASSERT ysr@777: _all_active = b; tonyp@1752: tonyp@1752: for (JavaThread* t = first; t; t = t->next()) { tonyp@1752: #ifdef ASSERT tonyp@1752: bool active = t->satb_mark_queue().is_active(); tonyp@1752: if (active != expected_active) { tonyp@1752: dump_active_values(first, expected_active); tonyp@1752: tonyp@1752: // I leave this here as a guarantee, instead of an assert, so tonyp@1752: // that it will still be compiled in if we choose to uncomment tonyp@1752: // the #ifdef ASSERT in a product build. The whole block is tonyp@1752: // within an #ifdef ASSERT so the guarantee will not be compiled tonyp@1752: // in a product build anyway. tonyp@1752: guarantee(false, tonyp@1752: "thread has an unexpected active value in its SATB queue"); tonyp@1752: } tonyp@1752: #endif // ASSERT 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) { iveresov@1546: BufferNode* 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; iveresov@1546: _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) { iveresov@1546: void **buf = BufferNode::make_buffer_from_node(nd); iveresov@1546: ObjPtrQueue::apply_closure_to_buffer(cl, buf, 0, _sz); iveresov@1546: deallocate_buffer(buf); ysr@777: return true; ysr@777: } else { ysr@777: return false; ysr@777: } ysr@777: } ysr@777: ysr@777: void SATBMarkQueueSet::abandon_partial_marking() { iveresov@1546: BufferNode* buffers_to_delete = NULL; ysr@777: { ysr@777: MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); ysr@777: while (_completed_buffers_head != NULL) { iveresov@1546: BufferNode* nd = _completed_buffers_head; iveresov@1546: _completed_buffers_head = nd->next(); iveresov@1546: nd->set_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@1280: DEBUG_ONLY(assert_completed_buffer_list_len_correct_locked()); ysr@777: } ysr@777: while (buffers_to_delete != NULL) { iveresov@1546: BufferNode* nd = buffers_to_delete; iveresov@1546: buffers_to_delete = nd->next(); iveresov@1546: deallocate_buffer(BufferNode::make_buffer_from_node(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: }