From 6292fd20c01a107459793b2d2ff139c29426e7be Mon Sep 17 00:00:00 2001 From: Hamlin-Li Date: Wed, 8 Sep 2021 17:45:08 +0800 Subject: [PATCH 1/5] refine par_iterate_regions_array_part_from --- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 3 +-- src/hotspot/share/gc/g1/g1CollectedHeap.hpp | 1 - src/hotspot/share/gc/g1/g1CollectionSet.cpp | 7 ++++++- src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp | 1 - 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index eca8f551e6d90..b68ee2494ad4a 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -2329,7 +2329,6 @@ void G1CollectedHeap::collection_set_iterate_increment_from(HeapRegionClosure *c void G1CollectedHeap::par_iterate_regions_array_part_from(HeapRegionClosure* cl, HeapRegionClaimer* hr_claimer, const uint* regions, - size_t offset, size_t length, uint worker_id) const { assert_at_safepoint(); @@ -2342,7 +2341,7 @@ void G1CollectedHeap::par_iterate_regions_array_part_from(HeapRegionClosure* cl, size_t cur_pos = start_pos; do { - uint region_idx = regions[cur_pos + offset]; + uint region_idx = regions[cur_pos]; if (hr_claimer == NULL || hr_claimer->claim_region(region_idx)) { HeapRegion* r = region_at(region_idx); bool result = cl->do_heap_region(r); diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index c3dfb31d013f3..68b6dbbf890ac 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -1161,7 +1161,6 @@ class G1CollectedHeap : public CollectedHeap { void par_iterate_regions_array_part_from(HeapRegionClosure* cl, HeapRegionClaimer* hr_claimer, const uint* regions, - size_t offset, size_t length, uint worker_id) const; diff --git a/src/hotspot/share/gc/g1/g1CollectionSet.cpp b/src/hotspot/share/gc/g1/g1CollectionSet.cpp index 62b3ad983a0d5..2b1e753b27132 100644 --- a/src/hotspot/share/gc/g1/g1CollectionSet.cpp +++ b/src/hotspot/share/gc/g1/g1CollectionSet.cpp @@ -232,7 +232,12 @@ void G1CollectionSet::iterate_part_from(HeapRegionClosure* cl, size_t offset, size_t length, uint worker_id) const { - _g1h->par_iterate_regions_array_part_from(cl, hr_claimer, _collection_set_regions, offset, length, worker_id); + assert(length >= offset, "Must be"); + _g1h->par_iterate_regions_array_part_from(cl, + hr_claimer, + &_collection_set_regions[offset], + length-offset, + worker_id); } void G1CollectionSet::update_young_region_prediction(HeapRegion* hr, diff --git a/src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp b/src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp index a6b7a16ce2816..899b167dbef32 100644 --- a/src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp +++ b/src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp @@ -52,7 +52,6 @@ void G1EvacFailureRegions::par_iterate(HeapRegionClosure* closure, G1CollectedHeap::heap()->par_iterate_regions_array_part_from(closure, _hrclaimer, _evac_failure_regions, - 0, Atomic::load(&_evac_failure_regions_cur_length), worker_id); } From 78da4ce79b623aa3a9d437b4fdb21a6fcac72596 Mon Sep 17 00:00:00 2001 From: Hamlin-Li Date: Thu, 9 Sep 2021 08:51:06 +0800 Subject: [PATCH 2/5] refine comments and code --- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 10 +++++----- src/hotspot/share/gc/g1/g1CollectedHeap.hpp | 14 +++++++------- src/hotspot/share/gc/g1/g1CollectionSet.cpp | 12 ++++++------ src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp | 10 +++++----- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index b68ee2494ad4a..f60e2ea70ed9d 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -2326,11 +2326,11 @@ void G1CollectedHeap::collection_set_iterate_increment_from(HeapRegionClosure *c _collection_set.iterate_incremental_part_from(cl, hr_claimer, worker_id); } -void G1CollectedHeap::par_iterate_regions_array_part_from(HeapRegionClosure* cl, - HeapRegionClaimer* hr_claimer, - const uint* regions, - size_t length, - uint worker_id) const { +void G1CollectedHeap::par_iterate_regions_array(HeapRegionClosure* cl, + HeapRegionClaimer* hr_claimer, + const uint regions[], + size_t length, + uint worker_id) const { assert_at_safepoint(); if (length == 0) { return; diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index 68b6dbbf890ac..1dbff82f7f8c4 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -1155,14 +1155,14 @@ class G1CollectedHeap : public CollectedHeap { collection_set_iterate_increment_from(blk, NULL, worker_id); } void collection_set_iterate_increment_from(HeapRegionClosure *blk, HeapRegionClaimer* hr_claimer, uint worker_id); - // Iterate part of an array of region indexes given by offset and length, applying + // Iterate an array of region indexes given by offset and length, applying // the given HeapRegionClosure on each region. The worker_id will determine where - // in the part to start the iteration to allow for more efficient parallel iteration. - void par_iterate_regions_array_part_from(HeapRegionClosure* cl, - HeapRegionClaimer* hr_claimer, - const uint* regions, - size_t length, - uint worker_id) const; + // to start the iteration to allow for more efficient parallel iteration. + void par_iterate_regions_array(HeapRegionClosure* cl, + HeapRegionClaimer* hr_claimer, + const uint regions[], + size_t length, + uint worker_id) const; // Returns the HeapRegion that contains addr. addr must not be NULL. template diff --git a/src/hotspot/share/gc/g1/g1CollectionSet.cpp b/src/hotspot/share/gc/g1/g1CollectionSet.cpp index 2b1e753b27132..223a9c1d330ba 100644 --- a/src/hotspot/share/gc/g1/g1CollectionSet.cpp +++ b/src/hotspot/share/gc/g1/g1CollectionSet.cpp @@ -232,12 +232,12 @@ void G1CollectionSet::iterate_part_from(HeapRegionClosure* cl, size_t offset, size_t length, uint worker_id) const { - assert(length >= offset, "Must be"); - _g1h->par_iterate_regions_array_part_from(cl, - hr_claimer, - &_collection_set_regions[offset], - length-offset, - worker_id); + assert(length > offset, "Must be"); + _g1h->par_iterate_regions_array(cl, + hr_claimer, + &_collection_set_regions[offset], + length - offset, + worker_id); } void G1CollectionSet::update_young_region_prediction(HeapRegion* hr, diff --git a/src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp b/src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp index 899b167dbef32..8560d02616f67 100644 --- a/src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp +++ b/src/hotspot/share/gc/g1/g1EvacFailureRegions.cpp @@ -49,11 +49,11 @@ void G1EvacFailureRegions::initialize(uint max_regions) { void G1EvacFailureRegions::par_iterate(HeapRegionClosure* closure, HeapRegionClaimer* _hrclaimer, uint worker_id) { - G1CollectedHeap::heap()->par_iterate_regions_array_part_from(closure, - _hrclaimer, - _evac_failure_regions, - Atomic::load(&_evac_failure_regions_cur_length), - worker_id); + G1CollectedHeap::heap()->par_iterate_regions_array(closure, + _hrclaimer, + _evac_failure_regions, + Atomic::load(&_evac_failure_regions_cur_length), + worker_id); } void G1EvacFailureRegions::reset() { From 489947ad1055c984f272d04ad05f84b00fc84e02 Mon Sep 17 00:00:00 2001 From: Hamlin-Li Date: Thu, 9 Sep 2021 11:57:34 +0800 Subject: [PATCH 3/5] Fix assert --- src/hotspot/share/gc/g1/g1CollectionSet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/g1/g1CollectionSet.cpp b/src/hotspot/share/gc/g1/g1CollectionSet.cpp index 223a9c1d330ba..6a3e856fecaee 100644 --- a/src/hotspot/share/gc/g1/g1CollectionSet.cpp +++ b/src/hotspot/share/gc/g1/g1CollectionSet.cpp @@ -232,7 +232,7 @@ void G1CollectionSet::iterate_part_from(HeapRegionClosure* cl, size_t offset, size_t length, uint worker_id) const { - assert(length > offset, "Must be"); + assert((length > offset) || (length == offset && length == 0), "Must be"); _g1h->par_iterate_regions_array(cl, hr_claimer, &_collection_set_regions[offset], From 46d5a3ccae541281e2bac2d7256fc6a6a0757b6a Mon Sep 17 00:00:00 2001 From: Hamlin-Li Date: Thu, 9 Sep 2021 14:41:19 +0800 Subject: [PATCH 4/5] Fix issue --- src/hotspot/share/gc/g1/g1CollectionSet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CollectionSet.cpp b/src/hotspot/share/gc/g1/g1CollectionSet.cpp index 6a3e856fecaee..9c385a0de441c 100644 --- a/src/hotspot/share/gc/g1/g1CollectionSet.cpp +++ b/src/hotspot/share/gc/g1/g1CollectionSet.cpp @@ -232,11 +232,10 @@ void G1CollectionSet::iterate_part_from(HeapRegionClosure* cl, size_t offset, size_t length, uint worker_id) const { - assert((length > offset) || (length == offset && length == 0), "Must be"); _g1h->par_iterate_regions_array(cl, hr_claimer, &_collection_set_regions[offset], - length - offset, + length, worker_id); } From af020d675dcac323993a1e2ee1a9c5ac659e3eb6 Mon Sep 17 00:00:00 2001 From: Hamlin-Li Date: Thu, 9 Sep 2021 17:23:47 +0800 Subject: [PATCH 5/5] Refine comments --- src/hotspot/share/gc/g1/g1CollectedHeap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index 1dbff82f7f8c4..6422672a8632c 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -1155,7 +1155,7 @@ class G1CollectedHeap : public CollectedHeap { collection_set_iterate_increment_from(blk, NULL, worker_id); } void collection_set_iterate_increment_from(HeapRegionClosure *blk, HeapRegionClaimer* hr_claimer, uint worker_id); - // Iterate an array of region indexes given by offset and length, applying + // Iterate over the array of region indexes, uint regions[length], applying // the given HeapRegionClosure on each region. The worker_id will determine where // to start the iteration to allow for more efficient parallel iteration. void par_iterate_regions_array(HeapRegionClosure* cl,