src/share/vm/utilities/numberSeq.hpp

Fri, 07 Nov 2008 09:29:38 -0800

author
kvn
date
Fri, 07 Nov 2008 09:29:38 -0800
changeset 855
a1980da045cc
parent 777
37f87013dfd8
child 1521
89f1b9ae8991
permissions
-rw-r--r--

6462850: generate biased locking code in C2 ideal graph
Summary: Inline biased locking code in C2 ideal graph during macro nodes expansion
Reviewed-by: never

     1 /*
     2  * Copyright 2001-2007 Sun Microsystems, Inc.  All Rights Reserved.
     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  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 /**
    26  **  This file contains a few classes that represent number sequence,
    27  **  x1, x2, x3, ..., xN, and can calculate their avg, max, and sd.
    28  **
    29  **  Here's a quick description of the classes:
    30  **
    31  **    AbsSeq: abstract superclass
    32  **    NumberSeq: the sequence is assumed to be very long and the
    33  **      maximum, avg, sd, davg, and dsd are calculated over all its elements
    34  **    TruncatedSeq: this class keeps track of the last L elements
    35  **      of the sequence and calculates avg, max, and sd only over them
    36  **/
    38 #define DEFAULT_ALPHA_VALUE 0.7
    40 class AbsSeq {
    41 private:
    42   void init(double alpha);
    44 protected:
    45   int    _num; // the number of elements in the sequence
    46   double _sum; // the sum of the elements in the sequence
    47   double _sum_of_squares; // the sum of squares of the elements in the sequence
    49   double _davg; // decaying average
    50   double _dvariance; // decaying variance
    51   double _alpha; // factor for the decaying average / variance
    53   // This is what we divide with to get the average. In a standard
    54   // number sequence, this should just be the number of elements in it.
    55   virtual double total() const { return (double) _num; };
    57 public:
    58   AbsSeq(double alpha = DEFAULT_ALPHA_VALUE);
    60   virtual void add(double val); // adds a new element to the sequence
    61   void add(unsigned val) { add((double) val); }
    62   virtual double maximum() const = 0; // maximum element in the sequence
    63   virtual double last() const = 0; // last element added in the sequence
    65   // the number of elements in the sequence
    66   int num() const { return _num; }
    67   // the sum of the elements in the sequence
    68   double sum() const { return _sum; }
    70   double avg() const; // the average of the sequence
    71   double variance() const; // the variance of the sequence
    72   double sd() const; // the standard deviation of the sequence
    74   double davg() const; // decaying average
    75   double dvariance() const; // decaying variance
    76   double dsd() const; // decaying "standard deviation"
    77 };
    79 class NumberSeq: public AbsSeq {
    80 private:
    81   bool check_nums(NumberSeq* total, int n, NumberSeq** parts);
    83 protected:
    84   double _last;
    85   double _maximum; // keep track of maximum value
    87 public:
    88   NumberSeq(double alpha = DEFAULT_ALPHA_VALUE);
    89   NumberSeq(NumberSeq* total, int n_parts, NumberSeq** parts);
    91   virtual void add(double val);
    92   virtual double maximum() const { return _maximum; }
    93   virtual double last() const { return _last; }
    94 };
    96 class TruncatedSeq: public AbsSeq {
    97 private:
    98   enum PrivateConstants {
    99     DefaultSeqLength = 10
   100   };
   101   void init();
   102 protected:
   103   double *_sequence; // buffers the last L elements in the sequence
   104   int     _length; // this is L
   105   int     _next;   // oldest slot in the array, i.e. next to be overwritten
   107 public:
   108   // accepts a value for L
   109   TruncatedSeq(int length = DefaultSeqLength,
   110                double alpha = DEFAULT_ALPHA_VALUE);
   111   virtual void add(double val);
   112   virtual double maximum() const;
   113   virtual double last() const; // the last value added to the sequence
   115   double oldest() const; // the oldest valid value in the sequence
   116   double predict_next() const; // prediction based on linear regression
   117 };

mercurial