Path: blob/master/src/hotspot/share/gc/g1/g1Analytics.cpp
40957 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "gc/g1/g1Analytics.hpp"26#include "gc/g1/g1Predictions.hpp"27#include "gc/shared/gc_globals.hpp"28#include "runtime/globals.hpp"29#include "runtime/os.hpp"30#include "utilities/debug.hpp"31#include "utilities/globalDefinitions.hpp"32#include "utilities/numberSeq.hpp"3334// Different defaults for different number of GC threads35// They were chosen by running GCOld and SPECjbb on debris with different36// numbers of GC threads and choosing them based on the results3738// all the same39static double rs_length_diff_defaults[] = {400.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.041};4243static double cost_per_logged_card_ms_defaults[] = {440.01, 0.005, 0.005, 0.003, 0.003, 0.002, 0.002, 0.001545};4647// all the same48static double young_card_merge_to_scan_ratio_defaults[] = {491.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.050};5152static double young_only_cost_per_card_scan_ms_defaults[] = {530.015, 0.01, 0.01, 0.008, 0.008, 0.0055, 0.0055, 0.00554};5556static double cost_per_byte_ms_defaults[] = {570.00006, 0.00003, 0.00003, 0.000015, 0.000015, 0.00001, 0.00001, 0.00000958};5960// these should be pretty consistent61static double constant_other_time_ms_defaults[] = {625.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.063};6465static double young_other_cost_per_region_ms_defaults[] = {660.3, 0.2, 0.2, 0.15, 0.15, 0.12, 0.12, 0.167};6869static double non_young_other_cost_per_region_ms_defaults[] = {701.0, 0.7, 0.7, 0.5, 0.5, 0.42, 0.42, 0.3071};7273G1Analytics::G1Analytics(const G1Predictions* predictor) :74_predictor(predictor),75_recent_gc_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),76_concurrent_mark_remark_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),77_concurrent_mark_cleanup_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),78_alloc_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),79_prev_collection_pause_end_ms(0.0),80_rs_length_diff_seq(new TruncatedSeq(TruncatedSeqLength)),81_concurrent_refine_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),82_dirtied_cards_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),83_young_card_merge_to_scan_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),84_mixed_card_merge_to_scan_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),85_young_cost_per_card_scan_ms_seq(new TruncatedSeq(TruncatedSeqLength)),86_mixed_cost_per_card_scan_ms_seq(new TruncatedSeq(TruncatedSeqLength)),87_young_cost_per_card_merge_ms_seq(new TruncatedSeq(TruncatedSeqLength)),88_mixed_cost_per_card_merge_ms_seq(new TruncatedSeq(TruncatedSeqLength)),89_copy_cost_per_byte_ms_seq(new TruncatedSeq(TruncatedSeqLength)),90_constant_other_time_ms_seq(new TruncatedSeq(TruncatedSeqLength)),91_young_other_cost_per_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)),92_non_young_other_cost_per_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)),93_pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)),94_rs_length_seq(new TruncatedSeq(TruncatedSeqLength)),95_cost_per_byte_ms_during_cm_seq(new TruncatedSeq(TruncatedSeqLength)),96_recent_prev_end_times_for_all_gcs_sec(new TruncatedSeq(NumPrevPausesForHeuristics)),97_long_term_pause_time_ratio(0.0),98_short_term_pause_time_ratio(0.0) {99100// Seed sequences with initial values.101_recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime());102_prev_collection_pause_end_ms = os::elapsedTime() * 1000.0;103104int index = MIN2(ParallelGCThreads - 1, 7u);105106_rs_length_diff_seq->add(rs_length_diff_defaults[index]);107// Start with inverse of maximum STW cost.108_concurrent_refine_rate_ms_seq->add(1/cost_per_logged_card_ms_defaults[0]);109// Some applications have very low rates for logging cards.110_dirtied_cards_rate_ms_seq->add(0.0);111_young_card_merge_to_scan_ratio_seq->add(young_card_merge_to_scan_ratio_defaults[index]);112_young_cost_per_card_scan_ms_seq->add(young_only_cost_per_card_scan_ms_defaults[index]);113114_copy_cost_per_byte_ms_seq->add(cost_per_byte_ms_defaults[index]);115_constant_other_time_ms_seq->add(constant_other_time_ms_defaults[index]);116_young_other_cost_per_region_ms_seq->add(young_other_cost_per_region_ms_defaults[index]);117_non_young_other_cost_per_region_ms_seq->add(non_young_other_cost_per_region_ms_defaults[index]);118119// start conservatively (around 50ms is about right)120_concurrent_mark_remark_times_ms->add(0.05);121_concurrent_mark_cleanup_times_ms->add(0.20);122}123124bool G1Analytics::enough_samples_available(TruncatedSeq const* seq) const {125return seq->num() >= 3;126}127128double G1Analytics::predict_in_unit_interval(TruncatedSeq const* seq) const {129return _predictor->predict_in_unit_interval(seq);130}131132size_t G1Analytics::predict_size(TruncatedSeq const* seq) const {133return (size_t)predict_zero_bounded(seq);134}135136double G1Analytics::predict_zero_bounded(TruncatedSeq const* seq) const {137return _predictor->predict_zero_bounded(seq);138}139140int G1Analytics::num_alloc_rate_ms() const {141return _alloc_rate_ms_seq->num();142}143144void G1Analytics::report_concurrent_mark_remark_times_ms(double ms) {145_concurrent_mark_remark_times_ms->add(ms);146}147148void G1Analytics::report_alloc_rate_ms(double alloc_rate) {149_alloc_rate_ms_seq->add(alloc_rate);150}151152void G1Analytics::compute_pause_time_ratios(double end_time_sec, double pause_time_ms) {153double long_interval_ms = (end_time_sec - oldest_known_gc_end_time_sec()) * 1000.0;154double gc_pause_time_ms = _recent_gc_times_ms->sum() - _recent_gc_times_ms->oldest() + pause_time_ms;155_long_term_pause_time_ratio = gc_pause_time_ms / long_interval_ms;156_long_term_pause_time_ratio = clamp(_long_term_pause_time_ratio, 0.0, 1.0);157158double short_interval_ms = (end_time_sec - most_recent_gc_end_time_sec()) * 1000.0;159_short_term_pause_time_ratio = pause_time_ms / short_interval_ms;160_short_term_pause_time_ratio = clamp(_short_term_pause_time_ratio, 0.0, 1.0);161}162163void G1Analytics::report_concurrent_refine_rate_ms(double cards_per_ms) {164_concurrent_refine_rate_ms_seq->add(cards_per_ms);165}166167void G1Analytics::report_dirtied_cards_rate_ms(double cards_per_ms) {168_dirtied_cards_rate_ms_seq->add(cards_per_ms);169}170171void G1Analytics::report_cost_per_card_scan_ms(double cost_per_card_ms, bool for_young_gc) {172if (for_young_gc) {173_young_cost_per_card_scan_ms_seq->add(cost_per_card_ms);174} else {175_mixed_cost_per_card_scan_ms_seq->add(cost_per_card_ms);176}177}178179void G1Analytics::report_cost_per_card_merge_ms(double cost_per_card_ms, bool for_young_gc) {180if (for_young_gc) {181_young_cost_per_card_merge_ms_seq->add(cost_per_card_ms);182} else {183_mixed_cost_per_card_merge_ms_seq->add(cost_per_card_ms);184}185}186187void G1Analytics::report_card_merge_to_scan_ratio(double merge_to_scan_ratio, bool for_young_gc) {188if (for_young_gc) {189_young_card_merge_to_scan_ratio_seq->add(merge_to_scan_ratio);190} else {191_mixed_card_merge_to_scan_ratio_seq->add(merge_to_scan_ratio);192}193}194195void G1Analytics::report_rs_length_diff(double rs_length_diff) {196_rs_length_diff_seq->add(rs_length_diff);197}198199void G1Analytics::report_cost_per_byte_ms(double cost_per_byte_ms, bool mark_or_rebuild_in_progress) {200if (mark_or_rebuild_in_progress) {201_cost_per_byte_ms_during_cm_seq->add(cost_per_byte_ms);202} else {203_copy_cost_per_byte_ms_seq->add(cost_per_byte_ms);204}205}206207void G1Analytics::report_young_other_cost_per_region_ms(double other_cost_per_region_ms) {208_young_other_cost_per_region_ms_seq->add(other_cost_per_region_ms);209}210211void G1Analytics::report_non_young_other_cost_per_region_ms(double other_cost_per_region_ms) {212_non_young_other_cost_per_region_ms_seq->add(other_cost_per_region_ms);213}214215void G1Analytics::report_constant_other_time_ms(double constant_other_time_ms) {216_constant_other_time_ms_seq->add(constant_other_time_ms);217}218219void G1Analytics::report_pending_cards(double pending_cards) {220_pending_cards_seq->add(pending_cards);221}222223void G1Analytics::report_rs_length(double rs_length) {224_rs_length_seq->add(rs_length);225}226227double G1Analytics::predict_alloc_rate_ms() const {228return predict_zero_bounded(_alloc_rate_ms_seq);229}230231double G1Analytics::predict_concurrent_refine_rate_ms() const {232return predict_zero_bounded(_concurrent_refine_rate_ms_seq);233}234235double G1Analytics::predict_dirtied_cards_rate_ms() const {236return predict_zero_bounded(_dirtied_cards_rate_ms_seq);237}238239double G1Analytics::predict_young_card_merge_to_scan_ratio() const {240return predict_in_unit_interval(_young_card_merge_to_scan_ratio_seq);241}242243size_t G1Analytics::predict_scan_card_num(size_t rs_length, bool for_young_gc) const {244if (for_young_gc || !enough_samples_available(_mixed_card_merge_to_scan_ratio_seq)) {245return (size_t)(rs_length * predict_young_card_merge_to_scan_ratio());246} else {247return (size_t)(rs_length * predict_in_unit_interval(_mixed_card_merge_to_scan_ratio_seq));248}249}250251double G1Analytics::predict_card_merge_time_ms(size_t card_num, bool for_young_gc) const {252if (for_young_gc || !enough_samples_available(_mixed_cost_per_card_merge_ms_seq)) {253return card_num * predict_zero_bounded(_young_cost_per_card_merge_ms_seq);254} else {255return card_num * predict_zero_bounded(_mixed_cost_per_card_merge_ms_seq);256}257}258259double G1Analytics::predict_card_scan_time_ms(size_t card_num, bool for_young_gc) const {260if (for_young_gc || !enough_samples_available(_mixed_cost_per_card_scan_ms_seq)) {261return card_num * predict_zero_bounded(_young_cost_per_card_scan_ms_seq);262} else {263return card_num * predict_zero_bounded(_mixed_cost_per_card_scan_ms_seq);264}265}266267double G1Analytics::predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) const {268if (!enough_samples_available(_cost_per_byte_ms_during_cm_seq)) {269return (1.1 * bytes_to_copy) * predict_zero_bounded(_copy_cost_per_byte_ms_seq);270} else {271return bytes_to_copy * predict_zero_bounded(_cost_per_byte_ms_during_cm_seq);272}273}274275double G1Analytics::predict_object_copy_time_ms(size_t bytes_to_copy, bool during_concurrent_mark) const {276if (during_concurrent_mark) {277return predict_object_copy_time_ms_during_cm(bytes_to_copy);278} else {279return bytes_to_copy * predict_zero_bounded(_copy_cost_per_byte_ms_seq);280}281}282283double G1Analytics::predict_constant_other_time_ms() const {284return predict_zero_bounded(_constant_other_time_ms_seq);285}286287double G1Analytics::predict_young_other_time_ms(size_t young_num) const {288return young_num * predict_zero_bounded(_young_other_cost_per_region_ms_seq);289}290291double G1Analytics::predict_non_young_other_time_ms(size_t non_young_num) const {292return non_young_num * predict_zero_bounded(_non_young_other_cost_per_region_ms_seq);293}294295double G1Analytics::predict_remark_time_ms() const {296return predict_zero_bounded(_concurrent_mark_remark_times_ms);297}298299double G1Analytics::predict_cleanup_time_ms() const {300return predict_zero_bounded(_concurrent_mark_cleanup_times_ms);301}302303size_t G1Analytics::predict_rs_length() const {304return predict_size(_rs_length_seq) + predict_size(_rs_length_diff_seq);305}306307size_t G1Analytics::predict_pending_cards() const {308return predict_size(_pending_cards_seq);309}310311double G1Analytics::oldest_known_gc_end_time_sec() const {312return _recent_prev_end_times_for_all_gcs_sec->oldest();313}314315double G1Analytics::most_recent_gc_end_time_sec() const {316return _recent_prev_end_times_for_all_gcs_sec->last();317}318319void G1Analytics::update_recent_gc_times(double end_time_sec,320double pause_time_ms) {321_recent_gc_times_ms->add(pause_time_ms);322_recent_prev_end_times_for_all_gcs_sec->add(end_time_sec);323}324325void G1Analytics::report_concurrent_mark_cleanup_times_ms(double ms) {326_concurrent_mark_cleanup_times_ms->add(ms);327}328329330