ysr@777: /* johnc@2781: * Copyright (c) 2001, 2011, 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: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" stefank@2314: #include "gc_implementation/g1/heapRegion.hpp" stefank@2314: #include "gc_implementation/g1/satbQueue.hpp" stefank@2314: #include "runtime/mutexLocker.hpp" stefank@2314: #include "runtime/thread.hpp" stefank@2314: #ifdef TARGET_OS_FAMILY_linux stefank@2314: # include "thread_linux.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_solaris stefank@2314: # include "thread_solaris.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_windows stefank@2314: # include "thread_windows.inline.hpp" stefank@2314: #endif 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) { johnc@2781: // Nulls should have been already filtered. johnc@2781: assert(pre_val->is_oop(true), "Error"); johnc@2781: 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@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: }