Skip to content

Commit

Permalink
8319313: G1: Rename G1EvacFailureInjector appropriately
Browse files Browse the repository at this point in the history
Reviewed-by: mli, iwalulya, ayang
  • Loading branch information
Thomas Schatzl committed Dec 7, 2023
1 parent a7f6016 commit 86f9b3f
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 289 deletions.
9 changes: 3 additions & 6 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#include "gc/g1/g1UncommitRegionTask.hpp"
#include "gc/g1/g1VMOperations.hpp"
#include "gc/g1/g1YoungCollector.hpp"
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
#include "gc/g1/heapRegion.inline.hpp"
#include "gc/g1/heapRegionRemSet.inline.hpp"
#include "gc/g1/heapRegionSet.inline.hpp"
Expand Down Expand Up @@ -1144,7 +1144,7 @@ G1CollectedHeap::G1CollectedHeap() :
_numa(G1NUMA::create()),
_hrm(),
_allocator(nullptr),
_evac_failure_injector(),
_allocation_failure_injector(),
_verifier(nullptr),
_summary_bytes_used(0),
_bytes_used_during_gc(0),
Expand Down Expand Up @@ -1432,7 +1432,7 @@ jint G1CollectedHeap::initialize() {

_collection_set.initialize(max_reserved_regions());

evac_failure_injector()->reset();
allocation_failure_injector()->reset();

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

void G1CollectedHeap::update_used_after_gc(bool evacuation_failed) {
if (evacuation_failed) {
// Reset the G1EvacuationFailureALot counters and flags
evac_failure_injector()->reset();

set_used(recalculate_used());
} else {
// The "used" of the collection set have already been subtracted
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/gc/g1/g1CollectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "gc/g1/g1MonotonicArenaFreePool.hpp"
#include "gc/g1/g1NUMA.hpp"
#include "gc/g1/g1SurvivorRegions.hpp"
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
#include "gc/g1/heapRegionManager.hpp"
#include "gc/g1/heapRegionSet.hpp"
#include "gc/shared/barrierSet.hpp"
Expand Down Expand Up @@ -220,7 +220,7 @@ class G1CollectedHeap : public CollectedHeap {
// Manages all allocations with regions except humongous object allocations.
G1Allocator* _allocator;

G1YoungGCEvacFailureInjector _evac_failure_injector;
G1YoungGCAllocationFailureInjector _allocation_failure_injector;

// Manages all heap verification.
G1HeapVerifier* _verifier;
Expand Down Expand Up @@ -550,7 +550,7 @@ class G1CollectedHeap : public CollectedHeap {
return _allocator;
}

G1YoungGCEvacFailureInjector* evac_failure_injector() { return &_evac_failure_injector; }
G1YoungGCAllocationFailureInjector* allocation_failure_injector() { return &_allocation_failure_injector; }

G1HeapVerifier* verifier() {
return _verifier;
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/gc/g1/g1ParScanThreadState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "gc/g1/g1RootClosures.hpp"
#include "gc/g1/g1StringDedup.hpp"
#include "gc/g1/g1Trace.hpp"
#include "gc/g1/g1YoungGCEvacFailureInjector.inline.hpp"
#include "gc/g1/g1YoungGCAllocationFailureInjector.inline.hpp"
#include "gc/shared/continuationGCSupport.inline.hpp"
#include "gc/shared/partialArrayTaskStepper.inline.hpp"
#include "gc/shared/preservedMarks.inline.hpp"
Expand Down Expand Up @@ -85,7 +85,7 @@ G1ParScanThreadState::G1ParScanThreadState(G1CollectedHeap* g1h,
_max_num_optional_regions(collection_set->optional_region_length()),
_numa(g1h->numa()),
_obj_alloc_stat(nullptr),
EVAC_FAILURE_INJECTOR_ONLY(_evac_failure_inject_counter(0) COMMA)
ALLOCATION_FAILURE_INJECTOR_ONLY(_allocation_failure_inject_counter(0) COMMA)
_preserved_marks(preserved_marks),
_evacuation_failed_info(),
_evac_failure_regions(evac_failure_regions),
Expand Down Expand Up @@ -427,9 +427,9 @@ HeapWord* G1ParScanThreadState::allocate_copy_slow(G1HeapRegionAttr* dest_attr,
return obj_ptr;
}

#if EVAC_FAILURE_INJECTOR
#if ALLOCATION_FAILURE_INJECTOR
bool G1ParScanThreadState::inject_allocation_failure(uint region_idx) {
return _g1h->evac_failure_injector()->evacuation_should_fail(_evac_failure_inject_counter, region_idx);
return _g1h->allocation_failure_injector()->allocation_should_fail(_allocation_failure_inject_counter, region_idx);
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/gc/g1/g1ParScanThreadState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "gc/g1/g1CollectedHeap.hpp"
#include "gc/g1/g1RedirtyCardsQueue.hpp"
#include "gc/g1/g1OopClosures.hpp"
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
#include "gc/g1/g1_globals.hpp"
#include "gc/shared/ageTable.hpp"
#include "gc/shared/copyFailedInfo.hpp"
Expand Down Expand Up @@ -104,7 +104,7 @@ class G1ParScanThreadState : public CHeapObj<mtGC> {
size_t* _obj_alloc_stat;

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

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

bool inject_allocation_failure(uint region_idx) EVAC_FAILURE_INJECTOR_RETURN_( return false; );
bool inject_allocation_failure(uint region_idx) ALLOCATION_FAILURE_INJECTOR_RETURN_( return false; );

public:
G1ParScanThreadState(G1CollectedHeap* g1h,
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/gc/g1/g1YoungCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "gc/g1/g1CollectorState.hpp"
#include "gc/g1/g1ConcurrentMark.hpp"
#include "gc/g1/g1GCPhaseTimes.hpp"
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
#include "gc/g1/g1EvacFailureRegions.inline.hpp"
#include "gc/g1/g1EvacInfo.hpp"
#include "gc/g1/g1HRPrinter.hpp"
Expand All @@ -46,6 +45,7 @@
#include "gc/g1/g1RootProcessor.hpp"
#include "gc/g1/g1Trace.hpp"
#include "gc/g1/g1YoungCollector.hpp"
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
#include "gc/g1/g1YoungGCPostEvacuateTasks.hpp"
#include "gc/g1/g1YoungGCPreEvacuateTasks.hpp"
#include "gc/g1/g1_globals.hpp"
Expand Down Expand Up @@ -243,8 +243,8 @@ WorkerThreads* G1YoungCollector::workers() const {
return _g1h->workers();
}

G1YoungGCEvacFailureInjector* G1YoungCollector::evac_failure_injector() const {
return _g1h->evac_failure_injector();
G1YoungGCAllocationFailureInjector* G1YoungCollector::allocation_failure_injector() const {
return _g1h->allocation_failure_injector();
}


Expand Down Expand Up @@ -534,7 +534,7 @@ void G1YoungCollector::pre_evacuate_collection_set(G1EvacInfo* evacuation_info)
DerivedPointerTable::clear();
#endif

evac_failure_injector()->arm_if_needed();
allocation_failure_injector()->arm_if_needed();
}

class G1ParEvacuateFollowersClosure : public VoidClosure {
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/gc/g1/g1YoungCollector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define SHARE_GC_G1_G1YOUNGCOLLECTOR_HPP

#include "gc/g1/g1EvacFailureRegions.hpp"
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
#include "gc/g1/g1YoungGCAllocationFailureInjector.hpp"
#include "gc/shared/gcCause.hpp"
#include "gc/shared/taskqueue.hpp"

Expand All @@ -49,7 +49,7 @@ class G1Policy;
class G1RedirtyCardsQueueSet;
class G1RemSet;
class G1SurvivorRegions;
class G1YoungGCEvacFailureInjector;
class G1YoungGCAllocationFailureInjector;
class STWGCTimer;
class WorkerThreads;

Expand Down Expand Up @@ -78,7 +78,7 @@ class G1YoungCollector {
G1SurvivorRegions* survivor_regions() const;
ReferenceProcessor* ref_processor_stw() const;
WorkerThreads* workers() const;
G1YoungGCEvacFailureInjector* evac_failure_injector() const;
G1YoungGCAllocationFailureInjector* allocation_failure_injector() const;

GCCause::Cause _gc_cause;

Expand Down
114 changes: 114 additions & 0 deletions src/hotspot/share/gc/g1/g1YoungGCAllocationFailureInjector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

#include "precompiled.hpp"

#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1YoungGCAllocationFailureInjector.inline.hpp"
#include "gc/g1/g1_globals.hpp"

#if ALLOCATION_FAILURE_INJECTOR

class SelectAllocationFailureRegionClosure : public HeapRegionClosure {
CHeapBitMap& _allocation_failure_regions;
size_t _allocation_failure_regions_num;

public:
SelectAllocationFailureRegionClosure(CHeapBitMap& allocation_failure_regions, size_t cset_length) :
_allocation_failure_regions(allocation_failure_regions),
_allocation_failure_regions_num(cset_length * G1GCAllocationFailureALotCSetPercent / 100) { }

bool do_heap_region(HeapRegion* r) override {
assert(r->in_collection_set(), "must be");
if (_allocation_failure_regions_num > 0) {
_allocation_failure_regions.set_bit(r->hrm_index());
--_allocation_failure_regions_num;
}
return _allocation_failure_regions_num == 0;
}
};

G1YoungGCAllocationFailureInjector::G1YoungGCAllocationFailureInjector()
: _inject_allocation_failure_for_current_gc(),
_last_collection_with_allocation_failure(),
_allocation_failure_regions(mtGC) {}

void G1YoungGCAllocationFailureInjector::select_allocation_failure_regions() {
G1CollectedHeap* g1h = G1CollectedHeap::heap();
_allocation_failure_regions.reinitialize(g1h->max_reserved_regions());
SelectAllocationFailureRegionClosure closure(_allocation_failure_regions, g1h->collection_set()->cur_length());
g1h->collection_set_iterate_all(&closure);
}

bool G1YoungGCAllocationFailureInjector::arm_if_needed_for_gc_type(bool for_young_only_phase,
bool during_concurrent_start,
bool mark_or_rebuild_in_progress) {
bool res = false;
if (mark_or_rebuild_in_progress) {
res |= G1GCAllocationFailureALotDuringConcMark;
}
if (during_concurrent_start) {
res |= G1GCAllocationFailureALotDuringConcurrentStart;
}
if (for_young_only_phase) {
res |= G1GCAllocationFailureALotDuringYoungGC;
} else {
// GCs are mixed
res |= G1GCAllocationFailureALotDuringMixedGC;
}
return res;
}

void G1YoungGCAllocationFailureInjector::arm_if_needed() {
if (G1GCAllocationFailureALot) {
G1CollectedHeap* g1h = G1CollectedHeap::heap();
// Check if we have gone over the interval.
const size_t gc_num = g1h->total_collections();
const size_t elapsed_gcs = gc_num - _last_collection_with_allocation_failure;

_inject_allocation_failure_for_current_gc = (elapsed_gcs >= G1GCAllocationFailureALotInterval);

// Now check if evacuation failure injection should be enabled for the current GC.
G1CollectorState* collector_state = g1h->collector_state();
const bool in_young_only_phase = collector_state->in_young_only_phase();
const bool in_concurrent_start_gc = collector_state->in_concurrent_start_gc();
const bool mark_or_rebuild_in_progress = collector_state->mark_or_rebuild_in_progress();

_inject_allocation_failure_for_current_gc &=
arm_if_needed_for_gc_type(in_young_only_phase,
in_concurrent_start_gc,
mark_or_rebuild_in_progress);

if (_inject_allocation_failure_for_current_gc) {
select_allocation_failure_regions();
}
}
}

void G1YoungGCAllocationFailureInjector::reset() {
_last_collection_with_allocation_failure = G1CollectedHeap::heap()->total_collections();
_inject_allocation_failure_for_current_gc = false;
}

#endif // #if ALLOCATION_FAILURE_INJECTOR
87 changes: 87 additions & 0 deletions src/hotspot/share/gc/g1/g1YoungGCAllocationFailureInjector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

#ifndef SHARE_GC_G1_G1YOUNGGCALLOCATIONFAILUREINJECTOR_HPP
#define SHARE_GC_G1_G1YOUNGGCALLOCATIONFAILUREINJECTOR_HPP

#include "gc/g1/g1_globals.hpp"
#include "memory/allStatic.hpp"
#include "utilities/globalDefinitions.hpp"

#if ALLOCATION_FAILURE_INJECTOR
#define ALLOCATION_FAILURE_INJECTOR_RETURN
#define ALLOCATION_FAILURE_INJECTOR_RETURN_(code)
#define ALLOCATION_FAILURE_INJECTOR_ONLY(code) code
#else
#define ALLOCATION_FAILURE_INJECTOR_RETURN { return; }
#define ALLOCATION_FAILURE_INJECTOR_RETURN_(code) { code }
#define ALLOCATION_FAILURE_INJECTOR_ONLY(code)
#endif // ALLOCATION_FAILURE_INJECTOR

// Support for injecting allocation failures based on the G1GCAllocationFailureALot*
// flags. Analogous to PromotionFailureALot for the other collectors.
//
// Every G1GCAllocationFailureALotInterval collections without evacuation failure
// in between we "arm" the injector to induce allocation failures after
// G1GCAllocationFailureALotCount successful evacuations.
//
// Available only when ALLOCATION_FAILURE_INJECTOR is defined.
class G1YoungGCAllocationFailureInjector {
#if ALLOCATION_FAILURE_INJECTOR
// Should we inject evacuation failures in the current GC.
bool _inject_allocation_failure_for_current_gc;

// Records the number of the last collection when allocation failure happened.
// Used to determine whether allocation failure injection should be in effect
// for the current GC.
size_t _last_collection_with_allocation_failure;

// Records the regions that will fail evacuation.
CHeapBitMap _allocation_failure_regions;
#endif

bool arm_if_needed_for_gc_type(bool for_young_only_phase,
bool during_concurrent_start,
bool mark_or_rebuild_in_progress) ALLOCATION_FAILURE_INJECTOR_RETURN_( return false; );

// Selects the regions that will fail allocation by G1GCAllocationFailureALotCSetPercent.
void select_allocation_failure_regions() ALLOCATION_FAILURE_INJECTOR_RETURN;
public:

G1YoungGCAllocationFailureInjector() ALLOCATION_FAILURE_INJECTOR_RETURN;

// Arm the allocation failure injector if needed for the current
// GC (based upon the type of GC and which command line flags are set);
void arm_if_needed() ALLOCATION_FAILURE_INJECTOR_RETURN;

// Return true if it's time to cause an allocation failure; the caller
// provides the (preferably thread-local) counter to minimize performance impact.
bool allocation_should_fail(size_t& counter, uint region_idx) ALLOCATION_FAILURE_INJECTOR_RETURN_( return false; );

// Reset the allocation failure injection counters. Should be called at
// the end of an evacuation pause in which an allocation failure occurred.
void reset() ALLOCATION_FAILURE_INJECTOR_RETURN;
};

#endif /* SHARE_GC_G1_G1YOUNGGCALLOCATIONFAILUREINJECTOR_HPP */
Loading

0 comments on commit 86f9b3f

Please sign in to comment.