|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * 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 { |
74 | 74 | } |
75 | 75 |
|
76 | 76 | 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 |
108 | 114 | } |
109 | 115 | } |
110 | 116 | } |
111 | 117 |
|
112 | 118 | private static void clearLeak() { |
113 | 119 | leak.clear(); |
| 120 | + System.gc(); |
114 | 121 | } |
115 | 122 |
|
116 | 123 | private static boolean hasChains(List<RecordedEvent> events) throws IOException { |
|
0 commit comments