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_GC_SHARED_CARDTABLERS_HPP
26 #define SHARE_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 clds.
38 class CLDRemSet {
39 bool _accumulate_modified_oops;
40 public:
41 CLDRemSet() : _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;
87 return _cur_youngergen_card_val;
88 }
89 void set_cur_youngergen_card_val(CardValue v) {
90 _cur_youngergen_card_val = v;
91 }
92 bool is_prev_youngergen_card_val(CardValue v) {
93 return
94 youngergen_card <= v &&
95 v < cur_youngergen_and_prev_nonclean_card &&
96 v != _cur_youngergen_card_val;
97 }
98 // Return a youngergen_card_value that is not currently in use.
99 CardValue find_unused_youngergenP_card_value();
100
101 public:
102 CardTableRS(MemRegion whole_heap, bool scanned_concurrently);
103 ~CardTableRS();
104
105 CLDRemSet* cld_rem_set() { return &_cld_rem_set; }
106
107 void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl, uint n_threads);
108
109 virtual void verify_used_region_at_save_marks(Space* sp) const NOT_DEBUG_RETURN;
110
111 // Override.
112 void prepare_for_younger_refs_iterate(bool parallel);
113
114 // Card table entries are cleared before application; "blk" is
115 // responsible for dirtying if the oop is still older-to-younger after
116 // closure application.
117 void younger_refs_iterate(Generation* g, OopsInGenClosure* blk, uint n_threads);
118
119 void inline_write_ref_field_gc(void* field, oop new_val) {
120 CardValue* byte = byte_for(field);
121 *byte = youngergen_card;
122 }
123 void write_ref_field_gc_work(void* field, oop new_val) {
124 inline_write_ref_field_gc(field, new_val);
125 }
126
127 bool is_aligned(HeapWord* addr) {
128 return is_card_aligned(addr);
129 }
130
131 void verify();
132 void initialize();
133
134 void clear_into_younger(Generation* old_gen);
135
136 void invalidate_or_clear(Generation* old_gen);
137
148
149 // *** Support for parallel card scanning.
150
151 // dirty and precleaned are equivalent wrt younger_refs_iter.
152 static bool card_is_dirty_wrt_gen_iter(CardValue cv) {
153 return cv == dirty_card;
154 }
155
156 // Returns "true" iff the value "cv" will cause the card containing it
157 // to be scanned in the current traversal. May be overridden by
158 // subtypes.
159 bool card_will_be_scanned(CardValue cv);
160
161 // Returns "true" iff the value "cv" may have represented a dirty card at
162 // some point.
163 bool card_may_have_been_dirty(CardValue cv);
164
165 // Iterate over the portion of the card-table which covers the given
166 // region mr in the given space and apply cl to any dirty sub-regions
167 // of mr. Clears the dirty cards as they are processed.
168 void non_clean_card_iterate_possibly_parallel(Space* sp, MemRegion mr,
169 OopsInGenClosure* cl, CardTableRS* ct,
170 uint n_threads);
171
172 // Work method used to implement non_clean_card_iterate_possibly_parallel()
173 // above in the parallel case.
174 virtual void non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr,
175 OopsInGenClosure* cl, CardTableRS* ct,
176 uint n_threads);
177
178 // This is an array, one element per covered region of the card table.
179 // Each entry is itself an array, with one element per chunk in the
180 // covered region. Each entry of these arrays is the lowest non-clean
181 // card of the corresponding chunk containing part of an object from the
182 // previous chunk, or else NULL.
183 typedef CardValue* CardPtr;
184 typedef CardPtr* CardArr;
185 CardArr* _lowest_non_clean;
186 size_t* _lowest_non_clean_chunk_size;
187 uintptr_t* _lowest_non_clean_base_chunk_index;
188 volatile int* _last_LNC_resizing_collection;
189
190 virtual bool is_in_young(oop obj) const;
191 };
192
193 class ClearNoncleanCardWrapper: public MemRegionClosure {
194 DirtyCardToOopClosure* _dirty_card_closure;
195 CardTableRS* _ct;
|
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_GC_SHARED_CARDTABLERS_HPP
26 #define SHARE_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
36 // Helper to remember modified oops in all clds.
37 class CLDRemSet {
38 bool _accumulate_modified_oops;
39 public:
40 CLDRemSet() : _accumulate_modified_oops(false) {}
41 void set_accumulate_modified_oops(bool value) { _accumulate_modified_oops = value; }
42 bool accumulate_modified_oops() { return _accumulate_modified_oops; }
43 bool mod_union_is_clear();
44 void clear_mod_union();
45 };
46
47 // This RemSet uses a card table both as shared data structure
48 // for a mod ref barrier set and for the rem set information.
49
50 class CardTableRS: public CardTable {
51 friend class VMStructs;
52 // Below are private classes used in impl.
53 friend class VerifyCTSpaceClosure;
54 friend class ClearNoncleanCardWrapper;
86 return _cur_youngergen_card_val;
87 }
88 void set_cur_youngergen_card_val(CardValue v) {
89 _cur_youngergen_card_val = v;
90 }
91 bool is_prev_youngergen_card_val(CardValue 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 CardValue find_unused_youngergenP_card_value();
99
100 public:
101 CardTableRS(MemRegion whole_heap, bool scanned_concurrently);
102 ~CardTableRS();
103
104 CLDRemSet* cld_rem_set() { return &_cld_rem_set; }
105
106 void younger_refs_in_space_iterate(Space* sp, HeapWord* gen_boundary, OopIterateClosure* cl, uint n_threads);
107
108 virtual void verify_used_region_at_save_marks(Space* sp) const NOT_DEBUG_RETURN;
109
110 // Override.
111 void prepare_for_younger_refs_iterate(bool parallel);
112
113 // Card table entries are cleared before application;
114 void at_younger_refs_iterate();
115
116 void inline_write_ref_field_gc(void* field, oop new_val) {
117 CardValue* 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 bool is_aligned(HeapWord* addr) {
125 return is_card_aligned(addr);
126 }
127
128 void verify();
129 void initialize();
130
131 void clear_into_younger(Generation* old_gen);
132
133 void invalidate_or_clear(Generation* old_gen);
134
145
146 // *** Support for parallel card scanning.
147
148 // dirty and precleaned are equivalent wrt younger_refs_iter.
149 static bool card_is_dirty_wrt_gen_iter(CardValue cv) {
150 return cv == dirty_card;
151 }
152
153 // Returns "true" iff the value "cv" will cause the card containing it
154 // to be scanned in the current traversal. May be overridden by
155 // subtypes.
156 bool card_will_be_scanned(CardValue cv);
157
158 // Returns "true" iff the value "cv" may have represented a dirty card at
159 // some point.
160 bool card_may_have_been_dirty(CardValue cv);
161
162 // Iterate over the portion of the card-table which covers the given
163 // region mr in the given space and apply cl to any dirty sub-regions
164 // of mr. Clears the dirty cards as they are processed.
165 void non_clean_card_iterate_possibly_parallel(Space* sp, HeapWord* gen_boundary,
166 MemRegion mr,
167 OopIterateClosure* cl, CardTableRS* ct,
168 uint n_threads);
169
170 // Work method used to implement non_clean_card_iterate_possibly_parallel()
171 // above in the parallel case.
172 virtual void non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr,
173 OopIterateClosure* cl, CardTableRS* ct,
174 uint n_threads);
175
176 // This is an array, one element per covered region of the card table.
177 // Each entry is itself an array, with one element per chunk in the
178 // covered region. Each entry of these arrays is the lowest non-clean
179 // card of the corresponding chunk containing part of an object from the
180 // previous chunk, or else NULL.
181 typedef CardValue* CardPtr;
182 typedef CardPtr* CardArr;
183 CardArr* _lowest_non_clean;
184 size_t* _lowest_non_clean_chunk_size;
185 uintptr_t* _lowest_non_clean_base_chunk_index;
186 volatile int* _last_LNC_resizing_collection;
187
188 virtual bool is_in_young(oop obj) const;
189 };
190
191 class ClearNoncleanCardWrapper: public MemRegionClosure {
192 DirtyCardToOopClosure* _dirty_card_closure;
193 CardTableRS* _ct;
|