1 /* 2 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_GC_SHARED_CARDTABLERS_HPP 26 #define SHARE_VM_GC_SHARED_CARDTABLERS_HPP 27 28 #include "gc/shared/cardTableModRefBS.hpp" 29 #include "gc/shared/genRemSet.hpp" 30 #include "memory/memRegion.hpp" 31 32 class Space; 33 class OopsInGenClosure; 34 35 // This kind of "GenRemSet" uses a card table both as shared data structure 36 // for a mod ref barrier set and for the rem set information. 37 38 class CardTableRS: public GenRemSet { 39 friend class VMStructs; 40 // Below are private classes used in impl. 41 friend class VerifyCTSpaceClosure; 42 friend class ClearNoncleanCardWrapper; 43 44 static jbyte clean_card_val() { 45 return CardTableModRefBS::clean_card; 46 } 47 48 static intptr_t clean_card_row() { 49 return CardTableModRefBS::clean_card_row; 50 } 51 52 static bool 53 card_is_dirty_wrt_gen_iter(jbyte cv) { 54 return CardTableModRefBS::card_is_dirty_wrt_gen_iter(cv); 55 } 56 57 CardTableModRefBSForCTRS* _ct_bs; 58 59 virtual void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl, uint n_threads); 60 61 void verify_space(Space* s, HeapWord* gen_start); 62 63 enum ExtendedCardValue { 64 youngergen_card = CardTableModRefBS::CT_MR_BS_last_reserved + 1, 65 // These are for parallel collection. 66 // There are three P (parallel) youngergen card values. In general, this 67 // needs to be more than the number of generations (including the perm 68 // gen) that might have younger_refs_do invoked on them separately. So 69 // if we add more gens, we have to add more values. 70 youngergenP1_card = CardTableModRefBS::CT_MR_BS_last_reserved + 2, 71 youngergenP2_card = CardTableModRefBS::CT_MR_BS_last_reserved + 3, 72 youngergenP3_card = CardTableModRefBS::CT_MR_BS_last_reserved + 4, 73 cur_youngergen_and_prev_nonclean_card = 74 CardTableModRefBS::CT_MR_BS_last_reserved + 5 75 }; 76 77 // An array that contains, for each generation, the card table value last 78 // used as the current value for a younger_refs_do iteration of that 79 // portion of the table. The perm gen is index 0. The young gen is index 1, 80 // but will always have the value "clean_card". The old gen is index 2. 81 jbyte* _last_cur_val_in_gen; 82 83 jbyte _cur_youngergen_card_val; 84 85 // Number of generations, plus one for lingering PermGen issues in CardTableRS. 86 static const int _regions_to_iterate = 3; 87 88 jbyte cur_youngergen_card_val() { 89 return _cur_youngergen_card_val; 90 } 91 void set_cur_youngergen_card_val(jbyte v) { 92 _cur_youngergen_card_val = v; 93 } 94 bool is_prev_youngergen_card_val(jbyte v) { 95 return 96 youngergen_card <= v && 97 v < cur_youngergen_and_prev_nonclean_card && 98 v != _cur_youngergen_card_val; 99 } 100 // Return a youngergen_card_value that is not currently in use. 101 jbyte find_unused_youngergenP_card_value(); 102 103 public: 104 CardTableRS(MemRegion whole_heap); 105 ~CardTableRS(); 106 107 // *** GenRemSet functions. 108 CardTableRS* as_CardTableRS() { return this; } 109 110 CardTableModRefBS* ct_bs() { return _ct_bs; } 111 112 // Override. 113 void prepare_for_younger_refs_iterate(bool parallel); 114 115 // Card table entries are cleared before application; "blk" is 116 // responsible for dirtying if the oop is still older-to-younger after 117 // closure application. 118 void younger_refs_iterate(Generation* g, OopsInGenClosure* blk, uint n_threads); 119 120 void inline_write_ref_field_gc(void* field, oop new_val) { 121 jbyte* byte = _ct_bs->byte_for(field); 122 *byte = youngergen_card; 123 } 124 void write_ref_field_gc_work(void* field, oop new_val) { 125 inline_write_ref_field_gc(field, new_val); 126 } 127 128 // Override. Might want to devirtualize this in the same fashion as 129 // above. Ensures that the value of the card for field says that it's 130 // a younger card in the current collection. 131 virtual void write_ref_field_gc_par(void* field, oop new_val); 132 133 void resize_covered_region(MemRegion new_region); 134 135 bool is_aligned(HeapWord* addr) { 136 return _ct_bs->is_card_aligned(addr); 137 } 138 139 void verify(); 140 141 void clear(MemRegion mr) { _ct_bs->clear(mr); } 142 void clear_into_younger(Generation* old_gen); 143 144 void invalidate(MemRegion mr, bool whole_heap = false) { 145 _ct_bs->invalidate(mr, whole_heap); 146 } 147 void invalidate_or_clear(Generation* old_gen); 148 149 static uintx ct_max_alignment_constraint() { 150 return CardTableModRefBS::ct_max_alignment_constraint(); 151 } 152 153 jbyte* byte_for(void* p) { return _ct_bs->byte_for(p); } 154 jbyte* byte_after(void* p) { return _ct_bs->byte_after(p); } 155 HeapWord* addr_for(jbyte* p) { return _ct_bs->addr_for(p); } 156 157 bool is_prev_nonclean_card_val(jbyte v) { 158 return 159 youngergen_card <= v && 160 v <= cur_youngergen_and_prev_nonclean_card && 161 v != _cur_youngergen_card_val; 162 } 163 164 static bool youngergen_may_have_been_dirty(jbyte cv) { 165 return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card; 166 } 167 168 }; 169 170 class ClearNoncleanCardWrapper: public MemRegionClosure { 171 DirtyCardToOopClosure* _dirty_card_closure; 172 CardTableRS* _ct; 173 bool _is_par; 174 private: 175 // Clears the given card, return true if the corresponding card should be 176 // processed. 177 inline bool clear_card(jbyte* entry); 178 // Work methods called by the clear_card() 179 inline bool clear_card_serial(jbyte* entry); 180 inline bool clear_card_parallel(jbyte* entry); 181 // check alignment of pointer 182 bool is_word_aligned(jbyte* entry); 183 184 public: 185 ClearNoncleanCardWrapper(DirtyCardToOopClosure* dirty_card_closure, CardTableRS* ct, bool is_par); 186 void do_MemRegion(MemRegion mr); 187 }; 188 189 #endif // SHARE_VM_GC_SHARED_CARDTABLERS_HPP