cardTableRS.hpp 5.7 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31
#ifndef SHARE_VM_MEMORY_CARDTABLERS_HPP
#define SHARE_VM_MEMORY_CARDTABLERS_HPP

#include "memory/cardTableModRefBS.hpp"
#include "memory/genRemSet.hpp"
#include "memory/memRegion.hpp"

D
duke 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
class Space;
class OopsInGenClosure;
class DirtyCardToOopClosure;

// This kind of "GenRemSet" uses a card table both as shared data structure
// for a mod ref barrier set and for the rem set information.

class CardTableRS: public GenRemSet {
  friend class VMStructs;
  // Below are private classes used in impl.
  friend class VerifyCTSpaceClosure;
  friend class ClearNoncleanCardWrapper;

  static jbyte clean_card_val() {
    return CardTableModRefBS::clean_card;
  }

  static bool
  card_is_dirty_wrt_gen_iter(jbyte cv) {
    return CardTableModRefBS::card_is_dirty_wrt_gen_iter(cv);
  }

54
  CardTableModRefBSForCTRS* _ct_bs;
D
duke 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

  virtual void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl);

  void verify_space(Space* s, HeapWord* gen_start);

  enum ExtendedCardValue {
    youngergen_card   = CardTableModRefBS::CT_MR_BS_last_reserved + 1,
    // These are for parallel collection.
    // There are three P (parallel) youngergen card values.  In general, this
    // needs to be more than the number of generations (including the perm
    // gen) that might have younger_refs_do invoked on them separately.  So
    // if we add more gens, we have to add more values.
    youngergenP1_card  = CardTableModRefBS::CT_MR_BS_last_reserved + 2,
    youngergenP2_card  = CardTableModRefBS::CT_MR_BS_last_reserved + 3,
    youngergenP3_card  = CardTableModRefBS::CT_MR_BS_last_reserved + 4,
    cur_youngergen_and_prev_nonclean_card =
      CardTableModRefBS::CT_MR_BS_last_reserved + 5
  };

  // An array that contains, for each generation, the card table value last
  // used as the current value for a younger_refs_do iteration of that
  // portion of the table.  (The perm gen is index 0; other gens are at
  // their level plus 1.  They youngest gen is in the table, but will
  // always have the value "clean_card".)
  jbyte* _last_cur_val_in_gen;

  jbyte _cur_youngergen_card_val;

83 84
  int _regions_to_iterate;

D
duke 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
  jbyte cur_youngergen_card_val() {
    return _cur_youngergen_card_val;
  }
  void set_cur_youngergen_card_val(jbyte v) {
    _cur_youngergen_card_val = v;
  }
  bool is_prev_youngergen_card_val(jbyte v) {
    return
      youngergen_card <= v &&
      v < cur_youngergen_and_prev_nonclean_card &&
      v != _cur_youngergen_card_val;
  }
  // Return a youngergen_card_value that is not currently in use.
  jbyte find_unused_youngergenP_card_value();

public:
  CardTableRS(MemRegion whole_heap, int max_covered_regions);

  // *** GenRemSet functions.
  GenRemSet::Name rs_kind() { return GenRemSet::CardTable; }

  CardTableRS* as_CardTableRS() { return this; }

108
  CardTableModRefBS* ct_bs() { return _ct_bs; }
D
duke 已提交
109 110 111 112 113 114 115 116 117

  // Override.
  void prepare_for_younger_refs_iterate(bool parallel);

  // Card table entries are cleared before application; "blk" is
  // responsible for dirtying if the oop is still older-to-younger after
  // closure application.
  void younger_refs_iterate(Generation* g, OopsInGenClosure* blk);

118
  void inline_write_ref_field_gc(void* field, oop new_val) {
119
    jbyte* byte = _ct_bs->byte_for(field);
D
duke 已提交
120 121
    *byte = youngergen_card;
  }
122
  void write_ref_field_gc_work(void* field, oop new_val) {
D
duke 已提交
123 124 125 126 127 128
    inline_write_ref_field_gc(field, new_val);
  }

  // Override.  Might want to devirtualize this in the same fashion as
  // above.  Ensures that the value of the card for field says that it's
  // a younger card in the current collection.
129
  virtual void write_ref_field_gc_par(void* field, oop new_val);
D
duke 已提交
130 131 132 133

  void resize_covered_region(MemRegion new_region);

  bool is_aligned(HeapWord* addr) {
134
    return _ct_bs->is_card_aligned(addr);
D
duke 已提交
135 136 137
  }

  void verify();
138
  void verify_aligned_region_empty(MemRegion mr);
D
duke 已提交
139

140
  void clear(MemRegion mr) { _ct_bs->clear(mr); }
D
duke 已提交
141 142
  void clear_into_younger(Generation* gen, bool clear_perm);

143 144 145
  void invalidate(MemRegion mr, bool whole_heap = false) {
    _ct_bs->invalidate(mr, whole_heap);
  }
D
duke 已提交
146 147 148 149 150 151
  void invalidate_or_clear(Generation* gen, bool younger, bool perm);

  static uintx ct_max_alignment_constraint() {
    return CardTableModRefBS::ct_max_alignment_constraint();
  }

152 153 154
  jbyte* byte_for(void* p)     { return _ct_bs->byte_for(p); }
  jbyte* byte_after(void* p)   { return _ct_bs->byte_after(p); }
  HeapWord* addr_for(jbyte* p) { return _ct_bs->addr_for(p); }
D
duke 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167

  bool is_prev_nonclean_card_val(jbyte v) {
    return
      youngergen_card <= v &&
      v <= cur_youngergen_and_prev_nonclean_card &&
      v != _cur_youngergen_card_val;
  }

  static bool youngergen_may_have_been_dirty(jbyte cv) {
    return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card;
  }

};
168 169

#endif // SHARE_VM_MEMORY_CARDTABLERS_HPP