Skip to content

Commit a93cf92

Browse files
committedSep 19, 2022
8293920: G1: Add index based heap region iteration
Reviewed-by: tschatzl, kbarrett
1 parent 36c9034 commit a93cf92

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed
 

‎src/hotspot/share/gc/g1/g1CollectedHeap.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,10 @@ void G1CollectedHeap::heap_region_iterate(HeapRegionClosure* cl) const {
22852285
_hrm.iterate(cl);
22862286
}
22872287

2288+
void G1CollectedHeap::heap_region_iterate(HeapRegionIndexClosure* cl) const {
2289+
_hrm.iterate(cl);
2290+
}
2291+
22882292
void G1CollectedHeap::heap_region_par_iterate_from_worker_offset(HeapRegionClosure* cl,
22892293
HeapRegionClaimer *hrclaimer,
22902294
uint worker_id) const {

‎src/hotspot/share/gc/g1/g1CollectedHeap.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ class G1CollectedHeap : public CollectedHeap {
10801080
// Iterate over heap regions, in address order, terminating the
10811081
// iteration early if the "do_heap_region" method returns "true".
10821082
void heap_region_iterate(HeapRegionClosure* blk) const;
1083+
void heap_region_iterate(HeapRegionIndexClosure* blk) const;
10831084

10841085
// Return the region with the given index. It assumes the index is valid.
10851086
inline HeapRegion* region_at(uint index) const;

‎src/hotspot/share/gc/g1/heapRegion.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -609,4 +609,23 @@ class HeapRegionClosure : public StackObj {
609609
bool is_complete() { return _is_complete; }
610610
};
611611

612+
class HeapRegionIndexClosure : public StackObj {
613+
friend class HeapRegionManager;
614+
friend class G1CollectionSet;
615+
friend class G1CollectionSetCandidates;
616+
617+
bool _is_complete;
618+
void set_incomplete() { _is_complete = false; }
619+
620+
public:
621+
HeapRegionIndexClosure(): _is_complete(true) {}
622+
623+
// Typically called on each region until it returns true.
624+
virtual bool do_heap_region_index(uint region_index) = 0;
625+
626+
// True after iteration if the closure was applied to all heap regions
627+
// and returned "false" in all cases.
628+
bool is_complete() { return _is_complete; }
629+
};
630+
612631
#endif // SHARE_GC_G1_HEAPREGION_HPP

‎src/hotspot/share/gc/g1/heapRegionManager.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,21 @@ void HeapRegionManager::iterate(HeapRegionClosure* blk) const {
526526
}
527527
}
528528

529+
void HeapRegionManager::iterate(HeapRegionIndexClosure* blk) const {
530+
uint len = reserved_length();
531+
532+
for (uint i = 0; i < len; i++) {
533+
if (!is_available(i)) {
534+
continue;
535+
}
536+
bool res = blk->do_heap_region_index(i);
537+
if (res) {
538+
blk->set_incomplete();
539+
return;
540+
}
541+
}
542+
}
543+
529544
uint HeapRegionManager::find_highest_free(bool* expanded) {
530545
// Loop downwards from the highest region index, looking for an
531546
// entry which is either free or not yet committed. If not yet

‎src/hotspot/share/gc/g1/heapRegionManager.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ class HeapRegionManager: public CHeapObj<mtGC> {
271271
// Apply blk->do_heap_region() on all committed regions in address order,
272272
// terminating the iteration early if do_heap_region() returns true.
273273
void iterate(HeapRegionClosure* blk) const;
274+
void iterate(HeapRegionIndexClosure* blk) const;
274275

275276
void par_iterate(HeapRegionClosure* blk, HeapRegionClaimer* hrclaimer, const uint start_index) const;
276277

0 commit comments

Comments
 (0)