< prev index next >

test/jdk/sun/tools/jmap/BasicJMapTest.java

Print this page

        

@@ -93,92 +93,56 @@
         OutputAnalyzer output = jmap("-histo:parallel=1");
         output.shouldHaveExitValue(0);
     }
 
     private static void testHistoToFile() throws Exception {
-        histoToFile(false);
+        histoToFile(false, false, 1);
     }
 
     private static void testHistoLiveToFile() throws Exception {
-        histoToFile(true);
+        histoToFile(true, false, 1);
     }
 
     private static void testHistoAllToFile() throws Exception {
-        boolean explicitAll = true;
-        histoToFile(false, explicitAll);
+        histoToFile(false, true, 1);
     }
 
     private static void testHistoFileParallelZero() throws Exception {
         histoToFile(false, false, 0);
     }
 
     private static void testHistoFileParallel() throws Exception {
         histoToFile(false, false, 2);
     }
 
-    private static void testHistoFileNonParallel() throws Exception {
-        histoToFile(false, false, 1);
-    }
-
-    private static void histoToFile(boolean live) throws Exception {
-        boolean explicitAll = false;
-        histoToFile(live, explicitAll);
-    }
-
-    private static void histoToFile(boolean live, boolean explicitAll) throws Exception {
-        if (live == true && explicitAll == true) {
-            fail("Illegal argument setting for jmap -histo");
-        }
-        File file = new File("jmap.histo.file" + System.currentTimeMillis() + ".histo");
-        if (file.exists()) {
-            file.delete();
-        }
-        OutputAnalyzer output;
-        if (live) {
-            output = jmap("-histo:live,file=" + file.getName());
-        } else if (explicitAll == true) {
-            output = jmap("-histo:all,file=" + file.getName());
-        } else {
-            output = jmap("-histo:file=" + file.getName());
-        }
-        output.shouldHaveExitValue(0);
-        output.shouldContain("Heap inspection file created");
-        file.delete();
-    }
-
     private static void histoToFile(boolean live,
                                     boolean explicitAll,
                                     int parallelThreadNum) throws Exception {
         String liveArg = "";
         String fileArg = "";
         String parArg = "parallel=" + parallelThreadNum;
         String allArgs = "-histo:";
 
-        if (live == true && explicitAll == true) {
+        if (live && explicitAll) {
             fail("Illegal argument setting for jmap -histo");
         }
-        if (live == true ) {
+        if (live) {
             liveArg = "live,";
-        } else if(explicitAll) {
+        }
+        if (explicitAll) {
             liveArg = "all,";
         }
 
         File file = new File("jmap.histo.file" + System.currentTimeMillis() + ".histo");
         if (file.exists()) {
             file.delete();
         }
         fileArg = "file=" + file.getName();
 
         OutputAnalyzer output;
-        allArgs = allArgs + liveArg + fileArg + "," + parArg + "";
-        if (live) {
+        allArgs = allArgs + liveArg + fileArg + ',' + parArg;
             output = jmap(allArgs);
-        } else if (explicitAll == true) {
-            output = jmap(allArgs);
-        } else {
-            output = jmap(allArgs);
-        }
         output.shouldHaveExitValue(0);
         output.shouldContain("Heap inspection file created");
         file.delete();
     }
 

@@ -191,47 +155,49 @@
         OutputAnalyzer output = jmap("-clstats");
         output.shouldHaveExitValue(0);
     }
 
     private static void testDump() throws Exception {
-        dump(false);
+        dump(false, false);
     }
 
     private static void testDumpLive() throws Exception {
-        dump(true);
+        dump(true, false);
     }
 
     private static void testDumpAll() throws Exception {
-        boolean explicitAll = true;
-        dump(false, explicitAll);
-    }
-
-    private static void dump(boolean live) throws Exception {
-        boolean explicitAll = false;
-        dump(live, explicitAll);
+        dump(false, true);
     }
 
     private static void dump(boolean live, boolean explicitAll) throws Exception {
-        if (live == true && explicitAll == true) {
+        String liveArg = "";
+        String fileArg = "";
+        String allArgs = "-dump:";
+
+        if (live && explicitAll) {
           fail("Illegal argument setting for jmap -dump");
         }
-        File dump = new File("jmap.dump." + System.currentTimeMillis() + ".hprof");
-        if (dump.exists()) {
-            dump.delete();
-        }
-        OutputAnalyzer output;
         if (live) {
-            output = jmap("-dump:live,format=b,file=" + dump.getName());
-        } else if (explicitAll == true) {
-            output = jmap("-dump:all,format=b,file=" + dump.getName());
-        } else {
-            output = jmap("-dump:format=b,file=" + dump.getName());
+            liveArg = "live,";
         }
+        if (explicitAll) {
+            liveArg = "all,";
+        }
+
+        File file = new File("jmap.dump" + System.currentTimeMillis() + ".hprof");
+        if (file.exists()) {
+            file.delete();
+        }
+        fileArg = "file=" + file.getName();
+
+        OutputAnalyzer output;
+        allArgs = allArgs + liveArg + "format=b," + fileArg;
+        output = jmap(allArgs);
         output.shouldHaveExitValue(0);
         output.shouldContain("Heap dump file created");
-        verifyDumpFile(dump);
-        dump.delete();
+        verifyDumpFile(file);
+        file.delete();
     }
 
     private static void verifyDumpFile(File dump) {
         assertTrue(dump.exists() && dump.isFile(), "Could not create dump file " + dump.getAbsolutePath());
         try {

@@ -257,7 +223,6 @@
         OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
         System.out.println(output.getOutput());
 
         return output;
     }
-
 }
< prev index next >