Skip to content

Commit

Permalink
8225313: serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatOb…
Browse files Browse the repository at this point in the history
…jectCorrectnessTest.java failed with Unexpected high difference percentage

Backport-of: 09e5321763f3fafe2b0b562f99ec0cd55a59583c
  • Loading branch information
GoeLin committed Oct 26, 2023
1 parent 8258f27 commit 2c75188
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
2 changes: 0 additions & 2 deletions test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ runtime/CompressedOops/CompressedClassPointers.java 8305765 generic-all
serviceability/sa/sadebugd/DebugdConnectTest.java 8239062,8270326 macosx-x64,macosx-aarch64
serviceability/sa/TestRevPtrsForInvokeDynamic.java 8241235 generic-all

serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatIntervalTest.java 8214032 generic-all
serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatArrayCorrectnessTest.java 8224150 generic-all
serviceability/jvmti/ModuleAwareAgents/ThreadStart/MAAThreadStart.java 8225354 windows-all
serviceability/dcmd/gc/RunFinalizationTest.java 8227120 linux-all,windows-x64

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Google and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -36,10 +36,16 @@
public class HeapMonitorStatArrayCorrectnessTest {

private static final int maxCount = 10;
// Do 100000 iterations and expect maxIteration / multiplier samples.
private static final int maxIteration = 100000;
// Do 200000 iterations and expect maxIteration / multiplier samples.
private static final int maxIteration = 200_000;
private static int array[];

// 15% error ensures a sanity test without becoming flaky.
// Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
// statistical geometric variable around the sampling interval. This means that the test could be
// unlucky and not achieve the mean average fast enough for the test case.
private static final int acceptedErrorPercentage = 15;

private static void allocate(int size) {
for (int j = 0; j < maxIteration; j++) {
array = new int[size];
Expand Down Expand Up @@ -85,11 +91,7 @@ public static void main(String[] args) {
expected *= 4;
expected /= samplingMultiplier;

// 10% error ensures a sanity test without becoming flaky.
// Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
// statistical geometric variable around the sampling interval. This means that the test could be
// unlucky and not achieve the mean average fast enough for the test case.
if (HeapMonitor.statsHaveExpectedNumberSamples((int) expected, 10)) {
if (HeapMonitor.statsHaveExpectedNumberSamples((int) expected, acceptedErrorPercentage)) {
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static boolean testIntervalOnce(int interval, boolean throwIfFailure) {
HeapMonitor.enableSamplingEvents();

int allocationTotal = 10 * 1024 * 1024;
int allocationIterations = 10;
int allocationIterations = 20;

double actualCount = 0;
for (int i = 0; i < allocationIterations; i++) {
Expand All @@ -58,13 +58,13 @@ private static boolean testIntervalOnce(int interval, boolean throwIfFailure) {
double error = Math.abs(actualCount - expectedCount);
double errorPercentage = error / expectedCount * 100;

boolean success = (errorPercentage < 10.0);
boolean success = (errorPercentage < 15.0);
System.out.println("Interval: " + interval + ", throw if failure: " + throwIfFailure
+ " - Expected count: " + expectedCount + ", allocationIterations: " + allocationIterations
+ ", actualCount: " + actualCount + " -> " + success);

if (!success && throwIfFailure) {
throw new RuntimeException("Interval average over 10% for interval " + interval + " -> "
throw new RuntimeException("Interval average over 15% for interval " + interval + " -> "
+ actualCount + ", " + expectedCount);
}

Expand All @@ -74,7 +74,7 @@ private static boolean testIntervalOnce(int interval, boolean throwIfFailure) {

private static void testInterval(int interval) {
// Test the interval twice, it can happen that the test is "unlucky" and the interval just goes above
// the 10% mark. So try again to squash flakiness.
// the 15% mark. So try again to squash flakiness.
// Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
// statistical geometric variable around the sampling interval. This means that the test could be
// unlucky and not achieve the mean average fast enough for the test case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@
/** This test is checking the object allocation path works with heap sampling. */
public class HeapMonitorStatObjectCorrectnessTest {

// Do 200000 iterations and expect maxIteration / multiplier samples.
private static final int maxIteration = 200000;
// Do 400000 iterations and expect maxIteration / multiplier samples.
private static final int maxIteration = 400_000;
private static BigObject obj;

private native static boolean statsHaveExpectedNumberSamples(int expected, int percentError);
// 15% error ensures a sanity test without becoming flaky.
// Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
// statistical geometric variable around the sampling interval. This means that the test could be
// unlucky and not achieve the mean average fast enough for the test case.
private static final int acceptedErrorPercentage = 15;

private static void allocate() {
emptyStorage();
Expand Down Expand Up @@ -83,11 +87,7 @@ private static void testBigAllocationInterval() {
double expected = maxIteration;
expected /= samplingMultiplier;

// 10% error ensures a sanity test without becoming flaky.
// Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
// statistical geometric variable around the sampling interval. This means that the test could be
// unlucky and not achieve the mean average fast enough for the test case.
if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, 10)) {
if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, acceptedErrorPercentage)) {
throw new RuntimeException("Statistics should show about " + expected + " samples.");
}
}
Expand All @@ -108,11 +108,7 @@ private static void testEveryAllocationSampled() {

double expected = maxIteration;

// 10% error ensures a sanity test without becoming flaky.
// Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
// statistical geometric variable around the sampling interval. This means that the test could be
// unlucky and not achieve the mean average fast enough for the test case.
if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, 10)) {
if (!HeapMonitor.statsHaveExpectedNumberSamples((int) expected, acceptedErrorPercentage)) {
throw new RuntimeException("Statistics should show about " + expected + " samples.");
}
}
Expand Down

1 comment on commit 2c75188

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.