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