Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8293920: G1: Add index based heap region iteration #10301

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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