1 #ifdef USE_PRAGMA_IDENT_HDR 2 #pragma ident "@(#)cardTableRS.hpp 1.29 07/05/05 17:05:44 JVM" 3 #endif 4 /* 5 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 class Space; 29 class OopsInGenClosure; 30 class DirtyCardToOopClosure; 31 32 // This kind of "GenRemSet" uses a card table both as shared data structure 33 // for a mod ref barrier set and for the rem set information. 34 35 class CardTableRS: public GenRemSet { 36 friend class VMStructs; 37 // Below are private classes used in impl. 38 friend class VerifyCTSpaceClosure; 39 friend class ClearNoncleanCardWrapper; 40 41 static jbyte clean_card_val() { 42 return CardTableModRefBS::clean_card; 43 } 44 45 static bool 46 card_is_dirty_wrt_gen_iter(jbyte cv) { 47 return CardTableModRefBS::card_is_dirty_wrt_gen_iter(cv); 48 } 49 50 CardTableModRefBSForCTRS* _ct_bs; 51 52 virtual void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl); 53 54 void verify_space(Space* s, HeapWord* gen_start); 55 56 enum ExtendedCardValue { 57 youngergen_card = CardTableModRefBS::CT_MR_BS_last_reserved + 1, 58 // These are for parallel collection. 59 // There are three P (parallel) youngergen card values. In general, this 60 // needs to be more than the number of generations (including the perm 61 // gen) that might have younger_refs_do invoked on them separately. So 62 // if we add more gens, we have to add more values. 63 youngergenP1_card = CardTableModRefBS::CT_MR_BS_last_reserved + 2, 64 youngergenP2_card = CardTableModRefBS::CT_MR_BS_last_reserved + 3, 65 youngergenP3_card = CardTableModRefBS::CT_MR_BS_last_reserved + 4, 66 cur_youngergen_and_prev_nonclean_card = 67 CardTableModRefBS::CT_MR_BS_last_reserved + 5 68 }; 69 70 // An array that contains, for each generation, the card table value last 71 // used as the current value for a younger_refs_do iteration of that 72 // portion of the table. (The perm gen is index 0; other gens are at 73 // their level plus 1. They youngest gen is in the table, but will 74 // always have the value "clean_card".) 75 jbyte* _last_cur_val_in_gen; 76 77 jbyte _cur_youngergen_card_val; 78 79 int _regions_to_iterate; 80 81 jbyte cur_youngergen_card_val() { 82 return _cur_youngergen_card_val; 83 } 84 void set_cur_youngergen_card_val(jbyte v) { 85 _cur_youngergen_card_val = v; 86 } 87 bool is_prev_youngergen_card_val(jbyte v) { 88 return 89 youngergen_card <= v && 90 v < cur_youngergen_and_prev_nonclean_card && 91 v != _cur_youngergen_card_val; 92 } 93 // Return a youngergen_card_value that is not currently in use. 94 jbyte find_unused_youngergenP_card_value(); 95 96 public: 97 CardTableRS(MemRegion whole_heap, int max_covered_regions); 98 99 // *** GenRemSet functions. 100 GenRemSet::Name rs_kind() { return GenRemSet::CardTable; } 101 102 CardTableRS* as_CardTableRS() { return this; } 103 104 CardTableModRefBS* ct_bs() { return _ct_bs; } 105 106 // Override. 107 void prepare_for_younger_refs_iterate(bool parallel); 108 109 // Card table entries are cleared before application; "blk" is 110 // responsible for dirtying if the oop is still older-to-younger after 111 // closure application. 112 void younger_refs_iterate(Generation* g, OopsInGenClosure* blk); 113 114 void inline_write_ref_field_gc(void* field, oop new_val) { 115 jbyte* byte = _ct_bs->byte_for(field); 116 *byte = youngergen_card; 117 } 118 void write_ref_field_gc_work(void* field, oop new_val) { 119 inline_write_ref_field_gc(field, new_val); 120 } 121 122 // Override. Might want to devirtualize this in the same fashion as 123 // above. Ensures that the value of the card for field says that it's 124 // a younger card in the current collection. 125 virtual void write_ref_field_gc_par(void* field, oop new_val); 126 127 void resize_covered_region(MemRegion new_region); 128 129 bool is_aligned(HeapWord* addr) { 130 return _ct_bs->is_card_aligned(addr); 131 } 132 133 void verify(); 134 void verify_aligned_region_empty(MemRegion mr); 135 136 void clear(MemRegion mr) { _ct_bs->clear(mr); } 137 void clear_into_younger(Generation* gen, bool clear_perm); 138 139 void invalidate(MemRegion mr, bool whole_heap = false) { 140 _ct_bs->invalidate(mr, whole_heap); 141 } 142 void invalidate_or_clear(Generation* gen, bool younger, bool perm); 143 144 static uintx ct_max_alignment_constraint() { 145 return CardTableModRefBS::ct_max_alignment_constraint(); 146 } 147 148 jbyte* byte_for(void* p) { return _ct_bs->byte_for(p); } 149 jbyte* byte_after(void* p) { return _ct_bs->byte_after(p); } 150 HeapWord* addr_for(jbyte* p) { return _ct_bs->addr_for(p); } 151 152 bool is_prev_nonclean_card_val(jbyte v) { 153 return 154 youngergen_card <= v && 155 v <= cur_youngergen_and_prev_nonclean_card && 156 v != _cur_youngergen_card_val; 157 } 158 159 static bool youngergen_may_have_been_dirty(jbyte cv) { 160 return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card; 161 } 162 163 };