Tue, 26 Jan 2010 16:52:29 -0800
6920090: G1: Disable ReduceInitialCardMarks at least until 6920109 is fixed
Summary: G1 now answers "no" to the query can_elide_initializing_store_barrier() in the product build. A debug flag allows alternate behaviour in debug builds.
Reviewed-by: iveresov, tonyp
1 /*
2 * Copyright 2001-2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 // Sparse remembered set for a heap region (the "owning" region). Maps
26 // indices of other regions to short sequences of cards in the other region
27 // that might contain pointers into the owner region.
29 // These tables only expand while they are accessed in parallel --
30 // deletions may be done in single-threaded code. This allows us to allow
31 // unsynchronized reads/iterations, as long as expansions caused by
32 // insertions only enqueue old versions for deletions, but do not delete
33 // old versions synchronously.
36 class SparsePRTEntry: public CHeapObj {
37 public:
39 enum SomePublicConstants {
40 CardsPerEntry = 4,
41 NullEntry = -1
42 };
44 private:
45 RegionIdx_t _region_ind;
46 int _next_index;
47 CardIdx_t _cards[CardsPerEntry];
49 public:
51 // Set the region_ind to the given value, and delete all cards.
52 inline void init(RegionIdx_t region_ind);
54 RegionIdx_t r_ind() const { return _region_ind; }
55 bool valid_entry() const { return r_ind() >= 0; }
56 void set_r_ind(RegionIdx_t rind) { _region_ind = rind; }
58 int next_index() const { return _next_index; }
59 int* next_index_addr() { return &_next_index; }
60 void set_next_index(int ni) { _next_index = ni; }
62 // Returns "true" iff the entry contains the given card index.
63 inline bool contains_card(CardIdx_t card_index) const;
65 // Returns the number of non-NULL card entries.
66 inline int num_valid_cards() const;
68 // Requires that the entry not contain the given card index. If there is
69 // space available, add the given card index to the entry and return
70 // "true"; otherwise, return "false" to indicate that the entry is full.
71 enum AddCardResult {
72 overflow,
73 found,
74 added
75 };
76 inline AddCardResult add_card(CardIdx_t card_index);
78 // Copy the current entry's cards into "cards".
79 inline void copy_cards(CardIdx_t* cards) const;
80 // Copy the current entry's cards into the "_card" array of "e."
81 inline void copy_cards(SparsePRTEntry* e) const;
83 inline CardIdx_t card(int i) const { return _cards[i]; }
84 };
87 class RSHashTable : public CHeapObj {
89 friend class RSHashTableIter;
91 enum SomePrivateConstants {
92 NullEntry = -1
93 };
95 size_t _capacity;
96 size_t _capacity_mask;
97 size_t _occupied_entries;
98 size_t _occupied_cards;
100 SparsePRTEntry* _entries;
101 int* _buckets;
102 int _free_region;
103 int _free_list;
105 // Requires that the caller hold a lock preventing parallel modifying
106 // operations, and that the the table be less than completely full. If
107 // an entry for "region_ind" is already in the table, finds it and
108 // returns its address; otherwise returns "NULL."
109 SparsePRTEntry* entry_for_region_ind(RegionIdx_t region_ind) const;
111 // Requires that the caller hold a lock preventing parallel modifying
112 // operations, and that the the table be less than completely full. If
113 // an entry for "region_ind" is already in the table, finds it and
114 // returns its address; otherwise allocates, initializes, inserts and
115 // returns a new entry for "region_ind".
116 SparsePRTEntry* entry_for_region_ind_create(RegionIdx_t region_ind);
118 // Returns the index of the next free entry in "_entries".
119 int alloc_entry();
120 // Declares the entry "fi" to be free. (It must have already been
121 // deleted from any bucket lists.
122 void free_entry(int fi);
124 public:
125 RSHashTable(size_t capacity);
126 ~RSHashTable();
128 // Attempts to ensure that the given card_index in the given region is in
129 // the sparse table. If successful (because the card was already
130 // present, or because it was successfullly added) returns "true".
131 // Otherwise, returns "false" to indicate that the addition would
132 // overflow the entry for the region. The caller must transfer these
133 // entries to a larger-capacity representation.
134 bool add_card(RegionIdx_t region_id, CardIdx_t card_index);
136 bool get_cards(RegionIdx_t region_id, CardIdx_t* cards);
137 bool delete_entry(RegionIdx_t region_id);
139 bool contains_card(RegionIdx_t region_id, CardIdx_t card_index) const;
141 void add_entry(SparsePRTEntry* e);
143 void clear();
145 size_t capacity() const { return _capacity; }
146 size_t capacity_mask() const { return _capacity_mask; }
147 size_t occupied_entries() const { return _occupied_entries; }
148 size_t occupied_cards() const { return _occupied_cards; }
149 size_t mem_size() const;
151 SparsePRTEntry* entry(int i) const { return &_entries[i]; }
153 void print();
154 };
156 // ValueObj because will be embedded in HRRS iterator.
157 class RSHashTableIter VALUE_OBJ_CLASS_SPEC {
158 int _tbl_ind; // [-1, 0.._rsht->_capacity)
159 int _bl_ind; // [-1, 0.._rsht->_capacity)
160 short _card_ind; // [0..CardsPerEntry)
161 RSHashTable* _rsht;
162 size_t _heap_bot_card_ind;
164 // If the bucket list pointed to by _bl_ind contains a card, sets
165 // _bl_ind to the index of that entry, and returns the card.
166 // Otherwise, returns SparseEntry::NullEntry.
167 CardIdx_t find_first_card_in_list();
169 // Computes the proper card index for the card whose offset in the
170 // current region (as indicated by _bl_ind) is "ci".
171 // This is subject to errors when there is iteration concurrent with
172 // modification, but these errors should be benign.
173 size_t compute_card_ind(CardIdx_t ci);
175 public:
176 RSHashTableIter(size_t heap_bot_card_ind) :
177 _tbl_ind(RSHashTable::NullEntry),
178 _bl_ind(RSHashTable::NullEntry),
179 _card_ind((SparsePRTEntry::CardsPerEntry-1)),
180 _rsht(NULL),
181 _heap_bot_card_ind(heap_bot_card_ind)
182 {}
184 void init(RSHashTable* rsht) {
185 _rsht = rsht;
186 _tbl_ind = -1; // So that first increment gets to 0.
187 _bl_ind = RSHashTable::NullEntry;
188 _card_ind = (SparsePRTEntry::CardsPerEntry-1);
189 }
191 bool has_next(size_t& card_index);
192 };
194 // Concurrent accesss to a SparsePRT must be serialized by some external
195 // mutex.
197 class SparsePRTIter;
199 class SparsePRT VALUE_OBJ_CLASS_SPEC {
200 // Iterations are done on the _cur hash table, since they only need to
201 // see entries visible at the start of a collection pause.
202 // All other operations are done using the _next hash table.
203 RSHashTable* _cur;
204 RSHashTable* _next;
206 HeapRegion* _hr;
208 enum SomeAdditionalPrivateConstants {
209 InitialCapacity = 16
210 };
212 void expand();
214 bool _expanded;
216 bool expanded() { return _expanded; }
217 void set_expanded(bool b) { _expanded = b; }
219 SparsePRT* _next_expanded;
221 SparsePRT* next_expanded() { return _next_expanded; }
222 void set_next_expanded(SparsePRT* nxt) { _next_expanded = nxt; }
224 static SparsePRT* _head_expanded_list;
226 public:
227 SparsePRT(HeapRegion* hr);
229 ~SparsePRT();
231 size_t occupied() const { return _next->occupied_cards(); }
232 size_t mem_size() const;
234 // Attempts to ensure that the given card_index in the given region is in
235 // the sparse table. If successful (because the card was already
236 // present, or because it was successfullly added) returns "true".
237 // Otherwise, returns "false" to indicate that the addition would
238 // overflow the entry for the region. The caller must transfer these
239 // entries to a larger-capacity representation.
240 bool add_card(RegionIdx_t region_id, CardIdx_t card_index);
242 // If the table hold an entry for "region_ind", Copies its
243 // cards into "cards", which must be an array of length at least
244 // "CardsPerEntry", and returns "true"; otherwise, returns "false".
245 bool get_cards(RegionIdx_t region_ind, CardIdx_t* cards);
247 // If there is an entry for "region_ind", removes it and return "true";
248 // otherwise returns "false."
249 bool delete_entry(RegionIdx_t region_ind);
251 // Clear the table, and reinitialize to initial capacity.
252 void clear();
254 // Ensure that "_cur" and "_next" point to the same table.
255 void cleanup();
257 // Clean up all tables on the expanded list. Called single threaded.
258 static void cleanup_all();
259 RSHashTable* cur() const { return _cur; }
261 void init_iterator(SparsePRTIter* sprt_iter);
263 static void add_to_expanded_list(SparsePRT* sprt);
264 static SparsePRT* get_from_expanded_list();
266 bool contains_card(RegionIdx_t region_id, CardIdx_t card_index) const {
267 return _next->contains_card(region_id, card_index);
268 }
270 #if 0
271 void verify_is_cleared();
272 void print();
273 #endif
274 };
277 class SparsePRTIter: public /* RSHashTable:: */RSHashTableIter {
278 public:
279 SparsePRTIter(size_t heap_bot_card_ind) :
280 /* RSHashTable:: */RSHashTableIter(heap_bot_card_ind)
281 {}
283 void init(const SparsePRT* sprt) {
284 RSHashTableIter::init(sprt->cur());
285 }
286 bool has_next(size_t& card_index) {
287 return RSHashTableIter::has_next(card_index);
288 }
289 };