annotate src/share/vm/utilities/numberSeq.cpp @ 5938:2c0751569716

7152954: G1: Native memory leak during full GCs Summary: Add destructor to TruncatedSeq and call delete when necessary Reviewed-by: johnc, tonyp
author brutisso
date Tue, 13 Mar 2012 21:12:53 +0100
parents f95d63e2154a
children bbc900c2482a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
1 /*
5938
2c0751569716 7152954: G1: Native memory leak during full GCs
brutisso
parents: 1972
diff changeset
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
4 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
7 * published by the Free Software Foundation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
8 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
13 * accompanied this code).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
14 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1086
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1086
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1086
diff changeset
21 * questions.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
22 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
23 */
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "utilities/debug.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "utilities/globalDefinitions.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "utilities/numberSeq.hpp"
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
30
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
31 AbsSeq::AbsSeq(double alpha) :
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
32 _num(0), _sum(0.0), _sum_of_squares(0.0),
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
33 _davg(0.0), _dvariance(0.0), _alpha(alpha) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
34 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
35
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
36 void AbsSeq::add(double val) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
37 if (_num == 0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
38 // if the sequence is empty, the davg is the same as the value
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
39 _davg = val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
40 // and the variance is 0
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
41 _dvariance = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
42 } else {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
43 // otherwise, calculate both
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
44 _davg = (1.0 - _alpha) * val + _alpha * _davg;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
45 double diff = val - _davg;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
46 _dvariance = (1.0 - _alpha) * diff * diff + _alpha * _dvariance;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
47 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
48 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
49
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
50 double AbsSeq::avg() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
51 if (_num == 0)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
52 return 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
53 else
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
54 return _sum / total();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
55 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
56
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
57 double AbsSeq::variance() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
58 if (_num <= 1)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
59 return 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
60
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
61 double x_bar = avg();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
62 double result = _sum_of_squares / total() - x_bar * x_bar;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
63 if (result < 0.0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
64 // due to loss-of-precision errors, the variance might be negative
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
65 // by a small bit
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
66
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
67 // guarantee(-0.1 < result && result < 0.0,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
68 // "if variance is negative, it should be very small");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
69 result = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
70 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
71 return result;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
72 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
73
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
74 double AbsSeq::sd() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
75 double var = variance();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
76 guarantee( var >= 0.0, "variance should not be negative" );
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
77 return sqrt(var);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
78 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
79
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
80 double AbsSeq::davg() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
81 return _davg;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
82 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
83
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
84 double AbsSeq::dvariance() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
85 if (_num <= 1)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
86 return 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
87
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
88 double result = _dvariance;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
89 if (result < 0.0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
90 // due to loss-of-precision errors, the variance might be negative
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
91 // by a small bit
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
92
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
93 guarantee(-0.1 < result && result < 0.0,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
94 "if variance is negative, it should be very small");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
95 result = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
96 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
97 return result;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
98 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
99
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
100 double AbsSeq::dsd() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
101 double var = dvariance();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
102 guarantee( var >= 0.0, "variance should not be negative" );
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
103 return sqrt(var);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
104 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
105
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
106 NumberSeq::NumberSeq(double alpha) :
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
107 AbsSeq(alpha), _maximum(0.0), _last(0.0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
108 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
109
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
110 bool NumberSeq::check_nums(NumberSeq *total, int n, NumberSeq **parts) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
111 for (int i = 0; i < n; ++i) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
112 if (parts[i] != NULL && total->num() != parts[i]->num())
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
113 return false;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
114 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
115 return true;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
116 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
117
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
118 NumberSeq::NumberSeq(NumberSeq *total, int n, NumberSeq **parts) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
119 guarantee(check_nums(total, n, parts), "all seq lengths should match");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
120 double sum = total->sum();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
121 for (int i = 0; i < n; ++i) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
122 if (parts[i] != NULL)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
123 sum -= parts[i]->sum();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
124 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
125
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
126 _num = total->num();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
127 _sum = sum;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
128
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
129 // we do not calculate these...
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
130 _sum_of_squares = -1.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
131 _maximum = -1.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
132 _davg = -1.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
133 _dvariance = -1.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
134 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
135
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
136 void NumberSeq::add(double val) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
137 AbsSeq::add(val);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
138
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
139 _last = val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
140 if (_num == 0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
141 _maximum = val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
142 } else {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
143 if (val > _maximum)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
144 _maximum = val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
145 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
146 _sum += val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
147 _sum_of_squares += val * val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
148 ++_num;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
149 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
150
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
151
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
152 TruncatedSeq::TruncatedSeq(int length, double alpha):
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
153 AbsSeq(alpha), _length(length), _next(0) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
154 _sequence = NEW_C_HEAP_ARRAY(double, _length);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
155 for (int i = 0; i < _length; ++i)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
156 _sequence[i] = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
157 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
158
5938
2c0751569716 7152954: G1: Native memory leak during full GCs
brutisso
parents: 1972
diff changeset
159 TruncatedSeq::~TruncatedSeq() {
2c0751569716 7152954: G1: Native memory leak during full GCs
brutisso
parents: 1972
diff changeset
160 FREE_C_HEAP_ARRAY(double, _sequence);
2c0751569716 7152954: G1: Native memory leak during full GCs
brutisso
parents: 1972
diff changeset
161 }
2c0751569716 7152954: G1: Native memory leak during full GCs
brutisso
parents: 1972
diff changeset
162
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
163 void TruncatedSeq::add(double val) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
164 AbsSeq::add(val);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
165
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
166 // get the oldest value in the sequence...
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
167 double old_val = _sequence[_next];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
168 // ...remove it from the sum and sum of squares
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
169 _sum -= old_val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
170 _sum_of_squares -= old_val * old_val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
171
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
172 // ...and update them with the new value
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
173 _sum += val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
174 _sum_of_squares += val * val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
175
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
176 // now replace the old value with the new one
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
177 _sequence[_next] = val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
178 _next = (_next + 1) % _length;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
179
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
180 // only increase it if the buffer is not full
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
181 if (_num < _length)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
182 ++_num;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
183
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
184 guarantee( variance() > -1.0, "variance should be >= 0" );
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
185 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
186
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
187 // can't easily keep track of this incrementally...
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
188 double TruncatedSeq::maximum() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
189 if (_num == 0)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
190 return 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
191 double ret = _sequence[0];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
192 for (int i = 1; i < _num; ++i) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
193 double val = _sequence[i];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
194 if (val > ret)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
195 ret = val;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
196 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
197 return ret;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
198 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
199
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
200 double TruncatedSeq::last() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
201 if (_num == 0)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
202 return 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
203 unsigned last_index = (_next + _length - 1) % _length;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
204 return _sequence[last_index];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
205 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
206
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
207 double TruncatedSeq::oldest() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
208 if (_num == 0)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
209 return 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
210 else if (_num < _length)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
211 // index 0 always oldest value until the array is full
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
212 return _sequence[0];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
213 else {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
214 // since the array is full, _next is over the oldest value
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
215 return _sequence[_next];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
216 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
217 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
218
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
219 double TruncatedSeq::predict_next() const {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
220 if (_num == 0)
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
221 return 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
222
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
223 double num = (double) _num;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
224 double x_squared_sum = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
225 double x_sum = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
226 double y_sum = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
227 double xy_sum = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
228 double x_avg = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
229 double y_avg = 0.0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
230
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
231 int first = (_next + _length - _num) % _length;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
232 for (int i = 0; i < _num; ++i) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
233 double x = (double) i;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
234 double y = _sequence[(first + i) % _length];
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
235
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
236 x_squared_sum += x * x;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
237 x_sum += x;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
238 y_sum += y;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
239 xy_sum += x * y;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
240 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
241 x_avg = x_sum / num;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
242 y_avg = y_sum / num;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
243
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
244 double Sxx = x_squared_sum - x_sum * x_sum / num;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
245 double Sxy = xy_sum - x_sum * y_sum / num;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
246 double b1 = Sxy / Sxx;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
247 double b0 = y_avg - b1 * x_avg;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
248
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
249 return b0 + b1 * num;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
250 }
1086
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
251
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
252
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
253 // Printing/Debugging Support
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
254
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
255 void AbsSeq::dump() { dump_on(gclog_or_tty); }
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
256
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
257 void AbsSeq::dump_on(outputStream* s) {
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
258 s->print_cr("\t _num = %d, _sum = %7.3f, _sum_of_squares = %7.3f",
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
259 _num, _sum, _sum_of_squares);
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
260 s->print_cr("\t _davg = %7.3f, _dvariance = %7.3f, _alpha = %7.3f",
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
261 _davg, _dvariance, _alpha);
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
262 }
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
263
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
264 void NumberSeq::dump_on(outputStream* s) {
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
265 AbsSeq::dump_on(s);
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
266 s->print_cr("\t\t _last = %7.3f, _maximum = %7.3f");
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
267 }
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
268
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
269 void TruncatedSeq::dump_on(outputStream* s) {
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
270 AbsSeq::dump_on(s);
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
271 s->print_cr("\t\t _length = %d, _next = %d", _length, _next);
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
272 for (int i = 0; i < _length; i++) {
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
273 if (i%5 == 0) {
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
274 s->cr();
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
275 s->print("\t");
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
276 }
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
277 s->print("\t[%d]=%7.3f", i, _sequence[i]);
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
278 }
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
279 s->print_cr("");
89f1b9ae8991 6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents: 342
diff changeset
280 }