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

8270100: Fix some inaccurate GC logging #4727

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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);
}
}
}
@@ -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);
@@ -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
@@ -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();
@@ -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");
@@ -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.