java 17 查看 运行时内存堆 的命令

Java 17

Windows 11

-

 

发生问题

运行了一个 java程序,基于 Java 17 的。

在使用 jmap 查看堆内存分配时,出现了错误:

>jmap -heap 8400
Error: -heap option used
Cannot connect to core dump or remote debug server. Use jhsdb jmap instead

提示使用 jhsdb jamp 替代。ben发布于博客园

 

jhsdb 帮助信息

>jhsdb --help

>jhsdb --help
    clhsdb              command line debugger
    hsdb                ui debugger
    debugd --help       to get more information
    jstack --help       to get more information
    jmap   --help       to get more information
    jinfo  --help       to get more information
    jsnap  --help       to get more information

注意,这里有 jmap、jstack、jinfo 等 子命令。

 

jhsdb jmap 帮助信息

>jhsdb jmap --helpben发布于博客园

>jhsdb jmap --help
    <no option>             To print same info as Solaris pmap.
    --heap                  To print java heap summary.
    --binaryheap            To dump java heap in hprof binary format.
    --dumpfile <name>       The name of the dump file. Only valid with --binaryheap.
    --gz <1-9>              The compression level for gzipped dump file. Only valid with --binaryheap.
    --histo                 To print histogram of java object heap.
    --clstats               To print class loader statistics.
    --finalizerinfo         To print information on objects awaiting finalization.
    --pid <pid>             To attach to and operate on the given live process.
    --core <corefile>       To operate on the given core file.
    --exe <executable for corefile>
    --connect [<serverid>@]<host>[:registryport][/servername] To connect to a remote debug server (debugd).

    The --core and --exe options must be set together to give the core
    file, and associated executable, to operate on. They can use
    absolute or relative paths.
    The --pid option can be set to operate on a live process.
    The --connect option can be set to connect to a debug server (debugd).
    --core, --pid, and --connect are mutually exclusive.

    Examples: jhsdb jmap --pid 1234
          or  jhsdb jmap --core ./core.1234 --exe ./myexe
          or  jhsdb jmap --connect serverid@debugserver:1234/servername

ben发布于博客园

jhsdb jmap 查看堆信息

错误命令:没有 --pid

>jhsdb jmap --heap 8400
SA agent option related exception occurred: You have to set --pid or --exe or --connect.
sun.jvm.hotspot.SAGetoptException: You have to set --pid or --exe or --connect.
        at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.buildAttachArgs(SALauncher.java:178)
        at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.runJMAP(SALauncher.java:340)
        at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.main(SALauncher.java:500)
    <no option>             To print same info as Solaris pmap.

ben发布于博客园

正确命令:

>jhsdb jmap --heap --pid 8400
Attaching to process ID 8400, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 17.0.10+13-LTS

using thread-local object allocation.
Garbage-First (G1) GC with 8 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 2118123520 (2020.0MB)
   NewSize                  = 1363144 (1.2999954223632812MB)
   MaxNewSize               = 1270874112 (1212.0MB)
   OldSize                  = 5452592 (5.1999969482421875MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 22020096 (21.0MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 1048576 (1.0MB)

Heap Usage:
G1 Heap:
   regions  = 2020
   capacity = 2118123520 (2020.0MB)
   used     = 75820528 (72.30809020996094MB)
   free     = 2042302992 (1947.691909790039MB)
   3.5796084262356898% used
G1 Young Generation:
Eden Space:
   regions  = 45
   capacity = 54525952 (52.0MB)
   used     = 47185920 (45.0MB)
   free     = 7340032 (7.0MB)
   86.53846153846153% used
Survivor Space:
   regions  = 3
   capacity = 4194304 (4.0MB)
   used     = 3507696 (3.3451995849609375MB)
   free     = 686608 (0.6548004150390625MB)
   83.62998962402344% used
G1 Old Generation:
   regions  = 25
   capacity = 38797312 (37.0MB)
   used     = 25126912 (23.962890625MB)
   free     = 13670400 (13.037109375MB)
   64.76456925675676% used

 

jhsdb是什么?

“JHSDB,即 Java HotSpot Serviceability Debugger,是OpenJDK提供的一款强大的进程外调试工具。”

“JHSDB虽然是JDK 9中才正式提供,但之前已经以sa-jdi.jar包里面的HSDB(可视化工 具)和CLHSDB(命令行工具)的形式存在了很长一段时间。它们两个都是JDK的正式成员,随着JDK一同发布,无须独立下载,使用也是完全免费的。”

 

 

---end---

 

参考资料:

1、深入探索OpenJDK的JHSDB工具:Java调试的新境界

https://developer.baidu.com/article/detail.html?id=3316553

作者:菠萝爱吃肉

2024.04.15 15:09

2、

 

ben发布于博客园

ben发布于博客园

 

posted @ 2024-09-29 10:10  快乐的欧阳天美1114  阅读(45)  评论(0编辑  收藏  举报