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/cardTableModRefBSForCTRS.hpp"
29 #include "memory/memRegion.hpp"
30
31 class Space;
32 class OopsInGenClosure;
33
34 // Helper to remember modified oops in all klasses.
35 class KlassRemSet {
36 bool _accumulate_modified_oops;
37 public:
38 KlassRemSet() : _accumulate_modified_oops(false) {}
39 void set_accumulate_modified_oops(bool value) { _accumulate_modified_oops = value; }
40 bool accumulate_modified_oops() { return _accumulate_modified_oops; }
41 bool mod_union_is_clear();
42 void clear_mod_union();
43 };
44
45 // This RemSet uses a card table both as shared data structure
46 // for a mod ref barrier set and for the rem set information.
47
48 class CardTableRS: public CHeapObj<mtGC> {
49 friend class VMStructs;
50 // Below are private classes used in impl.
51 friend class VerifyCTSpaceClosure;
52 friend class ClearNoncleanCardWrapper;
53
54 static jbyte clean_card_val() {
55 return CardTableModRefBSForCTRS::clean_card;
56 }
57
58 static intptr_t clean_card_row() {
59 return CardTableModRefBSForCTRS::clean_card_row;
60 }
61
62 static bool
63 card_is_dirty_wrt_gen_iter(jbyte cv) {
64 return CardTableModRefBSForCTRS::card_is_dirty_wrt_gen_iter(cv);
65 }
66
67 KlassRemSet _klass_rem_set;
68 BarrierSet* _bs;
69
70 CardTableModRefBSForCTRS* _ct_bs;
71
72 void verify_space(Space* s, HeapWord* gen_start);
73
74 enum ExtendedCardValue {
75 youngergen_card = CardTableModRefBSForCTRS::CT_MR_BS_last_reserved + 1,
76 // These are for parallel collection.
77 // There are three P (parallel) youngergen card values. In general, this
78 // needs to be more than the number of generations (including the perm
79 // gen) that might have younger_refs_do invoked on them separately. So
80 // if we add more gens, we have to add more values.
81 youngergenP1_card = CardTableModRefBSForCTRS::CT_MR_BS_last_reserved + 2,
82 youngergenP2_card = CardTableModRefBSForCTRS::CT_MR_BS_last_reserved + 3,
83 youngergenP3_card = CardTableModRefBSForCTRS::CT_MR_BS_last_reserved + 4,
84 cur_youngergen_and_prev_nonclean_card =
85 CardTableModRefBSForCTRS::CT_MR_BS_last_reserved + 5
86 };
87
88 // An array that contains, for each generation, the card table value last
89 // used as the current value for a younger_refs_do iteration of that
90 // portion of the table. The perm gen is index 0. The young gen is index 1,
91 // but will always have the value "clean_card". The old gen is index 2.
92 jbyte* _last_cur_val_in_gen;
93
94 jbyte _cur_youngergen_card_val;
95
96 // Number of generations, plus one for lingering PermGen issues in CardTableRS.
97 static const int _regions_to_iterate = 3;
98
99 jbyte cur_youngergen_card_val() {
100 return _cur_youngergen_card_val;
101 }
102 void set_cur_youngergen_card_val(jbyte v) {
103 _cur_youngergen_card_val = v;
104 }
105 bool is_prev_youngergen_card_val(jbyte v) {
106 return
107 youngergen_card <= v &&
108 v < cur_youngergen_and_prev_nonclean_card &&
109 v != _cur_youngergen_card_val;
110 }
111 // Return a youngergen_card_value that is not currently in use.
112 jbyte find_unused_youngergenP_card_value();
113
114 public:
115 CardTableRS(MemRegion whole_heap);
116 ~CardTableRS();
117
118 // Return the barrier set associated with "this."
119 BarrierSet* bs() { return _bs; }
120
121 // Set the barrier set.
122 void set_bs(BarrierSet* bs) { _bs = bs; }
123
124 KlassRemSet* klass_rem_set() { return &_klass_rem_set; }
125
126 CardTableModRefBSForCTRS* ct_bs() { return _ct_bs; }
127
128 void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl, uint n_threads);
129
130 // Override.
131 void prepare_for_younger_refs_iterate(bool parallel);
132
133 // Card table entries are cleared before application; "blk" is
134 // responsible for dirtying if the oop is still older-to-younger after
135 // closure application.
136 void younger_refs_iterate(Generation* g, OopsInGenClosure* blk, uint n_threads);
137
138 void inline_write_ref_field_gc(void* field, oop new_val) {
139 jbyte* byte = _ct_bs->byte_for(field);
140 *byte = youngergen_card;
141 }
142 void write_ref_field_gc_work(void* field, oop new_val) {
143 inline_write_ref_field_gc(field, new_val);
144 }
145
146 // Override. Might want to devirtualize this in the same fashion as
147 // above. Ensures that the value of the card for field says that it's
148 // a younger card in the current collection.
149 virtual void write_ref_field_gc_par(void* field, oop new_val);
150
151 void resize_covered_region(MemRegion new_region);
152
153 bool is_aligned(HeapWord* addr) {
154 return _ct_bs->is_card_aligned(addr);
155 }
156
157 void verify();
158
159 void clear(MemRegion mr) { _ct_bs->clear(mr); }
160 void clear_into_younger(Generation* old_gen);
161
162 void invalidate(MemRegion mr) {
163 _ct_bs->invalidate(mr);
164 }
165 void invalidate_or_clear(Generation* old_gen);
166
167 static uintx ct_max_alignment_constraint() {
168 return CardTableModRefBSForCTRS::ct_max_alignment_constraint();
169 }
170
171 jbyte* byte_for(void* p) { return _ct_bs->byte_for(p); }
172 jbyte* byte_after(void* p) { return _ct_bs->byte_after(p); }
173 HeapWord* addr_for(jbyte* p) { return _ct_bs->addr_for(p); }
174
175 bool is_prev_nonclean_card_val(jbyte v) {
176 return
177 youngergen_card <= v &&
178 v <= cur_youngergen_and_prev_nonclean_card &&
179 v != _cur_youngergen_card_val;
180 }
181
182 static bool youngergen_may_have_been_dirty(jbyte cv) {
183 return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card;
184 }
185
186 };
187
188 class ClearNoncleanCardWrapper: public MemRegionClosure {
189 DirtyCardToOopClosure* _dirty_card_closure;
190 CardTableRS* _ct;
191 bool _is_par;
192 private:
193 // Clears the given card, return true if the corresponding card should be
194 // processed.
195 inline bool clear_card(jbyte* entry);
196 // Work methods called by the clear_card()
197 inline bool clear_card_serial(jbyte* entry);
198 inline bool clear_card_parallel(jbyte* entry);
199 // check alignment of pointer
200 bool is_word_aligned(jbyte* entry);
201
202 public:
203 ClearNoncleanCardWrapper(DirtyCardToOopClosure* dirty_card_closure, CardTableRS* ct, bool is_par);
204 void do_MemRegion(MemRegion mr);
|
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/cardTable.hpp"
29 #include "memory/memRegion.hpp"
30 #include "oops/oop.hpp"
31
32 class DirtyCardToOopClosure;
33 class Generation;
34 class Space;
35 class OopsInGenClosure;
36
37 // Helper to remember modified oops in all klasses.
38 class KlassRemSet {
39 bool _accumulate_modified_oops;
40 public:
41 KlassRemSet() : _accumulate_modified_oops(false) {}
42 void set_accumulate_modified_oops(bool value) { _accumulate_modified_oops = value; }
43 bool accumulate_modified_oops() { return _accumulate_modified_oops; }
44 bool mod_union_is_clear();
45 void clear_mod_union();
46 };
47
48 // This RemSet uses a card table both as shared data structure
49 // for a mod ref barrier set and for the rem set information.
50
51 class CardTableRS: public CardTable {
52 friend class VMStructs;
53 // Below are private classes used in impl.
54 friend class VerifyCTSpaceClosure;
55 friend class ClearNoncleanCardWrapper;
56
57 KlassRemSet _klass_rem_set;
58
59 void verify_space(Space* s, HeapWord* gen_start);
60
61 enum ExtendedCardValue {
62 youngergen_card = CT_MR_BS_last_reserved + 1,
63 // These are for parallel collection.
64 // There are three P (parallel) youngergen card values. In general, this
65 // needs to be more than the number of generations (including the perm
66 // gen) that might have younger_refs_do invoked on them separately. So
67 // if we add more gens, we have to add more values.
68 youngergenP1_card = CT_MR_BS_last_reserved + 2,
69 youngergenP2_card = CT_MR_BS_last_reserved + 3,
70 youngergenP3_card = CT_MR_BS_last_reserved + 4,
71 cur_youngergen_and_prev_nonclean_card = CT_MR_BS_last_reserved + 5
72 };
73
74 // An array that contains, for each generation, the card table value last
75 // used as the current value for a younger_refs_do iteration of that
76 // portion of the table. The perm gen is index 0. The young gen is index 1,
77 // but will always have the value "clean_card". The old gen is index 2.
78 jbyte* _last_cur_val_in_gen;
79
80 jbyte _cur_youngergen_card_val;
81
82 // Number of generations, plus one for lingering PermGen issues in CardTableRS.
83 static const int _regions_to_iterate = 3;
84
85 jbyte cur_youngergen_card_val() {
86 return _cur_youngergen_card_val;
87 }
88 void set_cur_youngergen_card_val(jbyte v) {
89 _cur_youngergen_card_val = v;
90 }
91 bool is_prev_youngergen_card_val(jbyte v) {
92 return
93 youngergen_card <= v &&
94 v < cur_youngergen_and_prev_nonclean_card &&
95 v != _cur_youngergen_card_val;
96 }
97 // Return a youngergen_card_value that is not currently in use.
98 jbyte find_unused_youngergenP_card_value();
99
100 public:
101 CardTableRS(MemRegion whole_heap);
102 ~CardTableRS();
103
104 KlassRemSet* klass_rem_set() { return &_klass_rem_set; }
105
106 void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl, uint n_threads);
107
108 // Override.
109 void prepare_for_younger_refs_iterate(bool parallel);
110
111 // Card table entries are cleared before application; "blk" is
112 // responsible for dirtying if the oop is still older-to-younger after
113 // closure application.
114 void younger_refs_iterate(Generation* g, OopsInGenClosure* blk, uint n_threads);
115
116 void inline_write_ref_field_gc(void* field, oop new_val) {
117 jbyte* byte = byte_for(field);
118 *byte = youngergen_card;
119 }
120 void write_ref_field_gc_work(void* field, oop new_val) {
121 inline_write_ref_field_gc(field, new_val);
122 }
123
124 // Override. Might want to devirtualize this in the same fashion as
125 // above. Ensures that the value of the card for field says that it's
126 // a younger card in the current collection.
127 virtual void write_ref_field_gc_par(void* field, oop new_val);
128
129 bool is_aligned(HeapWord* addr) {
130 return is_card_aligned(addr);
131 }
132
133 void verify();
134 void initialize();
135
136 void clear_into_younger(Generation* old_gen);
137
138 void invalidate_or_clear(Generation* old_gen);
139
140 bool is_prev_nonclean_card_val(jbyte v) {
141 return
142 youngergen_card <= v &&
143 v <= cur_youngergen_and_prev_nonclean_card &&
144 v != _cur_youngergen_card_val;
145 }
146
147 static bool youngergen_may_have_been_dirty(jbyte cv) {
148 return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card;
149 }
150
151 // *** Support for parallel card scanning.
152
153 // dirty and precleaned are equivalent wrt younger_refs_iter.
154 static bool card_is_dirty_wrt_gen_iter(jbyte cv) {
155 return cv == dirty_card || cv == precleaned_card;
156 }
157
158 // Returns "true" iff the value "cv" will cause the card containing it
159 // to be scanned in the current traversal. May be overridden by
160 // subtypes.
161 bool card_will_be_scanned(jbyte cv);
162
163 // Returns "true" iff the value "cv" may have represented a dirty card at
164 // some point.
165 bool card_may_have_been_dirty(jbyte cv);
166
167 // Iterate over the portion of the card-table which covers the given
168 // region mr in the given space and apply cl to any dirty sub-regions
169 // of mr. Clears the dirty cards as they are processed.
170 void non_clean_card_iterate_possibly_parallel(Space* sp, MemRegion mr,
171 OopsInGenClosure* cl, CardTableRS* ct,
172 uint n_threads);
173
174 // Work method used to implement non_clean_card_iterate_possibly_parallel()
175 // above in the parallel case.
176 void non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr,
177 OopsInGenClosure* cl, CardTableRS* ct,
178 uint n_threads);
179
180 // This is an array, one element per covered region of the card table.
181 // Each entry is itself an array, with one element per chunk in the
182 // covered region. Each entry of these arrays is the lowest non-clean
183 // card of the corresponding chunk containing part of an object from the
184 // previous chunk, or else NULL.
185 typedef jbyte* CardPtr;
186 typedef CardPtr* CardArr;
187 CardArr* _lowest_non_clean;
188 size_t* _lowest_non_clean_chunk_size;
189 uintptr_t* _lowest_non_clean_base_chunk_index;
190 volatile int* _last_LNC_resizing_collection;
191
192 // Initializes "lowest_non_clean" to point to the array for the region
193 // covering "sp", and "lowest_non_clean_base_chunk_index" to the chunk
194 // index of the corresponding to the first element of that array.
195 // Ensures that these arrays are of sufficient size, allocating if necessary.
196 // May be called by several threads concurrently.
197 void get_LNC_array_for_space(Space* sp,
198 jbyte**& lowest_non_clean,
199 uintptr_t& lowest_non_clean_base_chunk_index,
200 size_t& lowest_non_clean_chunk_size);
201
202 // Returns the number of chunks necessary to cover "mr".
203 size_t chunks_to_cover(MemRegion mr) {
204 return (size_t)(addr_to_chunk_index(mr.last()) -
205 addr_to_chunk_index(mr.start()) + 1);
206 }
207
208 // Returns the index of the chunk in a stride which
209 // covers the given address.
210 uintptr_t addr_to_chunk_index(const void* addr) {
211 uintptr_t card = (uintptr_t) byte_for(addr);
212 return card / ParGCCardsPerStrideChunk;
213 }
214
215 // Apply cl, which must either itself apply dcto_cl or be dcto_cl,
216 // to the cards in the stride (of n_strides) within the given space.
217 void process_stride(Space* sp,
218 MemRegion used,
219 jint stride, int n_strides,
220 OopsInGenClosure* cl,
221 CardTableRS* ct,
222 jbyte** lowest_non_clean,
223 uintptr_t lowest_non_clean_base_chunk_index,
224 size_t lowest_non_clean_chunk_size);
225
226 // Makes sure that chunk boundaries are handled appropriately, by
227 // adjusting the min_done of dcto_cl, and by using a special card-table
228 // value to indicate how min_done should be set.
229 void process_chunk_boundaries(Space* sp,
230 DirtyCardToOopClosure* dcto_cl,
231 MemRegion chunk_mr,
232 MemRegion used,
233 jbyte** lowest_non_clean,
234 uintptr_t lowest_non_clean_base_chunk_index,
235 size_t lowest_non_clean_chunk_size);
236
237 virtual bool is_in_young(void* addr) const;
238
239 };
240
241 class ClearNoncleanCardWrapper: public MemRegionClosure {
242 DirtyCardToOopClosure* _dirty_card_closure;
243 CardTableRS* _ct;
244 bool _is_par;
245 private:
246 // Clears the given card, return true if the corresponding card should be
247 // processed.
248 inline bool clear_card(jbyte* entry);
249 // Work methods called by the clear_card()
250 inline bool clear_card_serial(jbyte* entry);
251 inline bool clear_card_parallel(jbyte* entry);
252 // check alignment of pointer
253 bool is_word_aligned(jbyte* entry);
254
255 public:
256 ClearNoncleanCardWrapper(DirtyCardToOopClosure* dirty_card_closure, CardTableRS* ct, bool is_par);
257 void do_MemRegion(MemRegion mr);
|