如何用jdk 11读取堆状态?

问题描述 投票:2回答:1

使用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 java-11
1个回答
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

编辑:还有一些关于在Java 11中调试内存问题的官方文档:https://docs.oracle.com/en/java/javase/11/troubleshoot/troubleshoot-memory-leaks.html

© www.soinside.com 2019 - 2024. All rights reserved.