-
Overview
- jstack related content
-
background
- I saw the related command line tools of jvm before
- jinfo
- jstat
- jmap
- jhat
- Their direction
- jvm startup parameters
- Memory resources
- gc statistics
- Stack snapshot
- Stack analysis
- Stack? Isn't it just the heap?
- Yes, what about the stack?
- I saw the related command line tools of jvm before
-
surroundings
-
ready
-
A java program
- I use the webmvc program based on spring-boot
- Hello world of a controller
- I use the webmvc program based on spring-boot
-
jps
- Get java program pid
-
It is best to have a little knowledge of jvm
- My level is not the same, basically the kind of crawling on the threshold
-
1. jstack
-
Overview
- Introduction to jstack
-
jstack
- jvm stack snapshot tool
-
Stack
- Where the jvm thread is active
-
The contents of the stack
- Split by thread
- Each thread has its own thing
- Various registers to store thread-specific information
- Method stack
- Each thread, in work, will have its own series of method calls
- These calls are stored in memory in the form of a stack
- Classification-This is not detailed
- java stack
- Store java method information
- Native method stack
- Store local method information
- For example, the C language called by java
- Store local method information
- The relationship between the two
- I honestly don't know ...
- java stack
-
- jvm stack snapshot tool
2. Command
-
command
> jstack <pid>
-
result
- This result is a bit complicated, I slowly say
3. Results
-
Overview
- Briefly explain the results of jstack
-
result
-
When the command is executed, the information in the jvm stack
- Mainly method invocation information
-
content
- A lot of content, I have 500 lines in a hello world ...
-
segment 1-jvm information
-
Snippet
2020-04-11 19:20:35
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.181-b13 mixed mode):
```
- content
-
2020-04-11 19:20:35
- jstack command execution time
-
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.181-b13 mixed mode):
- 64-Bit
- 64-bit system
- Server VM
- jvm server mode
- 25.181-b13
- jvm build number
- mixed mode
- The default mode of the HotSpot virtual machine
- Need to be added later
- The default mode of the HotSpot virtual machine
- 64-Bit
-
segment 2 - JNI global references
-
Snippet
# 这个位于 输出日志的 最下方 JNI global references: 1041
-
Explanation
- JNI global references: 1041
- JNI - Java Native Interface
- Java's native interface
- Responsible for calling and interacting with other languages
- global references
- JNI reference
- Local reference
- Variables in the native method of this thread
- Automatically release after returning to java
- Global Reference
- Multiple threads, used in multiple methods
- Need to manually create, release
- Weak Global Reference
- Consistent with Global Reference
- But it may be GC
- Local reference
- JNI reference
- 1041
- There are currently 1041 Global Reference
- JNI - Java Native Interface
- JNI global references: 1041
segment 3: VM Periodic Task Thread thread segment
-
Snippet
"VM Periodic Task Thread" os_prio=2 tid=0x000000003c4c5800 nid=0x5110 waiting on condition
-
Explanation
- "VM Periodic Task Thread"
- Thread name
- This is the monitoring process of HotSpot
- By performing periodic tasks, to obtain various information of jvm
- Thread name
- os_prio = 2
- System process priority
- This has something to do with the operating system
- We will talk about java thread priority later ...
- System process priority
- time = 0x000000003c4c5800
- java thread id
- Thread id in jvm
- java thread id
- not = 0x5110
- Native system thread id
- Each java thread has a thread id corresponding to the native system
- Native system thread id
- waiting on condition
- Indicates that the thread is waiting
- No specific conditions
- Indicates that the thread is waiting
- "VM Periodic Task Thread"
segment 4: GC thread segment
-
Snippet
# 这样类似的片段, 一共有 9 个 "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00000000031bb000 nid=0x1c54 runnable "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00000000031bd000 nid=0x3718 runnable ...
-
Explanation
- "GC task thread#0 (ParallelGC)"
- Thread name
- GC thread
- Number 0
- Using ParallelGC
- Thread name
- os_prio = 0
- System process priority
- time = 0x00000000031bb000
- java thread id
- not = 0x1c54
- Native system thread id
- runnable
- Thread state
- This is not here for the time being
- Thread state
- "GC task thread#0 (ParallelGC)"
segment 5: ordinary thread segment
-
Snippet
"http-nio-8080-ClientPoller-1" #45 daemon prio=5 os_prio=0 tid=0x000000003e78e800 nid=0x574 runnable [0x0000000040d8f000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.WindowsSelectorImpl\(SubSelector.poll0(Native Method) at sun.nio.ch.WindowsSelectorImpl\)SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x00000006768fe120> (a sun.nio.ch.Util\(3) - locked <0x00000006768fe110> (a java.util.Collections\)UnmodifiableSet)
- locked <0x00000006768fdfc0> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:743)
at java.lang.Thread.run(Thread.java:748)
```
- Explanation
- "http-nio-8080-ClientPoller-1"
- Thread name
-
45
- I've been searching for this for a long time, and I don't know what it's called
- I do n’t know why some threads do, some do n’t.
- Even the regularity of size is not clear
- I've been searching for this for a long time, and I don't know what it's called
- daemon
- Daemon thread
- Current thread, is a daemon thread
- Daemon thread
- prion = 5
- os_prio = 0
- time = 0x000000003e78e800
- not = 0x574
- runnable
- Executable state
- [0x0000000040d8f000]
- Thread's stack start address
- The starting address is [0x0000000000000000]
- These are usually jvm processes
- They need to deal with the operating system, so the starting point of the stack is the local method stack
- Of course not all jvm processes start with [0x0000000000000000]
- java.lang.Thread.State: RUNNABLE
- Thread status ...
- Stack information below
- The method call chain being executed by this thread
- New on top, old on bottom
- "http-nio-8080-ClientPoller-1"
ps
-
ref
-
- Official documents
- The content is a bit thin
-
JVM practical parameters (1) JVM type and compiler mode
- Translation is OK
- Old article from 2012 ...
- mix mode
-
JNI learning three (Local references & Global references and JNI memory leak)
- Explanation of JNI
- I don't care about this
- Explanation of JNI
-
- Speak clearly
- jstack dump information
- java thread state
- Lock related
- Speak clearly
-
- Well written
- Scientifically split the content
- And according to the component of the thread, it is clearly classified
- And it's still a series ...
- Take a good look
- Well written
-
Three examples demonstrate Java Thread Dump log analysis
- Worthy of reference
-
Full analysis of virtual machine stack
- Worthy of reference
-
-
Questions
- mix mode
- Thread state
- Thread state
- State transition
- Analyze and diagnose deadlock problems through jstack
- The principle of lock
- Understand thread state
- Locate deadlock thread
-
Follow up
- Visualization tool