Skip to content

Commit c9013a2

Browse files
committed
8298138: Shenandoah: HdrSeq asserts "sub-bucket index (512) overflow for value ( 1.00)"
Backport-of: c16eb89ce0d59f2ff83b6db0bee3e384ec8d5efe
1 parent 7765ba5 commit c9013a2

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

src/hotspot/share/gc/shenandoah/shenandoahNumberSeq.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void HdrSeq::add(double val) {
5656
int mag;
5757
if (v > 0) {
5858
mag = 0;
59-
while (v > 1) {
59+
while (v >= 1) {
6060
mag++;
6161
v /= 10;
6262
}
@@ -71,7 +71,7 @@ void HdrSeq::add(double val) {
7171
int bucket = -MagMinimum + mag;
7272
int sub_bucket = (int) (v * ValBuckets);
7373

74-
// Defensively saturate for product bits:
74+
// Defensively saturate for product bits
7575
if (bucket < 0) {
7676
assert (false, "bucket index (%d) underflow for value (%8.2f)", bucket, val);
7777
bucket = 0;

src/hotspot/share/gc/shenandoah/shenandoahNumberSeq.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class HdrSeq: public NumberSeq {
5555
// Binary magnitude sequence stores the power-of-two histogram.
5656
// It has very low memory requirements, and is thread-safe. When accuracy
5757
// is not needed, it is preferred over HdrSeq.
58-
class BinaryMagnitudeSeq {
58+
class BinaryMagnitudeSeq : public CHeapObj<mtGC> {
5959
private:
6060
size_t _sum;
6161
size_t* _mags;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* Copyright (c) 2022, Oracle and/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+
#include "precompiled.hpp"
26+
#include "gc/shenandoah/shenandoahNumberSeq.hpp"
27+
#include <iostream>
28+
#include "unittest.hpp"
29+
#include "utilities/ostream.hpp"
30+
31+
class ShenandoahNumberSeqTest: public ::testing::Test {
32+
protected:
33+
HdrSeq seq;
34+
};
35+
36+
class BasicShenandoahNumberSeqTest: public ShenandoahNumberSeqTest {
37+
protected:
38+
const double err = 0.5;
39+
BasicShenandoahNumberSeqTest() {
40+
seq.add(0);
41+
seq.add(1);
42+
seq.add(10);
43+
for (int i = 0; i < 7; i++) {
44+
seq.add(100);
45+
}
46+
std::cout << " p0 = " << seq.percentile(0);
47+
std::cout << " p10 = " << seq.percentile(10);
48+
std::cout << " p20 = " << seq.percentile(20);
49+
std::cout << " p30 = " << seq.percentile(30);
50+
std::cout << " p50 = " << seq.percentile(50);
51+
std::cout << " p80 = " << seq.percentile(80);
52+
std::cout << " p90 = " << seq.percentile(90);
53+
std::cout << " p100 = " << seq.percentile(100);
54+
}
55+
};
56+
57+
TEST_VM_F(BasicShenandoahNumberSeqTest, maximum_test) {
58+
EXPECT_EQ(seq.maximum(), 100);
59+
}
60+
61+
TEST_VM_F(BasicShenandoahNumberSeqTest, minimum_test) {
62+
EXPECT_EQ(0, seq.percentile(0));
63+
}
64+
65+
TEST_VM_F(BasicShenandoahNumberSeqTest, percentile_test) {
66+
EXPECT_NEAR(0, seq.percentile(10), err);
67+
EXPECT_NEAR(1, seq.percentile(20), err);
68+
EXPECT_NEAR(10, seq.percentile(30), err);
69+
EXPECT_NEAR(100, seq.percentile(40), err);
70+
EXPECT_NEAR(100, seq.percentile(50), err);
71+
EXPECT_NEAR(100, seq.percentile(75), err);
72+
EXPECT_NEAR(100, seq.percentile(90), err);
73+
EXPECT_NEAR(100, seq.percentile(100), err);
74+
}

0 commit comments

Comments
 (0)