Skip to content

Commit

Permalink
8305931: jdk/jfr/jcmd/TestJcmdDumpPathToGCRoots.java failed with "Exp…
Browse files Browse the repository at this point in the history
…ected chains but found none"

Backport-of: 65be5e0c547d74ca7de288b164aa9bd6d6855685
  • Loading branch information
roberttoyonaga authored and jerboaa committed Apr 30, 2024
1 parent c248531 commit d32f526
Showing 1 changed file with 39 additions and 32 deletions.
71 changes: 39 additions & 32 deletions test/jdk/jdk/jfr/jcmd/TestJcmdDumpPathToGCRoots.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -76,43 +76,50 @@ public static void main(String[] args) throws Exception {
}

private static void testDump(String pathToGcRoots, Map<String, String> settings, boolean expectedChains) throws Exception {
try (Recording r = new Recording()) {
Map<String, String> p = new HashMap<>(settings);
p.put(EventNames.OldObjectSample + "#" + Enabled.NAME, "true");
r.setName("dodo");
r.setSettings(p);
r.setToDisk(true);
r.start();
clearLeak();
System.out.println("Recording id: " + r.getId());
System.out.println("Settings: " + settings.toString());
System.out.println("Command: JFR.dump " + pathToGcRoots);
System.out.println("Chains expected: " + expectedChains);
buildLeak();
System.gc();
System.gc();
File recording = new File("TestJcmdDumpPathToGCRoots" + r.getId() + ".jfr");
recording.delete();
JcmdHelper.jcmd("JFR.dump", "name=dodo", pathToGcRoots, "filename=" + recording.getAbsolutePath());
r.setSettings(Collections.emptyMap());
List<RecordedEvent> events = RecordingFile.readAllEvents(recording.toPath());
if (events.isEmpty()) {
throw new Exception("No events found in recoding");
}
boolean chains = hasChains(events);
if (expectedChains && !chains) {
System.out.println(events);
throw new Exception("Expected chains but found none");
}
if (!expectedChains && chains) {
System.out.println(events);
throw new Exception("Didn't expect chains but found some");
while (true) {
try (Recording r = new Recording()) {
Map<String, String> p = new HashMap<>(settings);
p.put(EventNames.OldObjectSample + "#" + Enabled.NAME, "true");
r.setName("dodo");
r.setSettings(p);
r.setToDisk(true);
r.start();
clearLeak();
System.out.println("Recording id: " + r.getId());
System.out.println("Settings: " + settings.toString());
System.out.println("Command: JFR.dump " + pathToGcRoots);
System.out.println("Chains expected: " + expectedChains);
buildLeak();
System.gc();
System.gc();
File recording = new File("TestJcmdDumpPathToGCRoots" + r.getId() + ".jfr");
recording.delete();
JcmdHelper.jcmd("JFR.dump", "name=dodo", pathToGcRoots, "filename=" + recording.getAbsolutePath());
r.setSettings(Collections.emptyMap());
List<RecordedEvent> events = RecordingFile.readAllEvents(recording.toPath());
if (events.isEmpty()) {
System.out.println("No events found in recording. Retrying.");
continue;
}
boolean chains = hasChains(events);
if (expectedChains && !chains) {
System.out.println(events);
System.out.println("Expected chains but found none. Retrying.");
continue;
}
if (!expectedChains && chains) {
System.out.println(events);
System.out.println("Didn't expect chains but found some. Retrying.");
continue;
}
return; // Success
}
}
}

private static void clearLeak() {
leak.clear();
System.gc();
}

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

0 comments on commit d32f526

Please sign in to comment.