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(" --heap\tto print java heap summary");
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(" --clstats\tto print class loader statistics");
System.out.println(" --finalizerinfo\tto print information on objects awaiting finalization");
@ -241,13 +242,15 @@ public class SALauncher {
private static void runJMAP(String[] oldArgs) {
SAGetopt sg = new SAGetopt(oldArgs);
String[] longOpts = {"exe=", "core=", "pid=",
"heap", "binaryheap", "histo", "clstats", "finalizerinfo"};
"heap", "binaryheap", "dumpfile=", "histo", "clstats", "finalizerinfo"};
ArrayList<String> newArgs = new ArrayList();
String pid = null;
String exe = null;
String core = null;
String s = null;
String dumpfile = null;
boolean requestHeapdump = false;
while((s = sg.next(null, longOpts)) != null) {
if (s.equals("exe")) {
@ -267,7 +270,11 @@ public class SALauncher {
continue;
}
if (s.equals("binaryheap")) {
newArgs.add("-heap:format=b");
requestHeapdump = true;
continue;
}
if (s.equals("dumpfile")) {
dumpfile = sg.getOptarg();
continue;
}
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);
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_FINALIZERINFO = 6;
private static String dumpfile = "heap.bin";
public void run() {
Tool tool = null;
switch (mode) {
@ -92,11 +94,11 @@ public class JMap extends Tool {
break;
case MODE_HEAP_GRAPH_HPROF_BIN:
writeHeapHprofBin();
writeHeapHprofBin(dumpfile);
return;
case MODE_HEAP_GRAPH_GXL:
writeHeapGXL();
writeHeapGXL(dumpfile);
return;
case MODE_FINALIZERINFO:
@ -127,18 +129,34 @@ public class JMap extends Tool {
} else if (modeFlag.equals("-finalizerinfo")) {
mode = MODE_FINALIZERINFO;
} else {
int index = modeFlag.indexOf("-heap:format=");
int index = modeFlag.indexOf("-heap:");
if (index != -1) {
String format = modeFlag.substring(1 + modeFlag.indexOf('='));
if (format.equals("b")) {
mode = MODE_HEAP_GRAPH_HPROF_BIN;
} else if (format.equals("x")) {
mode = MODE_HEAP_GRAPH_GXL;
} else {
System.err.println("unknown heap format:" + format);
String[] options = modeFlag.substring(6).split(",");
for (String option : options) {
String[] keyValue = option.split("=");
if (keyValue[0].equals("format")) {
if (keyValue[1].equals("b")) {
mode = MODE_HEAP_GRAPH_HPROF_BIN;
} else if (keyValue[1].equals("x")) {
mode = MODE_HEAP_GRAPH_GXL;
} else {
System.err.println("unknown heap format:" + keyValue[0]);
// Exit with error status
System.exit(1);
// Exit with error status
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 {
copyArgs = false;