Skip to content

Commit db23ecd

Browse files
author
Thomas Schatzl
committed
8274191: Improve g1 evacuation failure injector performance
Reviewed-by: kbarrett, ayang
1 parent d91e227 commit db23ecd

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ G1ParScanThreadState::G1ParScanThreadState(G1CollectedHeap* g1h,
8585
_num_optional_regions(optional_cset_length),
8686
_numa(g1h->numa()),
8787
_obj_alloc_stat(NULL),
88+
NOT_PRODUCT(_evac_failure_inject_counter(0) COMMA)
8889
_preserved_marks(preserved_marks),
8990
_evacuation_failed_info(),
9091
_evac_failure_regions(evac_failure_regions)
@@ -414,6 +415,12 @@ HeapWord* G1ParScanThreadState::allocate_copy_slow(G1HeapRegionAttr* dest_attr,
414415
return obj_ptr;
415416
}
416417

418+
#ifndef PRODUCT
419+
bool G1ParScanThreadState::inject_evacuation_failure() {
420+
return _g1h->evac_failure_injector()->evacuation_should_fail(_evac_failure_inject_counter);
421+
}
422+
#endif
423+
417424
NOINLINE
418425
void G1ParScanThreadState::undo_allocation(G1HeapRegionAttr dest_attr,
419426
HeapWord* obj_ptr,
@@ -458,7 +465,7 @@ oop G1ParScanThreadState::do_copy_to_survivor_space(G1HeapRegionAttr const regio
458465
assert(_g1h->is_in_reserved(obj_ptr), "Allocated memory should be in the heap");
459466

460467
// Should this evacuation fail?
461-
if (_g1h->evac_failure_injector()->evacuation_should_fail()) {
468+
if (inject_evacuation_failure()) {
462469
// Doing this after all the allocation attempts also tests the
463470
// undo_allocation() method too.
464471
undo_allocation(dest_attr, obj_ptr, word_sz, node_index);
@@ -515,7 +522,6 @@ oop G1ParScanThreadState::do_copy_to_survivor_space(G1HeapRegionAttr const regio
515522
G1SkipCardEnqueueSetter x(&_scanner, dest_attr.is_young());
516523
obj->oop_iterate_backwards(&_scanner, klass);
517524
return obj;
518-
519525
} else {
520526
_plab_allocator->undo_allocation(dest_attr, obj_ptr, word_sz, node_index);
521527
return forward_ptr;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,15 @@ class G1ParScanThreadState : public CHeapObj<mtGC> {
9898
size_t* _obj_alloc_stat;
9999

100100
// Per-thread evacuation failure data structures.
101+
#ifndef PRODUCT
102+
size_t _evac_failure_inject_counter;
103+
#endif
101104
PreservedMarks* _preserved_marks;
102105
EvacuationFailedInfo _evacuation_failed_info;
103106
G1EvacFailureRegions* _evac_failure_regions;
104107

108+
bool inject_evacuation_failure() PRODUCT_RETURN_( return false; );
109+
105110
public:
106111
G1ParScanThreadState(G1CollectedHeap* g1h,
107112
G1RedirtyCardsQueueSet* rdcqs,

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,8 @@ void G1YoungGCEvacFailureInjector::arm_if_needed() {
7272
}
7373

7474
void G1YoungGCEvacFailureInjector::reset() {
75-
if (G1EvacuationFailureALot) {
76-
_last_collection_with_evacuation_failure = G1CollectedHeap::heap()->total_collections();
77-
_evacuation_failure_object_count = 0;
78-
_inject_evacuation_failure_for_current_gc = false;
79-
}
75+
_last_collection_with_evacuation_failure = G1CollectedHeap::heap()->total_collections();
76+
_inject_evacuation_failure_for_current_gc = false;
8077
}
8178

8279
#endif // #ifndef PRODUCT

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ class G1YoungGCEvacFailureInjector {
4545
// Used to determine whether evacuation failure injection should be in effect
4646
// for the current GC.
4747
size_t _last_collection_with_evacuation_failure;
48-
49-
// The number of evacuations between induced failures.
50-
volatile size_t _evacuation_failure_object_count;
5148
#endif
5249

5350
bool arm_if_needed_for_gc_type(bool for_young_gc,
@@ -59,8 +56,9 @@ class G1YoungGCEvacFailureInjector {
5956
// GC (based upon the type of GC and which command line flags are set);
6057
void arm_if_needed() PRODUCT_RETURN;
6158

62-
// Return true if it's time to cause an evacuation failure.
63-
bool evacuation_should_fail() PRODUCT_RETURN_( return false; );
59+
// Return true if it's time to cause an evacuation failure; the caller
60+
// provides the (preferably thread-local) counter to minimize performance impact.
61+
bool evacuation_should_fail(size_t& counter) PRODUCT_RETURN_( return false; );
6462

6563
// Reset the evacuation failure injection counters. Should be called at
6664
// the end of an evacuation pause in which an evacuation failure occurred.

src/hotspot/share/gc/g1/g1YoungGCEvacFailureInjector.inline.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,21 @@
2525
#ifndef SHARE_GC_G1_G1YOUNGGCEVACUATIONFAILUREINJECTOR_INLINE_HPP
2626
#define SHARE_GC_G1_G1YOUNGGCEVACUATIONFAILUREINJECTOR_INLINE_HPP
2727

28+
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
29+
2830
#include "gc/g1/g1_globals.hpp"
2931
#include "gc/g1/g1CollectedHeap.inline.hpp"
30-
#include "gc/g1/g1YoungGCEvacFailureInjector.hpp"
3132

3233
#ifndef PRODUCT
3334

34-
inline bool G1YoungGCEvacFailureInjector::evacuation_should_fail() {
35-
if (!G1EvacuationFailureALot || !_inject_evacuation_failure_for_current_gc) {
35+
inline bool G1YoungGCEvacFailureInjector::evacuation_should_fail(size_t& counter) {
36+
if (!_inject_evacuation_failure_for_current_gc) {
3637
return false;
3738
}
38-
// Injecting evacuation failures is in effect for current GC
39-
// Access to _evacuation_failure_alot_count is not atomic;
40-
// the value does not have to be exact.
41-
if (++_evacuation_failure_object_count < G1EvacuationFailureALotCount) {
39+
if (++counter < G1EvacuationFailureALotCount) {
4240
return false;
4341
}
44-
_evacuation_failure_object_count = 0;
42+
counter = 0;
4543
return true;
4644
}
4745

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
\
276276
develop(uintx, G1EvacuationFailureALotCount, 1000, \
277277
"Number of successful evacuations between evacuation failures " \
278-
"occurring at object copying") \
278+
"occurring at object copying per thread") \
279279
\
280280
develop(uintx, G1EvacuationFailureALotInterval, 5, \
281281
"Total collections between forced triggering of evacuation " \

0 commit comments

Comments
 (0)