hotspot/test/native/gc/g1/test_g1Predictions.cpp
author kzhaldyb
Mon, 22 Aug 2016 16:43:56 +0300
changeset 40904 5189925f9ece
parent 33214 hotspot/src/share/vm/gc/g1/g1Predictions.cpp@5a00fba36171
permissions -rw-r--r--
8164028: Convert TestPredictions_test to GTest Reviewed-by: jwilhelm, dfazunen, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
     1
/*
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
     4
 *
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
     8
 *
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    14
 *
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    18
 *
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    21
 * questions.
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    22
 *
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    23
 */
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    24
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    25
#include "precompiled.hpp"
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    26
#include "gc/g1/g1Predictions.hpp"
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    27
#include "unittest.hpp"
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    28
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    29
static const double epsilon = 1e-6;
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    30
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    31
// Some basic formula tests with confidence = 0.0
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    32
TEST_VM(G1Predictions, basic_predictions) {
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    33
  G1Predictions predictor(0.0);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    34
  TruncatedSeq s;
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    35
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    36
  double p0 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    37
  ASSERT_LT(p0, epsilon) << "Initial prediction of empty sequence must be 0.0";
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    38
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    39
  s.add(5.0);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    40
  double p1 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    41
  ASSERT_NEAR(p1, 5.0, epsilon);
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    42
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    43
  for (int i = 0; i < 40; i++) {
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    44
    s.add(5.0);
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    45
  }
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    46
  double p2 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    47
  ASSERT_NEAR(p2, 5.0, epsilon);
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    48
}
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    49
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    50
// The following tests checks that the initial predictions are based on
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    51
// the average of the sequence and not on the stddev (which is 0).
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    52
TEST_VM(G1Predictions, average_not_stdev_predictions) {
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    53
  G1Predictions predictor(0.5);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    54
  TruncatedSeq s;
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    55
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    56
  s.add(1.0);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    57
  double p1 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    58
  ASSERT_GT(p1, s.davg()) << "First prediction must be greater than average";
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    59
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    60
  s.add(1.0);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    61
  double p2 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    62
  ASSERT_GT(p1, p2) << "First prediction must be greater than second";
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    63
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    64
  s.add(1.0);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    65
  double p3 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    66
  ASSERT_GT(p2, p3) << "Second prediction must be greater than third";
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    67
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    68
  s.add(1.0);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    69
  s.add(1.0); // Five elements are now in the sequence.
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    70
  double p4 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    71
  ASSERT_LT(p4, p3) << "Fourth prediction must be smaller than third";
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    72
  ASSERT_NEAR(p4, 1.0, epsilon);
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    73
}
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    74
40904
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    75
// The following tests checks that initially prediction based on
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    76
// the average is used, that gets overridden by the stddev prediction at
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    77
// the end.
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    78
TEST_VM(G1Predictions, average_stdev_predictions) {
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    79
  G1Predictions predictor(0.5);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    80
  TruncatedSeq s;
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    81
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    82
  s.add(0.5);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    83
  double p1 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    84
  ASSERT_GT(p1, s.davg()) << "First prediction must be greater than average";
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    85
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    86
  s.add(0.2);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    87
  double p2 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    88
  ASSERT_GT(p1, p2) << "First prediction must be greater than second";
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    89
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    90
  s.add(0.5);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    91
  double p3 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    92
  ASSERT_GT(p2, p3) << "Second prediction must be greater than third";
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    93
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    94
  s.add(0.2);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    95
  s.add(2.0);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    96
  double p4 = predictor.get_new_prediction(&s);
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    97
  ASSERT_GT(p4, p3) << "Fourth prediction must be greater than third";
5189925f9ece 8164028: Convert TestPredictions_test to GTest
kzhaldyb
parents: 33214
diff changeset
    98
}