src/share/vm/utilities/numberSeq.hpp

Mon, 03 Jan 2011 14:09:11 -0500

author
coleenp
date
Mon, 03 Jan 2011 14:09:11 -0500
changeset 2418
36c186bcc085
parent 2314
f95d63e2154a
child 3641
2c0751569716
permissions
-rw-r--r--

6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
Summary: enhance the error reporting mechanism to help user to fix the problem rather than making it look like a VM error.
Reviewed-by: kvn, kamg

ysr@777 1 /*
stefank@2314 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
stefank@2314 25 #ifndef SHARE_VM_UTILITIES_NUMBERSEQ_HPP
stefank@2314 26 #define SHARE_VM_UTILITIES_NUMBERSEQ_HPP
stefank@2314 27
ysr@777 28 /**
ysr@777 29 ** This file contains a few classes that represent number sequence,
ysr@777 30 ** x1, x2, x3, ..., xN, and can calculate their avg, max, and sd.
ysr@777 31 **
ysr@777 32 ** Here's a quick description of the classes:
ysr@777 33 **
ysr@777 34 ** AbsSeq: abstract superclass
ysr@777 35 ** NumberSeq: the sequence is assumed to be very long and the
ysr@777 36 ** maximum, avg, sd, davg, and dsd are calculated over all its elements
ysr@777 37 ** TruncatedSeq: this class keeps track of the last L elements
ysr@777 38 ** of the sequence and calculates avg, max, and sd only over them
ysr@777 39 **/
ysr@777 40
ysr@777 41 #define DEFAULT_ALPHA_VALUE 0.7
ysr@777 42
ysr@777 43 class AbsSeq {
ysr@777 44 private:
ysr@777 45 void init(double alpha);
ysr@777 46
ysr@777 47 protected:
ysr@777 48 int _num; // the number of elements in the sequence
ysr@777 49 double _sum; // the sum of the elements in the sequence
ysr@777 50 double _sum_of_squares; // the sum of squares of the elements in the sequence
ysr@777 51
ysr@777 52 double _davg; // decaying average
ysr@777 53 double _dvariance; // decaying variance
ysr@777 54 double _alpha; // factor for the decaying average / variance
ysr@777 55
ysr@777 56 // This is what we divide with to get the average. In a standard
ysr@777 57 // number sequence, this should just be the number of elements in it.
ysr@777 58 virtual double total() const { return (double) _num; };
ysr@777 59
ysr@777 60 public:
ysr@777 61 AbsSeq(double alpha = DEFAULT_ALPHA_VALUE);
ysr@777 62
ysr@777 63 virtual void add(double val); // adds a new element to the sequence
ysr@777 64 void add(unsigned val) { add((double) val); }
ysr@777 65 virtual double maximum() const = 0; // maximum element in the sequence
ysr@777 66 virtual double last() const = 0; // last element added in the sequence
ysr@777 67
ysr@777 68 // the number of elements in the sequence
ysr@777 69 int num() const { return _num; }
ysr@777 70 // the sum of the elements in the sequence
ysr@777 71 double sum() const { return _sum; }
ysr@777 72
ysr@777 73 double avg() const; // the average of the sequence
ysr@777 74 double variance() const; // the variance of the sequence
ysr@777 75 double sd() const; // the standard deviation of the sequence
ysr@777 76
ysr@777 77 double davg() const; // decaying average
ysr@777 78 double dvariance() const; // decaying variance
ysr@777 79 double dsd() const; // decaying "standard deviation"
ysr@1521 80
ysr@1521 81 // Debugging/Printing
ysr@1521 82 virtual void dump();
ysr@1521 83 virtual void dump_on(outputStream* s);
ysr@777 84 };
ysr@777 85
ysr@777 86 class NumberSeq: public AbsSeq {
ysr@777 87 private:
ysr@777 88 bool check_nums(NumberSeq* total, int n, NumberSeq** parts);
ysr@777 89
ysr@777 90 protected:
ysr@777 91 double _last;
ysr@777 92 double _maximum; // keep track of maximum value
ysr@777 93
ysr@777 94 public:
ysr@777 95 NumberSeq(double alpha = DEFAULT_ALPHA_VALUE);
ysr@777 96 NumberSeq(NumberSeq* total, int n_parts, NumberSeq** parts);
ysr@777 97
ysr@777 98 virtual void add(double val);
ysr@777 99 virtual double maximum() const { return _maximum; }
ysr@777 100 virtual double last() const { return _last; }
ysr@1521 101
ysr@1521 102 // Debugging/Printing
ysr@1521 103 virtual void dump_on(outputStream* s);
ysr@777 104 };
ysr@777 105
ysr@777 106 class TruncatedSeq: public AbsSeq {
ysr@777 107 private:
ysr@777 108 enum PrivateConstants {
ysr@777 109 DefaultSeqLength = 10
ysr@777 110 };
ysr@777 111 void init();
ysr@777 112 protected:
ysr@777 113 double *_sequence; // buffers the last L elements in the sequence
ysr@777 114 int _length; // this is L
ysr@777 115 int _next; // oldest slot in the array, i.e. next to be overwritten
ysr@777 116
ysr@777 117 public:
ysr@777 118 // accepts a value for L
ysr@777 119 TruncatedSeq(int length = DefaultSeqLength,
ysr@777 120 double alpha = DEFAULT_ALPHA_VALUE);
ysr@777 121 virtual void add(double val);
ysr@777 122 virtual double maximum() const;
ysr@777 123 virtual double last() const; // the last value added to the sequence
ysr@777 124
ysr@777 125 double oldest() const; // the oldest valid value in the sequence
ysr@777 126 double predict_next() const; // prediction based on linear regression
ysr@1521 127
ysr@1521 128 // Debugging/Printing
ysr@1521 129 virtual void dump_on(outputStream* s);
ysr@777 130 };
stefank@2314 131
stefank@2314 132 #endif // SHARE_VM_UTILITIES_NUMBERSEQ_HPP

mercurial