Path: blob/master/test/hotspot/gtest/gc/g1/test_g1Predictions.cpp
41149 views
/*1* Copyright (c) 2016, 2019, 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/g1Predictions.hpp"26#include "unittest.hpp"2728#include "utilities/ostream.hpp"2930static const double epsilon = 1e-6;3132// Some basic formula tests with confidence = 0.033TEST_VM(G1Predictions, basic_predictions) {34G1Predictions predictor(0.0);35TruncatedSeq s;3637double p0 = predictor.predict(&s);38ASSERT_LT(p0, epsilon) << "Initial prediction of empty sequence must be 0.0";3940s.add(5.0);41double p1 = predictor.predict(&s);42ASSERT_NEAR(p1, 5.0, epsilon);4344for (int i = 0; i < 40; i++) {45s.add(5.0);46}47double p2 = predictor.predict(&s);48ASSERT_NEAR(p2, 5.0, epsilon);49}5051// The following tests checks that the initial predictions are based on52// the average of the sequence and not on the stddev (which is 0).53TEST_VM(G1Predictions, average_not_stdev_predictions) {54G1Predictions predictor(0.5);55TruncatedSeq s;5657s.add(1.0);58double p1 = predictor.predict(&s);59ASSERT_GT(p1, s.davg()) << "First prediction must be greater than average";6061s.add(1.0);62double p2 = predictor.predict(&s);63ASSERT_GT(p1, p2) << "First prediction must be greater than second";6465s.add(1.0);66double p3 = predictor.predict(&s);67ASSERT_GT(p2, p3) << "Second prediction must be greater than third";6869s.add(1.0);70s.add(1.0); // Five elements are now in the sequence.71double p4 = predictor.predict(&s);72ASSERT_LT(p4, p3) << "Fourth prediction must be smaller than third";73ASSERT_NEAR(p4, 1.0, epsilon);74}7576// The following tests checks that initially prediction based on77// the average is used, that gets overridden by the stddev prediction at78// the end.79TEST_VM(G1Predictions, average_stdev_predictions) {80G1Predictions predictor(0.5);81TruncatedSeq s;8283s.add(0.5);84double p1 = predictor.predict(&s);85ASSERT_GT(p1, s.davg()) << "First prediction must be greater than average";8687s.add(0.2);88double p2 = predictor.predict(&s);89ASSERT_GT(p1, p2) << "First prediction must be greater than second";9091s.add(0.5);92double p3 = predictor.predict(&s);93ASSERT_GT(p2, p3) << "Second prediction must be greater than third";9495s.add(0.2);96s.add(2.0);97double p4 = predictor.predict(&s);98ASSERT_GT(p4, p3) << "Fourth prediction must be greater than third";99}100101// Some tests to verify bounding between [0 .. 1]102TEST_VM(G1Predictions, unit_predictions) {103G1Predictions predictor(0.5);104TruncatedSeq s;105106double p0 = predictor.predict_in_unit_interval(&s);107ASSERT_LT(p0, epsilon) << "Initial prediction of empty sequence must be 0.0";108109s.add(100.0);110double p1 = predictor.predict_in_unit_interval(&s);111ASSERT_NEAR(p1, 1.0, epsilon);112113// Feed the sequence additional positive values to test the high bound.114for (int i = 0; i < 3; i++) {115s.add(2.0);116}117ASSERT_NEAR(predictor.predict_in_unit_interval(&s), 1.0, epsilon);118119// Feed the sequence additional large negative value to test the low bound.120for (int i = 0; i < 4; i++) {121s.add(-200.0);122}123ASSERT_NEAR(predictor.predict_in_unit_interval(&s), 0.0, epsilon);124}125126// Some tests to verify bounding between [0 .. +inf]127TEST_VM(G1Predictions, lower_bound_zero_predictions) {128G1Predictions predictor(0.5);129TruncatedSeq s;130131double p0 = predictor.predict_zero_bounded(&s);132ASSERT_LT(p0, epsilon) << "Initial prediction of empty sequence must be 0.0";133134s.add(100.0);135// Feed the sequence additional positive values to see that the high bound is not136// bounded by e.g. 1.0137for (int i = 0; i < 3; i++) {138s.add(2.0);139}140ASSERT_GT(predictor.predict_zero_bounded(&s), 1.0);141142// Feed the sequence additional large negative value to test the low bound.143for (int i = 0; i < 4; i++) {144s.add(-200.0);145}146ASSERT_NEAR(predictor.predict_zero_bounded(&s), 0.0, epsilon);147}148149150