Skip to content

Commit 3f5e536

Browse files
roberttoyonagashipilev
authored andcommitted
8305931: jdk/jfr/jcmd/TestJcmdDumpPathToGCRoots.java failed with "Expected chains but found none"
Backport-of: 65be5e0c547d74ca7de288b164aa9bd6d6855685
1 parent bcc83cd commit 3f5e536

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

test/jdk/jdk/jfr/jcmd/TestJcmdDumpPathToGCRoots.java

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, 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
@@ -74,43 +74,50 @@ public static void main(String[] args) throws Exception {
7474
}
7575

7676
private static void testDump(String pathToGcRoots, Map<String, String> settings, boolean expectedChains) throws Exception {
77-
try (Recording r = new Recording()) {
78-
Map<String, String> p = new HashMap<>(settings);
79-
p.put(EventNames.OldObjectSample + "#" + Enabled.NAME, "true");
80-
r.setName("dodo");
81-
r.setSettings(p);
82-
r.setToDisk(true);
83-
r.start();
84-
clearLeak();
85-
System.out.println("Recording id: " + r.getId());
86-
System.out.println("Settings: " + settings.toString());
87-
System.out.println("Command: JFR.dump " + pathToGcRoots);
88-
System.out.println("Chains expected: " + expectedChains);
89-
buildLeak();
90-
System.gc();
91-
System.gc();
92-
File recording = new File("TestJcmdDumpPathToGCRoots" + r.getId() + ".jfr");
93-
recording.delete();
94-
JcmdHelper.jcmd("JFR.dump", "name=dodo", pathToGcRoots, "filename=" + recording.getAbsolutePath());
95-
r.setSettings(Collections.emptyMap());
96-
List<RecordedEvent> events = RecordingFile.readAllEvents(recording.toPath());
97-
if (events.isEmpty()) {
98-
throw new Exception("No events found in recoding");
99-
}
100-
boolean chains = hasChains(events);
101-
if (expectedChains && !chains) {
102-
System.out.println(events);
103-
throw new Exception("Expected chains but found none");
104-
}
105-
if (!expectedChains && chains) {
106-
System.out.println(events);
107-
throw new Exception("Didn't expect chains but found some");
77+
while (true) {
78+
try (Recording r = new Recording()) {
79+
Map<String, String> p = new HashMap<>(settings);
80+
p.put(EventNames.OldObjectSample + "#" + Enabled.NAME, "true");
81+
r.setName("dodo");
82+
r.setSettings(p);
83+
r.setToDisk(true);
84+
r.start();
85+
clearLeak();
86+
System.out.println("Recording id: " + r.getId());
87+
System.out.println("Settings: " + settings.toString());
88+
System.out.println("Command: JFR.dump " + pathToGcRoots);
89+
System.out.println("Chains expected: " + expectedChains);
90+
buildLeak();
91+
System.gc();
92+
System.gc();
93+
File recording = new File("TestJcmdDumpPathToGCRoots" + r.getId() + ".jfr");
94+
recording.delete();
95+
JcmdHelper.jcmd("JFR.dump", "name=dodo", pathToGcRoots, "filename=" + recording.getAbsolutePath());
96+
r.setSettings(Collections.emptyMap());
97+
List<RecordedEvent> events = RecordingFile.readAllEvents(recording.toPath());
98+
if (events.isEmpty()) {
99+
System.out.println("No events found in recording. Retrying.");
100+
continue;
101+
}
102+
boolean chains = hasChains(events);
103+
if (expectedChains && !chains) {
104+
System.out.println(events);
105+
System.out.println("Expected chains but found none. Retrying.");
106+
continue;
107+
}
108+
if (!expectedChains && chains) {
109+
System.out.println(events);
110+
System.out.println("Didn't expect chains but found some. Retrying.");
111+
continue;
112+
}
113+
return; // Success
108114
}
109115
}
110116
}
111117

112118
private static void clearLeak() {
113119
leak.clear();
120+
System.gc();
114121
}
115122

116123
private static boolean hasChains(List<RecordedEvent> events) throws IOException {

0 commit comments

Comments
 (0)