author | brutisso |
Tue, 13 Mar 2012 21:12:53 +0100 | |
changeset 12117 | 23b52cd6ca73 |
parent 7397 | 5b173b4ca846 |
child 12781 | dd6480eea079 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
12117 | 2 |
* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
1374 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4456
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4456
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4456
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_UTILITIES_NUMBERSEQ_HPP |
26 |
#define SHARE_VM_UTILITIES_NUMBERSEQ_HPP |
|
27 |
||
1374 | 28 |
/** |
29 |
** This file contains a few classes that represent number sequence, |
|
30 |
** x1, x2, x3, ..., xN, and can calculate their avg, max, and sd. |
|
31 |
** |
|
32 |
** Here's a quick description of the classes: |
|
33 |
** |
|
34 |
** AbsSeq: abstract superclass |
|
35 |
** NumberSeq: the sequence is assumed to be very long and the |
|
36 |
** maximum, avg, sd, davg, and dsd are calculated over all its elements |
|
37 |
** TruncatedSeq: this class keeps track of the last L elements |
|
38 |
** of the sequence and calculates avg, max, and sd only over them |
|
39 |
**/ |
|
40 |
||
41 |
#define DEFAULT_ALPHA_VALUE 0.7 |
|
42 |
||
43 |
class AbsSeq { |
|
44 |
private: |
|
45 |
void init(double alpha); |
|
46 |
||
47 |
protected: |
|
48 |
int _num; // the number of elements in the sequence |
|
49 |
double _sum; // the sum of the elements in the sequence |
|
50 |
double _sum_of_squares; // the sum of squares of the elements in the sequence |
|
51 |
||
52 |
double _davg; // decaying average |
|
53 |
double _dvariance; // decaying variance |
|
54 |
double _alpha; // factor for the decaying average / variance |
|
55 |
||
56 |
// This is what we divide with to get the average. In a standard |
|
57 |
// number sequence, this should just be the number of elements in it. |
|
58 |
virtual double total() const { return (double) _num; }; |
|
59 |
||
60 |
public: |
|
61 |
AbsSeq(double alpha = DEFAULT_ALPHA_VALUE); |
|
62 |
||
63 |
virtual void add(double val); // adds a new element to the sequence |
|
64 |
void add(unsigned val) { add((double) val); } |
|
65 |
virtual double maximum() const = 0; // maximum element in the sequence |
|
66 |
virtual double last() const = 0; // last element added in the sequence |
|
67 |
||
68 |
// the number of elements in the sequence |
|
69 |
int num() const { return _num; } |
|
70 |
// the sum of the elements in the sequence |
|
71 |
double sum() const { return _sum; } |
|
72 |
||
73 |
double avg() const; // the average of the sequence |
|
74 |
double variance() const; // the variance of the sequence |
|
75 |
double sd() const; // the standard deviation of the sequence |
|
76 |
||
77 |
double davg() const; // decaying average |
|
78 |
double dvariance() const; // decaying variance |
|
79 |
double dsd() const; // decaying "standard deviation" |
|
4456
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
80 |
|
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
81 |
// Debugging/Printing |
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
82 |
virtual void dump(); |
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
83 |
virtual void dump_on(outputStream* s); |
1374 | 84 |
}; |
85 |
||
86 |
class NumberSeq: public AbsSeq { |
|
87 |
private: |
|
88 |
bool check_nums(NumberSeq* total, int n, NumberSeq** parts); |
|
89 |
||
90 |
protected: |
|
91 |
double _last; |
|
92 |
double _maximum; // keep track of maximum value |
|
93 |
||
94 |
public: |
|
95 |
NumberSeq(double alpha = DEFAULT_ALPHA_VALUE); |
|
96 |
NumberSeq(NumberSeq* total, int n_parts, NumberSeq** parts); |
|
97 |
||
98 |
virtual void add(double val); |
|
99 |
virtual double maximum() const { return _maximum; } |
|
100 |
virtual double last() const { return _last; } |
|
4456
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
101 |
|
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
102 |
// Debugging/Printing |
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
103 |
virtual void dump_on(outputStream* s); |
1374 | 104 |
}; |
105 |
||
106 |
class TruncatedSeq: public AbsSeq { |
|
107 |
private: |
|
108 |
enum PrivateConstants { |
|
109 |
DefaultSeqLength = 10 |
|
110 |
}; |
|
111 |
void init(); |
|
112 |
protected: |
|
113 |
double *_sequence; // buffers the last L elements in the sequence |
|
114 |
int _length; // this is L |
|
115 |
int _next; // oldest slot in the array, i.e. next to be overwritten |
|
116 |
||
117 |
public: |
|
118 |
// accepts a value for L |
|
119 |
TruncatedSeq(int length = DefaultSeqLength, |
|
120 |
double alpha = DEFAULT_ALPHA_VALUE); |
|
12117 | 121 |
~TruncatedSeq(); |
1374 | 122 |
virtual void add(double val); |
123 |
virtual double maximum() const; |
|
124 |
virtual double last() const; // the last value added to the sequence |
|
125 |
||
126 |
double oldest() const; // the oldest valid value in the sequence |
|
127 |
double predict_next() const; // prediction based on linear regression |
|
4456
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
128 |
|
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
129 |
// Debugging/Printing |
fa02c2ef7a70
6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
ysr
parents:
1374
diff
changeset
|
130 |
virtual void dump_on(outputStream* s); |
1374 | 131 |
}; |
7397 | 132 |
|
133 |
#endif // SHARE_VM_UTILITIES_NUMBERSEQ_HPP |