1 /*
2 * Copyright (c) 2018, 2019, Red Hat, 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHNUMBERSEQ_HPP
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHNUMBERSEQ_HPP
27
28 #include "utilities/numberSeq.hpp"
29
30 // HDR sequence stores the low-resolution high-dynamic-range values.
31 // It does so by maintaining the double array, where first array defines
32 // the magnitude of the value being stored, and the second array maintains
33 // the low resolution histogram within that magnitude. For example, storing
34 // 4.352819 * 10^3 increments the bucket _hdr[3][435]. This allows for
35 // memory efficient storage of huge amount of samples.
36 //
37 // Accepts positive numbers only.
38 class HdrSeq: public NumberSeq {
39 private:
40 enum PrivateConstants {
41 ValBuckets = 512,
42 MagBuckets = 24,
43 MagMinimum = -12
44 };
45 int** _hdr;
46
47 public:
48 HdrSeq();
49 ~HdrSeq();
50
51 virtual void add(double val);
52 void add(const HdrSeq& other);
53 double percentile(double level) const;
54 void clear();
55 };
56
57 // Binary magnitude sequence stores the power-of-two histogram.
58 // It has very low memory requirements, and is thread-safe. When accuracy
59 // is not needed, it is preferred over HdrSeq.
60 class BinaryMagnitudeSeq : public CHeapObj<mtGC> {
61 private:
62 size_t _sum;
63 size_t* _mags;
64
65 public:
66 BinaryMagnitudeSeq();
67 ~BinaryMagnitudeSeq();
68
69 void add(size_t val);
70 size_t num() const;
71 size_t level(int level) const;
72 size_t sum() const;
73 int min_level() const;
74 int max_level() const;
75 void clear();
76 };
77
78 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHNUMBERSEQ_HPP