Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8270100: Fix some inaccurate GC logging
Reviewed-by: ayang, tschatzl
  • Loading branch information
simonis committed Jul 14, 2021
1 parent b1bb05b commit fb86d13
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
43 changes: 23 additions & 20 deletions src/hotspot/share/gc/serial/defNewGeneration.cpp
Expand Up @@ -313,29 +313,31 @@ bool DefNewGeneration::expand(size_t bytes) {
return success;
}

size_t DefNewGeneration::calculate_thread_increase_size(int threads_count) const {
size_t thread_increase_size = 0;
// Check an overflow at 'threads_count * NewSizeThreadIncrease'.
if (threads_count > 0 && NewSizeThreadIncrease <= max_uintx / threads_count) {
thread_increase_size = threads_count * NewSizeThreadIncrease;
}
return thread_increase_size;
}

size_t DefNewGeneration::adjust_for_thread_increase(size_t new_size_candidate,
size_t new_size_before,
size_t alignment) const {
size_t alignment,
size_t thread_increase_size) const {
size_t desired_new_size = new_size_before;

if (NewSizeThreadIncrease > 0) {
int threads_count;
size_t thread_increase_size = 0;

// 1. Check an overflow at 'threads_count * NewSizeThreadIncrease'.
threads_count = Threads::number_of_non_daemon_threads();
if (threads_count > 0 && NewSizeThreadIncrease <= max_uintx / threads_count) {
thread_increase_size = threads_count * NewSizeThreadIncrease;
if (NewSizeThreadIncrease > 0 && thread_increase_size > 0) {

// 2. Check an overflow at 'new_size_candidate + thread_increase_size'.
if (new_size_candidate <= max_uintx - thread_increase_size) {
new_size_candidate += thread_increase_size;
// 1. Check an overflow at 'new_size_candidate + thread_increase_size'.
if (new_size_candidate <= max_uintx - thread_increase_size) {
new_size_candidate += thread_increase_size;

// 3. Check an overflow at 'align_up'.
size_t aligned_max = ((max_uintx - alignment) & ~(alignment-1));
if (new_size_candidate <= aligned_max) {
desired_new_size = align_up(new_size_candidate, alignment);
}
// 2. Check an overflow at 'align_up'.
size_t aligned_max = ((max_uintx - alignment) & ~(alignment-1));
if (new_size_candidate <= aligned_max) {
desired_new_size = align_up(new_size_candidate, alignment);
}
}
}
Expand Down Expand Up @@ -364,13 +366,14 @@ void DefNewGeneration::compute_new_size() {
// All space sizes must be multiples of Generation::GenGrain.
size_t alignment = Generation::GenGrain;

int threads_count = 0;
size_t thread_increase_size = 0;
int threads_count = Threads::number_of_non_daemon_threads();
size_t thread_increase_size = calculate_thread_increase_size(threads_count);

size_t new_size_candidate = old_size / NewRatio;
// Compute desired new generation size based on NewRatio and NewSizeThreadIncrease
// and reverts to previous value if any overflow happens
size_t desired_new_size = adjust_for_thread_increase(new_size_candidate, new_size_before, alignment);
size_t desired_new_size = adjust_for_thread_increase(new_size_candidate, new_size_before,
alignment, thread_increase_size);

// Adjust new generation size
desired_new_size = clamp(desired_new_size, min_new_size, max_new_size);
Expand Down
5 changes: 4 additions & 1 deletion src/hotspot/share/gc/serial/defNewGeneration.hpp
Expand Up @@ -341,7 +341,10 @@ class DefNewGeneration: public Generation {
// If any overflow happens, revert to previous new size.
size_t adjust_for_thread_increase(size_t new_size_candidate,
size_t new_size_before,
size_t alignment) const;
size_t alignment,
size_t thread_increase_size) const;

size_t calculate_thread_increase_size(int threads_count) const;


// Scavenge support
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/gc/serial/tenuredGeneration.cpp
Expand Up @@ -51,7 +51,8 @@ TenuredGeneration::TenuredGeneration(ReservedSpace rs,
HeapWord* end = (HeapWord*) _virtual_space.high();
_the_space = new TenuredSpace(_bts, MemRegion(bottom, end));
_the_space->reset_saved_mark();
_shrink_factor = 0;
// If we don't shrink the heap in steps, '_shrink_factor' is always 100%.
_shrink_factor = ShrinkHeapInSteps ? 0 : 100;
_capacity_at_prologue = 0;

_gc_stats = new GCStats();
Expand Down
11 changes: 9 additions & 2 deletions src/hotspot/share/gc/shared/cardGeneration.cpp
Expand Up @@ -41,9 +41,11 @@ CardGeneration::CardGeneration(ReservedSpace rs,
size_t initial_byte_size,
CardTableRS* remset) :
Generation(rs, initial_byte_size), _rs(remset),
_shrink_factor(0), _min_heap_delta_bytes(), _capacity_at_prologue(),
_min_heap_delta_bytes(), _capacity_at_prologue(),
_used_at_prologue()
{
// If we don't shrink the heap in steps, '_shrink_factor' is always 100%.
_shrink_factor = ShrinkHeapInSteps ? 0 : 100;
HeapWord* start = (HeapWord*)rs.base();
size_t reserved_byte_size = rs.size();
assert((uintptr_t(start) & 3) == 0, "bad alignment");
Expand Down Expand Up @@ -186,7 +188,12 @@ void CardGeneration::invalidate_remembered_set() {
void CardGeneration::compute_new_size() {
assert(_shrink_factor <= 100, "invalid shrink factor");
size_t current_shrink_factor = _shrink_factor;
_shrink_factor = 0;
if (ShrinkHeapInSteps) {
// Always reset '_shrink_factor' if the heap is shrunk in steps.
// If we shrink the heap in this iteration, '_shrink_factor' will
// be recomputed based on the old value further down in this fuction.
_shrink_factor = 0;
}

// We don't have floating point command-line arguments
// Note: argument processing ensures that MinHeapFreeRatio < 100.
Expand Down

1 comment on commit fb86d13

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.