Java 死循环调试命令 - jmap

JMap

命令格式

jmap [option]  LVMID
  1. option 参数
  • dump: 生成堆转储快照。
  • finalizerinfo: 显示在 F-Queue 队列等待 Finalizer 线程指向 finalizer 方法的对象。
  • heap: 显示 java 堆详细信息。
  • permstat: 显示永久代的信息。
  • F: 当 dump 没有响应时,强制生成 dump 快照。

例子

1.打印dump文件: -dump::live,format=b,file=<filename> pid

ubuntu@VM-0-7-ubuntu:~$ jmap -dump:live,format=b,file=dump.hprof 17281

Dumping heap to /home/ubuntu/dump.hprof ...
Heap dump file created

使用 Memory Anlysis Tool 打开 dump.hprof 文件。

2.打印等待回收对象的信息: finalizerinfo

ubuntu@VM-0-7-ubuntu:~$ jmap -finalizerinfo 17281\

Attaching to process ID 17281, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.181-b13
Number of objects pending for finalization: 0

3.打印 heap 概要信息,GC 算法,heap 的配置及 wise heap 的使用情况。

ubuntu@VM-0-7-ubuntu:~$ jmap -heap 17281

Attaching to process ID 17281, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.181-b13

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

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 4294967296 (4096.0MB)
   NewSize                  = 1363144 (1.2999954223632812MB)
   MaxNewSize               = 2576351232 (2457.0MB)
   OldSize                  = 5452592 (5.1999969482421875MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 1048576 (1.0MB)

Heap Usage:
G1 Heap:
   regions  = 4096
   capacity = 4294967296 (4096.0MB)
   used     = 201207848 (191.88675689697266MB)
   free     = 4093759448 (3904.1132431030273MB)
   4.6847352758049965% used
G1 Young Generation:
Eden Space:
   regions  = 110
   capacity = 676331520 (645.0MB)
   used     = 115343360 (110.0MB)
   free     = 560988160 (535.0MB)
   17.05426356589147% used
Survivor Space:
   regions  = 0
   capacity = 0 (0.0MB)
   used     = 0 (0.0MB)
   free     = 0 (0.0MB)
   0.0% used
G1 Old Generation:
   regions  = 84
   capacity = 397410304 (379.0MB)
   used     = 85864488 (81.88675689697266MB)
   free     = 311545816 (297.11324310302734MB)
   21.60600445830413% used

18946 interned Strings occupying 1962664 bytes.

4.打印堆的对象统计,包括对象数、内存大小

因为在 dump:live 前会进行 full gc,如果带上 live 则只统计活对象,因此不加live的堆大小要大于加 live 堆的大小。

ubuntu@VM-0-7-ubuntu:~$ jmap -histo:live 17281 | more

 num     #instances         #bytes  class name
----------------------------------------------
   1:       1114112       17825792  litchi.core.dispatch.disruptor.MessageBuffer
   2:         54327       17504752  [Ljava.lang.Object;
   3:         62303        6787608  [C
   4:        118637        4745480  java.util.LinkedHashMap$Entry
   5:          3929        4598656  [I
   6:        100741        3223712  java.util.HashMap$Node
   7:          2681        3000848  [B
   8:         35196        2534112  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$ShortcutDependencyDescriptor
   9:         18731        2422224  [Ljava.util.HashMap$Node;
  10:         96340        2312160  java.lang.String
  11:        112836        1805376  java.lang.Integer
  12:         63212        1517088  java.util.ArrayList
  13:         35196        1407840  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement
  14:         18581        1040536  java.util.LinkedHashMap
  15:         28470         911040  java.util.concurrent.ConcurrentHashMap$Node
  16:          8158         903496  java.lang.Class
  17:         37532         900768  java.util.LinkedList$Node
  18:         35205         844880  [Ljava.lang.annotation.Annotation;
  19:         18931         605792  java.lang.ref.WeakReference
  20:         16263         460424  [Ljava.lang.Class;
  21:          9415         451920  java.util.HashMap
  22:         17895         429480  litchi.core.common.extend.Dual
  23:          4603         405064  java.lang.reflect.Method
  24:           546         358176  io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue
  25:          2538         304560  com.kd.shared.dataconfig.model.MonsterArmyConfig

class name 是对象类型,说明如下:

  • B: byte
  • C: char
  • D: double
  • F: float
  • I: int
  • J: long
  • Z: boolean
  • [ : 数组,如[I表示int[]
  • [L + 类名 其他对象

5.参数 -F

强制模式。如果指定的pid没有响应,请使用jmap -dumpjmap -histo选项。此模式下,不支持live子选项。

JProfiler

JProfiler 分析导出的文件,看下面的线程 Actor-4-1,圈红的函数发生了死循环。
在这里插入图片描述
idea 可以有插件使用:
在这里插入图片描述

window 杀死进程

taskkill -f /pid   9884

9884 是进程id,可以通过 jps 查看

[1] JProfiler11安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值