2222 */
2323
2424import static jdk .test .lib .Asserts .assertTrue ;
25+ import static jdk .test .lib .Asserts .assertFalse ;
2526import static jdk .test .lib .Asserts .fail ;
2627
2728import java .io .File ;
29+ import java .nio .file .Files ;
2830import java .util .Arrays ;
31+ import java .util .List ;
2932
3033import jdk .test .lib .JDKToolLauncher ;
3134import jdk .test .lib .Utils ;
@@ -114,6 +117,7 @@ public static void main(String[] args) throws Exception {
114117 testDump ();
115118 testDumpLive ();
116119 testDumpAll ();
120+ testDumpCompressed ();
117121 }
118122
119123 private static void testHisto () throws Exception {
@@ -211,20 +215,25 @@ private static void testClstats() throws Exception {
211215 }
212216
213217 private static void testDump () throws Exception {
214- dump (false , false );
218+ dump (false , false , false );
215219 }
216220
217221 private static void testDumpLive () throws Exception {
218- dump (true , false );
222+ dump (true , false , false );
219223 }
220224
221225 private static void testDumpAll () throws Exception {
222- dump (false , true );
226+ dump (false , true , false );
223227 }
224228
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 {
226234 String liveArg = "" ;
227235 String fileArg = "" ;
236+ String compressArg = "" ;
228237 String allArgs = "-dump:" ;
229238
230239 if (live && explicitAll ) {
@@ -237,14 +246,20 @@ private static void dump(boolean live, boolean explicitAll) throws Exception {
237246 liveArg = "all," ;
238247 }
239248
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 );
241256 if (file .exists ()) {
242257 file .delete ();
243258 }
244259 fileArg = "file=" + file .getName ();
245260
246261 OutputAnalyzer output ;
247- allArgs = allArgs + liveArg + "format=b," + fileArg ;
262+ allArgs = allArgs + liveArg + compressArg + "format=b," + fileArg ;
248263 output = jmap (allArgs );
249264 output .shouldHaveExitValue (0 );
250265 output .shouldContain ("Heap dump file created" );
@@ -255,7 +270,18 @@ private static void dump(boolean live, boolean explicitAll) throws Exception {
255270 private static void verifyDumpFile (File dump ) {
256271 assertTrue (dump .exists () && dump .isFile (), "Could not create dump file " + dump .getAbsolutePath ());
257272 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 ();
259285 } catch (Exception e ) {
260286 e .printStackTrace ();
261287 fail ("Could not parse dump file " + dump .getAbsolutePath ());
0 commit comments