Skip to content

Commit 8361216

Browse files
lkorinthpull[bot]
authored andcommitted
8283223: gc/stringdedup/TestStringDeduplicationFullGC.java#Parallel failed with "RuntimeException: String verification failed"
Reviewed-by: tschatzl, kbarrett
1 parent 8006dd8 commit 8361216

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

test/hotspot/jtreg/gc/stringdedup/TestStringDeduplicationTools.java

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,8 @@
3131
import java.lang.reflect.*;
3232
import java.lang.management.*;
3333
import java.util.*;
34+
import java.util.stream.Collectors;
35+
3436
import javax.management.*;
3537
import javax.management.openmbean.*;
3638
import jdk.test.lib.process.ProcessTools;
@@ -85,6 +87,32 @@ private static Object getValue(String string) {
8587
}
8688
}
8789

90+
/**
91+
* Get system load.
92+
*
93+
* <dl>
94+
* <dt>load() ~= 1 </dt><dd> fully loaded system, all cores are used 100%</dd>
95+
* <dt>load() &lt; 1 </dt><dd> some cpu resources are available</dd>
96+
* <dt>load() &gt; 1 </dt><dd> system is overloaded</dd>
97+
* </dl>
98+
*
99+
* @return the load of the system or Optional.empty() if the load can not be determined.
100+
*/
101+
private static Optional<Double> systemLoad() {
102+
OperatingSystemMXBean bean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
103+
double average = bean.getSystemLoadAverage() / bean.getAvailableProcessors();
104+
return (average < 0)
105+
? Optional.empty()
106+
: Optional.of(average);
107+
}
108+
109+
private static String minMax(List<Optional<Double>> l) {
110+
DoubleSummaryStatistics minmax = l.stream().flatMap(Optional::stream).collect(Collectors.summarizingDouble(d -> d));
111+
return minmax.getCount() != 0
112+
? "min: " + minmax.getMin() + ", max: " + minmax.getMax()
113+
: "could not gather load statistics from system";
114+
}
115+
88116
private static void doFullGc(int numberOfTimes) {
89117
List<List<String>> newStrings = new ArrayList<List<String>>();
90118
for (int i = 0; i < numberOfTimes; i++) {
@@ -179,13 +207,15 @@ private static void forceDeduplication(int ageThreshold, String gcType) {
179207
}
180208
}
181209

182-
private static boolean waitForDeduplication(String s1, String s2) {
210+
private static void waitForDeduplication(String s1, String s2) {
183211
boolean first = true;
184212
int timeout = 10000; // 10sec in ms
185213
int iterationWait = 100; // 100ms
214+
List<Optional<Double>> loadHistory = new ArrayList<>();
186215
for (int attempts = 0; attempts < (timeout / iterationWait); attempts++) {
216+
loadHistory.add(systemLoad());
187217
if (getValue(s1) == getValue(s2)) {
188-
return true;
218+
return;
189219
}
190220
if (first) {
191221
System.out.println("Waiting for deduplication...");
@@ -194,10 +224,10 @@ private static boolean waitForDeduplication(String s1, String s2) {
194224
try {
195225
Thread.sleep(iterationWait);
196226
} catch (Exception e) {
197-
throw new RuntimeException(e);
227+
throw new RuntimeException("Deduplication has not occurred: Thread.sleep() threw", e);
198228
}
199229
}
200-
return false;
230+
throw new RuntimeException("Deduplication has not occurred, load history: " + minMax(loadHistory));
201231
}
202232

203233
private static String generateString(int id) {
@@ -240,7 +270,9 @@ private static ArrayList<String> createStrings(int total, int unique) {
240270
*/
241271
private static void verifyStrings(ArrayList<String> list, int uniqueExpected) {
242272
boolean passed = false;
273+
List<Optional<Double>> loadHistory = new ArrayList<>();
243274
for (int attempts = 0; attempts < 10; attempts++) {
275+
loadHistory.add(systemLoad());
244276
// Check number of deduplicated strings
245277
ArrayList<Object> unique = new ArrayList<Object>(uniqueExpected);
246278
for (String string: list) {
@@ -277,7 +309,7 @@ private static void verifyStrings(ArrayList<String> list, int uniqueExpected) {
277309
}
278310
}
279311
if (!passed) {
280-
throw new RuntimeException("String verification failed");
312+
throw new RuntimeException("String verification failed, load history: " + minMax(loadHistory));
281313
}
282314
}
283315

@@ -361,9 +393,7 @@ public static void main(String[] args) {
361393
// and be inserted into the deduplication hashtable.
362394
forceDeduplication(ageThreshold, FullGC);
363395

364-
if (!waitForDeduplication(dupString1, baseString)) {
365-
throw new RuntimeException("Deduplication has not occurred");
366-
}
396+
waitForDeduplication(dupString1, baseString);
367397

368398
// Create a new duplicate of baseString
369399
StringBuilder sb2 = new StringBuilder(baseString);
@@ -398,9 +428,7 @@ public static void main(String[] args) {
398428

399429
forceDeduplication(ageThreshold, FullGC);
400430

401-
if (!waitForDeduplication(dupString3, internedString)) {
402-
throw new RuntimeException("Deduplication has not occurred for string 3");
403-
}
431+
waitForDeduplication(dupString3, internedString);
404432

405433
if (afterInternedValue != getValue(dupString2)) {
406434
throw new RuntimeException("Interned string value changed");

0 commit comments

Comments
 (0)