Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8257234 : Add gz option to SA jmap to write a gzipped heap dump #1712

Closed
wants to merge 25 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a915f06
8257234 : Add gz option to SA jmap to write a gzipped heap dump
linzang Dec 1, 2020
909ee24
refine comments
linzang Dec 10, 2020
ef353ac
delete unnecessary print
linzang Dec 10, 2020
e7b5358
refine segment heap dump
linzang Jan 18, 2021
c720aca
Merge branch 'master' into sa
linzang Jan 19, 2021
b11434a
code refine
linzang Jan 19, 2021
8dc6057
fix issue of setting gz option with no value
linzang Jan 19, 2021
49a3a92
fix serveral issues and add test cases
linzang Jan 22, 2021
efad1b4
fix coding style issue
linzang Jan 25, 2021
d1f5494
fix commandline argument issue and refine test cases
linzang Jan 27, 2021
5a00c25
update copyright info
linzang Jan 27, 2021
0d6d69d
fix issue cause JMapHProfLargeHeapTest fail and code refine
linzang Jan 27, 2021
876c851
fix code in CommandProcessor
linzang Jan 27, 2021
db38b6a
fix the logic of using gz= as file name
linzang Jan 27, 2021
51b2e73
fix jcmd jmap issue and add test in BascJMapTest and code refine
linzang Jan 29, 2021
0d30aaf
fix an issue of double printing error message.
linzang Jan 29, 2021
0aa703d
refine help message and also refactor the logic in CommandProcessor
linzang Feb 5, 2021
86f358a
revert changes in jcmd jmap
linzang Feb 5, 2021
8f38b97
add test in HeapDumpTest and fix in argument parsing
linzang Feb 5, 2021
d87a027
refine code for argument parsing
linzang Feb 8, 2021
47d93a9
remove redundant check
linzang Feb 9, 2021
6fe0f79
refine code in test.
linzang Feb 9, 2021
5b89e75
fix help message issue and Use ByteBuffer for integer writing
linzang Feb 10, 2021
7c25d58
fix indentation isue
linzang Feb 10, 2021
73b6c29
refine the argument name
linzang Feb 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1789,6 +1789,7 @@ public void doit(Tokens t) {
* dumpheap gz=1 file;
* dumpheap gz=1;
* dumpheap file;
* dumpheap
*/
if (cntTokens == 2) {
/* First argument is compression level, second is filename */
@@ -1800,25 +1801,25 @@ public void doit(Tokens t) {
}
/* Parse filename. */
filename = t.nextToken();
// Don't accept filename that start with "gz=" to avoid case like
// "dumpheap gz=1 gz=2"
if (filename.startsWith("gz=")) {
err.println("Illegal filename \" + filename + \" should not start with \"gz=\".");
usage();
return;
}
} else if (cntTokens == 1) {
filename = option;
// Try to parse "gz=" option.
if (option.startsWith("gz=")) {
gzlevel = parseHeapDumpCompressionLevel(option);
if (gzlevel == 0) {
usage();
return;
usage();
return;
}
filename = "heap.bin.gz";
}
}
// Don't accept filename that start with "gz=" to avoid case like
// "dumpheap gz=1 gz=2"
if (filename.startsWith("gz=")) {
err.println("Illegal filename \" + filename + \" should not start with \"gz=\".");
usage();
return;
}
try {
jmap.writeHeapHprofBin(filename, gzlevel);
} catch (Exception e) {
Original file line number Diff line number Diff line change
@@ -50,18 +50,18 @@ public String getName() {
}

protected String getCommandFlags() {
return "-heap|-heap:format=b[,gz=<1-9>]|-histo|-clstats|-finalizerinfo";
return "-heap|-heap:format=b[,gz=<1-9>][,file=<dumpfile>]|-heap:format=x[,file=<dumpfile>]|{-histo|-clstats|-finalizerinfo";
}

protected void printFlagsUsage() {
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:format=b[,gz=<1-9>]\tTo dump java heap in hprof binary format.");
System.out.println(" \tIf gz specified, the heap dump is written");
System.out.println(" \tin gzipped format using the given compression level.");
System.err.println(" \t1 (recommended) is the fastest, 9 the strongest compression.");
System.out.println(" -heap:format=x \tTo dump java heap in GXL format.");
System.out.println(" \tPlease be aware that \"gz\" option is not valid for heap dump in GXL format.");
System.out.println(" -heap:format=b[,gz=<1-9>][,file=<dumpfile>] \tTo dump java heap in hprof binary format.");
System.out.println(" \tIf gz specified, the heap dump is written");
System.out.println(" \tin gzipped format using the given compression level.");
System.err.println(" \t1 (recommended) is the fastest, 9 the strongest compression.");
System.out.println(" -heap:format=x[,file=<dumpfile>] \tTo dump java heap in GXL format.");
System.out.println(" \tPlease be aware that \"gz\" option is not valid for heap dump in GXL format.");
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.");
2 changes: 1 addition & 1 deletion src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ private static void dump(String pid, String options)
// ignore format (not needed at this time)
} else if (subopt.startsWith("gz=")) {
compress_level = subopt.substring("gz=".length());
if (compress_level == null) {
if (compress_level == null || compress_level.length() == 0) {
System.err.println("Fail: no number provided in option: '" + subopt + "'");
usage(1);
}
31 changes: 25 additions & 6 deletions test/jdk/sun/tools/jmap/BasicJMapTest.java
Original file line number Diff line number Diff line change
@@ -118,6 +118,7 @@ public static void main(String[] args) throws Exception {
testDumpLive();
testDumpAll();
testDumpCompressed();
testDumpIllegalCompressedArgs();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating this test to better check the args, but it looks like I pointed you to the wrong test. This is testing the pmap tool, which already had the gz option. I actually meant for you to add testing for the gz option support you added to "jhsdb jmap --binaryheap" , which is what you added to SALauncher.java. The testing for "jhsdb jmap --binaryheap" is done in test/jdk/sun/tools/jhsdb/HeapDumpTest.java.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Chris!,
I have created another PR and move jcmd jmap fix and this test case enhancement there. (#2399)

I will add the test in HeapDumpTest.java in this PR.

}

private static void testHisto() throws Exception {
@@ -230,7 +231,23 @@ private static void testDumpCompressed() throws Exception {
dump(true, false, true);
}

private static void testDumpIllegalCompressedArgs() throws Exception{
dump(true, false, true, "0", 1, "Compression level out of range");
dump(true, false, true, "100", 1, "Compression level out of range");
dump(true, false, true, "abc", 1, "Invalid compress level");
dump(true, false, true, "", 1, "Fail: no number provided in option:");
}

private static void dump(boolean live, boolean explicitAll, boolean compressed) throws Exception {
dump(live, explicitAll, compressed, "1", 0, "Heap dump file created");
}

private static void dump(boolean live,
boolean explicitAll,
boolean compressed,
String compressLevel,
int expExitValue,
String expOutput) throws Exception {
String liveArg = "";
String fileArg = "";
String compressArg = "";
@@ -248,22 +265,24 @@ private static void dump(boolean live, boolean explicitAll, boolean compressed)

String filePath = "jmap.dump" + System.currentTimeMillis() + ".hprof";
if (compressed) {
compressArg = "gz=1,";
compressArg = "gz=" + compressLevel;
filePath = filePath + ".gz";
}

File file = new File(filePath);
if (file.exists()) {
file.delete();
}
fileArg = "file=" + file.getName();
fileArg = "file=" + file.getName() + ",";

OutputAnalyzer output;
allArgs = allArgs + liveArg + compressArg + "format=b," + fileArg;
allArgs = allArgs + liveArg + "format=b," + fileArg + compressArg;
output = jmap(allArgs);
output.shouldHaveExitValue(0);
output.shouldContain("Heap dump file created");
verifyDumpFile(file);
output.shouldHaveExitValue(expExitValue);
output.shouldContain(expOutput);
if (expExitValue == 0) {
verifyDumpFile(file);
}
file.delete();
}