src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp

Thu, 05 Jun 2008 15:57:56 -0700

author
ysr
date
Thu, 05 Jun 2008 15:57:56 -0700
changeset 777
37f87013dfd8
child 1280
df6caf649ff7
permissions
-rw-r--r--

6711316: Open source the Garbage-First garbage collector
Summary: First mercurial integration of the code for the Garbage-First garbage collector.
Reviewed-by: apetrusenko, iveresov, jmasa, sgoldman, tonyp, ysr

ysr@777 1 /*
ysr@777 2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
ysr@777 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ysr@777 20 * CA 95054 USA or visit www.sun.com if you need additional information or
ysr@777 21 * have any questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
ysr@777 25 #include "incls/_precompiled.incl"
ysr@777 26 #include "incls/_g1SATBCardTableModRefBS.cpp.incl"
ysr@777 27
ysr@777 28 G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap,
ysr@777 29 int max_covered_regions) :
ysr@777 30 CardTableModRefBSForCTRS(whole_heap, max_covered_regions)
ysr@777 31 {
ysr@777 32 _kind = G1SATBCT;
ysr@777 33 }
ysr@777 34
ysr@777 35
ysr@777 36 void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
ysr@777 37 if (!JavaThread::satb_mark_queue_set().active()) return;
ysr@777 38 Thread* thr = Thread::current();
ysr@777 39 if (thr->is_Java_thread()) {
ysr@777 40 JavaThread* jt = (JavaThread*)thr;
ysr@777 41 jt->satb_mark_queue().enqueue(pre_val);
ysr@777 42 } else {
ysr@777 43 MutexLocker x(Shared_SATB_Q_lock);
ysr@777 44 JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
ysr@777 45 }
ysr@777 46 }
ysr@777 47
ysr@777 48 // When we know the current java thread:
ysr@777 49 void
ysr@777 50 G1SATBCardTableModRefBS::write_ref_field_pre_static(void* field,
ysr@777 51 oop newVal,
ysr@777 52 JavaThread* jt) {
ysr@777 53 if (!JavaThread::satb_mark_queue_set().active()) return;
ysr@777 54 assert(!UseCompressedOops, "Else will need to modify this to deal with narrowOop");
ysr@777 55 oop preVal = *(oop*)field;
ysr@777 56 if (preVal != NULL) {
ysr@777 57 jt->satb_mark_queue().enqueue(preVal);
ysr@777 58 }
ysr@777 59 }
ysr@777 60
ysr@777 61 void
ysr@777 62 G1SATBCardTableModRefBS::write_ref_array_pre(MemRegion mr) {
ysr@777 63 if (!JavaThread::satb_mark_queue_set().active()) return;
ysr@777 64 assert(!UseCompressedOops, "Else will need to modify this to deal with narrowOop");
ysr@777 65 oop* elem_ptr = (oop*)mr.start();
ysr@777 66 while ((HeapWord*)elem_ptr < mr.end()) {
ysr@777 67 oop elem = *elem_ptr;
ysr@777 68 if (elem != NULL) enqueue(elem);
ysr@777 69 elem_ptr++;
ysr@777 70 }
ysr@777 71 }
ysr@777 72
ysr@777 73
ysr@777 74
ysr@777 75 G1SATBCardTableLoggingModRefBS::
ysr@777 76 G1SATBCardTableLoggingModRefBS(MemRegion whole_heap,
ysr@777 77 int max_covered_regions) :
ysr@777 78 G1SATBCardTableModRefBS(whole_heap, max_covered_regions),
ysr@777 79 _dcqs(JavaThread::dirty_card_queue_set())
ysr@777 80 {
ysr@777 81 _kind = G1SATBCTLogging;
ysr@777 82 }
ysr@777 83
ysr@777 84 void
ysr@777 85 G1SATBCardTableLoggingModRefBS::write_ref_field_work(void* field,
ysr@777 86 oop new_val) {
ysr@777 87 jbyte* byte = byte_for(field);
ysr@777 88 if (*byte != dirty_card) {
ysr@777 89 *byte = dirty_card;
ysr@777 90 Thread* thr = Thread::current();
ysr@777 91 if (thr->is_Java_thread()) {
ysr@777 92 JavaThread* jt = (JavaThread*)thr;
ysr@777 93 jt->dirty_card_queue().enqueue(byte);
ysr@777 94 } else {
ysr@777 95 MutexLockerEx x(Shared_DirtyCardQ_lock,
ysr@777 96 Mutex::_no_safepoint_check_flag);
ysr@777 97 _dcqs.shared_dirty_card_queue()->enqueue(byte);
ysr@777 98 }
ysr@777 99 }
ysr@777 100 }
ysr@777 101
ysr@777 102 void
ysr@777 103 G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field,
ysr@777 104 oop new_val) {
ysr@777 105 uintptr_t field_uint = (uintptr_t)field;
ysr@777 106 uintptr_t new_val_uint = (uintptr_t)new_val;
ysr@777 107 uintptr_t comb = field_uint ^ new_val_uint;
ysr@777 108 comb = comb >> HeapRegion::LogOfHRGrainBytes;
ysr@777 109 if (comb == 0) return;
ysr@777 110 if (new_val == NULL) return;
ysr@777 111 // Otherwise, log it.
ysr@777 112 G1SATBCardTableLoggingModRefBS* g1_bs =
ysr@777 113 (G1SATBCardTableLoggingModRefBS*)Universe::heap()->barrier_set();
ysr@777 114 g1_bs->write_ref_field_work(field, new_val);
ysr@777 115 }
ysr@777 116
ysr@777 117 void
ysr@777 118 G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) {
ysr@777 119 jbyte* byte = byte_for(mr.start());
ysr@777 120 jbyte* last_byte = byte_for(mr.last());
ysr@777 121 Thread* thr = Thread::current();
ysr@777 122 if (whole_heap) {
ysr@777 123 while (byte <= last_byte) {
ysr@777 124 *byte = dirty_card;
ysr@777 125 byte++;
ysr@777 126 }
ysr@777 127 } else {
ysr@777 128 // Enqueue if necessary.
ysr@777 129 if (thr->is_Java_thread()) {
ysr@777 130 JavaThread* jt = (JavaThread*)thr;
ysr@777 131 while (byte <= last_byte) {
ysr@777 132 if (*byte != dirty_card) {
ysr@777 133 *byte = dirty_card;
ysr@777 134 jt->dirty_card_queue().enqueue(byte);
ysr@777 135 }
ysr@777 136 byte++;
ysr@777 137 }
ysr@777 138 } else {
ysr@777 139 MutexLockerEx x(Shared_DirtyCardQ_lock,
ysr@777 140 Mutex::_no_safepoint_check_flag);
ysr@777 141 while (byte <= last_byte) {
ysr@777 142 if (*byte != dirty_card) {
ysr@777 143 *byte = dirty_card;
ysr@777 144 _dcqs.shared_dirty_card_queue()->enqueue(byte);
ysr@777 145 }
ysr@777 146 byte++;
ysr@777 147 }
ysr@777 148 }
ysr@777 149 }
ysr@777 150 }

mercurial