前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >虚拟机性能监控、故障处理关于控制台的命令整理

虚拟机性能监控、故障处理关于控制台的命令整理

原创
作者头像
eeaters
修改2022-02-21 18:04:37
4760
修改2022-02-21 18:04:37
举报
文章被收录于专栏:阿杰阿杰

虚拟机性能监控、故障处理关于命令行的工具

  • 前置
  • jps: 虚拟机进程状况工具
  • jstat: 虚拟机统计信息监视工具
    • class
    • gc
    • gccapacity
    • gcutil
    • gccause
    • compiler
    • printcompilation
  • jinfo: Java配置信息工具
  • jmap: 内存映像工具
    • dump
    • finalizerinfo
    • heap
    • histo
    • permstat
  • jhat: 虚拟机堆栈存储快照分析工具
  • jstack: Java堆栈跟踪工具
    • 默认
    • F
    • l
    • m

前置

对深入理解JAVA虚拟机中第四章的部分内容进行跟踪整理

  1. 正常的JAVA环境
  2. 随机找一个JAVA程序即可
  3. jdk版本: jdk1.8.0_73

jps: 虚拟机进程状况工具

JVM Process State

可以查找正在运行的虚拟机进程号,并显示主类名称和本地虚拟机唯一id,命令格式

jps [option] [hostid]

选项

作用

空参数 常用

输出主类名称和LVMID

-q

只输出LVMID

-m

输出虚拟机启动时传递给主类的参数

-l 常用

当我们启动JAR包时,会输出JAR路径; 进一步确认自己要确认的进程id

-v

输出启动时的JVM参数

jstat: 虚拟机统计信息监视工具

JVM Statistics Monitoring Tool

监视虚拟机各种运行状态信息;显示进程中的 类加载、内存、垃圾收集、即时编译 等; 如果没有GUI图形化界面的服务器,可以通过该命令查看运行状况,命令格式:

jstat [option vmid [interval[s|ms] [count]] ]

示例: jstat -gc 12252 500 10 ⇒ 打印进程12252的gc信息,500ms一次,打印10次

针对jstat有一个专门的博客: jstat命令查看jvm的GC情况 (以Linux为例)

class

jstat -class 12252

Loaded

Bytes

Unloaded

Bytes

Time

6003

10740.9

0

0.0

1.55

  1. loaded: 已加载的类
  2. Bytes: 已加载的类锁占用的空间
  3. Unloaded: 未加载数量
  4. Bytes: 未加载占用空间
  5. Time: 时间

gc

GC需要对堆的分布有一定了解; 简单分为:年轻代的Eden区、幸存区(from+to), 老年代,永久代

jstat -gc 12252

S0C

S1C

S0U

S1U

EC

EU

OC

OU

MC

MU

CCSC

CCSU

YGC

YGCT

FGC

FGCT

GCT

9728.0

5120.0

0.0

5098.8

66560.0

64001.7

58880.0

10236.9

28032.0

26079.1

3968.0

3521.6

5

0.022

1

0.020

0.042

  1. S代表: Survivor, S0/S1代表的是幸存区的from和to;
  2. E代表: Eden区
  3. O代表: 老年代
  4. M代表: Meta-space 元空间 注意: 自动内存管理 章节中提到: 在JDK1.7之前被错误的等价于永久代;在JDK1.8后完全废弃了永久代,全部移动到了元空间中;如有不对,还请见谅
  5. CC代表: 压缩类空间Compressed Class,参考文章: JVM调优中,压缩类空间(Compressed Class space)如何理解,有多重要?
  6. YGC: Young GC,发生在新生代的GC
  7. FGC: Full GC, 收集整个堆,包括young gen、old gen、perm gen(元空间)的模式

后缀的话U:use, C:count, T:time

gccapacity

jstat -gccapacity 12252

这里可以指定具体的空间;如:年轻代-gcnewcapacity/老年代-gcoldcapacity/ 元空间-gcpermcapacity

NGCMN

NGCMX

NGC

S0C

S1C

EC

OGCMN

OGCMX OGC

OC

MCMN

MCMX

MC

CCSMN

CCSMX

CCSC

YGC

FGC

43520.0

692224.0

158208.0

9216.0

9216.0

102400.0

87552.0

1384448.0

58880.0

58880.0

0.0

1077248.0

31616.0

0.0

1048576.0

4480.0

7

  1. NGC: 年轻代/MN:最小/MX:最大
  2. S0/S1/EC/YGC/FGC :参考gc选项中描述
  3. OGC: 老年代/MN:最小/MX:最大
  4. O: 当前的老年代容量
  5. MC: 元空间/MN:最小/MX:最大
  6. CC: 参考gc选项中的描述

gcutil

统计各区域gc的情况,指令参考 gc选项中的描述

jstat -gcutil 12252

S0

S1

E

O

M

CCS

YGC

YGCT

FGC

FGCT

GCT

91.11

0.00

3.82

17.43

91.74

88.10

8

0.042

1

0.020

0.062

gccause

展示上一次回收失败的原因:可能展示出的错误参考: jvm源码阅读笔记7-从jstat -gccause命令谈到jvm中都有哪些GC cause

jstat -gccause 12252

S0

S1

E

O

M

CCS

YGC

YGCT

FGC

FGCT

GCT

LGCC

GCC

91.11

0.00

8.89

17.43

91.74

88.10

8

0.042

1

0.020

0.062

Allocation Failure

No GC

compiler

jstat -compiler 12252

统计即时编译过的方法和耗时,没有简写,可读性强

Compiled

Failed

Invalid

Time

FailedType

FailedMethod

3208

0

0

0.64

0

printcompilation

jstat -printcompilation 12252

输出已经被即使编译过的方法

Compiled

Size

Type

Method

3208

10

1

java/util/Collections$UnmodifiableMap$UnmodifiableEntrySet$1 hasNext

  1. Size表示最近被编译方法的字节码数量
  2. Type表示也是最近被编译方法的类型

jinfo: Java配置信息工具

Configuration Info for Java,在JDK 9中被集成到了JHSDB中

实时查看和调整虚机各项参数; jps -v只能查看显式被指定的; 未被显式指定需要通过该指令查找,命令格式:

jinfo [option] pid

我们看下提示:

代码语言:javascript
复制
D:\doc>jinfo
Usage:
    jinfo [option] <pid>
        (to connect to running process)
    jinfo [option] <executable <core>
        (to connect to a core file)
    jinfo [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)
where <option> is one of:
    -flag <name>         to print the value of the named VM flag
    -flag [+|-]<name>    to enable or disable the named VM flag
    -flag <name>=<value> to set the named VM flag to the given value
    -flags               to print VM flags
    -sysprops            to print Java system properties
    <no option>          to print both of the above
    -h | -help           to print this help message

看下所有的配置信息:

代码语言:javascript
复制
jinfo -flags 12252
Attaching to process ID 12252, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.73-b02
Non-default VM flags: -XX:-BytecodeVerificationLocal -XX:-BytecodeVerificationRemote -XX:CICompilerCount=4 -XX:InitialHeapSize=134217728 -XX:+ManagementServer -XX:MaxHeapSize=2126512128 -XX:MaxNewSize=708837376 -XX:Min
HeapDeltaBytes=524288 -XX:NewSize=44564480 -XX:OldSize=89653248 -XX:TieredStopAtLevel=1 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:
+UseParallelGC
Command line:  -XX:TieredStopAtLevel=1 -Xverify:none -Dspring.output.ansi.enabled=always -javaagent:D:\framework\idea\IntelliJ IDEA 2021.2\lib\idea_rt.jar=53149:D:\framework\idea\IntelliJ IDEA 2021.2\bin -Dcom.sun.mana
gement.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8

也可以查询单个,如:

代码语言:javascript
复制
D:\doc>jinfo -flag NewSize 12252
-XX:NewSize=44564480

jmap: 内存映像工具

Memory Map for Java

用于生成堆栈存储快照、查询finalize执行队列、Java堆方法区的详细信息(如:空间使用率、当前使用的收集器),命令格式:

jmap [option] vmid

dump

这个命令生产环境一般不会乱放开,生成快照会有STW的问题,线上环境一定不可以在高峰期搞这种事情(碰到过因为想纠结一个bug而让运维高峰期搞这种事情导致线上故障的)

示例: jmap -dump:live,format=b,file=D:\heap.hprof 12252

生成dump文件有多种方式,如

  1. jmap -dump命令
  2. -XX:+HeapDumpOnCtrlBreak : 可以使用Ctrl+Break 生成快照文件
  3. -XX:+HeapDumpOnOutOfMemoryError : 内存溢出自动生成堆栈快照文件
  4. Linux系统通过Kill -3恐吓虚拟机
  5. jConsole的可视化界面中也可以通过jmx生成dump文件

分析dump文件可以使用如:jhat/jprofile等工具进行分析

finalizerinfo

显式在F-Queue中等待Finalizer县城执行finalize方法的对象

代码语言:javascript
复制
jmap -finalizerinfo 12252
Attaching to process ID 12252, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.73-b02
Number of objects pending for finalization: 0

heap

查看java堆的详细信息,包括类、实例数量、合计容量

代码语言:javascript
复制
jmap -heap 12252
Attaching to process ID 12252, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.73-b02
using thread-local object allocation.
Parallel GC with 10 thread(s)
Heap Configuration:
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 2126512128 (2028.0MB)
   NewSize                  = 44564480 (42.5MB)
   MaxNewSize               = 708837376 (676.0MB)
   OldSize                  = 89653248 (85.5MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)
   capacity = 10485760 (10.0MB)
Heap Usage:
PS Young Generation
Eden Space:
   capacity = 95420416 (91.0MB)
   used     = 37705416 (35.95868682861328MB)
   free     = 57715000 (55.04131317138672MB)
   39.51504047100361% used
From Space:
   capacity = 4194304 (4.0MB)
   used     = 0 (0.0MB)
   free     = 4194304 (4.0MB)
   0.0% used
To Space:
   capacity = 10485760 (10.0MB)
   used     = 0 (0.0MB)
   free     = 10485760 (10.0MB)
   0.0% used
PS Old Generation
   capacity = 92274688 (88.0MB)
   used     = 8235968 (7.85443115234375MB)
   free     = 84038720 (80.14556884765625MB)
   8.92548994584517% used
10869 interned Strings occupying 972216 bytes.

histo

截了一段,因为会打印所有对象的统计信息,包括类/实例数量/合计容量; 当我们看dump文件的时候也有相同的内容

代码语言:javascript
复制
jmap -histo 12252
 num     #instances         #bytes  class name
----------------------------------------------
   1:        127133       11521344  [C
   2:         39218        7555416  [B
   3:        128165        4763152  [Ljava.lang.Object;
   4:         24278        3558352  [I
   5:         68132        2180224  java.io.ObjectStreamClass$WeakClassKey
   6:         79936        1918464  java.lang.String
   7:         11253        1170312  java.io.ObjectStreamClass

permstat

以ClassLoader为统计根显式永久代的内存状态,但是只能在Linux/Solaris中使用; windows压根不支持

jhat: 虚拟机堆栈存储快照分析工具

jmap中生成了dump文件; 这里进行分析,在JDK 9中被JHSDB替代

代码语言:javascript
复制
jhat D:\heap.hprof
Reading from D:\heap.hprof...
Dump file created Sat Dec 11 23:18:25 CST 2021
Snapshot read, resolving...
Resolving 166946 objects...
Chasing references, expect 33 dots.................................
Eliminating duplicate references.................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.

然后本地访问: localhost:7000

但是界面操作不够友好; 同类型的还有: VisualVM、Eclipse Memory Analyzer、IBM HeapAnalyzer, 而我选择jprofile分析…

jstack: Java堆栈跟踪工具

Stack Trace for Java ,在JDK 9中被集成到了JHSDB中

生成虚拟机当前时刻的线程快照,线程快照就是当前虚拟机中每一个线程正在执行的方法堆栈集合, 主要目的是为了定位线程长时间停顿的原因, 是否有死锁/死循环/外部资源导致长时间挂起等; 命令格式:

jstack [option] vmid

由于Thread从JDK1.5后提供了getAllStackTraces(); 因此可以写一个工具方法实现这个小工具的功能, 不过还是测试一下

换一段会死锁的代码进行跟踪:

代码语言:javascript
复制
public class Main {
    static Object lock1 = new Object();
    static Object lock2 = new Object();


    public static void main(String[] args)  {
        new Thread(() -> methodA()).start();
        new Thread(() -> methodB()).start();
    }

    private static void methodA() {
        synchronized (lock1) {
            secondSleep(1);
            synchronized (lock2) {
                secondSleep(1);
                System.out.print("methodA");
            }
        }
    }
    private static void methodB()  {
        synchronized (lock2) {
            secondSleep(1);
            synchronized (lock1) {
                secondSleep(1);
                System.out.print("methodB");
            }
        }
    }


    public static void secondSleep(int second) {
        try {
            TimeUnit.SECONDS.sleep(second);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

默认

代码语言:javascript
复制
$ jstack 15996
2021-12-12 07:51:35
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.73-b02 mixed mode):

"DestroyJavaVM" #14 prio=5 os_prio=0 tid=0x000000001a186800 nid=0x3f88 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Thread-1" #13 prio=5 os_prio=0 tid=0x000000001a182800 nid=0x4b94 waiting for monitor entry [0x000000001c76e000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at com.caicai.study.sa_token.Main.methodB(Main.java:29)
        - waiting to lock <0x00000000d5f51db8> (a java.lang.Object)
        - locked <0x00000000d5f51dc8> (a java.lang.Object)
        at com.caicai.study.sa_token.Main.lambda$main$1(Main.java:13)
        at com.caicai.study.sa_token.Main$$Lambda$2/769287236.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)

"Thread-0" #12 prio=5 os_prio=0 tid=0x000000001a188800 nid=0xe08 waiting for monitor entry [0x000000001c66e000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at com.caicai.study.sa_token.Main.methodA(Main.java:20)
        - waiting to lock <0x00000000d5f51dc8> (a java.lang.Object)
        - locked <0x00000000d5f51db8> (a java.lang.Object)
        at com.caicai.study.sa_token.Main.lambda$main$0(Main.java:12)
        at com.caicai.study.sa_token.Main$$Lambda$1/1867750575.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)

"Service Thread" #11 daemon prio=9 os_prio=0 tid=0x000000001a189800 nid=0x4060 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

F

当正常输出的请求不被响应时,强制输出堆栈

代码语言:javascript
复制
$ jstack -F 15996
Attaching to process ID 15996, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.73-b02
Deadlock Detection:

Found one Java-level deadlock:
=============================

"Thread-0":
  waiting to lock Monitor@0x000000000385adb8 (Object@0x00000000d5f51dc8, a java/lang/Object),
  which is held by "Thread-1"
"Thread-1":
  waiting to lock Monitor@0x000000000385d648 (Object@0x00000000d5f51db8, a java/lang/Object),
  which is held by "Thread-0"

Found a total of 1 deadlock.

Thread 1: (state = BLOCKED)


Thread 25: (state = BLOCKED)
 - com.caicai.study.sa_token.Main.methodB() @bci=16, line=29 (Interpreted frame)
 - com.caicai.study.sa_token.Main.lambda$main$1() @bci=0, line=13 (Interpreted frame)
 - com.caicai.study.sa_token.Main$$Lambda$2.run() @bci=0 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)
 - ... 省略一下

l

除堆栈外,还会显示锁的附加信息

代码语言:javascript
复制
$ jstack -l 15996
2021-12-12 08:00:20
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.73-b02 mixed mode):

"DestroyJavaVM" #14 prio=5 os_prio=0 tid=0x000000001a186800 nid=0x3f88 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
        - None

"Thread-1" #13 prio=5 os_prio=0 tid=0x000000001a182800 nid=0x4b94 waiting for monitor entry [0x000000001c76e000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at com.caicai.study.sa_token.Main.methodB(Main.java:29)
        - waiting to lock <0x00000000d5f51db8> (a java.lang.Object)
        - locked <0x00000000d5f51dc8> (a java.lang.Object)
        at com.caicai.study.sa_token.Main.lambda$main$1(Main.java:13)
        at com.caicai.study.sa_token.Main$$Lambda$2/769287236.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)

   Locked ownable synchronizers:
        - None

"Thread-0" #12 prio=5 os_prio=0 tid=0x000000001a188800 nid=0xe08 waiting for monitor entry [0x000000001c66e000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at com.caicai.study.sa_token.Main.methodA(Main.java:20)
        - waiting to lock <0x00000000d5f51dc8> (a java.lang.Object)
        - locked <0x00000000d5f51db8> (a java.lang.Object)
        at com.caicai.study.sa_token.Main.lambda$main$0(Main.java:12)
        at com.caicai.study.sa_token.Main$$Lambda$1/1867750575.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)

   Locked ownable synchronizers:
        - None

"Service Thread" #11 daemon prio=9 os_prio=0 tid=0x000000001a189800 nid=0x4060 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
        - None

"C1 CompilerThread3" #10 daemon prio=9 os_prio=2 tid=0x000000001a37a800 nid=0x7a0 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
        - None

"C2 CompilerThread2" #9 daemon prio=9 os_prio=2 tid=0x000000001a37a000 nid=0x4954 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
        - None

"C2 CompilerThread1" #8 daemon prio=9 os_prio=2 tid=0x000000001a379000 nid=0x2708 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
        - None

"C2 CompilerThread0" #7 daemon prio=9 os_prio=2 tid=0x000000001a2b6800 nid=0x46b0 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
        - None

"Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x000000001a187000 nid=0x4620 runnable [0x000000001b76e000]
   java.lang.Thread.State: RUNNABLE
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
        at java.net.SocketInputStream.read(SocketInputStream.java:170)
        at java.net.SocketInputStream.read(SocketInputStream.java:141)
        at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
        at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
        - locked <0x00000000d5ed9d28> (a java.io.InputStreamReader)
        at java.io.InputStreamReader.read(InputStreamReader.java:184)
        at java.io.BufferedReader.fill(BufferedReader.java:161)
        at java.io.BufferedReader.readLine(BufferedReader.java:324)
        - locked <0x00000000d5ed9d28> (a java.io.InputStreamReader)
        at java.io.BufferedReader.readLine(BufferedReader.java:389)
        at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:49)

   Locked ownable synchronizers:
        - None

"Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x000000001a188000 nid=0x15b0 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
        - None

"Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x000000001a185000 nid=0x4828 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
        - None

"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x000000000385d800 nid=0x487c in Object.wait() [0x000000001b46e000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000000d5c07110> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
        - locked <0x00000000d5c07110> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)

   Locked ownable synchronizers:
        - None

"Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x0000000018a1c800 nid=0x46b4 in Object.wait() [0x000000001b36e000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000000d5c06b50> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:502)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:157)
        - locked <0x00000000d5c06b50> (a java.lang.ref.Reference$Lock)

   Locked ownable synchronizers:
        - None

"VM Thread" os_prio=2 tid=0x0000000018a16800 nid=0x16b4 runnable

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000003779800 nid=0x102c runnable

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x000000000377b000 nid=0x4fc runnable

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x000000000377c800 nid=0x377c runnable

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x000000000377f000 nid=0x359c runnable

"GC task thread#4 (ParallelGC)" os_prio=0 tid=0x0000000003781800 nid=0x451c runnable

"GC task thread#5 (ParallelGC)" os_prio=0 tid=0x0000000003782800 nid=0x4738 runnable

"GC task thread#6 (ParallelGC)" os_prio=0 tid=0x0000000003786000 nid=0x3a44 runnable

"GC task thread#7 (ParallelGC)" os_prio=0 tid=0x0000000003787000 nid=0x2a1c runnable

"GC task thread#8 (ParallelGC)" os_prio=0 tid=0x0000000003788000 nid=0x7ec runnable

"GC task thread#9 (ParallelGC)" os_prio=0 tid=0x0000000003789800 nid=0x4a40 runnable

"VM Periodic Task Thread" os_prio=2 tid=0x000000001a487000 nid=0x1154 waiting on condition

JNI global references: 319


Found one Java-level deadlock:
=============================
"Thread-1":
  waiting to lock monitor 0x000000000385d648 (object 0x00000000d5f51db8, a java.lang.Object),
  which is held by "Thread-0"
"Thread-0":
  waiting to lock monitor 0x000000000385adb8 (object 0x00000000d5f51dc8, a java.lang.Object),
  which is held by "Thread-1"

Java stack information for the threads listed above:
===================================================
"Thread-1":
        at com.caicai.study.sa_token.Main.methodB(Main.java:29)
        - waiting to lock <0x00000000d5f51db8> (a java.lang.Object)
        - locked <0x00000000d5f51dc8> (a java.lang.Object)
        at com.caicai.study.sa_token.Main.lambda$main$1(Main.java:13)
        at com.caicai.study.sa_token.Main$$Lambda$2/769287236.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)
"Thread-0":
        at com.caicai.study.sa_token.Main.methodA(Main.java:20)
        - waiting to lock <0x00000000d5f51dc8> (a java.lang.Object)
        - locked <0x00000000d5f51db8> (a java.lang.Object)
        at com.caicai.study.sa_token.Main.lambda$main$0(Main.java:12)
        at com.caicai.study.sa_token.Main$$Lambda$1/1867750575.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)

Found 1 deadlock.

m

如果调用到本地方法的话,可以显示C、C++的堆栈

代码语言:javascript
复制
$ jstack -m 15996
Attaching to process ID 15996, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.73-b02
Deadlock Detection:

Found one Java-level deadlock:
=============================

"Thread-0":
  waiting to lock Monitor@0x000000000385adb8 (Object@0x00000000d5f51dc8, a java/lang/Object),
  which is held by "Thread-1"
"Thread-1":
  waiting to lock Monitor@0x000000000385d648 (Object@0x00000000d5f51db8, a java/lang/Object),
  which is held by "Thread-0"

Found a total of 1 deadlock.

----------------- 0 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
0xec8b485741564155              ????????
sun.jvm.hotspot.debugger.DebuggerException: Windbg Error: ReadVirtual failed!
        at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.readBytesFromProcess0(Native Method)
        at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.readBytesFromProcess(WindbgDebuggerLocal.java:490)
        at sun.jvm.hotspot.debugger.DebuggerBase$Fetcher.fetchPage(DebuggerBase.java:80)
        at sun.jvm.hotspot.debugger.PageCache.getPage(PageCache.java:178)
        at sun.jvm.hotspot.debugger.PageCache.getLong(PageCache.java:100)
        at sun.jvm.hotspot.debugger.DebuggerBase.readCInteger(DebuggerBase.java:364)
        at sun.jvm.hotspot.debugger.DebuggerBase.readAddressValue(DebuggerBase.java:462)
        at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.readAddress(WindbgDebuggerLocal.java:316)
        at sun.jvm.hotspot.debugger.windbg.WindbgAddress.getAddressAt(WindbgAddress.java:72)
        at sun.jvm.hotspot.debugger.windows.amd64.WindowsAMD64CFrame.sender(WindowsAMD64CFrame.java:60)
        at sun.jvm.hotspot.tools.PStack.run(PStack.java:161)
        at sun.jvm.hotspot.tools.PStack.run(PStack.java:58)
        at sun.jvm.hotspot.tools.PStack.run(PStack.java:53)
        at sun.jvm.hotspot.tools.JStack.run(JStack.java:66)
        at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
        at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
        at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
        at sun.tools.jstack.JStack.main(JStack.java:106)
----------------- 1 -----------------
----------------- 2 -----------------
----------------- 3 -----------------
----------------- 4 -----------------
----------------- 5 -----------------
----------------- 6 -----------------
----------------- 7 -----------------
----------------- 8 -----------------
----------------- 9 -----------------
----------------- 10 -----------------
----------------- 11 -----------------
----------------- 12 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 13 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 14 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 15 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 16 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 17 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 18 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 19 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 20 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 21 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 22 -----------------
----------------- 23 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 24 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14
----------------- 25 -----------------
0x00007ffb49b8cdf4      ntdll!ZwWaitForSingleObject + 0x14

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前置
  • jps: 虚拟机进程状况工具
  • jstat: 虚拟机统计信息监视工具
    • class
      • gc
        • gccapacity
          • gcutil
            • gccause
              • compiler
                • printcompilation
                • jinfo: Java配置信息工具
                • jmap: 内存映像工具
                  • dump
                    • finalizerinfo
                      • heap
                        • histo
                          • permstat
                          • jhat: 虚拟机堆栈存储快照分析工具
                          • jstack: Java堆栈跟踪工具
                            • 默认
                              • F
                                • l
                                  • m
                                  相关产品与服务
                                  应用性能监控
                                  应用性能监控(Application Performance Management,APM)是一款应用性能管理平台,基于实时多语言应用探针全量采集技术,为您提供分布式性能分析和故障自检能力。APM 协助您在复杂的业务系统里快速定位性能问题,降低 MTTR(平均故障恢复时间),实时了解并追踪应用性能,提升用户体验。
                                  领券
                                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档