使用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发生的时间
答案 0 :(得分:1)
有一些JVM选项可以通过记录GC信息来帮助您:
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintHeapAtGC
-XX:+PrintTenuringDistribution
-XX:+PrintGCApplicationStoppedTime
-XX:+HeapDumpOnOutOfMemoryError
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=10
-XX:GCLogFileSize=10M
可以使用JDK附带的工具分析HeapDumpOnOutOfMemoryError创建的文件。另请参见https://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/clopts.html
edit:还有一些有关调试Java 11中的内存问题的官方文档:https://docs.oracle.com/en/java/javase/11/troubleshoot/troubleshoot-memory-leaks.html
答案 1 :(得分:1)
对于较新的 Java 版本(如 JDK 11),您可以使用以下命令:
void handleRequest() {
// some logic to activate the hardware
server.send(200, "text/html", "1");
}
输出几乎与 Java 8 和 jhsdb jmap --heap --pid <pid>
相同。