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