8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
Summary: Move class specific code to the helper method
Reviewed-by: kbarrett, tschatzl
--- a/hotspot/src/share/vm/gc/g1/g1EvacStats.cpp Fri Feb 24 12:41:26 2017 -0500
+++ b/hotspot/src/share/vm/gc/g1/g1EvacStats.cpp Thu Feb 23 12:50:49 2017 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -46,29 +46,7 @@
_failure_waste * HeapWordSize);
}
-void G1EvacStats::adjust_desired_plab_sz() {
- log_plab_allocation();
-
- if (!ResizePLAB) {
- // Clear accumulators for next round.
- reset();
- return;
- }
-
- assert(is_object_aligned(max_size()) && min_size() <= max_size(),
- "PLAB clipping computation may be incorrect");
-
- if (_allocated == 0) {
- assert((_unused == 0),
- "Inconsistency in PLAB stats: "
- "_allocated: " SIZE_FORMAT ", "
- "_wasted: " SIZE_FORMAT ", "
- "_region_end_waste: " SIZE_FORMAT ", "
- "_unused: " SIZE_FORMAT ", "
- "_used : " SIZE_FORMAT,
- _allocated, _wasted, _region_end_waste, _unused, used());
- _allocated = 1;
- }
+size_t G1EvacStats::compute_desired_plab_sz() {
// The size of the PLAB caps the amount of space that can be wasted at the
// end of the collection. In the worst case the last PLAB could be completely
// empty.
@@ -109,13 +87,7 @@
size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct;
size_t const cur_plab_sz = (size_t)((double)total_waste_allowed / G1LastPLABAverageOccupancy);
- // Take historical weighted average
- _filter.sample(cur_plab_sz);
- _desired_net_plab_sz = MAX2(min_size(), (size_t)_filter.average());
-
- log_sizing(cur_plab_sz, _desired_net_plab_sz);
- // Clear accumulators for next round.
- reset();
+ return cur_plab_sz;
}
G1EvacStats::G1EvacStats(const char* description, size_t desired_plab_sz_, unsigned wt) :
--- a/hotspot/src/share/vm/gc/g1/g1EvacStats.hpp Fri Feb 24 12:41:26 2017 -0500
+++ b/hotspot/src/share/vm/gc/g1/g1EvacStats.hpp Thu Feb 23 12:50:49 2017 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -53,13 +53,13 @@
virtual void log_plab_allocation();
+ virtual size_t compute_desired_plab_sz();
+
public:
G1EvacStats(const char* description, size_t desired_plab_sz_, unsigned wt);
~G1EvacStats();
- virtual void adjust_desired_plab_sz();
-
uint regions_filled() const { return _regions_filled; }
size_t region_end_waste() const { return _region_end_waste; }
size_t direct_allocated() const { return _direct_allocated; }
--- a/hotspot/src/share/vm/gc/shared/plab.cpp Fri Feb 24 12:41:26 2017 -0500
+++ b/hotspot/src/share/vm/gc/shared/plab.cpp Thu Feb 23 12:50:49 2017 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, 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
@@ -154,30 +154,33 @@
assert(is_object_aligned(max_size()) && min_size() <= max_size(),
"PLAB clipping computation may be incorrect");
- if (_allocated == 0) {
- assert(_unused == 0,
- "Inconsistency in PLAB stats: "
- "_allocated: " SIZE_FORMAT ", "
- "_wasted: " SIZE_FORMAT ", "
- "_unused: " SIZE_FORMAT ", "
- "_undo_wasted: " SIZE_FORMAT,
- _allocated, _wasted, _unused, _undo_wasted);
+ assert(_allocated != 0 || _unused == 0,
+ "Inconsistency in PLAB stats: "
+ "_allocated: " SIZE_FORMAT ", "
+ "_wasted: " SIZE_FORMAT ", "
+ "_unused: " SIZE_FORMAT ", "
+ "_undo_wasted: " SIZE_FORMAT,
+ _allocated, _wasted, _unused, _undo_wasted);
- _allocated = 1;
- }
- double wasted_frac = (double)_unused / (double)_allocated;
+ size_t plab_sz = compute_desired_plab_sz();
+ // Take historical weighted average
+ _filter.sample(plab_sz);
+ _desired_net_plab_sz = MAX2(min_size(), (size_t)_filter.average());
+
+ log_sizing(plab_sz, _desired_net_plab_sz);
+ // Clear accumulators for next round
+ reset();
+}
+
+size_t PLABStats::compute_desired_plab_sz() {
+ size_t allocated = MAX2(_allocated, size_t(1));
+ double wasted_frac = (double)_unused / (double)allocated;
size_t target_refills = (size_t)((wasted_frac * TargetSurvivorRatio) / TargetPLABWastePct);
if (target_refills == 0) {
target_refills = 1;
}
- size_t used = _allocated - _wasted - _unused;
+ size_t used = allocated - _wasted - _unused;
// Assumed to have 1 gc worker thread
size_t recent_plab_sz = used / target_refills;
- // Take historical weighted average
- _filter.sample(recent_plab_sz);
- _desired_net_plab_sz = MAX2(min_size(), (size_t)_filter.average());
-
- log_sizing(recent_plab_sz, _desired_net_plab_sz);
-
- reset();
+ return recent_plab_sz;
}
--- a/hotspot/src/share/vm/gc/shared/plab.hpp Fri Feb 24 12:41:26 2017 -0500
+++ b/hotspot/src/share/vm/gc/shared/plab.hpp Thu Feb 23 12:50:49 2017 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, 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
@@ -165,6 +165,10 @@
virtual void log_plab_allocation();
virtual void log_sizing(size_t calculated, size_t net_desired);
+
+ // helper for adjust_desired_plab_sz().
+ virtual size_t compute_desired_plab_sz();
+
public:
PLABStats(const char* description, size_t desired_net_plab_sz_, unsigned wt) :
_description(description),
@@ -197,7 +201,7 @@
// Updates the current desired PLAB size. Computes the new desired PLAB size with one gc worker thread,
// updates _desired_plab_sz and clears sensor accumulators.
- virtual void adjust_desired_plab_sz();
+ void adjust_desired_plab_sz();
inline void add_allocated(size_t v);