22
22
*/
23
23
24
24
import static jdk .test .lib .Asserts .assertTrue ;
25
+ import static jdk .test .lib .Asserts .assertFalse ;
25
26
import static jdk .test .lib .Asserts .fail ;
26
27
27
28
import java .io .File ;
29
+ import java .nio .file .Files ;
28
30
import java .util .Arrays ;
31
+ import java .util .List ;
29
32
30
33
import jdk .test .lib .JDKToolLauncher ;
31
34
import jdk .test .lib .Utils ;
@@ -114,6 +117,7 @@ public static void main(String[] args) throws Exception {
114
117
testDump ();
115
118
testDumpLive ();
116
119
testDumpAll ();
120
+ testDumpCompressed ();
117
121
}
118
122
119
123
private static void testHisto () throws Exception {
@@ -211,20 +215,25 @@ private static void testClstats() throws Exception {
211
215
}
212
216
213
217
private static void testDump () throws Exception {
214
- dump (false , false );
218
+ dump (false , false , false );
215
219
}
216
220
217
221
private static void testDumpLive () throws Exception {
218
- dump (true , false );
222
+ dump (true , false , false );
219
223
}
220
224
221
225
private static void testDumpAll () throws Exception {
222
- dump (false , true );
226
+ dump (false , true , false );
223
227
}
224
228
225
- private static void dump (boolean live , boolean explicitAll ) throws Exception {
229
+ private static void testDumpCompressed () throws Exception {
230
+ dump (true , false , true );
231
+ }
232
+
233
+ private static void dump (boolean live , boolean explicitAll , boolean compressed ) throws Exception {
226
234
String liveArg = "" ;
227
235
String fileArg = "" ;
236
+ String compressArg = "" ;
228
237
String allArgs = "-dump:" ;
229
238
230
239
if (live && explicitAll ) {
@@ -237,14 +246,20 @@ private static void dump(boolean live, boolean explicitAll) throws Exception {
237
246
liveArg = "all," ;
238
247
}
239
248
240
- File file = new File ("jmap.dump" + System .currentTimeMillis () + ".hprof" );
249
+ String filePath = "jmap.dump" + System .currentTimeMillis () + ".hprof" ;
250
+ if (compressed ) {
251
+ compressArg = "gz=1," ;
252
+ filePath = filePath + ".gz" ;
253
+ }
254
+
255
+ File file = new File (filePath );
241
256
if (file .exists ()) {
242
257
file .delete ();
243
258
}
244
259
fileArg = "file=" + file .getName ();
245
260
246
261
OutputAnalyzer output ;
247
- allArgs = allArgs + liveArg + "format=b," + fileArg ;
262
+ allArgs = allArgs + liveArg + compressArg + "format=b," + fileArg ;
248
263
output = jmap (allArgs );
249
264
output .shouldHaveExitValue (0 );
250
265
output .shouldContain ("Heap dump file created" );
@@ -255,7 +270,18 @@ private static void dump(boolean live, boolean explicitAll) throws Exception {
255
270
private static void verifyDumpFile (File dump ) {
256
271
assertTrue (dump .exists () && dump .isFile (), "Could not create dump file " + dump .getAbsolutePath ());
257
272
try {
258
- HprofParser .parse (dump );
273
+ File out = HprofParser .parse (dump );
274
+
275
+ assertTrue (out != null && out .exists () && out .isFile (),
276
+ "Could not find hprof parser output file" );
277
+ List <String > lines = Files .readAllLines (out .toPath ());
278
+ assertTrue (lines .size () > 0 , "hprof parser output file is empty" );
279
+ for (String line : lines ) {
280
+ assertFalse (line .matches (".*WARNING(?!.*Failed to resolve " +
281
+ "object.*constantPoolOop.*).*" ));
282
+ }
283
+
284
+ out .delete ();
259
285
} catch (Exception e ) {
260
286
e .printStackTrace ();
261
287
fail ("Could not parse dump file " + dump .getAbsolutePath ());
0 commit comments