author | tschatzl |
Fri, 29 Nov 2019 10:20:16 +0100 | |
changeset 59320 | 11ff4e485670 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
33214
5a00fba36171
8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff
changeset
|
1 |
/* |
40904 | 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 | 27 |
#include "unittest.hpp" |
33214
5a00fba36171
8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff
changeset
|
28 |
|
59320
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
29 |
#include "utilities/ostream.hpp" |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
30 |
|
40904 | 31 |
static const double epsilon = 1e-6; |
33214
5a00fba36171
8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff
changeset
|
32 |
|
40904 | 33 |
// Some basic formula tests with confidence = 0.0 |
34 |
TEST_VM(G1Predictions, basic_predictions) { |
|
35 |
G1Predictions predictor(0.0); |
|
36 |
TruncatedSeq s; |
|
33214
5a00fba36171
8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff
changeset
|
37 |
|
40904 | 38 |
double p0 = predictor.get_new_prediction(&s); |
39 |
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
|
40 |
|
40904 | 41 |
s.add(5.0); |
42 |
double p1 = predictor.get_new_prediction(&s); |
|
43 |
ASSERT_NEAR(p1, 5.0, epsilon); |
|
33214
5a00fba36171
8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff
changeset
|
44 |
|
40904 | 45 |
for (int i = 0; i < 40; i++) { |
46 |
s.add(5.0); |
|
33214
5a00fba36171
8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff
changeset
|
47 |
} |
40904 | 48 |
double p2 = predictor.get_new_prediction(&s); |
49 |
ASSERT_NEAR(p2, 5.0, epsilon); |
|
33214
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 |
|
40904 | 52 |
// The following tests checks that the initial predictions are based on |
53 |
// the average of the sequence and not on the stddev (which is 0). |
|
54 |
TEST_VM(G1Predictions, average_not_stdev_predictions) { |
|
55 |
G1Predictions predictor(0.5); |
|
56 |
TruncatedSeq s; |
|
57 |
||
58 |
s.add(1.0); |
|
59 |
double p1 = predictor.get_new_prediction(&s); |
|
60 |
ASSERT_GT(p1, s.davg()) << "First prediction must be greater than average"; |
|
61 |
||
62 |
s.add(1.0); |
|
63 |
double p2 = predictor.get_new_prediction(&s); |
|
64 |
ASSERT_GT(p1, p2) << "First prediction must be greater than second"; |
|
65 |
||
66 |
s.add(1.0); |
|
67 |
double p3 = predictor.get_new_prediction(&s); |
|
68 |
ASSERT_GT(p2, p3) << "Second prediction must be greater than third"; |
|
69 |
||
70 |
s.add(1.0); |
|
71 |
s.add(1.0); // Five elements are now in the sequence. |
|
72 |
double p4 = predictor.get_new_prediction(&s); |
|
73 |
ASSERT_LT(p4, p3) << "Fourth prediction must be smaller than third"; |
|
74 |
ASSERT_NEAR(p4, 1.0, epsilon); |
|
33214
5a00fba36171
8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff
changeset
|
75 |
} |
5a00fba36171
8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents:
diff
changeset
|
76 |
|
40904 | 77 |
// The following tests checks that initially prediction based on |
78 |
// the average is used, that gets overridden by the stddev prediction at |
|
79 |
// the end. |
|
80 |
TEST_VM(G1Predictions, average_stdev_predictions) { |
|
81 |
G1Predictions predictor(0.5); |
|
82 |
TruncatedSeq s; |
|
83 |
||
84 |
s.add(0.5); |
|
85 |
double p1 = predictor.get_new_prediction(&s); |
|
86 |
ASSERT_GT(p1, s.davg()) << "First prediction must be greater than average"; |
|
87 |
||
88 |
s.add(0.2); |
|
89 |
double p2 = predictor.get_new_prediction(&s); |
|
90 |
ASSERT_GT(p1, p2) << "First prediction must be greater than second"; |
|
91 |
||
92 |
s.add(0.5); |
|
93 |
double p3 = predictor.get_new_prediction(&s); |
|
94 |
ASSERT_GT(p2, p3) << "Second prediction must be greater than third"; |
|
95 |
||
96 |
s.add(0.2); |
|
97 |
s.add(2.0); |
|
98 |
double p4 = predictor.get_new_prediction(&s); |
|
99 |
ASSERT_GT(p4, p3) << "Fourth prediction must be greater than third"; |
|
100 |
} |
|
59320
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
101 |
|
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
102 |
// Some tests to verify bounding between [0 .. 1] |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
103 |
TEST_VM(G1Predictions, unit_predictions) { |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
104 |
G1Predictions predictor(0.5); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
105 |
TruncatedSeq s; |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
106 |
|
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
107 |
double p0 = predictor.get_new_unit_prediction(&s); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
108 |
ASSERT_LT(p0, epsilon) << "Initial prediction of empty sequence must be 0.0"; |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
109 |
|
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
110 |
s.add(100.0); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
111 |
double p1 = predictor.get_new_unit_prediction(&s); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
112 |
ASSERT_NEAR(p1, 1.0, epsilon); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
113 |
|
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
114 |
// Feed the sequence additional positive values to test the high bound. |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
115 |
for (int i = 0; i < 3; i++) { |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
116 |
s.add(2.0); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
117 |
} |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
118 |
ASSERT_NEAR(predictor.get_new_unit_prediction(&s), 1.0, epsilon); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
119 |
|
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
120 |
// Feed the sequence additional large negative value to test the low bound. |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
121 |
for (int i = 0; i < 4; i++) { |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
122 |
s.add(-200.0); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
123 |
} |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
124 |
ASSERT_NEAR(predictor.get_new_unit_prediction(&s), 0.0, epsilon); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
125 |
} |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
126 |
|
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
127 |
// Some tests to verify bounding between [0 .. +inf] |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
128 |
TEST_VM(G1Predictions, lower_bound_zero_predictions) { |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
129 |
G1Predictions predictor(0.5); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
130 |
TruncatedSeq s; |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
131 |
|
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
132 |
double p0 = predictor.get_new_lower_zero_bound_prediction(&s); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
133 |
ASSERT_LT(p0, epsilon) << "Initial prediction of empty sequence must be 0.0"; |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
134 |
|
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
135 |
s.add(100.0); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
136 |
// Feed the sequence additional positive values to see that the high bound is not |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
137 |
// bounded by e.g. 1.0 |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
138 |
for (int i = 0; i < 3; i++) { |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
139 |
s.add(2.0); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
140 |
} |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
141 |
ASSERT_GT(predictor.get_new_lower_zero_bound_prediction(&s), 1.0); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
142 |
|
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
143 |
// Feed the sequence additional large negative value to test the low bound. |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
144 |
for (int i = 0; i < 4; i++) { |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
145 |
s.add(-200.0); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
146 |
} |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
147 |
ASSERT_NEAR(predictor.get_new_lower_zero_bound_prediction(&s), 0.0, epsilon); |
11ff4e485670
8227434: G1 predictions may over/underflow with high variance input
tschatzl
parents:
47216
diff
changeset
|
148 |
} |