< prev index next >

src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java

Print this page




 159             } catch (IOException ioe) {
 160               return null;
 161             }
 162         }
 163         // no filename
 164         return null;
 165     }
 166 
 167     private static String add_option(String cmd, String opt) {
 168        if (cmd.isEmpty()) {
 169            return opt;
 170        }
 171        return cmd + "," + opt;
 172     }
 173 
 174     private static void histo(String pid, String options)
 175         throws AttachNotSupportedException, IOException,
 176                UnsupportedEncodingException {
 177         String liveopt = "-all";
 178         String filename = null;
 179         String parallelthreadnum = null;
 180         String subopts[] = options.split(",");
 181         boolean set_all = false;
 182         boolean set_live = false;
 183         String cmdline = "";
 184 
 185         for (int i = 0; i < subopts.length; i++) {
 186             String subopt = subopts[i];
 187             if (subopt.equals("") || subopt.equals("all")) {
 188                 cmdline = add_option(cmdline, "-all");
 189                 set_all = true;
 190             } else if (subopt.equals("live")) {
 191                 // Add '-' for compatibility.
 192                 cmdline = add_option(cmdline, "-live");
 193                 set_live = true;
 194             } else if (subopt.startsWith("file=")) {
 195                 filename = parseFileName(subopt);
 196                 if (filename == null) {
 197                     usage(1); // invalid options or no filename
 198                 }
 199                 cmdline = add_option(cmdline, filename);
 200             } else if (subopt.startsWith("parallelThreadNum=")) {
 201                parallelthreadnum = subopt.substring(19);
 202                if (parallelthreadnum == null) {
 203                     usage(1);
 204                }
 205                // Add "parallelThreadsNum=<>" for later check
 206                cmdline = add_option(cmdline, subopt);
 207             } else {
 208                 usage(1);
 209             }
 210         }
 211         if (set_live && set_all) {
 212             usage(1);
 213         }
 214 
 215         System.out.flush();
 216         // inspectHeap is not the same as jcmd GC.class_histogram
 217         executeCommandForPid(pid, "inspectheap", cmdline);
 218     }
 219 
 220     private static void dump(String pid, String options)
 221         throws AttachNotSupportedException, IOException,
 222                UnsupportedEncodingException {


 294         System.err.println("        to connect to running process and print information on objects awaiting finalization");
 295         System.err.println("    jmap -histo[:[<histo-options>]] <pid>");
 296         System.err.println("        to connect to running process and print histogram of java object heap");
 297         System.err.println("    jmap -dump:<dump-options> <pid>");
 298         System.err.println("        to connect to running process and dump java heap");
 299         System.err.println("    jmap -? -h --help");
 300         System.err.println("        to print this help message");
 301         System.err.println("");
 302         System.err.println("    dump-options:");
 303         System.err.println("      live         dump only live objects");
 304         System.err.println("      all          dump all objects in the heap (default if one of \"live\" or \"all\" is not specified");
 305         System.err.println("      format=b     binary format");
 306         System.err.println("      file=<file>  dump heap to <file>");
 307         System.err.println("");
 308         System.err.println("    Example: jmap -dump:live,format=b,file=heap.bin <pid>");
 309         System.err.println("");
 310         System.err.println("    histo-options:");
 311         System.err.println("      live         count only live objects");
 312         System.err.println("      all          count all objects in the heap (default if one of \"live\" or \"all\" is not specified)");
 313         System.err.println("      file=<file>  dump data to <file>");
 314         System.err.println("      parallelThreadNum=<number>  parallel threads number for heap iteration:");
 315         System.err.println("                                  parallelThreadNum=0 default behavior, use predefined number of threads");
 316         System.err.println("                                  parallelThreadNum=1 disable parallel heap iteration");
 317         System.err.println("                                  parallelThreadNum=<N> use N threads for parallel heap iteration");
 318         System.err.println("");
 319         System.err.println("    Example: jmap -histo:live,file=/tmp/histo.data <pid>");
 320         System.exit(exit);
 321     }
 322 }


 159             } catch (IOException ioe) {
 160               return null;
 161             }
 162         }
 163         // no filename
 164         return null;
 165     }
 166 
 167     private static String add_option(String cmd, String opt) {
 168        if (cmd.isEmpty()) {
 169            return opt;
 170        }
 171        return cmd + "," + opt;
 172     }
 173 
 174     private static void histo(String pid, String options)
 175         throws AttachNotSupportedException, IOException,
 176                UnsupportedEncodingException {
 177         String liveopt = "-all";
 178         String filename = null;
 179         String parallel = null;
 180         String subopts[] = options.split(",");
 181         boolean set_all = false;
 182         boolean set_live = false;
 183         String cmdline = "";
 184 
 185         for (int i = 0; i < subopts.length; i++) {
 186             String subopt = subopts[i];
 187             if (subopt.equals("") || subopt.equals("all")) {
 188                 cmdline = add_option(cmdline, "-all");
 189                 set_all = true;
 190             } else if (subopt.equals("live")) {
 191                 // Add '-' for compatibility.
 192                 cmdline = add_option(cmdline, "-live");
 193                 set_live = true;
 194             } else if (subopt.startsWith("file=")) {
 195                 filename = parseFileName(subopt);
 196                 if (filename == null) {
 197                     usage(1); // invalid options or no filename
 198                 }
 199                 cmdline = add_option(cmdline, filename);
 200             } else if (subopt.startsWith("parallel=")) {
 201                parallel = subopt.substring("parallel=".length());
 202                if (parallel == null) {
 203                     usage(1);
 204                }
 205                // Add "parallelThreadsNum=<>" for later check
 206                cmdline = add_option(cmdline, subopt);
 207             } else {
 208                 usage(1);
 209             }
 210         }
 211         if (set_live && set_all) {
 212             usage(1);
 213         }
 214 
 215         System.out.flush();
 216         // inspectHeap is not the same as jcmd GC.class_histogram
 217         executeCommandForPid(pid, "inspectheap", cmdline);
 218     }
 219 
 220     private static void dump(String pid, String options)
 221         throws AttachNotSupportedException, IOException,
 222                UnsupportedEncodingException {


 294         System.err.println("        to connect to running process and print information on objects awaiting finalization");
 295         System.err.println("    jmap -histo[:[<histo-options>]] <pid>");
 296         System.err.println("        to connect to running process and print histogram of java object heap");
 297         System.err.println("    jmap -dump:<dump-options> <pid>");
 298         System.err.println("        to connect to running process and dump java heap");
 299         System.err.println("    jmap -? -h --help");
 300         System.err.println("        to print this help message");
 301         System.err.println("");
 302         System.err.println("    dump-options:");
 303         System.err.println("      live         dump only live objects");
 304         System.err.println("      all          dump all objects in the heap (default if one of \"live\" or \"all\" is not specified");
 305         System.err.println("      format=b     binary format");
 306         System.err.println("      file=<file>  dump heap to <file>");
 307         System.err.println("");
 308         System.err.println("    Example: jmap -dump:live,format=b,file=heap.bin <pid>");
 309         System.err.println("");
 310         System.err.println("    histo-options:");
 311         System.err.println("      live         count only live objects");
 312         System.err.println("      all          count all objects in the heap (default if one of \"live\" or \"all\" is not specified)");
 313         System.err.println("      file=<file>  dump data to <file>");
 314         System.err.println("      parallel=<number>  parallel threads number for heap iteration:");
 315         System.err.println("                                  parallel=0 default behavior, use predefined number of threads");
 316         System.err.println("                                  parallel=1 disable parallel heap iteration");
 317         System.err.println("                                  parallel=<N> use N threads for parallel heap iteration");
 318         System.err.println("");
 319         System.err.println("    Example: jmap -histo:live,file=/tmp/histo.data <pid>");
 320         System.exit(exit);
 321     }
 322 }
< prev index next >