0N/A/*
2273N/A * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "gc_implementation/shared/gcUtil.hpp"
0N/A
0N/A// Catch-all file for utility classes
0N/A
0N/Afloat AdaptiveWeightedAverage::compute_adaptive_average(float new_sample,
0N/A float average) {
0N/A // We smooth the samples by not using weight() directly until we've
0N/A // had enough data to make it meaningful. We'd like the first weight
3385N/A // used to be 1, the second to be 1/2, etc until we have
3385N/A // OLD_THRESHOLD/weight samples.
3385N/A unsigned count_weight = 0;
3385N/A
3385N/A // Avoid division by zero if the counter wraps (7158457)
3385N/A if (!is_old()) {
3385N/A count_weight = OLD_THRESHOLD/count();
3385N/A }
3385N/A
0N/A unsigned adaptive_weight = (MAX2(weight(), count_weight));
0N/A
0N/A float new_avg = exp_avg(average, new_sample, adaptive_weight);
0N/A
0N/A return new_avg;
0N/A}
0N/A
0N/Avoid AdaptiveWeightedAverage::sample(float new_sample) {
0N/A increment_count();
0N/A
0N/A // Compute the new weighted average
0N/A float new_avg = compute_adaptive_average(new_sample, average());
0N/A set_average(new_avg);
0N/A _last_sample = new_sample;
0N/A}
0N/A
1145N/Avoid AdaptiveWeightedAverage::print() const {
1145N/A print_on(tty);
1145N/A}
1145N/A
1145N/Avoid AdaptiveWeightedAverage::print_on(outputStream* st) const {
1145N/A guarantee(false, "NYI");
1145N/A}
1145N/A
1145N/Avoid AdaptivePaddedAverage::print() const {
1145N/A print_on(tty);
1145N/A}
1145N/A
1145N/Avoid AdaptivePaddedAverage::print_on(outputStream* st) const {
1145N/A guarantee(false, "NYI");
1145N/A}
1145N/A
1145N/Avoid AdaptivePaddedNoZeroDevAverage::print() const {
1145N/A print_on(tty);
1145N/A}
1145N/A
1145N/Avoid AdaptivePaddedNoZeroDevAverage::print_on(outputStream* st) const {
1145N/A guarantee(false, "NYI");
1145N/A}
1145N/A
0N/Avoid AdaptivePaddedAverage::sample(float new_sample) {
1145N/A // Compute new adaptive weighted average based on new sample.
0N/A AdaptiveWeightedAverage::sample(new_sample);
0N/A
1145N/A // Now update the deviation and the padded average.
0N/A float new_avg = average();
0N/A float new_dev = compute_adaptive_average(fabsd(new_sample - new_avg),
0N/A deviation());
0N/A set_deviation(new_dev);
0N/A set_padded_average(new_avg + padding() * new_dev);
0N/A _last_sample = new_sample;
0N/A}
0N/A
0N/Avoid AdaptivePaddedNoZeroDevAverage::sample(float new_sample) {
0N/A // Compute our parent classes sample information
0N/A AdaptiveWeightedAverage::sample(new_sample);
0N/A
0N/A float new_avg = average();
0N/A if (new_sample != 0) {
0N/A // We only create a new deviation if the sample is non-zero
0N/A float new_dev = compute_adaptive_average(fabsd(new_sample - new_avg),
0N/A deviation());
0N/A
0N/A set_deviation(new_dev);
0N/A }
0N/A set_padded_average(new_avg + padding() * deviation());
0N/A _last_sample = new_sample;
0N/A}
0N/A
0N/ALinearLeastSquareFit::LinearLeastSquareFit(unsigned weight) :
2070N/A _sum_x(0), _sum_x_squared(0), _sum_y(0), _sum_xy(0),
2070N/A _intercept(0), _slope(0), _mean_x(weight), _mean_y(weight) {}
0N/A
0N/Avoid LinearLeastSquareFit::update(double x, double y) {
0N/A _sum_x = _sum_x + x;
0N/A _sum_x_squared = _sum_x_squared + x * x;
0N/A _sum_y = _sum_y + y;
0N/A _sum_xy = _sum_xy + x * y;
0N/A _mean_x.sample(x);
0N/A _mean_y.sample(y);
0N/A assert(_mean_x.count() == _mean_y.count(), "Incorrect count");
0N/A if ( _mean_x.count() > 1 ) {
0N/A double slope_denominator;
0N/A slope_denominator = (_mean_x.count() * _sum_x_squared - _sum_x * _sum_x);
0N/A // Some tolerance should be injected here. A denominator that is
0N/A // nearly 0 should be avoided.
0N/A
0N/A if (slope_denominator != 0.0) {
0N/A double slope_numerator;
0N/A slope_numerator = (_mean_x.count() * _sum_xy - _sum_x * _sum_y);
0N/A _slope = slope_numerator / slope_denominator;
0N/A
0N/A // The _mean_y and _mean_x are decaying averages and can
0N/A // be used to discount earlier data. If they are used,
0N/A // first consider whether all the quantities should be
0N/A // kept as decaying averages.
0N/A // _intercept = _mean_y.average() - _slope * _mean_x.average();
0N/A _intercept = (_sum_y - _slope * _sum_x) / ((double) _mean_x.count());
0N/A }
0N/A }
0N/A}
0N/A
0N/Adouble LinearLeastSquareFit::y(double x) {
0N/A double new_y;
0N/A
0N/A if ( _mean_x.count() > 1 ) {
0N/A new_y = (_intercept + _slope * x);
0N/A return new_y;
0N/A } else {
0N/A return _mean_y.average();
0N/A }
0N/A}
0N/A
0N/A// Both decrement_will_decrease() and increment_will_decrease() return
0N/A// true for a slope of 0. That is because a change is necessary before
0N/A// a slope can be calculated and a 0 slope will, in general, indicate
0N/A// that no calculation of the slope has yet been done. Returning true
0N/A// for a slope equal to 0 reflects the intuitive expectation of the
0N/A// dependence on the slope. Don't use the complement of these functions
0N/A// since that untuitive expectation is not built into the complement.
0N/Abool LinearLeastSquareFit::decrement_will_decrease() {
0N/A return (_slope >= 0.00);
0N/A}
0N/A
0N/Abool LinearLeastSquareFit::increment_will_decrease() {
0N/A return (_slope <= 0.00);
0N/A}