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

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,205 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
    1.30 +#include "gc_implementation/g1/heapRegion.hpp"
    1.31 +#include "gc_implementation/g1/satbQueue.hpp"
    1.32 +#include "runtime/mutexLocker.hpp"
    1.33 +#include "runtime/thread.inline.hpp"
    1.34 +
    1.35 +G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap,
    1.36 +                                                 int max_covered_regions) :
    1.37 +    CardTableModRefBSForCTRS(whole_heap, max_covered_regions)
    1.38 +{
    1.39 +  _kind = G1SATBCT;
    1.40 +}
    1.41 +
    1.42 +
    1.43 +void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
    1.44 +  // Nulls should have been already filtered.
    1.45 +  assert(pre_val->is_oop(true), "Error");
    1.46 +
    1.47 +  if (!JavaThread::satb_mark_queue_set().is_active()) return;
    1.48 +  Thread* thr = Thread::current();
    1.49 +  if (thr->is_Java_thread()) {
    1.50 +    JavaThread* jt = (JavaThread*)thr;
    1.51 +    jt->satb_mark_queue().enqueue(pre_val);
    1.52 +  } else {
    1.53 +    MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
    1.54 +    JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
    1.55 +  }
    1.56 +}
    1.57 +
    1.58 +template <class T> void
    1.59 +G1SATBCardTableModRefBS::write_ref_array_pre_work(T* dst, int count) {
    1.60 +  if (!JavaThread::satb_mark_queue_set().is_active()) return;
    1.61 +  T* elem_ptr = dst;
    1.62 +  for (int i = 0; i < count; i++, elem_ptr++) {
    1.63 +    T heap_oop = oopDesc::load_heap_oop(elem_ptr);
    1.64 +    if (!oopDesc::is_null(heap_oop)) {
    1.65 +      enqueue(oopDesc::decode_heap_oop_not_null(heap_oop));
    1.66 +    }
    1.67 +  }
    1.68 +}
    1.69 +
    1.70 +bool G1SATBCardTableModRefBS::mark_card_deferred(size_t card_index) {
    1.71 +  jbyte val = _byte_map[card_index];
    1.72 +  // It's already processed
    1.73 +  if ((val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val()) {
    1.74 +    return false;
    1.75 +  }
    1.76 +
    1.77 +  if  (val == g1_young_gen) {
    1.78 +    // the card is for a young gen region. We don't need to keep track of all pointers into young
    1.79 +    return false;
    1.80 +  }
    1.81 +
    1.82 +  // Cached bit can be installed either on a clean card or on a claimed card.
    1.83 +  jbyte new_val = val;
    1.84 +  if (val == clean_card_val()) {
    1.85 +    new_val = (jbyte)deferred_card_val();
    1.86 +  } else {
    1.87 +    if (val & claimed_card_val()) {
    1.88 +      new_val = val | (jbyte)deferred_card_val();
    1.89 +    }
    1.90 +  }
    1.91 +  if (new_val != val) {
    1.92 +    Atomic::cmpxchg(new_val, &_byte_map[card_index], val);
    1.93 +  }
    1.94 +  return true;
    1.95 +}
    1.96 +
    1.97 +void G1SATBCardTableModRefBS::g1_mark_as_young(const MemRegion& mr) {
    1.98 +  jbyte *const first = byte_for(mr.start());
    1.99 +  jbyte *const last = byte_after(mr.last());
   1.100 +
   1.101 +  // Below we may use an explicit loop instead of memset() because on
   1.102 +  // certain platforms memset() can give concurrent readers phantom zeros.
   1.103 +  if (UseMemSetInBOT) {
   1.104 +    memset(first, g1_young_gen, last - first);
   1.105 +  } else {
   1.106 +    for (jbyte* i = first; i < last; i++) {
   1.107 +      *i = g1_young_gen;
   1.108 +    }
   1.109 +  }
   1.110 +}
   1.111 +
   1.112 +#ifndef PRODUCT
   1.113 +void G1SATBCardTableModRefBS::verify_g1_young_region(MemRegion mr) {
   1.114 +  verify_region(mr, g1_young_gen,  true);
   1.115 +}
   1.116 +#endif
   1.117 +
   1.118 +G1SATBCardTableLoggingModRefBS::
   1.119 +G1SATBCardTableLoggingModRefBS(MemRegion whole_heap,
   1.120 +                               int max_covered_regions) :
   1.121 +  G1SATBCardTableModRefBS(whole_heap, max_covered_regions),
   1.122 +  _dcqs(JavaThread::dirty_card_queue_set())
   1.123 +{
   1.124 +  _kind = G1SATBCTLogging;
   1.125 +}
   1.126 +
   1.127 +void
   1.128 +G1SATBCardTableLoggingModRefBS::write_ref_field_work(void* field,
   1.129 +                                                     oop new_val,
   1.130 +                                                     bool release) {
   1.131 +  volatile jbyte* byte = byte_for(field);
   1.132 +  if (*byte == g1_young_gen) {
   1.133 +    return;
   1.134 +  }
   1.135 +  OrderAccess::storeload();
   1.136 +  if (*byte != dirty_card) {
   1.137 +    *byte = dirty_card;
   1.138 +    Thread* thr = Thread::current();
   1.139 +    if (thr->is_Java_thread()) {
   1.140 +      JavaThread* jt = (JavaThread*)thr;
   1.141 +      jt->dirty_card_queue().enqueue(byte);
   1.142 +    } else {
   1.143 +      MutexLockerEx x(Shared_DirtyCardQ_lock,
   1.144 +                      Mutex::_no_safepoint_check_flag);
   1.145 +      _dcqs.shared_dirty_card_queue()->enqueue(byte);
   1.146 +    }
   1.147 +  }
   1.148 +}
   1.149 +
   1.150 +void
   1.151 +G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field,
   1.152 +                                                       oop new_val) {
   1.153 +  uintptr_t field_uint = (uintptr_t)field;
   1.154 +  uintptr_t new_val_uint = cast_from_oop<uintptr_t>(new_val);
   1.155 +  uintptr_t comb = field_uint ^ new_val_uint;
   1.156 +  comb = comb >> HeapRegion::LogOfHRGrainBytes;
   1.157 +  if (comb == 0) return;
   1.158 +  if (new_val == NULL) return;
   1.159 +  // Otherwise, log it.
   1.160 +  G1SATBCardTableLoggingModRefBS* g1_bs =
   1.161 +    (G1SATBCardTableLoggingModRefBS*)Universe::heap()->barrier_set();
   1.162 +  g1_bs->write_ref_field_work(field, new_val);
   1.163 +}
   1.164 +
   1.165 +void
   1.166 +G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) {
   1.167 +  volatile jbyte* byte = byte_for(mr.start());
   1.168 +  jbyte* last_byte = byte_for(mr.last());
   1.169 +  Thread* thr = Thread::current();
   1.170 +  if (whole_heap) {
   1.171 +    while (byte <= last_byte) {
   1.172 +      *byte = dirty_card;
   1.173 +      byte++;
   1.174 +    }
   1.175 +  } else {
   1.176 +    // skip all consecutive young cards
   1.177 +    for (; byte <= last_byte && *byte == g1_young_gen; byte++);
   1.178 +
   1.179 +    if (byte <= last_byte) {
   1.180 +      OrderAccess::storeload();
   1.181 +      // Enqueue if necessary.
   1.182 +      if (thr->is_Java_thread()) {
   1.183 +        JavaThread* jt = (JavaThread*)thr;
   1.184 +        for (; byte <= last_byte; byte++) {
   1.185 +          if (*byte == g1_young_gen) {
   1.186 +            continue;
   1.187 +          }
   1.188 +          if (*byte != dirty_card) {
   1.189 +            *byte = dirty_card;
   1.190 +            jt->dirty_card_queue().enqueue(byte);
   1.191 +          }
   1.192 +        }
   1.193 +      } else {
   1.194 +        MutexLockerEx x(Shared_DirtyCardQ_lock,
   1.195 +                        Mutex::_no_safepoint_check_flag);
   1.196 +        for (; byte <= last_byte; byte++) {
   1.197 +          if (*byte == g1_young_gen) {
   1.198 +            continue;
   1.199 +          }
   1.200 +          if (*byte != dirty_card) {
   1.201 +            *byte = dirty_card;
   1.202 +            _dcqs.shared_dirty_card_queue()->enqueue(byte);
   1.203 +          }
   1.204 +        }
   1.205 +      }
   1.206 +    }
   1.207 +  }
   1.208 +}

mercurial