Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shared/allocationStats.hpp
38920 views
/*1* Copyright (c) 2001, 2014, 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#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP25#define SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP2627#include "utilities/macros.hpp"28#include "memory/allocation.hpp"29#include "utilities/globalDefinitions.hpp"30#include "gc_implementation/shared/gcUtil.hpp"3132class AllocationStats VALUE_OBJ_CLASS_SPEC {33// A duration threshold (in ms) used to filter34// possibly unreliable samples.35static float _threshold;3637// We measure the demand between the end of the previous sweep and38// beginning of this sweep:39// Count(end_last_sweep) - Count(start_this_sweep)40// + split_births(between) - split_deaths(between)41// The above number divided by the time since the end of the42// previous sweep gives us a time rate of demand for blocks43// of this size. We compute a padded average of this rate as44// our current estimate for the time rate of demand for blocks45// of this size. Similarly, we keep a padded average for the time46// between sweeps. Our current estimate for demand for blocks of47// this size is then simply computed as the product of these two48// estimates.49AdaptivePaddedAverage _demand_rate_estimate;5051ssize_t _desired; // Demand stimate computed as described above52ssize_t _coal_desired; // desired +/- small-percent for tuning coalescing5354ssize_t _surplus; // count - (desired +/- small-percent),55// used to tune splitting in best fit56ssize_t _bfr_surp; // surplus at start of current sweep57ssize_t _prev_sweep; // count from end of previous sweep58ssize_t _before_sweep; // count from before current sweep59ssize_t _coal_births; // additional chunks from coalescing60ssize_t _coal_deaths; // loss from coalescing61ssize_t _split_births; // additional chunks from splitting62ssize_t _split_deaths; // loss from splitting63size_t _returned_bytes; // number of bytes returned to list.64public:65void initialize(bool split_birth = false) {66AdaptivePaddedAverage* dummy =67new (&_demand_rate_estimate) AdaptivePaddedAverage(CMS_FLSWeight,68CMS_FLSPadding);69_desired = 0;70_coal_desired = 0;71_surplus = 0;72_bfr_surp = 0;73_prev_sweep = 0;74_before_sweep = 0;75_coal_births = 0;76_coal_deaths = 0;77_split_births = (split_birth ? 1 : 0);78_split_deaths = 0;79_returned_bytes = 0;80}8182AllocationStats() {83initialize();84}8586// The rate estimate is in blocks per second.87void compute_desired(size_t count,88float inter_sweep_current,89float inter_sweep_estimate,90float intra_sweep_estimate) {91// If the latest inter-sweep time is below our granularity92// of measurement, we may call in here with93// inter_sweep_current == 0. However, even for suitably small94// but non-zero inter-sweep durations, we may not trust the accuracy95// of accumulated data, since it has not been "integrated"96// (read "low-pass-filtered") long enough, and would be97// vulnerable to noisy glitches. In such cases, we98// ignore the current sample and use currently available99// historical estimates.100assert(prev_sweep() + split_births() + coal_births() // "Total Production Stock"101>= split_deaths() + coal_deaths() + (ssize_t)count, // "Current stock + depletion"102"Conservation Principle");103if (inter_sweep_current > _threshold) {104ssize_t demand = prev_sweep() - (ssize_t)count + split_births() + coal_births()105- split_deaths() - coal_deaths();106assert(demand >= 0,107err_msg("Demand (" SSIZE_FORMAT ") should be non-negative for "108PTR_FORMAT " (size=" SIZE_FORMAT ")",109demand, p2i(this), count));110// Defensive: adjust for imprecision in event counting111if (demand < 0) {112demand = 0;113}114float old_rate = _demand_rate_estimate.padded_average();115float rate = ((float)demand)/inter_sweep_current;116_demand_rate_estimate.sample(rate);117float new_rate = _demand_rate_estimate.padded_average();118ssize_t old_desired = _desired;119float delta_ise = (CMSExtrapolateSweep ? intra_sweep_estimate : 0.0);120_desired = (ssize_t)(new_rate * (inter_sweep_estimate + delta_ise));121if (PrintFLSStatistics > 1) {122gclog_or_tty->print_cr(123"demand: " SSIZE_FORMAT ", old_rate: %f, current_rate: %f, new_rate: %f, old_desired: " SSIZE_FORMAT ", new_desired: " SSIZE_FORMAT,124demand, old_rate, rate, new_rate, old_desired, _desired);125}126}127}128129ssize_t desired() const { return _desired; }130void set_desired(ssize_t v) { _desired = v; }131132ssize_t coal_desired() const { return _coal_desired; }133void set_coal_desired(ssize_t v) { _coal_desired = v; }134135ssize_t surplus() const { return _surplus; }136void set_surplus(ssize_t v) { _surplus = v; }137void increment_surplus() { _surplus++; }138void decrement_surplus() { _surplus--; }139140ssize_t bfr_surp() const { return _bfr_surp; }141void set_bfr_surp(ssize_t v) { _bfr_surp = v; }142ssize_t prev_sweep() const { return _prev_sweep; }143void set_prev_sweep(ssize_t v) { _prev_sweep = v; }144ssize_t before_sweep() const { return _before_sweep; }145void set_before_sweep(ssize_t v) { _before_sweep = v; }146147ssize_t coal_births() const { return _coal_births; }148void set_coal_births(ssize_t v) { _coal_births = v; }149void increment_coal_births() { _coal_births++; }150151ssize_t coal_deaths() const { return _coal_deaths; }152void set_coal_deaths(ssize_t v) { _coal_deaths = v; }153void increment_coal_deaths() { _coal_deaths++; }154155ssize_t split_births() const { return _split_births; }156void set_split_births(ssize_t v) { _split_births = v; }157void increment_split_births() { _split_births++; }158159ssize_t split_deaths() const { return _split_deaths; }160void set_split_deaths(ssize_t v) { _split_deaths = v; }161void increment_split_deaths() { _split_deaths++; }162163NOT_PRODUCT(164size_t returned_bytes() const { return _returned_bytes; }165void set_returned_bytes(size_t v) { _returned_bytes = v; }166)167};168169#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP170171172