JDK-8218131 : Add dump to file support for jmap -histo
  • Type: CSR
  • Component: core-svc
  • Sub-Component: tools
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 13
  • Submitted: 2019-01-31
  • Updated: 2019-02-17
  • Resolved: 2019-02-11
Related Reports
CSR :  
Description
Summary
-------

Add the options "file=<file>" to JMap -histo to improve JMap's ability

Problem
-------

Currently the "JMap -histo" tool doesn't support to dump result to a file directly.

Solution
--------

Add "file=<file>" option that let JMap -histo to dump directly to file. 
Please be aware that this is subset of  enhancement of JMap More detail please refer to https://bugs.openjdk.java.net/browse/JDK-8214535

Specification
-------------

Diff:

    --- old/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java
    +++ new/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java
    @@ -246,21 +266,27 @@
             System.err.println("        to connect to running process and print class loader statistics");
             System.err.println("    jmap -finalizerinfo <pid>");
             System.err.println("        to connect to running process and print information on objects awaiting finalization");
    -        System.err.println("    jmap -histo[:live] <pid>");
    +        System.err.println("    jmap -histo[:[<histo-options>]] <pid>");
             System.err.println("        to connect to running process and print histogram of java object heap");
    -        System.err.println("        if the \"live\" suboption is specified, only count live objects");
             System.err.println("    jmap -dump:<dump-options> <pid>");
             System.err.println("        to connect to running process and dump java heap");
             System.err.println("    jmap -? -h --help");
             System.err.println("        to print this help message");
             System.err.println("");
             System.err.println("    dump-options:");
    -        System.err.println("      live         dump only live objects; if not specified,");
    -        System.err.println("                   all objects in the heap are dumped.");
    +        System.err.println("      live         dump only live objects");
    +        System.err.println("      all          dump all objects in the heap (default if one of \"live\" or \"all\" is not specified);
             System.err.println("      format=b     binary format");
             System.err.println("      file=<file>  dump heap to <file>");
             System.err.println("");
             System.err.println("    Example: jmap -dump:live,format=b,file=heap.bin <pid>");
    +        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("");
    +        System.err.println("    Example: jmap -histo:live,file=/tmp/histo.data <pid>");
             System.exit(exit);
        }   
    }

Updated specification:

    jmap -clstats <pid>
        to connect to running process and print class loader statistics
    jmap -finalizerinfo <pid>
        to connect to running process and print information on objects awaiting finalization
    jmap -histo[:<histo-options>] <pid>
        to connect to running process and print histogram of java object heap
    jmap -dump:<dump-options> <pid>
        to connect to running process and dump java heap
    jmap -? -h --help
        to print this help message

    dump-options:
      live         dump only live objects; if not specified, use "all".
      all          all objects in the heap are dumped.
      format=b     binary format
      file=<file>  dump heap to <file>

    Example: jmap -dump:live,format=b,file=heap.bin <pid>

    histo-options:
      live         only count live objects; if not specified, use "all".
      all          count all objects in the heap
      file=<file>  dump data to <file>

    Example: jmap -histo:live,file=/tmp/histo.data <pid>

Comments
Moving to Approved.
11-02-2019

No objection to the feature but just to say that we looked at this back in JDK 6 when retrofitting jmap to work with the attach mechanism. At the time it didn't seem worth it as it was easy to redirect the output to a file.
11-02-2019

I've changed to request to Proposed state rather than Finalized since there are some issues to be addressed before it can be Approved. However, I'm comfortable to vote to advance it to the intermediate Provisional state. Before the request is finalized please: * Set the fixVersions field to be particular release, presumably JDK 13 * Do not have the assignee be one of the reviewers * Clarify that the default of "live" is not changing * I strongly suggest changing the spec for "live"/"all" to something like live only count live objects (default if one of live and all is not specified) all count all objects in the heap
08-02-2019

[~xiaofeya] Please move this to "Finalized" state so it can be fast tracked. I see no compatibility issues with adding this extra option to the jmap tool.
06-02-2019