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/_g1SATBCardTableModRefBS.cpp.incl" ysr@777: ysr@777: G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap, ysr@777: int max_covered_regions) : ysr@777: CardTableModRefBSForCTRS(whole_heap, max_covered_regions) ysr@777: { ysr@777: _kind = G1SATBCT; ysr@777: } ysr@777: ysr@777: ysr@777: void G1SATBCardTableModRefBS::enqueue(oop pre_val) { ysr@1280: assert(pre_val->is_oop_or_null(true), "Error"); tonyp@1752: if (!JavaThread::satb_mark_queue_set().is_active()) return; ysr@777: Thread* thr = Thread::current(); ysr@777: if (thr->is_Java_thread()) { ysr@777: JavaThread* jt = (JavaThread*)thr; ysr@777: jt->satb_mark_queue().enqueue(pre_val); ysr@777: } else { ysr@777: MutexLocker x(Shared_SATB_Q_lock); ysr@777: JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val); ysr@777: } ysr@777: } ysr@777: ysr@777: // When we know the current java thread: ysr@1280: template void ysr@1280: G1SATBCardTableModRefBS::write_ref_field_pre_static(T* field, ysr@1280: oop new_val, ysr@777: JavaThread* jt) { tonyp@1752: if (!JavaThread::satb_mark_queue_set().is_active()) return; ysr@1280: T heap_oop = oopDesc::load_heap_oop(field); ysr@1280: if (!oopDesc::is_null(heap_oop)) { ysr@1280: oop pre_val = oopDesc::decode_heap_oop_not_null(heap_oop); ysr@1280: assert(pre_val->is_oop(true /* ignore mark word */), "Error"); ysr@1280: jt->satb_mark_queue().enqueue(pre_val); ysr@777: } ysr@777: } ysr@777: ysr@1280: template void ysr@1280: G1SATBCardTableModRefBS::write_ref_array_pre_work(T* dst, int count) { tonyp@1752: if (!JavaThread::satb_mark_queue_set().is_active()) return; ysr@1280: T* elem_ptr = dst; ysr@1280: for (int i = 0; i < count; i++, elem_ptr++) { ysr@1280: T heap_oop = oopDesc::load_heap_oop(elem_ptr); ysr@1280: if (!oopDesc::is_null(heap_oop)) { ysr@1280: enqueue(oopDesc::decode_heap_oop_not_null(heap_oop)); ysr@1280: } ysr@777: } ysr@777: } ysr@777: ysr@777: G1SATBCardTableLoggingModRefBS:: ysr@777: G1SATBCardTableLoggingModRefBS(MemRegion whole_heap, ysr@777: int max_covered_regions) : ysr@777: G1SATBCardTableModRefBS(whole_heap, max_covered_regions), ysr@777: _dcqs(JavaThread::dirty_card_queue_set()) ysr@777: { ysr@777: _kind = G1SATBCTLogging; ysr@777: } ysr@777: ysr@777: void ysr@777: G1SATBCardTableLoggingModRefBS::write_ref_field_work(void* field, ysr@777: oop new_val) { ysr@777: jbyte* byte = byte_for(field); ysr@777: if (*byte != dirty_card) { ysr@777: *byte = dirty_card; ysr@777: Thread* thr = Thread::current(); ysr@777: if (thr->is_Java_thread()) { ysr@777: JavaThread* jt = (JavaThread*)thr; ysr@777: jt->dirty_card_queue().enqueue(byte); ysr@777: } else { ysr@777: MutexLockerEx x(Shared_DirtyCardQ_lock, ysr@777: Mutex::_no_safepoint_check_flag); ysr@777: _dcqs.shared_dirty_card_queue()->enqueue(byte); ysr@777: } ysr@777: } ysr@777: } ysr@777: ysr@777: void ysr@777: G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field, ysr@777: oop new_val) { ysr@777: uintptr_t field_uint = (uintptr_t)field; ysr@777: uintptr_t new_val_uint = (uintptr_t)new_val; ysr@777: uintptr_t comb = field_uint ^ new_val_uint; ysr@777: comb = comb >> HeapRegion::LogOfHRGrainBytes; ysr@777: if (comb == 0) return; ysr@777: if (new_val == NULL) return; ysr@777: // Otherwise, log it. ysr@777: G1SATBCardTableLoggingModRefBS* g1_bs = ysr@777: (G1SATBCardTableLoggingModRefBS*)Universe::heap()->barrier_set(); ysr@777: g1_bs->write_ref_field_work(field, new_val); ysr@777: } ysr@777: ysr@777: void ysr@777: G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) { ysr@777: jbyte* byte = byte_for(mr.start()); ysr@777: jbyte* last_byte = byte_for(mr.last()); ysr@777: Thread* thr = Thread::current(); ysr@777: if (whole_heap) { ysr@777: while (byte <= last_byte) { ysr@777: *byte = dirty_card; ysr@777: byte++; ysr@777: } ysr@777: } else { ysr@777: // Enqueue if necessary. ysr@777: if (thr->is_Java_thread()) { ysr@777: JavaThread* jt = (JavaThread*)thr; ysr@777: while (byte <= last_byte) { ysr@777: if (*byte != dirty_card) { ysr@777: *byte = dirty_card; ysr@777: jt->dirty_card_queue().enqueue(byte); ysr@777: } ysr@777: byte++; ysr@777: } ysr@777: } else { ysr@777: MutexLockerEx x(Shared_DirtyCardQ_lock, ysr@777: Mutex::_no_safepoint_check_flag); ysr@777: while (byte <= last_byte) { ysr@777: if (*byte != dirty_card) { ysr@777: *byte = dirty_card; ysr@777: _dcqs.shared_dirty_card_queue()->enqueue(byte); ysr@777: } ysr@777: byte++; ysr@777: } ysr@777: } ysr@777: } ysr@777: }