1 /*
   2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHNUMBERSEQ_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHNUMBERSEQ_HPP
  26 
  27 #include "utilities/numberSeq.hpp"
  28 
  29 // HDR sequence stores the low-resolution high-dynamic-range values.
  30 // It does so by maintaining the double array, where first array defines
  31 // the magnitude of the value being stored, and the second array maintains
  32 // the low resolution histogram within that magnitude. For example, storing
  33 // 4.352819 * 10^3 increments the bucket _hdr[3][435]. This allows for
  34 // memory efficient storage of huge amount of samples.
  35 //
  36 // Accepts positive numbers only.
  37 class HdrSeq: public NumberSeq {
  38 private:
  39   enum PrivateConstants {
  40     ValBuckets = 512,
  41     MagBuckets = 24,
  42     MagMinimum = -12,
  43   };
  44   int** _hdr;
  45 
  46 public:
  47   HdrSeq();
  48   ~HdrSeq();
  49 
  50   virtual void add(double val);
  51   double percentile(double level) const;
  52 };
  53 
  54 // Binary magnitude sequence stores the power-of-two histogram.
  55 // It has very low memory requirements, and is thread-safe. When accuracy
  56 // is not needed, it is preferred over HdrSeq.
  57 class BinaryMagnitudeSeq {
  58 private:
  59   size_t  _sum;
  60   size_t* _mags;
  61 
  62 public:
  63   BinaryMagnitudeSeq();
  64   ~BinaryMagnitudeSeq();
  65 
  66   void add(size_t val);
  67   size_t num() const;
  68   size_t level(int level) const;
  69   size_t sum() const;
  70   int min_level() const;
  71   int max_level() const;
  72 };
  73 
  74 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHNUMBERSEQ_HPP