--- old/src/hotspot/share/gc/g1/g1CollectedHeap.cpp 2020-06-03 22:34:36.281925698 +0000 +++ new/src/hotspot/share/gc/g1/g1CollectedHeap.cpp 2020-06-03 22:34:35.893918250 +0000 @@ -871,7 +871,8 @@ result = humongous_obj_allocate(word_size); if (result != NULL) { size_t size_in_regions = humongous_obj_size_in_regions(word_size); - policy()->add_bytes_allocated_in_old_since_last_gc(size_in_regions * HeapRegion::GrainBytes); + policy()->old_gen_alloc_tracker()-> + add_allocated_bytes_since_last_gc(size_in_regions * HeapRegion::GrainBytes); return result; } @@ -4085,7 +4086,8 @@ } void G1CollectedHeap::record_obj_copy_mem_stats() { - policy()->add_bytes_allocated_in_old_since_last_gc(_old_evac_stats.allocated() * HeapWordSize); + policy()->old_gen_alloc_tracker()-> + add_allocated_bytes_since_last_gc(_old_evac_stats.allocated() * HeapWordSize); _gc_tracer_stw->report_evacuation_statistics(create_g1_evac_summary(&_survivor_evac_stats), create_g1_evac_summary(&_old_evac_stats)); @@ -4186,7 +4188,7 @@ g1h->alloc_buffer_stats(G1HeapRegionAttr::Old)->add_failure_used_and_waste(_failure_used_words, _failure_waste_words); G1Policy *policy = g1h->policy(); - policy->add_bytes_allocated_in_old_since_last_gc(_bytes_allocated_in_old_since_last_gc); + policy->old_gen_alloc_tracker()->add_allocated_bytes_since_last_gc(_bytes_allocated_in_old_since_last_gc); policy->record_rs_length(_rs_length); policy->cset_regions_freed(); } --- old/src/hotspot/share/gc/g1/g1Policy.cpp 2020-06-03 22:34:37.573950498 +0000 +++ new/src/hotspot/share/gc/g1/g1Policy.cpp 2020-06-03 22:34:37.197943280 +0000 @@ -73,7 +73,7 @@ _rs_length(0), _rs_length_prediction(0), _pending_cards_at_gc_start(0), - _bytes_allocated_in_old_since_last_gc(0), + _old_gen_alloc_tracker(), _initial_mark_to_mixed(), _collection_set(NULL), _g1h(NULL), @@ -460,7 +460,7 @@ update_young_list_max_and_target_length(); update_rs_length_prediction(); - _bytes_allocated_in_old_since_last_gc = 0; + _old_gen_alloc_tracker.reset_after_full_gc(); record_pause(FullGC, _full_collection_start_sec, end_sec); } @@ -795,11 +795,11 @@ // predicted target occupancy. size_t last_unrestrained_young_length = update_young_list_max_and_target_length(); - update_ihop_prediction(app_time_ms / 1000.0, - _bytes_allocated_in_old_since_last_gc, + _old_gen_alloc_tracker.reset_after_incremental_gc(app_time_ms / 1000.0); + update_ihop_prediction(_old_gen_alloc_tracker.last_cycle_duration(), + _old_gen_alloc_tracker.last_cycle_old_bytes(), last_unrestrained_young_length * HeapRegion::GrainBytes, this_pause_was_young_only); - _bytes_allocated_in_old_since_last_gc = 0; _ihop_control->send_trace_event(_g1h->gc_tracer_stw()); } else { --- old/src/hotspot/share/gc/g1/g1Policy.hpp 2020-06-03 22:34:38.829974607 +0000 +++ new/src/hotspot/share/gc/g1/g1Policy.hpp 2020-06-03 22:34:38.453967390 +0000 @@ -30,6 +30,7 @@ #include "gc/g1/g1HeapRegionAttr.hpp" #include "gc/g1/g1InitialMarkToMixedTimeTracker.hpp" #include "gc/g1/g1MMUTracker.hpp" +#include "gc/g1/g1OldGenAllocationTracker.hpp" #include "gc/g1/g1RemSetTrackingPolicy.hpp" #include "gc/g1/g1Predictions.hpp" #include "gc/g1/g1YoungGenSizer.hpp" @@ -102,9 +103,9 @@ size_t _pending_cards_at_gc_start; - // The amount of allocated bytes in old gen during the last mutator and the following - // young GC phase. - size_t _bytes_allocated_in_old_since_last_gc; + // Tracking the allocation in the old generation between + // two GCs. + G1OldGenAllocationTracker _old_gen_alloc_tracker; G1InitialMarkToMixedTimeTracker _initial_mark_to_mixed; @@ -119,8 +120,7 @@ G1RemSetTrackingPolicy* remset_tracker() { return &_remset_tracker; } - // Add the given number of bytes to the total number of allocated bytes in the old gen. - void add_bytes_allocated_in_old_since_last_gc(size_t bytes) { _bytes_allocated_in_old_since_last_gc += bytes; } + G1OldGenAllocationTracker* old_gen_alloc_tracker() { return &_old_gen_alloc_tracker; } void set_region_eden(HeapRegion* hr) { hr->set_eden(); --- /dev/null 2020-05-05 16:06:32.280000000 +0000 +++ new/src/hotspot/share/gc/g1/g1OldGenAllocationTracker.cpp 2020-06-03 22:34:39.633990040 +0000 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020, Amazon.com, Inc. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "precompiled.hpp" +#include "gc/g1/g1OldGenAllocationTracker.hpp" + +G1OldGenAllocationTracker::G1OldGenAllocationTracker() : + _last_cycle_old_bytes(0), + _last_cycle_duration(0.0), + _allocated_bytes_since_last_gc(0) { +} + +void G1OldGenAllocationTracker::reset_after_full_gc() { + _last_cycle_duration = 0; + reset_cycle_after_gc(); +} + +void G1OldGenAllocationTracker::reset_after_incremental_gc(double allocation_duration_s) { + _last_cycle_duration = allocation_duration_s; + reset_cycle_after_gc(); +} \ No newline at end of file --- /dev/null 2020-05-05 16:06:32.280000000 +0000 +++ new/src/hotspot/share/gc/g1/g1OldGenAllocationTracker.hpp 2020-06-03 22:34:40.778011999 +0000 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2020, Amazon.com, Inc. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef SHARE_VM_GC_G1_G1OLDGENALLOCATIONTRACKER_HPP +#define SHARE_VM_GC_G1_G1OLDGENALLOCATIONTRACKER_HPP + +#include "gc/g1/heapRegion.hpp" +#include "memory/allocation.hpp" + +// Track allocation details in the old generation. +class G1OldGenAllocationTracker : public CHeapObj { +private: + // New bytes allocated in old gen between the end of the last GC and + // the end of the GC before that. + size_t _last_cycle_old_bytes; + // The number of seconds between the end of the last GC and + // the end of the GC before that. + double _last_cycle_duration; + + size_t _allocated_bytes_since_last_gc; + + void reset_cycle_after_gc() { + _last_cycle_old_bytes = _allocated_bytes_since_last_gc; + _allocated_bytes_since_last_gc = 0; + } + +public: + G1OldGenAllocationTracker(); + // Add the given number of bytes to the total number of allocated bytes in the old gen. + void add_allocated_bytes_since_last_gc(size_t bytes) { _allocated_bytes_since_last_gc += bytes; } + + size_t last_cycle_old_bytes() { return _last_cycle_old_bytes; } + + double last_cycle_duration() { return _last_cycle_duration; } + + // Reset stats after a collection. + void reset_after_full_gc(); + void reset_after_incremental_gc(double allocation_duration_s); +}; + +#endif // SHARE_VM_GC_G1_G1OLDGENALLOCATIONTRACKER_HPP \ No newline at end of file