170 class HeapRegionRemSet : public CHeapObj<mtGC> {
171 friend class VMStructs;
172 friend class HeapRegionRemSetIterator;
173
174 private:
175 G1BlockOffsetTable* _bot;
176
177 // A set of code blobs (nmethods) whose code contains pointers into
178 // the region that owns this RSet.
179 G1CodeRootSet _code_roots;
180
181 Mutex _m;
182
183 OtherRegionsTable _other_regions;
184
185 public:
186 HeapRegionRemSet(G1BlockOffsetTable* bot, HeapRegion* hr);
187
188 static void setup_remset_size();
189
190 bool is_empty() const {
191 return (strong_code_roots_list_length() == 0) && _other_regions.is_empty();
192 }
193
194 bool occupancy_less_or_equal_than(size_t occ) const {
195 return (strong_code_roots_list_length() == 0) && _other_regions.occupancy_less_or_equal_than(occ);
196 }
197
198 size_t occupied() {
199 MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
200 return occupied_locked();
201 }
202 size_t occupied_locked() {
203 return _other_regions.occupied();
204 }
205 size_t occ_fine() const {
206 return _other_regions.occ_fine();
207 }
208 size_t occ_coarse() const {
209 return _other_regions.occ_coarse();
210 }
211 size_t occ_sparse() const {
336
337 #ifndef PRODUCT
338 static void print_from_card_cache() {
339 G1FromCardCache::print();
340 }
341 #endif
342
343 // These are wrappers for the similarly-named methods on
344 // SparsePRT. Look at sparsePRT.hpp for more details.
345 static void reset_for_cleanup_tasks();
346 void do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task);
347 static void finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task);
348
349 // Run unit tests.
350 #ifndef PRODUCT
351 static void test();
352 #endif
353 };
354
355 class HeapRegionRemSetIterator : public StackObj {
356 private:
357 // The region RSet over which we are iterating.
358 HeapRegionRemSet* _hrrs;
359
360 // Local caching of HRRS fields.
361 const BitMap* _coarse_map;
362
363 G1BlockOffsetTable* _bot;
364 G1CollectedHeap* _g1h;
365
366 // The number of cards yielded since initialization.
367 size_t _n_yielded_fine;
368 size_t _n_yielded_coarse;
369 size_t _n_yielded_sparse;
370
371 // Indicates what granularity of table that we are currently iterating over.
372 // We start iterating over the sparse table, progress to the fine grain
373 // table, and then finish with the coarse table.
374 enum IterState {
375 Sparse,
376 Fine,
384
385 // Current region index for the Coarse remembered set iteration.
386 int _coarse_cur_region_index;
387 size_t _coarse_cur_region_cur_card;
388
389 bool coarse_has_next(size_t& card_index);
390
391 // The PRT we are currently iterating over.
392 PerRegionTable* _fine_cur_prt;
393 // Card offset within the current PRT.
394 size_t _cur_card_in_prt;
395
396 // Update internal variables when switching to the given PRT.
397 void switch_to_prt(PerRegionTable* prt);
398 bool fine_has_next();
399 bool fine_has_next(size_t& card_index);
400
401 // The Sparse remembered set iterator.
402 SparsePRTIter _sparse_iter;
403
404 public:
405 HeapRegionRemSetIterator(HeapRegionRemSet* hrrs);
406
407 // If there remains one or more cards to be yielded, returns true and
408 // sets "card_index" to one of those cards (which is then considered
409 // yielded.) Otherwise, returns false (and leaves "card_index"
410 // undefined.)
411 bool has_next(size_t& card_index);
412
413 size_t n_yielded_fine() { return _n_yielded_fine; }
414 size_t n_yielded_coarse() { return _n_yielded_coarse; }
415 size_t n_yielded_sparse() { return _n_yielded_sparse; }
416 size_t n_yielded() {
417 return n_yielded_fine() + n_yielded_coarse() + n_yielded_sparse();
418 }
419 };
420
421 #endif // SHARE_VM_GC_G1_HEAPREGIONREMSET_HPP
|
170 class HeapRegionRemSet : public CHeapObj<mtGC> {
171 friend class VMStructs;
172 friend class HeapRegionRemSetIterator;
173
174 private:
175 G1BlockOffsetTable* _bot;
176
177 // A set of code blobs (nmethods) whose code contains pointers into
178 // the region that owns this RSet.
179 G1CodeRootSet _code_roots;
180
181 Mutex _m;
182
183 OtherRegionsTable _other_regions;
184
185 public:
186 HeapRegionRemSet(G1BlockOffsetTable* bot, HeapRegion* hr);
187
188 static void setup_remset_size();
189
190 bool cardset_is_empty() const {
191 return _other_regions.is_empty();
192 }
193
194 bool is_empty() const {
195 return (strong_code_roots_list_length() == 0) && cardset_is_empty();
196 }
197
198 bool occupancy_less_or_equal_than(size_t occ) const {
199 return (strong_code_roots_list_length() == 0) && _other_regions.occupancy_less_or_equal_than(occ);
200 }
201
202 size_t occupied() {
203 MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
204 return occupied_locked();
205 }
206 size_t occupied_locked() {
207 return _other_regions.occupied();
208 }
209 size_t occ_fine() const {
210 return _other_regions.occ_fine();
211 }
212 size_t occ_coarse() const {
213 return _other_regions.occ_coarse();
214 }
215 size_t occ_sparse() const {
340
341 #ifndef PRODUCT
342 static void print_from_card_cache() {
343 G1FromCardCache::print();
344 }
345 #endif
346
347 // These are wrappers for the similarly-named methods on
348 // SparsePRT. Look at sparsePRT.hpp for more details.
349 static void reset_for_cleanup_tasks();
350 void do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task);
351 static void finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task);
352
353 // Run unit tests.
354 #ifndef PRODUCT
355 static void test();
356 #endif
357 };
358
359 class HeapRegionRemSetIterator : public StackObj {
360 private:
361 // The region RSet over which we are iterating.
362 HeapRegionRemSet* _hrrs;
363
364 // Local caching of HRRS fields.
365 const BitMap* _coarse_map;
366
367 G1BlockOffsetTable* _bot;
368 G1CollectedHeap* _g1h;
369
370 // The number of cards yielded since initialization.
371 size_t _n_yielded_fine;
372 size_t _n_yielded_coarse;
373 size_t _n_yielded_sparse;
374
375 // Indicates what granularity of table that we are currently iterating over.
376 // We start iterating over the sparse table, progress to the fine grain
377 // table, and then finish with the coarse table.
378 enum IterState {
379 Sparse,
380 Fine,
388
389 // Current region index for the Coarse remembered set iteration.
390 int _coarse_cur_region_index;
391 size_t _coarse_cur_region_cur_card;
392
393 bool coarse_has_next(size_t& card_index);
394
395 // The PRT we are currently iterating over.
396 PerRegionTable* _fine_cur_prt;
397 // Card offset within the current PRT.
398 size_t _cur_card_in_prt;
399
400 // Update internal variables when switching to the given PRT.
401 void switch_to_prt(PerRegionTable* prt);
402 bool fine_has_next();
403 bool fine_has_next(size_t& card_index);
404
405 // The Sparse remembered set iterator.
406 SparsePRTIter _sparse_iter;
407
408 public:
409 HeapRegionRemSetIterator(HeapRegionRemSet* hrrs);
410
411 // If there remains one or more cards to be yielded, returns true and
412 // sets "card_index" to one of those cards (which is then considered
413 // yielded.) Otherwise, returns false (and leaves "card_index"
414 // undefined.)
415 bool has_next(size_t& card_index);
416
417 size_t n_yielded_fine() { return _n_yielded_fine; }
418 size_t n_yielded_coarse() { return _n_yielded_coarse; }
419 size_t n_yielded_sparse() { return _n_yielded_sparse; }
420 size_t n_yielded() {
421 return n_yielded_fine() + n_yielded_coarse() + n_yielded_sparse();
422 }
423 };
424
425 #endif // SHARE_VM_GC_G1_HEAPREGIONREMSET_HPP
|