Skip to content

Commit

Permalink
8293920: G1: Add index based heap region iteration
Browse files Browse the repository at this point in the history
Reviewed-by: tschatzl, kbarrett
  • Loading branch information
albertnetymk committed Sep 19, 2022
1 parent 36c9034 commit a93cf92
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Expand Up @@ -2285,6 +2285,10 @@ void G1CollectedHeap::heap_region_iterate(HeapRegionClosure* cl) const {
_hrm.iterate(cl);
}

void G1CollectedHeap::heap_region_iterate(HeapRegionIndexClosure* cl) const {
_hrm.iterate(cl);
}

void G1CollectedHeap::heap_region_par_iterate_from_worker_offset(HeapRegionClosure* cl,
HeapRegionClaimer *hrclaimer,
uint worker_id) const {
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/g1/g1CollectedHeap.hpp
Expand Up @@ -1080,6 +1080,7 @@ class G1CollectedHeap : public CollectedHeap {
// Iterate over heap regions, in address order, terminating the
// iteration early if the "do_heap_region" method returns "true".
void heap_region_iterate(HeapRegionClosure* blk) const;
void heap_region_iterate(HeapRegionIndexClosure* blk) const;

// Return the region with the given index. It assumes the index is valid.
inline HeapRegion* region_at(uint index) const;
Expand Down
19 changes: 19 additions & 0 deletions src/hotspot/share/gc/g1/heapRegion.hpp
Expand Up @@ -609,4 +609,23 @@ class HeapRegionClosure : public StackObj {
bool is_complete() { return _is_complete; }
};

class HeapRegionIndexClosure : public StackObj {
friend class HeapRegionManager;
friend class G1CollectionSet;
friend class G1CollectionSetCandidates;

bool _is_complete;
void set_incomplete() { _is_complete = false; }

public:
HeapRegionIndexClosure(): _is_complete(true) {}

// Typically called on each region until it returns true.
virtual bool do_heap_region_index(uint region_index) = 0;

// True after iteration if the closure was applied to all heap regions
// and returned "false" in all cases.
bool is_complete() { return _is_complete; }
};

#endif // SHARE_GC_G1_HEAPREGION_HPP
15 changes: 15 additions & 0 deletions src/hotspot/share/gc/g1/heapRegionManager.cpp
Expand Up @@ -526,6 +526,21 @@ void HeapRegionManager::iterate(HeapRegionClosure* blk) const {
}
}

void HeapRegionManager::iterate(HeapRegionIndexClosure* blk) const {
uint len = reserved_length();

for (uint i = 0; i < len; i++) {
if (!is_available(i)) {
continue;
}
bool res = blk->do_heap_region_index(i);
if (res) {
blk->set_incomplete();
return;
}
}
}

uint HeapRegionManager::find_highest_free(bool* expanded) {
// Loop downwards from the highest region index, looking for an
// entry which is either free or not yet committed. If not yet
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/g1/heapRegionManager.hpp
Expand Up @@ -271,6 +271,7 @@ class HeapRegionManager: public CHeapObj<mtGC> {
// Apply blk->do_heap_region() on all committed regions in address order,
// terminating the iteration early if do_heap_region() returns true.
void iterate(HeapRegionClosure* blk) const;
void iterate(HeapRegionIndexClosure* blk) const;

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

Expand Down

1 comment on commit a93cf92

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.