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

changeset 777
37f87013dfd8
child 1280
df6caf649ff7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp	Thu Jun 05 15:57:56 2008 -0700
     1.3 @@ -0,0 +1,150 @@
     1.4 +/*
     1.5 + * Copyright 2001-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_g1SATBCardTableModRefBS.cpp.incl"
    1.30 +
    1.31 +G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap,
    1.32 +                                                 int max_covered_regions) :
    1.33 +    CardTableModRefBSForCTRS(whole_heap, max_covered_regions)
    1.34 +{
    1.35 +  _kind = G1SATBCT;
    1.36 +}
    1.37 +
    1.38 +
    1.39 +void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
    1.40 +  if (!JavaThread::satb_mark_queue_set().active()) return;
    1.41 +  Thread* thr = Thread::current();
    1.42 +  if (thr->is_Java_thread()) {
    1.43 +    JavaThread* jt = (JavaThread*)thr;
    1.44 +    jt->satb_mark_queue().enqueue(pre_val);
    1.45 +  } else {
    1.46 +    MutexLocker x(Shared_SATB_Q_lock);
    1.47 +    JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
    1.48 +  }
    1.49 +}
    1.50 +
    1.51 +// When we know the current java thread:
    1.52 +void
    1.53 +G1SATBCardTableModRefBS::write_ref_field_pre_static(void* field,
    1.54 +                                                    oop newVal,
    1.55 +                                                    JavaThread* jt) {
    1.56 +  if (!JavaThread::satb_mark_queue_set().active()) return;
    1.57 +  assert(!UseCompressedOops, "Else will need to modify this to deal with narrowOop");
    1.58 +  oop preVal = *(oop*)field;
    1.59 +  if (preVal != NULL) {
    1.60 +    jt->satb_mark_queue().enqueue(preVal);
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +void
    1.65 +G1SATBCardTableModRefBS::write_ref_array_pre(MemRegion mr) {
    1.66 +  if (!JavaThread::satb_mark_queue_set().active()) return;
    1.67 +  assert(!UseCompressedOops, "Else will need to modify this to deal with narrowOop");
    1.68 +  oop* elem_ptr = (oop*)mr.start();
    1.69 +  while ((HeapWord*)elem_ptr < mr.end()) {
    1.70 +    oop elem = *elem_ptr;
    1.71 +    if (elem != NULL) enqueue(elem);
    1.72 +    elem_ptr++;
    1.73 +  }
    1.74 +}
    1.75 +
    1.76 +
    1.77 +
    1.78 +G1SATBCardTableLoggingModRefBS::
    1.79 +G1SATBCardTableLoggingModRefBS(MemRegion whole_heap,
    1.80 +                               int max_covered_regions) :
    1.81 +  G1SATBCardTableModRefBS(whole_heap, max_covered_regions),
    1.82 +  _dcqs(JavaThread::dirty_card_queue_set())
    1.83 +{
    1.84 +  _kind = G1SATBCTLogging;
    1.85 +}
    1.86 +
    1.87 +void
    1.88 +G1SATBCardTableLoggingModRefBS::write_ref_field_work(void* field,
    1.89 +                                                     oop new_val) {
    1.90 +  jbyte* byte = byte_for(field);
    1.91 +  if (*byte != dirty_card) {
    1.92 +    *byte = dirty_card;
    1.93 +    Thread* thr = Thread::current();
    1.94 +    if (thr->is_Java_thread()) {
    1.95 +      JavaThread* jt = (JavaThread*)thr;
    1.96 +      jt->dirty_card_queue().enqueue(byte);
    1.97 +    } else {
    1.98 +      MutexLockerEx x(Shared_DirtyCardQ_lock,
    1.99 +                      Mutex::_no_safepoint_check_flag);
   1.100 +      _dcqs.shared_dirty_card_queue()->enqueue(byte);
   1.101 +    }
   1.102 +  }
   1.103 +}
   1.104 +
   1.105 +void
   1.106 +G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field,
   1.107 +                                                       oop new_val) {
   1.108 +  uintptr_t field_uint = (uintptr_t)field;
   1.109 +  uintptr_t new_val_uint = (uintptr_t)new_val;
   1.110 +  uintptr_t comb = field_uint ^ new_val_uint;
   1.111 +  comb = comb >> HeapRegion::LogOfHRGrainBytes;
   1.112 +  if (comb == 0) return;
   1.113 +  if (new_val == NULL) return;
   1.114 +  // Otherwise, log it.
   1.115 +  G1SATBCardTableLoggingModRefBS* g1_bs =
   1.116 +    (G1SATBCardTableLoggingModRefBS*)Universe::heap()->barrier_set();
   1.117 +  g1_bs->write_ref_field_work(field, new_val);
   1.118 +}
   1.119 +
   1.120 +void
   1.121 +G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) {
   1.122 +  jbyte* byte = byte_for(mr.start());
   1.123 +  jbyte* last_byte = byte_for(mr.last());
   1.124 +  Thread* thr = Thread::current();
   1.125 +  if (whole_heap) {
   1.126 +    while (byte <= last_byte) {
   1.127 +      *byte = dirty_card;
   1.128 +      byte++;
   1.129 +    }
   1.130 +  } else {
   1.131 +    // Enqueue if necessary.
   1.132 +    if (thr->is_Java_thread()) {
   1.133 +      JavaThread* jt = (JavaThread*)thr;
   1.134 +      while (byte <= last_byte) {
   1.135 +        if (*byte != dirty_card) {
   1.136 +          *byte = dirty_card;
   1.137 +          jt->dirty_card_queue().enqueue(byte);
   1.138 +        }
   1.139 +        byte++;
   1.140 +      }
   1.141 +    } else {
   1.142 +      MutexLockerEx x(Shared_DirtyCardQ_lock,
   1.143 +                      Mutex::_no_safepoint_check_flag);
   1.144 +      while (byte <= last_byte) {
   1.145 +        if (*byte != dirty_card) {
   1.146 +          *byte = dirty_card;
   1.147 +          _dcqs.shared_dirty_card_queue()->enqueue(byte);
   1.148 +        }
   1.149 +        byte++;
   1.150 +      }
   1.151 +    }
   1.152 +  }
   1.153 +}

mercurial