Skip to content

Commit 86f9b3f

Browse files
author
Thomas Schatzl
committed
8319313: G1: Rename G1EvacFailureInjector appropriately
Reviewed-by: mli, iwalulya, ayang
1 parent a7f6016 commit 86f9b3f

17 files changed

+297
-289
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
#include "gc/g1/g1UncommitRegionTask.hpp"
7171
#include "gc/g1/g1VMOperations.hpp"
7272
#include "gc/g1/g1YoungCollector.hpp"
73-
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
73+
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
7474
#include "gc/g1/heapRegion.inline.hpp"
7575
#include "gc/g1/heapRegionRemSet.inline.hpp"
7676
#include "gc/g1/heapRegionSet.inline.hpp"
@@ -1144,7 +1144,7 @@ G1CollectedHeap::G1CollectedHeap() :
11441144
_numa(G1NUMA::create()),
11451145
_hrm(),
11461146
_allocator(nullptr),
1147-
_evac_failure_injector(),
1147+
_allocation_failure_injector(),
11481148
_verifier(nullptr),
11491149
_summary_bytes_used(0),
11501150
_bytes_used_during_gc(0),
@@ -1432,7 +1432,7 @@ jint G1CollectedHeap::initialize() {
14321432

14331433
_collection_set.initialize(max_reserved_regions());
14341434

1435-
evac_failure_injector()->reset();
1435+
allocation_failure_injector()->reset();
14361436

14371437
CPUTimeCounters::create_counter(CPUTimeGroups::CPUTimeType::gc_parallel_workers);
14381438
CPUTimeCounters::create_counter(CPUTimeGroups::CPUTimeType::gc_conc_mark);
@@ -3002,9 +3002,6 @@ void G1CollectedHeap::unregister_nmethod(nmethod* nm) {
30023002

30033003
void G1CollectedHeap::update_used_after_gc(bool evacuation_failed) {
30043004
if (evacuation_failed) {
3005-
// Reset the G1EvacuationFailureALot counters and flags
3006-
evac_failure_injector()->reset();
3007-
30083005
set_used(recalculate_used());
30093006
} else {
30103007
// The "used" of the collection set have already been subtracted

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "gc/g1/g1MonotonicArenaFreePool.hpp"
4545
#include "gc/g1/g1NUMA.hpp"
4646
#include "gc/g1/g1SurvivorRegions.hpp"
47-
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
47+
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
4848
#include "gc/g1/heapRegionManager.hpp"
4949
#include "gc/g1/heapRegionSet.hpp"
5050
#include "gc/shared/barrierSet.hpp"
@@ -220,7 +220,7 @@ class G1CollectedHeap : public CollectedHeap {
220220
// Manages all allocations with regions except humongous object allocations.
221221
G1Allocator* _allocator;
222222

223-
G1YoungGCEvacFailureInjector _evac_failure_injector;
223+
G1YoungGCAllocationFailureInjector _allocation_failure_injector;
224224

225225
// Manages all heap verification.
226226
G1HeapVerifier* _verifier;
@@ -550,7 +550,7 @@ class G1CollectedHeap : public CollectedHeap {
550550
return _allocator;
551551
}
552552

553-
G1YoungGCEvacFailureInjector* evac_failure_injector() { return &_evac_failure_injector; }
553+
G1YoungGCAllocationFailureInjector* allocation_failure_injector() { return &_allocation_failure_injector; }
554554

555555
G1HeapVerifier* verifier() {
556556
return _verifier;

src/hotspot/share/gc/g1/g1ParScanThreadState.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "gc/g1/g1RootClosures.hpp"
3333
#include "gc/g1/g1StringDedup.hpp"
3434
#include "gc/g1/g1Trace.hpp"
35-
#include "gc/g1/g1YoungGCEvacFailureInjector.inline.hpp"
35+
#include "gc/g1/g1YoungGCAllocationFailureInjector.inline.hpp"
3636
#include "gc/shared/continuationGCSupport.inline.hpp"
3737
#include "gc/shared/partialArrayTaskStepper.inline.hpp"
3838
#include "gc/shared/preservedMarks.inline.hpp"
@@ -85,7 +85,7 @@ G1ParScanThreadState::G1ParScanThreadState(G1CollectedHeap* g1h,
8585
_max_num_optional_regions(collection_set->optional_region_length()),
8686
_numa(g1h->numa()),
8787
_obj_alloc_stat(nullptr),
88-
EVAC_FAILURE_INJECTOR_ONLY(_evac_failure_inject_counter(0) COMMA)
88+
ALLOCATION_FAILURE_INJECTOR_ONLY(_allocation_failure_inject_counter(0) COMMA)
8989
_preserved_marks(preserved_marks),
9090
_evacuation_failed_info(),
9191
_evac_failure_regions(evac_failure_regions),
@@ -427,9 +427,9 @@ HeapWord* G1ParScanThreadState::allocate_copy_slow(G1HeapRegionAttr* dest_attr,
427427
return obj_ptr;
428428
}
429429

430-
#if EVAC_FAILURE_INJECTOR
430+
#if ALLOCATION_FAILURE_INJECTOR
431431
bool G1ParScanThreadState::inject_allocation_failure(uint region_idx) {
432-
return _g1h->evac_failure_injector()->evacuation_should_fail(_evac_failure_inject_counter, region_idx);
432+
return _g1h->allocation_failure_injector()->allocation_should_fail(_allocation_failure_inject_counter, region_idx);
433433
}
434434
#endif
435435

src/hotspot/share/gc/g1/g1ParScanThreadState.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "gc/g1/g1CollectedHeap.hpp"
2929
#include "gc/g1/g1RedirtyCardsQueue.hpp"
3030
#include "gc/g1/g1OopClosures.hpp"
31-
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
31+
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
3232
#include "gc/g1/g1_globals.hpp"
3333
#include "gc/shared/ageTable.hpp"
3434
#include "gc/shared/copyFailedInfo.hpp"
@@ -104,7 +104,7 @@ class G1ParScanThreadState : public CHeapObj<mtGC> {
104104
size_t* _obj_alloc_stat;
105105

106106
// Per-thread evacuation failure data structures.
107-
EVAC_FAILURE_INJECTOR_ONLY(size_t _evac_failure_inject_counter;)
107+
ALLOCATION_FAILURE_INJECTOR_ONLY(size_t _allocation_failure_inject_counter;)
108108

109109
PreservedMarks* _preserved_marks;
110110
EvacuationFailedInfo _evacuation_failed_info;
@@ -120,7 +120,7 @@ class G1ParScanThreadState : public CHeapObj<mtGC> {
120120
// Enqueue the card of p into the (evacuation failed) region.
121121
template <class T> void enqueue_card_into_evac_fail_region(T* p, oop obj);
122122

123-
bool inject_allocation_failure(uint region_idx) EVAC_FAILURE_INJECTOR_RETURN_( return false; );
123+
bool inject_allocation_failure(uint region_idx) ALLOCATION_FAILURE_INJECTOR_RETURN_( return false; );
124124

125125
public:
126126
G1ParScanThreadState(G1CollectedHeap* g1h,

src/hotspot/share/gc/g1/g1YoungCollector.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "gc/g1/g1CollectorState.hpp"
3535
#include "gc/g1/g1ConcurrentMark.hpp"
3636
#include "gc/g1/g1GCPhaseTimes.hpp"
37-
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
3837
#include "gc/g1/g1EvacFailureRegions.inline.hpp"
3938
#include "gc/g1/g1EvacInfo.hpp"
4039
#include "gc/g1/g1HRPrinter.hpp"
@@ -46,6 +45,7 @@
4645
#include "gc/g1/g1RootProcessor.hpp"
4746
#include "gc/g1/g1Trace.hpp"
4847
#include "gc/g1/g1YoungCollector.hpp"
48+
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
4949
#include "gc/g1/g1YoungGCPostEvacuateTasks.hpp"
5050
#include "gc/g1/g1YoungGCPreEvacuateTasks.hpp"
5151
#include "gc/g1/g1_globals.hpp"
@@ -243,8 +243,8 @@ WorkerThreads* G1YoungCollector::workers() const {
243243
return _g1h->workers();
244244
}
245245

246-
G1YoungGCEvacFailureInjector* G1YoungCollector::evac_failure_injector() const {
247-
return _g1h->evac_failure_injector();
246+
G1YoungGCAllocationFailureInjector* G1YoungCollector::allocation_failure_injector() const {
247+
return _g1h->allocation_failure_injector();
248248
}
249249

250250

@@ -534,7 +534,7 @@ void G1YoungCollector::pre_evacuate_collection_set(G1EvacInfo* evacuation_info)
534534
DerivedPointerTable::clear();
535535
#endif
536536

537-
evac_failure_injector()->arm_if_needed();
537+
allocation_failure_injector()->arm_if_needed();
538538
}
539539

540540
class G1ParEvacuateFollowersClosure : public VoidClosure {

src/hotspot/share/gc/g1/g1YoungCollector.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define SHARE_GC_G1_G1YOUNGCOLLECTOR_HPP
2727

2828
#include "gc/g1/g1EvacFailureRegions.hpp"
29-
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
29+
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
3030
#include "gc/shared/gcCause.hpp"
3131
#include "gc/shared/taskqueue.hpp"
3232

@@ -49,7 +49,7 @@ class G1Policy;
4949
class G1RedirtyCardsQueueSet;
5050
class G1RemSet;
5151
class G1SurvivorRegions;
52-
class G1YoungGCEvacFailureInjector;
52+
class G1YoungGCAllocationFailureInjector;
5353
class STWGCTimer;
5454
class WorkerThreads;
5555

@@ -78,7 +78,7 @@ class G1YoungCollector {
7878
G1SurvivorRegions* survivor_regions() const;
7979
ReferenceProcessor* ref_processor_stw() const;
8080
WorkerThreads* workers() const;
81-
G1YoungGCEvacFailureInjector* evac_failure_injector() const;
81+
G1YoungGCAllocationFailureInjector* allocation_failure_injector() const;
8282

8383
GCCause::Cause _gc_cause;
8484

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#include "precompiled.hpp"
26+
27+
#include "gc/g1/g1CollectedHeap.inline.hpp"
28+
#include "gc/g1/g1YoungGCAllocationFailureInjector.inline.hpp"
29+
#include "gc/g1/g1_globals.hpp"
30+
31+
#if ALLOCATION_FAILURE_INJECTOR
32+
33+
class SelectAllocationFailureRegionClosure : public HeapRegionClosure {
34+
CHeapBitMap& _allocation_failure_regions;
35+
size_t _allocation_failure_regions_num;
36+
37+
public:
38+
SelectAllocationFailureRegionClosure(CHeapBitMap& allocation_failure_regions, size_t cset_length) :
39+
_allocation_failure_regions(allocation_failure_regions),
40+
_allocation_failure_regions_num(cset_length * G1GCAllocationFailureALotCSetPercent / 100) { }
41+
42+
bool do_heap_region(HeapRegion* r) override {
43+
assert(r->in_collection_set(), "must be");
44+
if (_allocation_failure_regions_num > 0) {
45+
_allocation_failure_regions.set_bit(r->hrm_index());
46+
--_allocation_failure_regions_num;
47+
}
48+
return _allocation_failure_regions_num == 0;
49+
}
50+
};
51+
52+
G1YoungGCAllocationFailureInjector::G1YoungGCAllocationFailureInjector()
53+
: _inject_allocation_failure_for_current_gc(),
54+
_last_collection_with_allocation_failure(),
55+
_allocation_failure_regions(mtGC) {}
56+
57+
void G1YoungGCAllocationFailureInjector::select_allocation_failure_regions() {
58+
G1CollectedHeap* g1h = G1CollectedHeap::heap();
59+
_allocation_failure_regions.reinitialize(g1h->max_reserved_regions());
60+
SelectAllocationFailureRegionClosure closure(_allocation_failure_regions, g1h->collection_set()->cur_length());
61+
g1h->collection_set_iterate_all(&closure);
62+
}
63+
64+
bool G1YoungGCAllocationFailureInjector::arm_if_needed_for_gc_type(bool for_young_only_phase,
65+
bool during_concurrent_start,
66+
bool mark_or_rebuild_in_progress) {
67+
bool res = false;
68+
if (mark_or_rebuild_in_progress) {
69+
res |= G1GCAllocationFailureALotDuringConcMark;
70+
}
71+
if (during_concurrent_start) {
72+
res |= G1GCAllocationFailureALotDuringConcurrentStart;
73+
}
74+
if (for_young_only_phase) {
75+
res |= G1GCAllocationFailureALotDuringYoungGC;
76+
} else {
77+
// GCs are mixed
78+
res |= G1GCAllocationFailureALotDuringMixedGC;
79+
}
80+
return res;
81+
}
82+
83+
void G1YoungGCAllocationFailureInjector::arm_if_needed() {
84+
if (G1GCAllocationFailureALot) {
85+
G1CollectedHeap* g1h = G1CollectedHeap::heap();
86+
// Check if we have gone over the interval.
87+
const size_t gc_num = g1h->total_collections();
88+
const size_t elapsed_gcs = gc_num - _last_collection_with_allocation_failure;
89+
90+
_inject_allocation_failure_for_current_gc = (elapsed_gcs >= G1GCAllocationFailureALotInterval);
91+
92+
// Now check if evacuation failure injection should be enabled for the current GC.
93+
G1CollectorState* collector_state = g1h->collector_state();
94+
const bool in_young_only_phase = collector_state->in_young_only_phase();
95+
const bool in_concurrent_start_gc = collector_state->in_concurrent_start_gc();
96+
const bool mark_or_rebuild_in_progress = collector_state->mark_or_rebuild_in_progress();
97+
98+
_inject_allocation_failure_for_current_gc &=
99+
arm_if_needed_for_gc_type(in_young_only_phase,
100+
in_concurrent_start_gc,
101+
mark_or_rebuild_in_progress);
102+
103+
if (_inject_allocation_failure_for_current_gc) {
104+
select_allocation_failure_regions();
105+
}
106+
}
107+
}
108+
109+
void G1YoungGCAllocationFailureInjector::reset() {
110+
_last_collection_with_allocation_failure = G1CollectedHeap::heap()->total_collections();
111+
_inject_allocation_failure_for_current_gc = false;
112+
}
113+
114+
#endif // #if ALLOCATION_FAILURE_INJECTOR
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#ifndef SHARE_GC_G1_G1YOUNGGCALLOCATIONFAILUREINJECTOR_HPP
26+
#define SHARE_GC_G1_G1YOUNGGCALLOCATIONFAILUREINJECTOR_HPP
27+
28+
#include "gc/g1/g1_globals.hpp"
29+
#include "memory/allStatic.hpp"
30+
#include "utilities/globalDefinitions.hpp"
31+
32+
#if ALLOCATION_FAILURE_INJECTOR
33+
#define ALLOCATION_FAILURE_INJECTOR_RETURN
34+
#define ALLOCATION_FAILURE_INJECTOR_RETURN_(code)
35+
#define ALLOCATION_FAILURE_INJECTOR_ONLY(code) code
36+
#else
37+
#define ALLOCATION_FAILURE_INJECTOR_RETURN { return; }
38+
#define ALLOCATION_FAILURE_INJECTOR_RETURN_(code) { code }
39+
#define ALLOCATION_FAILURE_INJECTOR_ONLY(code)
40+
#endif // ALLOCATION_FAILURE_INJECTOR
41+
42+
// Support for injecting allocation failures based on the G1GCAllocationFailureALot*
43+
// flags. Analogous to PromotionFailureALot for the other collectors.
44+
//
45+
// Every G1GCAllocationFailureALotInterval collections without evacuation failure
46+
// in between we "arm" the injector to induce allocation failures after
47+
// G1GCAllocationFailureALotCount successful evacuations.
48+
//
49+
// Available only when ALLOCATION_FAILURE_INJECTOR is defined.
50+
class G1YoungGCAllocationFailureInjector {
51+
#if ALLOCATION_FAILURE_INJECTOR
52+
// Should we inject evacuation failures in the current GC.
53+
bool _inject_allocation_failure_for_current_gc;
54+
55+
// Records the number of the last collection when allocation failure happened.
56+
// Used to determine whether allocation failure injection should be in effect
57+
// for the current GC.
58+
size_t _last_collection_with_allocation_failure;
59+
60+
// Records the regions that will fail evacuation.
61+
CHeapBitMap _allocation_failure_regions;
62+
#endif
63+
64+
bool arm_if_needed_for_gc_type(bool for_young_only_phase,
65+
bool during_concurrent_start,
66+
bool mark_or_rebuild_in_progress) ALLOCATION_FAILURE_INJECTOR_RETURN_( return false; );
67+
68+
// Selects the regions that will fail allocation by G1GCAllocationFailureALotCSetPercent.
69+
void select_allocation_failure_regions() ALLOCATION_FAILURE_INJECTOR_RETURN;
70+
public:
71+
72+
G1YoungGCAllocationFailureInjector() ALLOCATION_FAILURE_INJECTOR_RETURN;
73+
74+
// Arm the allocation failure injector if needed for the current
75+
// GC (based upon the type of GC and which command line flags are set);
76+
void arm_if_needed() ALLOCATION_FAILURE_INJECTOR_RETURN;
77+
78+
// Return true if it's time to cause an allocation failure; the caller
79+
// provides the (preferably thread-local) counter to minimize performance impact.
80+
bool allocation_should_fail(size_t& counter, uint region_idx) ALLOCATION_FAILURE_INJECTOR_RETURN_( return false; );
81+
82+
// Reset the allocation failure injection counters. Should be called at
83+
// the end of an evacuation pause in which an allocation failure occurred.
84+
void reset() ALLOCATION_FAILURE_INJECTOR_RETURN;
85+
};
86+
87+
#endif /* SHARE_GC_G1_G1YOUNGGCALLOCATIONFAILUREINJECTOR_HPP */

0 commit comments

Comments
 (0)