--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SALauncher.java Mon May 09 15:46:12 2016 +0200
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SALauncher.java Tue May 10 11:50:45 2016 +0000
@@ -73,6 +73,7 @@
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 @@
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 @@
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 @@
}
}
+ 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()]));
}
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JMap.java Mon May 09 15:46:12 2016 +0200
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JMap.java Tue May 10 11:50:45 2016 +0000
@@ -71,6 +71,8 @@
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 @@
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 @@
} 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;