28
28
#include " gc/shenandoah/shenandoahHeapRegion.hpp"
29
29
#include " gc/shenandoah/shenandoahMetrics.hpp"
30
30
31
- ShenandoahMetricsSnapshot::ShenandoahMetricsSnapshot () {
32
- _heap = ShenandoahHeap::heap ();
31
+ ShenandoahMetricsSnapshot::ShenandoahMetricsSnapshot (ShenandoahFreeSet* free_set)
32
+ : _free_set(free_set)
33
+ , _used_before(free_set->used ())
34
+ , _if_before(free_set->internal_fragmentation ())
35
+ , _ef_before(free_set->external_fragmentation ()) {
33
36
}
34
37
35
- void ShenandoahMetricsSnapshot::snap_before () {
36
- _used_before = _heap->used ();
37
- _if_before = _heap->free_set ()->internal_fragmentation ();
38
- _ef_before = _heap->free_set ()->external_fragmentation ();
39
- }
40
- void ShenandoahMetricsSnapshot::snap_after () {
41
- _used_after = _heap->used ();
42
- _if_after = _heap->free_set ()->internal_fragmentation ();
43
- _ef_after = _heap->free_set ()->external_fragmentation ();
44
- }
45
-
46
- // For degenerated GC, generation is Young in generational mode, Global in non-generational mode.
47
- // For full GC, generation is always Global.
48
- //
49
- // Note that the size of the chosen collection set is proportional to the relevant generation's collection set.
50
- // Note also that the generation size may change following selection of the collection set, as a side effect
51
- // of evacuation. Evacuation may promote objects, causing old to grow and young to shrink. Or this may be a
52
- // mixed evacuation. When old regions are evacuated, this typically allows young to expand. In all of these
53
- // various scenarios, the purpose of asking is_good_progress() is to determine if there is enough memory available
54
- // within young generation to justify making an attempt to perform a concurrent collection. For this reason, we'll
55
- // use the current size of the generation (which may not be different than when the collection set was chosen) to
56
- // assess how much free memory we require in order to consider the most recent GC to have had good progress.
57
-
58
- bool ShenandoahMetricsSnapshot::is_good_progress (ShenandoahGeneration* generation) {
38
+ bool ShenandoahMetricsSnapshot::is_good_progress () const {
59
39
// Under the critical threshold?
60
- ShenandoahFreeSet* free_set = _heap->free_set ();
61
- size_t free_actual = free_set->available ();
40
+ const size_t free_actual = _free_set->available ();
62
41
assert (free_actual != ShenandoahFreeSet::FreeSetUnderConstruction, " Avoid this race" );
63
42
64
- // ShenandoahCriticalFreeThreshold is expressed as a percentage. We multiple this percentage by 1/100th
65
- // of the generation capacity to determine whether the available memory within the generation exceeds the
66
- // critical threshold.
67
- size_t free_expected = (ShenandoahHeap::heap ()->soft_max_capacity () / 100 ) * ShenandoahCriticalFreeThreshold;
68
-
69
- bool prog_free = free_actual >= free_expected;
70
- log_info (gc, ergo)(" %s progress for free space: %zu%s, need %zu%s" ,
71
- prog_free ? " Good" : " Bad" ,
72
- byte_size_in_proper_unit (free_actual), proper_unit_for_byte_size (free_actual),
73
- byte_size_in_proper_unit (free_expected), proper_unit_for_byte_size (free_expected));
43
+ // ShenandoahCriticalFreeThreshold is expressed as a percentage. We multiply this percentage by 1/100th
44
+ // of the soft max capacity to determine whether the available memory within the mutator partition of the
45
+ // freeset exceeds the critical threshold.
46
+ const size_t free_expected = (ShenandoahHeap::heap ()->soft_max_capacity () / 100 ) * ShenandoahCriticalFreeThreshold;
47
+ const bool prog_free = free_actual >= free_expected;
48
+ log_info (gc, ergo)(" %s progress for free space: " PROPERFMT " , need " PROPERFMT,
49
+ prog_free ? " Good" : " Bad" , PROPERFMTARGS (free_actual), PROPERFMTARGS (free_expected));
74
50
if (!prog_free) {
75
51
return false ;
76
52
}
77
53
78
54
// Freed up enough?
79
- size_t progress_actual = (_used_before > _used_after) ? _used_before - _used_after : 0 ;
80
- size_t progress_expected = ShenandoahHeapRegion::region_size_bytes ();
81
- bool prog_used = progress_actual >= progress_expected;
82
- log_info (gc, ergo)(" %s progress for used space: %zu%s, need %zu%s" ,
83
- prog_used ? " Good" : " Bad" ,
84
- byte_size_in_proper_unit (progress_actual), proper_unit_for_byte_size (progress_actual),
85
- byte_size_in_proper_unit (progress_expected), proper_unit_for_byte_size (progress_expected));
55
+ const size_t used_after = _free_set->used ();
56
+ const size_t progress_actual = (_used_before > used_after) ? _used_before - used_after : 0 ;
57
+ const size_t progress_expected = ShenandoahHeapRegion::region_size_bytes ();
58
+ const bool prog_used = progress_actual >= progress_expected;
59
+ log_info (gc, ergo)(" %s progress for used space: " PROPERFMT " , need " PROPERFMT,
60
+ prog_used ? " Good" : " Bad" , PROPERFMTARGS (progress_actual), PROPERFMTARGS (progress_expected));
86
61
if (prog_used) {
87
62
return true ;
88
63
}
89
64
90
65
// Internal fragmentation is down?
91
- double if_actual = _if_before - _if_after;
92
- double if_expected = 0.01 ; // 1% should be enough
93
- bool prog_if = if_actual >= if_expected;
66
+ const double if_after = _free_set->internal_fragmentation ();
67
+ const double if_actual = _if_before - if_after;
68
+ const double if_expected = 0.01 ; // 1% should be enough
69
+ const bool prog_if = if_actual >= if_expected;
94
70
log_info (gc, ergo)(" %s progress for internal fragmentation: %.1f%%, need %.1f%%" ,
95
71
prog_if ? " Good" : " Bad" ,
96
72
if_actual * 100 , if_expected * 100 );
@@ -99,9 +75,10 @@ bool ShenandoahMetricsSnapshot::is_good_progress(ShenandoahGeneration* generatio
99
75
}
100
76
101
77
// External fragmentation is down?
102
- double ef_actual = _ef_before - _ef_after;
103
- double ef_expected = 0.01 ; // 1% should be enough
104
- bool prog_ef = ef_actual >= ef_expected;
78
+ const double ef_after = _free_set->external_fragmentation ();
79
+ const double ef_actual = _ef_before - ef_after;
80
+ const double ef_expected = 0.01 ; // 1% should be enough
81
+ const bool prog_ef = ef_actual >= ef_expected;
105
82
log_info (gc, ergo)(" %s progress for external fragmentation: %.1f%%, need %.1f%%" ,
106
83
prog_ef ? " Good" : " Bad" ,
107
84
ef_actual * 100 , ef_expected * 100 );
0 commit comments