--- old/src/hotspot/share/gc/g1/g1IHOPControl.cpp 2020-08-11 02:05:03.845075289 +0000 +++ new/src/hotspot/share/gc/g1/g1IHOPControl.cpp 2020-08-11 02:05:03.581070098 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2020, 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 @@ -29,11 +29,12 @@ #include "gc/g1/g1Trace.hpp" #include "logging/log.hpp" -G1IHOPControl::G1IHOPControl(double initial_ihop_percent) : +G1IHOPControl::G1IHOPControl(double initial_ihop_percent, + G1OldGenAllocationTracker const* old_gen_alloc_tracker) : _initial_ihop_percent(initial_ihop_percent), _target_occupancy(0), _last_allocation_time_s(0.0), - _last_allocated_bytes(0) + _old_gen_alloc_tracker(old_gen_alloc_tracker) { assert(_initial_ihop_percent >= 0.0 && _initial_ihop_percent <= 100.0, "Initial IHOP value must be between 0 and 100 but is %.3f", initial_ihop_percent); } @@ -44,11 +45,10 @@ _target_occupancy = new_target_occupancy; } -void G1IHOPControl::update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size) { +void G1IHOPControl::update_allocation_info(double allocation_time_s, size_t additional_buffer_size) { assert(allocation_time_s >= 0.0, "Allocation time must be positive but is %.3f", allocation_time_s); _last_allocation_time_s = allocation_time_s; - _last_allocated_bytes = allocated_bytes; } void G1IHOPControl::print() { @@ -60,9 +60,9 @@ percent_of(cur_conc_mark_start_threshold, _target_occupancy), _target_occupancy, G1CollectedHeap::heap()->used(), - _last_allocated_bytes, + _old_gen_alloc_tracker->last_period_old_bytes(), _last_allocation_time_s * 1000.0, - _last_allocation_time_s > 0.0 ? _last_allocated_bytes / _last_allocation_time_s : 0.0, + _last_allocation_time_s > 0.0 ? _old_gen_alloc_tracker->last_period_old_bytes() / _last_allocation_time_s : 0.0, last_marking_length_s() * 1000.0); } @@ -71,21 +71,23 @@ tracer->report_basic_ihop_statistics(get_conc_mark_start_threshold(), _target_occupancy, G1CollectedHeap::heap()->used(), - _last_allocated_bytes, + _old_gen_alloc_tracker->last_period_old_bytes(), _last_allocation_time_s, last_marking_length_s()); } -G1StaticIHOPControl::G1StaticIHOPControl(double ihop_percent) : - G1IHOPControl(ihop_percent), +G1StaticIHOPControl::G1StaticIHOPControl(double ihop_percent, + G1OldGenAllocationTracker const* old_gen_alloc_tracker) : + G1IHOPControl(ihop_percent, old_gen_alloc_tracker), _last_marking_length_s(0.0) { } G1AdaptiveIHOPControl::G1AdaptiveIHOPControl(double ihop_percent, + G1OldGenAllocationTracker const* old_gen_alloc_tracker, G1Predictions const* predictor, size_t heap_reserve_percent, size_t heap_waste_percent) : - G1IHOPControl(ihop_percent), + G1IHOPControl(ihop_percent, old_gen_alloc_tracker), _heap_reserve_percent(heap_reserve_percent), _heap_waste_percent(heap_waste_percent), _predictor(predictor), @@ -145,13 +147,27 @@ } } +double G1AdaptiveIHOPControl::last_mutator_period_old_allocation_rate() const { + // The upper limit of the freed region count is the number of regions allocated + // since the last gc. When more humongous regions survived the current gc than + // survived the previous one, deduct the increment. + assert(_last_allocation_time_s > 0, "This should not be called when the last GC is full"); + size_t freed_humongous_bytes = _old_gen_alloc_tracker->_last_period_humongous_bytes; + size_t humongous_bytes_after_penultimate_gc = _old_gen_alloc_tracker->_humongous_bytes_after_penultimate_gc; + size_t humongous_bytes_after_last_gc = _old_gen_alloc_tracker->_humongous_bytes_after_last_gc; + size_t last_period_old_bytes = _old_gen_alloc_tracker->last_period_old_bytes(); + + if (freed_humongous_bytes > 0 && humongous_bytes_after_penultimate_gc < humongous_bytes_after_last_gc) { + freed_humongous_bytes -= humongous_bytes_after_last_gc - humongous_bytes_after_penultimate_gc; + } + assert(last_period_old_bytes >= freed_humongous_bytes, "Allocation rate cannot be negative"); + return (last_period_old_bytes - freed_humongous_bytes) / _last_allocation_time_s; + } + void G1AdaptiveIHOPControl::update_allocation_info(double allocation_time_s, - size_t allocated_bytes, size_t additional_buffer_size) { - G1IHOPControl::update_allocation_info(allocation_time_s, allocated_bytes, additional_buffer_size); - - double allocation_rate = (double) allocated_bytes / allocation_time_s; - _allocation_rate_s.add(allocation_rate); + G1IHOPControl::update_allocation_info(allocation_time_s, additional_buffer_size); + _allocation_rate_s.add(last_mutator_period_old_allocation_rate()); _last_unrestrained_young_size = additional_buffer_size; }