Java 基础教程

Java 面向对象

Java 高级教程

Java 笔记

java 如何查看堆的年轻代、老年代、永久代(或元空间)等空间信息

Java 笔记 Java 笔记


java 中可以通过 jdk 命令行工具 jmap 可以查看堆的信息,如年轻代、老年代、永久代(在 java 8 之后,变为元空间 metaspace)等空间信息。

堆各种代信息查看

可以通过 jmap -heap <pid> 命令查看堆各种代信息,前提是必须安装 java-openjdk-debug 插件,而且需要和 openjdk 小版本必须一致。

具体示例如下:

[linux@Linux ~]$ jmap -heap 1054
Attaching to process ID 1054, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.191-b12

using thread-local object allocation.
Parallel GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 10737418240 (10240.0MB)
   NewSize                  = 1073741824 (1024.0MB)
   MaxNewSize               = 1073741824 (1024.0MB)
   OldSize                  = 9663676416 (9216.0MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 1024458752 (977.0MB)
   used     = 895629296 (854.1386566162109MB)
   free     = 128829456 (122.86134338378906MB)
   87.42463220227339% used
From Space:
   capacity = 24641536 (23.5MB)
   used     = 8913424 (8.500503540039062MB)
   free     = 15728112 (14.999496459960938MB)
   36.172355489527924% used
To Space:
   capacity = 24117248 (23.0MB)
   used     = 0 (0.0MB)
   free     = 24117248 (23.0MB)
   0.0% used
PS Old Generation
   capacity = 9663676416 (9216.0MB)
   used     = 6273107080 (5982.501106262207MB)
   free     = 3390569336 (3233.498893737793MB)
   64.91429151760207% used