< prev index next >
src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java
Print this page
rev 58082 : 8214535: Parallel heap inspection for jmap histo (G1)
Summary: Add parallel heap inspection to speedup jmap -histo, this patch support G1
Reviewed-by:
Contributed-by: lzang
*** 162,198 ****
}
// no filename
return null;
}
private static void histo(String pid, String options)
throws AttachNotSupportedException, IOException,
UnsupportedEncodingException {
String liveopt = "-all";
String filename = null;
String subopts[] = options.split(",");
for (int i = 0; i < subopts.length; i++) {
String subopt = subopts[i];
if (subopt.equals("") || subopt.equals("all")) {
! // pass
} else if (subopt.equals("live")) {
! liveopt = "-live";
} else if (subopt.startsWith("file=")) {
filename = parseFileName(subopt);
if (filename == null) {
usage(1); // invalid options or no filename
}
} else {
usage(1);
}
}
System.out.flush();
-
// inspectHeap is not the same as jcmd GC.class_histogram
! executeCommandForPid(pid, "inspectheap", liveopt, filename);
}
private static void dump(String pid, String options)
throws AttachNotSupportedException, IOException,
UnsupportedEncodingException {
--- 162,222 ----
}
// no filename
return null;
}
+ private static String add_option(String cmd, String opt) {
+ if (cmd.isEmpty()) {
+ return opt;
+ }
+ return cmd + "," + opt;
+ }
+
private static void histo(String pid, String options)
throws AttachNotSupportedException, IOException,
UnsupportedEncodingException {
String liveopt = "-all";
String filename = null;
+ String parallelthreadnum = null;
String subopts[] = options.split(",");
+ boolean set_all = false;
+ boolean set_live = false;
+ String cmdline = "";
for (int i = 0; i < subopts.length; i++) {
String subopt = subopts[i];
if (subopt.equals("") || subopt.equals("all")) {
! cmdline = add_option(cmdline, "-all");
! set_all = true;
} else if (subopt.equals("live")) {
! // Add '-' for compatibility.
! cmdline = add_option(cmdline, "-live");
! set_live = true;
} else if (subopt.startsWith("file=")) {
filename = parseFileName(subopt);
if (filename == null) {
usage(1); // invalid options or no filename
}
+ cmdline = add_option(cmdline, filename);
+ } else if (subopt.startsWith("parallelThreadNum=")) {
+ parallelthreadnum = subopt.substring(19);
+ if (parallelthreadnum == null) {
+ usage(1);
+ }
+ // Add "parallelThreadsNum=<>" for later check
+ cmdline = add_option(cmdline, subopt);
} else {
usage(1);
}
}
+ if (set_live && set_all) {
+ usage(1);
+ }
System.out.flush();
// inspectHeap is not the same as jcmd GC.class_histogram
! executeCommandForPid(pid, "inspectheap", cmdline);
}
private static void dump(String pid, String options)
throws AttachNotSupportedException, IOException,
UnsupportedEncodingException {
*** 285,294 ****
--- 309,322 ----
System.err.println("");
System.err.println(" histo-options:");
System.err.println(" live count only live objects");
System.err.println(" all count all objects in the heap (default if one of \"live\" or \"all\" is not specified)");
System.err.println(" file=<file> dump data to <file>");
+ System.err.println(" parallelThreadNum=<number> parallel threads number for heap iteration:");
+ System.err.println(" parallelThreadNum=0 default behavior, use predefined number of threads");
+ System.err.println(" parallelThreadNum=1 disable parallel heap iteration");
+ System.err.println(" parallelThreadNum=<N> use N threads for parallel heap iteration");
System.err.println("");
System.err.println(" Example: jmap -histo:live,file=/tmp/histo.data <pid>");
System.exit(exit);
}
}
< prev index next >