src/share/vm/utilities/numberSeq.hpp

Fri, 13 Nov 2009 11:55:26 -0800

author
ysr
date
Fri, 13 Nov 2009 11:55:26 -0800
changeset 1521
89f1b9ae8991
parent 777
37f87013dfd8
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6898948: G1: forensic instrumentation for out-of-bounds recent_avg_pause_time_ratio()
Summary: Added instrumentation and (temporary) assert in non-product mode; clipped the value when found out-of-bounds in product mode. Fix of original issue will follow collection of data from this instrumentation.
Reviewed-by: jcoomes, tonyp

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

mercurial