8156033: jhsdb jmap cannot set heapdump name

Reviewed-by: dsamersoff
This commit is contained in:
Yasumasa Suenaga 2016-05-07 10:29:16 +09:00
parent c052a98d6f
commit f2e1814b1a
2 changed files with 50 additions and 14 deletions

View File

@ -73,6 +73,7 @@ public class SALauncher {
System.out.println(" <no option>\tto print same info as Solaris pmap"); System.out.println(" <no option>\tto print same info as Solaris pmap");
System.out.println(" --heap\tto print java heap summary"); System.out.println(" --heap\tto print java heap summary");
System.out.println(" --binaryheap\tto dump java heap in hprof binary format"); System.out.println(" --binaryheap\tto dump java heap in hprof binary format");
System.out.println(" --dumpfile\tname of the dump file");
System.out.println(" --histo\tto print histogram of java object heap"); System.out.println(" --histo\tto print histogram of java object heap");
System.out.println(" --clstats\tto print class loader statistics"); System.out.println(" --clstats\tto print class loader statistics");
System.out.println(" --finalizerinfo\tto print information on objects awaiting finalization"); System.out.println(" --finalizerinfo\tto print information on objects awaiting finalization");
@ -241,13 +242,15 @@ public class SALauncher {
private static void runJMAP(String[] oldArgs) { private static void runJMAP(String[] oldArgs) {
SAGetopt sg = new SAGetopt(oldArgs); SAGetopt sg = new SAGetopt(oldArgs);
String[] longOpts = {"exe=", "core=", "pid=", String[] longOpts = {"exe=", "core=", "pid=",
"heap", "binaryheap", "histo", "clstats", "finalizerinfo"}; "heap", "binaryheap", "dumpfile=", "histo", "clstats", "finalizerinfo"};
ArrayList<String> newArgs = new ArrayList(); ArrayList<String> newArgs = new ArrayList();
String pid = null; String pid = null;
String exe = null; String exe = null;
String core = null; String core = null;
String s = null; String s = null;
String dumpfile = null;
boolean requestHeapdump = false;
while((s = sg.next(null, longOpts)) != null) { while((s = sg.next(null, longOpts)) != null) {
if (s.equals("exe")) { if (s.equals("exe")) {
@ -267,7 +270,11 @@ public class SALauncher {
continue; continue;
} }
if (s.equals("binaryheap")) { if (s.equals("binaryheap")) {
newArgs.add("-heap:format=b"); requestHeapdump = true;
continue;
}
if (s.equals("dumpfile")) {
dumpfile = sg.getOptarg();
continue; continue;
} }
if (s.equals("histo")) { if (s.equals("histo")) {
@ -284,6 +291,17 @@ public class SALauncher {
} }
} }
if (!requestHeapdump && (dumpfile != null)) {
throw new IllegalArgumentException("Unexpected argument dumpfile");
}
if (requestHeapdump) {
if (dumpfile == null) {
newArgs.add("-heap:format=b");
} else {
newArgs.add("-heap:format=b,file=" + dumpfile);
}
}
buildAttachArgs(newArgs, pid, exe, core, false); buildAttachArgs(newArgs, pid, exe, core, false);
JMap.main(newArgs.toArray(new String[newArgs.size()])); JMap.main(newArgs.toArray(new String[newArgs.size()]));
} }

View File

@ -71,6 +71,8 @@ public class JMap extends Tool {
public static final int MODE_HEAP_GRAPH_GXL = 5; public static final int MODE_HEAP_GRAPH_GXL = 5;
public static final int MODE_FINALIZERINFO = 6; public static final int MODE_FINALIZERINFO = 6;
private static String dumpfile = "heap.bin";
public void run() { public void run() {
Tool tool = null; Tool tool = null;
switch (mode) { switch (mode) {
@ -92,11 +94,11 @@ public class JMap extends Tool {
break; break;
case MODE_HEAP_GRAPH_HPROF_BIN: case MODE_HEAP_GRAPH_HPROF_BIN:
writeHeapHprofBin(); writeHeapHprofBin(dumpfile);
return; return;
case MODE_HEAP_GRAPH_GXL: case MODE_HEAP_GRAPH_GXL:
writeHeapGXL(); writeHeapGXL(dumpfile);
return; return;
case MODE_FINALIZERINFO: case MODE_FINALIZERINFO:
@ -127,19 +129,35 @@ public class JMap extends Tool {
} else if (modeFlag.equals("-finalizerinfo")) { } else if (modeFlag.equals("-finalizerinfo")) {
mode = MODE_FINALIZERINFO; mode = MODE_FINALIZERINFO;
} else { } else {
int index = modeFlag.indexOf("-heap:format="); int index = modeFlag.indexOf("-heap:");
if (index != -1) { if (index != -1) {
String format = modeFlag.substring(1 + modeFlag.indexOf('=')); String[] options = modeFlag.substring(6).split(",");
if (format.equals("b")) { for (String option : options) {
String[] keyValue = option.split("=");
if (keyValue[0].equals("format")) {
if (keyValue[1].equals("b")) {
mode = MODE_HEAP_GRAPH_HPROF_BIN; mode = MODE_HEAP_GRAPH_HPROF_BIN;
} else if (format.equals("x")) { } else if (keyValue[1].equals("x")) {
mode = MODE_HEAP_GRAPH_GXL; mode = MODE_HEAP_GRAPH_GXL;
} else { } else {
System.err.println("unknown heap format:" + format); System.err.println("unknown heap format:" + keyValue[0]);
// Exit with error status // Exit with error status
System.exit(1); System.exit(1);
} }
} else if (keyValue[0].equals("file")) {
if ((keyValue[1] == null) || keyValue[1].equals("")) {
System.err.println("File name must be set.");
System.exit(1);
}
dumpfile = keyValue[1];
} else {
System.err.println("unknown option:" + keyValue[0]);
// Exit with error status
System.exit(1);
}
}
} else { } else {
copyArgs = false; copyArgs = false;
} }