Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8311978: Shenandoah: Create abstraction over heap metrics for heuristics #14856

Closed
Original file line number Diff line number Diff line change
@@ -54,8 +54,8 @@ const double ShenandoahAdaptiveHeuristics::HIGHEST_EXPECTED_AVAILABLE_AT_END = 0
const double ShenandoahAdaptiveHeuristics::MINIMUM_CONFIDENCE = 0.319; // 25%
const double ShenandoahAdaptiveHeuristics::MAXIMUM_CONFIDENCE = 3.291; // 99.9%

ShenandoahAdaptiveHeuristics::ShenandoahAdaptiveHeuristics(ShenandoahHeapStats* heap_stats) :
ShenandoahHeuristics(heap_stats),
ShenandoahAdaptiveHeuristics::ShenandoahAdaptiveHeuristics(ShenandoahSpaceInfo* space_info) :
ShenandoahHeuristics(space_info),
_margin_of_error_sd(ShenandoahAdaptiveInitialConfidence),
_spike_threshold_sd(ShenandoahAdaptiveInitialSpikeThreshold),
_last_trigger(OTHER) { }
@@ -84,7 +84,7 @@ void ShenandoahAdaptiveHeuristics::choose_collection_set_from_regiondata(Shenand
// we hit max_cset. When max_cset is hit, we terminate the cset selection. Note that in this scheme,
// ShenandoahGarbageThreshold is the soft threshold which would be ignored until min_garbage is hit.

size_t capacity = _heap_stats->soft_max_capacity();
size_t capacity = _space_info->soft_max_capacity();
size_t max_cset = (size_t)((1.0 * capacity / 100 * ShenandoahEvacReserve) / ShenandoahEvacWaste);
size_t free_target = (capacity / 100 * ShenandoahMinFreeThreshold) + max_cset;
size_t min_garbage = (free_target > actual_free ? (free_target - actual_free) : 0);
@@ -128,7 +128,7 @@ void ShenandoahAdaptiveHeuristics::record_cycle_start() {
void ShenandoahAdaptiveHeuristics::record_success_concurrent() {
ShenandoahHeuristics::record_success_concurrent();

size_t available = _heap_stats->available();
size_t available = _space_info->available();

_available.add(available);
double z_score = 0.0;
@@ -196,10 +196,10 @@ static double saturate(double value, double min, double max) {
}

bool ShenandoahAdaptiveHeuristics::should_start_gc() {
size_t max_capacity = _heap_stats->max_capacity();
size_t capacity = _heap_stats->soft_max_capacity();
size_t available = _heap_stats->available();
size_t allocated = _heap_stats->bytes_allocated_since_gc_start();
size_t max_capacity = _space_info->max_capacity();
size_t capacity = _space_info->soft_max_capacity();
size_t available = _space_info->available();
size_t allocated = _space_info->bytes_allocated_since_gc_start();

// Make sure the code below treats available without the soft tail.
size_t soft_tail = max_capacity - capacity;
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
#define SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHADAPTIVEHEURISTICS_HPP

#include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
#include "gc/shenandoah/heuristics/shenandoahHeapStats.hpp"
#include "gc/shenandoah/heuristics/shenandoahSpaceInfo.hpp"
#include "gc/shenandoah/shenandoahPhaseTimings.hpp"
#include "utilities/numberSeq.hpp"

@@ -65,7 +65,7 @@ class ShenandoahAllocationRate : public CHeapObj<mtGC> {
*/
class ShenandoahAdaptiveHeuristics : public ShenandoahHeuristics {
public:
ShenandoahAdaptiveHeuristics(ShenandoahHeapStats* heap_stats);
ShenandoahAdaptiveHeuristics(ShenandoahSpaceInfo* space_info);

virtual ~ShenandoahAdaptiveHeuristics();

Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@
#include "logging/logTag.hpp"
#include "runtime/os.hpp"

ShenandoahAggressiveHeuristics::ShenandoahAggressiveHeuristics(ShenandoahHeapStats* heap_stats) :
ShenandoahHeuristics(heap_stats) {
ShenandoahAggressiveHeuristics::ShenandoahAggressiveHeuristics(ShenandoahSpaceInfo* space_info) :
ShenandoahHeuristics(space_info) {
// Do not shortcut evacuation
SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahImmediateThreshold, 100);

Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
*/
class ShenandoahAggressiveHeuristics : public ShenandoahHeuristics {
public:
ShenandoahAggressiveHeuristics(ShenandoahHeapStats* heap_stats);
ShenandoahAggressiveHeuristics(ShenandoahSpaceInfo* space_info);

virtual void choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset,
RegionData* data, size_t size,
Original file line number Diff line number Diff line change
@@ -32,8 +32,8 @@
#include "logging/log.hpp"
#include "logging/logTag.hpp"

ShenandoahCompactHeuristics::ShenandoahCompactHeuristics(ShenandoahHeapStats* heap_stats) :
ShenandoahHeuristics(heap_stats) {
ShenandoahCompactHeuristics::ShenandoahCompactHeuristics(ShenandoahSpaceInfo* space_info) :
ShenandoahHeuristics(space_info) {
SHENANDOAH_ERGO_ENABLE_FLAG(ExplicitGCInvokesConcurrent);
SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahImplicitGCInvokesConcurrent);
SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahUncommit);
@@ -46,9 +46,9 @@ ShenandoahCompactHeuristics::ShenandoahCompactHeuristics(ShenandoahHeapStats* he
}

bool ShenandoahCompactHeuristics::should_start_gc() {
size_t max_capacity = _heap_stats->max_capacity();
size_t capacity = _heap_stats->soft_max_capacity();
size_t available = _heap_stats->available();
size_t max_capacity = _space_info->max_capacity();
size_t capacity = _space_info->soft_max_capacity();
size_t available = _space_info->available();

// Make sure the code below treats available without the soft tail.
size_t soft_tail = max_capacity - capacity;
@@ -64,7 +64,7 @@ bool ShenandoahCompactHeuristics::should_start_gc() {
return true;
}

size_t bytes_allocated = _heap_stats->bytes_allocated_since_gc_start();
size_t bytes_allocated = _space_info->bytes_allocated_since_gc_start();
if (bytes_allocated > threshold_bytes_allocated) {
log_info(gc)("Trigger: Allocated since last cycle (" SIZE_FORMAT "%s) is larger than allocation threshold (" SIZE_FORMAT "%s)",
byte_size_in_proper_unit(bytes_allocated), proper_unit_for_byte_size(bytes_allocated),
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
*/
class ShenandoahCompactHeuristics : public ShenandoahHeuristics {
public:
ShenandoahCompactHeuristics(ShenandoahHeapStats* heap_stats);
ShenandoahCompactHeuristics(ShenandoahSpaceInfo* space_info);

virtual bool should_start_gc();

Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@ int ShenandoahHeuristics::compare_by_garbage(RegionData a, RegionData b) {
else return 0;
}

ShenandoahHeuristics::ShenandoahHeuristics(ShenandoahHeapStats* heap_stats) :
_heap_stats(heap_stats),
ShenandoahHeuristics::ShenandoahHeuristics(ShenandoahSpaceInfo* space_info) :
_space_info(space_info),
_region_data(nullptr),
_degenerated_cycles_in_a_row(0),
_successful_cycles_in_a_row(0),
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
#ifndef SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP
#define SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP

#include "gc/shenandoah/heuristics/shenandoahHeapStats.hpp"
#include "gc/shenandoah/heuristics/shenandoahSpaceInfo.hpp"
#include "gc/shenandoah/shenandoahHeap.hpp"
#include "gc/shenandoah/shenandoahPhaseTimings.hpp"
#include "gc/shenandoah/shenandoahSharedVariables.hpp"
@@ -75,8 +75,8 @@ class ShenandoahHeuristics : public CHeapObj<mtGC> {
size_t _garbage;
} RegionData;

// Source of information about the heap
ShenandoahHeapStats* _heap_stats;
// Source of information about the memory space managed by this heuristic
ShenandoahSpaceInfo* _space_info;

RegionData* _region_data;

@@ -102,7 +102,7 @@ class ShenandoahHeuristics : public CHeapObj<mtGC> {
void adjust_penalty(intx step);

public:
ShenandoahHeuristics(ShenandoahHeapStats* heap_stats);
ShenandoahHeuristics(ShenandoahSpaceInfo* space_info);
virtual ~ShenandoahHeuristics();

void record_metaspace_oom() { _metaspace_oom.set(); }
Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@
#include "logging/log.hpp"
#include "logging/logTag.hpp"

ShenandoahPassiveHeuristics::ShenandoahPassiveHeuristics(ShenandoahHeapStats* heap_stats) :
ShenandoahHeuristics(heap_stats) {}
ShenandoahPassiveHeuristics::ShenandoahPassiveHeuristics(ShenandoahSpaceInfo* space_info) :
ShenandoahHeuristics(space_info) {}

bool ShenandoahPassiveHeuristics::should_start_gc() {
// Never do concurrent GCs.
@@ -56,7 +56,7 @@ void ShenandoahPassiveHeuristics::choose_collection_set_from_regiondata(Shenando

// Do not select too large CSet that would overflow the available free space.
// Take at least the entire evacuation reserve, and be free to overflow to free space.
size_t max_capacity = _heap_stats->max_capacity();
size_t max_capacity = _space_info->max_capacity();
size_t available = MAX2(max_capacity / 100 * ShenandoahEvacReserve, actual_free);
size_t max_cset = (size_t)(available / ShenandoahEvacWaste);

Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
*/
class ShenandoahPassiveHeuristics : public ShenandoahHeuristics {
public:
ShenandoahPassiveHeuristics(ShenandoahHeapStats* heap_stats);
ShenandoahPassiveHeuristics(ShenandoahSpaceInfo* space_info);

virtual bool should_start_gc();

Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@
* future operational modes of Shenandoah in which the heap may be split
* into generations.
*/
class ShenandoahHeapStats {
class ShenandoahSpaceInfo {
public:
virtual size_t soft_max_capacity() const = 0;
virtual size_t max_capacity() const = 0;
Original file line number Diff line number Diff line change
@@ -32,18 +32,18 @@
#include "logging/log.hpp"
#include "logging/logTag.hpp"

ShenandoahStaticHeuristics::ShenandoahStaticHeuristics(ShenandoahHeapStats* heap_stats) :
ShenandoahHeuristics(heap_stats) {
ShenandoahStaticHeuristics::ShenandoahStaticHeuristics(ShenandoahSpaceInfo* space_info) :
ShenandoahHeuristics(space_info) {
SHENANDOAH_ERGO_ENABLE_FLAG(ExplicitGCInvokesConcurrent);
SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahImplicitGCInvokesConcurrent);
}

ShenandoahStaticHeuristics::~ShenandoahStaticHeuristics() {}

bool ShenandoahStaticHeuristics::should_start_gc() {
size_t max_capacity = _heap_stats->max_capacity();
size_t capacity = _heap_stats->soft_max_capacity();
size_t available = _heap_stats->available();
size_t max_capacity = _space_info->max_capacity();
size_t capacity = _space_info->soft_max_capacity();
size_t available = _space_info->available();

// Make sure the code below treats available without the soft tail.
size_t soft_tail = max_capacity - capacity;
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@
*/
class ShenandoahStaticHeuristics : public ShenandoahHeuristics {
public:
ShenandoahStaticHeuristics(ShenandoahHeapStats* heap_stats);
ShenandoahStaticHeuristics(ShenandoahSpaceInfo* space_info);

virtual ~ShenandoahStaticHeuristics();

4 changes: 2 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
#include "gc/shared/markBitMap.hpp"
#include "gc/shared/softRefPolicy.hpp"
#include "gc/shared/collectedHeap.hpp"
#include "gc/shenandoah/heuristics/shenandoahHeapStats.hpp"
#include "gc/shenandoah/heuristics/shenandoahSpaceInfo.hpp"
#include "gc/shenandoah/shenandoahAsserts.hpp"
#include "gc/shenandoah/shenandoahAllocRequest.hpp"
#include "gc/shenandoah/shenandoahLock.hpp"
@@ -117,7 +117,7 @@ typedef Stack<oop, mtGC> ShenandoahScanObjectStack;
// to encode forwarding data. See BrooksPointer for details on forwarding data encoding.
// See ShenandoahControlThread for GC cycle structure.
//
class ShenandoahHeap : public CollectedHeap, public ShenandoahHeapStats {
class ShenandoahHeap : public CollectedHeap, public ShenandoahSpaceInfo {
friend class ShenandoahAsserts;
friend class VMStructs;
friend class ShenandoahGCSession;