hotspot/src/share/vm/gc/g1/g1Predictions.cpp
author tschatzl
Thu, 15 Oct 2015 10:07:28 +0200
changeset 33214 5a00fba36171
permissions -rw-r--r--
8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up Summary: Factor out G1 prediction code from G1CollectorPolicy into its own class, constify methods of G1CollectorPolicy and move more implementations to the cpp file. Reviewed-by: jmasa, sangheki, ecaspole, kbarrett
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
/*
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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"
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    27
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    28
#ifndef PRODUCT
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    29
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    30
void G1Predictions::test() {
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    31
  double const epsilon = 1e-6;
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    32
  {
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    33
    // Some basic formula tests with confidence = 0.0
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    34
    G1Predictions predictor(0.0);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    35
    TruncatedSeq s;
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    36
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    37
    double p0 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    38
    assert(p0 < epsilon, "Initial prediction of empty sequence must be 0.0 but is %f", p0);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    39
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    40
    s.add(5.0);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    41
    double p1 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    42
    assert(fabs(p1 - 5.0) < epsilon, "Prediction should be 5.0 but is %f", p1);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    43
    for (int i = 0; i < 40; i++) {
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    44
      s.add(5.0);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    45
    }
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    46
    double p2 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    47
    assert(fabs(p2 - 5.0) < epsilon, "Prediction should be 5.0 but is %f", p1);
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
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    50
  {
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    51
    // The following tests checks that the initial predictions are based on the
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    52
    // average of the sequence and not on the stddev (which is 0).
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    53
    G1Predictions predictor(0.5);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    54
    TruncatedSeq s;
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    55
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    56
    s.add(1.0);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    57
    double p1 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    58
    assert(p1 > 1.0, "First prediction must be larger than average, but avg is %f and prediction %f", s.davg(), p1);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    59
    s.add(1.0);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    60
    double p2 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    61
    assert(p2 < p1, "First prediction must be larger than second, but they are %f %f", p1, p2);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    62
    s.add(1.0);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    63
    double p3 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    64
    assert(p3 < p2, "Second prediction must be larger than third, but they are %f %f", p2, p3);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    65
    s.add(1.0);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    66
    s.add(1.0); // Five elements are now in the sequence.
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    67
    double p5 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    68
    assert(p5 < p3, "Fifth prediction must be smaller than third, but they are %f %f", p3, p5);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    69
    assert(fabs(p5 - 1.0) < epsilon, "Prediction must be 1.0+epsilon, but is %f", p5);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    70
  }
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    71
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    72
  {
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    73
    // The following tests checks that initially prediction based on the average is
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    74
    // used, that gets overridden by the stddev prediction at the end.
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    75
    G1Predictions predictor(0.5);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    76
    TruncatedSeq s;
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    77
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    78
    s.add(0.5);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    79
    double p1 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    80
    assert(p1 > 0.5, "First prediction must be larger than average, but avg is %f and prediction %f", s.davg(), p1);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    81
    s.add(0.2);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    82
    double p2 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    83
    assert(p2 < p1, "First prediction must be larger than second, but they are %f %f", p1, p2);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    84
    s.add(0.5);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    85
    double p3 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    86
    assert(p3 < p2, "Second prediction must be larger than third, but they are %f %f", p2, p3);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    87
    s.add(0.2);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    88
    s.add(2.0);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    89
    double p5 = predictor.get_new_prediction(&s);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    90
    assert(p5 > p3, "Fifth prediction must be bigger than third, but they are %f %f", p3, p5);
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    91
  }
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    92
}
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    93
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    94
void TestPredictions_test() {
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    95
  G1Predictions::test();
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    96
}
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    97
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff changeset
    98
#endif