< prev index next >

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

Print this page




 152             String filename = opt.substring(5);
 153             try {
 154                 // Get the canonical path - important to avoid just
 155                 // passing a "heap.bin" and having the dump created
 156                 // in the target VM working directory rather than the
 157                 // directory where jmap is executed.
 158                 return new File(filename).getCanonicalPath();
 159             } catch (IOException ioe) {
 160               return null;
 161             }
 162         }
 163         // no filename
 164         return null;
 165     }
 166 
 167     private static void histo(String pid, String options)
 168         throws AttachNotSupportedException, IOException,
 169                UnsupportedEncodingException {
 170         String liveopt = "-all";
 171         String filename = null;

 172         String subopts[] = options.split(",");


 173 
 174         for (int i = 0; i < subopts.length; i++) {
 175             String subopt = subopts[i];
 176             if (subopt.equals("") || subopt.equals("all")) {
 177                 // pass

 178             } else if (subopt.equals("live")) {


 179                 liveopt = "-live";
 180             } else if (subopt.startsWith("file=")) {
 181                 filename = parseFileName(subopt);
 182                 if (filename == null) {

 183                     usage(1); // invalid options or no filename
 184                 }






 185             } else {

 186                 usage(1);
 187             }
 188         }
 189 



 190         System.out.flush();
 191 
 192         // inspectHeap is not the same as jcmd GC.class_histogram
 193         executeCommandForPid(pid, "inspectheap", liveopt, filename);
 194     }
 195 
 196     private static void dump(String pid, String options)
 197         throws AttachNotSupportedException, IOException,
 198                UnsupportedEncodingException {
 199 
 200         String subopts[] = options.split(",");
 201         String filename = null;
 202         String liveopt = "-all";
 203 
 204         for (int i = 0; i < subopts.length; i++) {
 205             String subopt = subopts[i];
 206             if (subopt.equals("live")) {
 207                 liveopt = "-live";
 208             } else if (subopt.startsWith("file=")) {
 209                 filename = parseFileName(subopt);
 210             }
 211         }
 212 
 213         if (filename == null) {

 214             usage(1);  // invalid options or no filename
 215         }
 216 
 217         // dumpHeap is not the same as jcmd GC.heap_dump
 218         executeCommandForPid(pid, "dumpheap", filename, liveopt);
 219     }
 220 
 221     private static void checkForUnsupportedOptions(String[] args) {
 222         // Check arguments for -F, -m, and non-numeric value
 223         // and warn the user that SA is not supported anymore
 224 
 225         int paramCount = 0;
 226 
 227         for (String s : args) {
 228             if (s.equals("-F")) {
 229                 SAOptionError("-F option used");
 230             }
 231 
 232             if (s.equals("-heap")) {
 233                 SAOptionError("-heap option used");


 270         System.err.println("        to connect to running process and print information on objects awaiting finalization");
 271         System.err.println("    jmap -histo[:[<histo-options>]] <pid>");
 272         System.err.println("        to connect to running process and print histogram of java object heap");
 273         System.err.println("    jmap -dump:<dump-options> <pid>");
 274         System.err.println("        to connect to running process and dump java heap");
 275         System.err.println("    jmap -? -h --help");
 276         System.err.println("        to print this help message");
 277         System.err.println("");
 278         System.err.println("    dump-options:");
 279         System.err.println("      live         dump only live objects");
 280         System.err.println("      all          dump all objects in the heap (default if one of \"live\" or \"all\" is not specified");
 281         System.err.println("      format=b     binary format");
 282         System.err.println("      file=<file>  dump heap to <file>");
 283         System.err.println("");
 284         System.err.println("    Example: jmap -dump:live,format=b,file=heap.bin <pid>");
 285         System.err.println("");
 286         System.err.println("    histo-options:");
 287         System.err.println("      live         count only live objects");
 288         System.err.println("      all          count all objects in the heap (default if one of \"live\" or \"all\" is not specified)");
 289         System.err.println("      file=<file>  dump data to <file>");




 290         System.err.println("");
 291         System.err.println("    Example: jmap -histo:live,file=/tmp/histo.data <pid>");
 292         System.exit(exit);
 293     }
 294 }


 152             String filename = opt.substring(5);
 153             try {
 154                 // Get the canonical path - important to avoid just
 155                 // passing a "heap.bin" and having the dump created
 156                 // in the target VM working directory rather than the
 157                 // directory where jmap is executed.
 158                 return new File(filename).getCanonicalPath();
 159             } catch (IOException ioe) {
 160               return null;
 161             }
 162         }
 163         // no filename
 164         return null;
 165     }
 166 
 167     private static void histo(String pid, String options)
 168         throws AttachNotSupportedException, IOException,
 169                UnsupportedEncodingException {
 170         String liveopt = "-all";
 171         String filename = null;
 172         String parallel = null;
 173         String subopts[] = options.split(",");
 174         boolean set_all = false;
 175         boolean set_live = false;
 176 
 177         for (int i = 0; i < subopts.length; i++) {
 178             String subopt = subopts[i];
 179             if (subopt.equals("") || subopt.equals("all")) {
 180                 set_all = true;
 181                 liveopt = "-all";
 182             } else if (subopt.equals("live")) {
 183                 // Add '-' for compatibility.
 184                 set_live = true;
 185                 liveopt = "-live";
 186             } else if (subopt.startsWith("file=")) {
 187                 filename = parseFileName(subopt);
 188                 if (filename == null) {
 189                     System.err.println("Fail at processing option '" + subopt +"'");
 190                     usage(1); // invalid options or no filename
 191                 }
 192             } else if (subopt.startsWith("parallel=")) {
 193                parallel = subopt.substring("parallel=".length());
 194                if (parallel == null) {
 195                     System.err.println("Fail at processing option '" + subopt + "'");
 196                     usage(1);
 197                }
 198             } else {
 199                 System.err.println("Fail at processing option '" + subopt + "'");
 200                 usage(1);
 201             }
 202         }
 203         // backward compitable: if both "live" and "all" set, use "live".
 204         if (set_live && set_all) {
 205            liveopt = "-live";
 206         }
 207         System.out.flush();

 208         // inspectHeap is not the same as jcmd GC.class_histogram
 209         executeCommandForPid(pid, "inspectheap", liveopt, filename, parallel);
 210     }
 211 
 212     private static void dump(String pid, String options)
 213         throws AttachNotSupportedException, IOException,
 214                UnsupportedEncodingException {
 215 
 216         String subopts[] = options.split(",");
 217         String filename = null;
 218         String liveopt = "-all";
 219 
 220         for (int i = 0; i < subopts.length; i++) {
 221             String subopt = subopts[i];
 222             if (subopt.equals("live")) {
 223                 liveopt = "-live";
 224             } else if (subopt.startsWith("file=")) {
 225                 filename = parseFileName(subopt);
 226             }
 227         }
 228 
 229         if (filename == null) {
 230             System.err.println("Fail at processing option 'file'");
 231             usage(1);  // invalid options or no filename
 232         }
 233 
 234         // dumpHeap is not the same as jcmd GC.heap_dump
 235         executeCommandForPid(pid, "dumpheap", filename, liveopt);
 236     }
 237 
 238     private static void checkForUnsupportedOptions(String[] args) {
 239         // Check arguments for -F, -m, and non-numeric value
 240         // and warn the user that SA is not supported anymore
 241 
 242         int paramCount = 0;
 243 
 244         for (String s : args) {
 245             if (s.equals("-F")) {
 246                 SAOptionError("-F option used");
 247             }
 248 
 249             if (s.equals("-heap")) {
 250                 SAOptionError("-heap option used");


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