使用 jdk 8 时,这些是我计算进程运行时消耗多少内存的步骤:
/usr/java/latest/bin>: ./jps
27116 Main
7591 Jps
2879 AmbusProcessor
然后选取进程 ID 来检查堆的状态:
/usr/java/latest/bin>: ./jmap -heap 2879
Attaching to process ID 2879, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.45-b08
using thread-local object allocation.
Parallel GC with 13 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 68719476736 (65536.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 21757952 (20.75MB)
MaxPermSize = 134217728 (128.0MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 15427698688 (14713.0MB)
used = 9122094480 (8699.507217407227MB)
free = 6305604208 (6013.492782592773MB)
59.128031111311266% used
From Space:
capacity = 2062024704 (1966.5MB)
used = 813973552 (776.2656707763672MB)
free = 1248051152 (1190.2343292236328MB)
39.474481097196396% used
To Space:
capacity = 1944059904 (1854.0MB)
used = 0 (0.0MB)
free = 1944059904 (1854.0MB)
0.0% used
PS Old Generation
capacity = 8520204288 (8125.5MB)
used = 6649238896 (6341.208358764648MB)
free = 1870965392 (1784.2916412353516MB)
78.04083882548333% used
PS Perm Generation
capacity = 31981568 (30.5MB)
used = 16156728 (15.408256530761719MB)
free = 15824840 (15.091743469238281MB)
50.518873871349896% used
6141 interned Strings occupying 609896 bytes.
我正在寻找一种读取状态的方法,该状态应类似于上述示例,但是,找不到像 openjdk 11 这样的选项。我已经在 openjdk11 上的 jmap 上尝试了所有可能的选项。还有没有办法使用 openjdk11 获得这种状态读取?我正在尝试在 outOfMemory 发生时准确转储
对于较新的 Java 版本(如 JDK 11(,您可以使用以下命令:
jhsdb jmap --heap --pid <pid>
输出与Java 8和jmap
几乎相同。
有一些 JVM 选项可以通过记录 GC 信息来帮助您:
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintHeapAtGC
-XX:+PrintTenuringDistribution
-XX:+PrintGCApplicationStoppedTime
-XX:+HeapDumpOnOutOfMemoryError
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=10
-XX:GCLogFileSize=10M
由 HeapDumpOnOutOfMemoryError 创建的文件可以使用 JDK 附带的工具进行分析。另请参阅 https://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/clopts.html
编辑:还有一些关于在Java 11中调试内存问题的官方文档:https://docs.oracle.com/en/java/javase/11/troubleshoot/troubleshoot-memory-leaks.html