Java-JVM-Introduction to JStack

  1. Overview

    1. jstack related content
  2. background

    1. I saw the related command line tools of jvm before
      1. jinfo
      2. jstat
      3. jmap
      4. jhat
    2. Their direction
      1. jvm startup parameters
      2. Memory resources
        1. gc statistics
        2. Stack snapshot
        3. Stack analysis
    3. Stack? Isn't it just the heap?
      1. Yes, what about the stack?
  3. surroundings

  4. ready

    1. A java program

      1. I use the webmvc program based on spring-boot
        1. Hello world of a controller
    2. jps

      1. Get java program pid
    3. It is best to have a little knowledge of jvm

      1. My level is not the same, basically the kind of crawling on the threshold

1. jstack

  1. Overview

    1. Introduction to jstack
  2. jstack

    1. jvm stack snapshot tool
      1. Stack

        1. Where the jvm thread is active
      2. The contents of the stack

        1. Split by thread
        2. Each thread has its own thing
          1. Various registers to store thread-specific information
          2. Method stack
            1. Each thread, in work, will have its own series of method calls
            2. These calls are stored in memory in the form of a stack
        3. Classification-This is not detailed
          1. java stack
            1. Store java method information
          2. Native method stack
            1. Store local method information
              1. For example, the C language called by java
          3. The relationship between the two
            1. I honestly don't know ...

2. Command

  1. command

    > jstack <pid>
    
  2. result

    1. This result is a bit complicated, I slowly say

3. Results

  1. Overview

    1. Briefly explain the results of jstack
  2. result

    1. When the command is executed, the information in the jvm stack

      1. Mainly method invocation information
    2. content

      1. A lot of content, I have 500 lines in a hello world ...

segment 1-jvm information

  1. Snippet

    2020-04-11 19:20:35
    

Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.181-b13 mixed mode):
```

  1. content
    1. 2020-04-11 19:20:35

      1. jstack command execution time
    2. Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.181-b13 mixed mode):

      1. 64-Bit
        1. 64-bit system
      2. Server VM
        1. jvm server mode
      3. 25.181-b13
        1. jvm build number
      4. mixed mode
        1. The default mode of the HotSpot virtual machine
          1. Need to be added later

segment 2 - JNI global references

  1. Snippet

    # 这个位于 输出日志的 最下方
    JNI global references: 1041
    
  2. Explanation

    1. JNI global references: 1041
      1. JNI - Java Native Interface
        1. Java's native interface
        2. Responsible for calling and interacting with other languages
      2. global references
        1. JNI reference
          1. Local reference
            1. Variables in the native method of this thread
            2. Automatically release after returning to java
          2. Global Reference
            1. Multiple threads, used in multiple methods
            2. Need to manually create, release
          3. Weak Global Reference
            1. Consistent with Global Reference
            2. But it may be GC
      3. 1041
        1. There are currently 1041 Global Reference

segment 3: VM Periodic Task Thread thread segment

  1. Snippet

    "VM Periodic Task Thread" os_prio=2 tid=0x000000003c4c5800 nid=0x5110 waiting on condition 
    
  2. Explanation

    1. "VM Periodic Task Thread"
      1. Thread name
        1. This is the monitoring process of HotSpot
        2. By performing periodic tasks, to obtain various information of jvm
    2. os_prio = 2
      1. System process priority
        1. This has something to do with the operating system
        2. We will talk about java thread priority later ...
    3. time = 0x000000003c4c5800
      1. java thread id
        1. Thread id in jvm
    4. not = 0x5110
      1. Native system thread id
        1. Each java thread has a thread id corresponding to the native system
    5. waiting on condition
      1. Indicates that the thread is waiting
        1. No specific conditions

segment 4: GC thread segment

  1. 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 
    
    ...
    
  2. Explanation

    1. "GC task thread#0 (ParallelGC)"
      1. Thread name
        1. GC thread
        2. Number 0
        3. Using ParallelGC
    2. os_prio = 0
      1. System process priority
    3. time = 0x00000000031bb000
      1. java thread id
    4. not = 0x1c54
      1. Native system thread id
    5. runnable
      1. Thread state
        1. This is not here for the time being

segment 5: ordinary thread segment

  1. 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)

```
  1. Explanation
    1. "http-nio-8080-ClientPoller-1"
      1. Thread name
    2. 45

      1. I've been searching for this for a long time, and I don't know what it's called
        1. I do n’t know why some threads do, some do n’t.
        2. Even the regularity of size is not clear
    3. daemon
      1. Daemon thread
        1. Current thread, is a daemon thread
    4. prion = 5
    5. os_prio = 0
    6. time = 0x000000003e78e800
    7. not = 0x574
    8. runnable
      1. Executable state
    9. [0x0000000040d8f000]
      1. Thread's stack start address
      2. The starting address is [0x0000000000000000]
        1. These are usually jvm processes
        2. They need to deal with the operating system, so the starting point of the stack is the local method stack
        3. Of course not all jvm processes start with [0x0000000000000000]
    10. java.lang.Thread.State: RUNNABLE
      1. Thread status ...
    11. Stack information below
      1. The method call chain being executed by this thread
      2. New on top, old on bottom

ps

  1. ref

    1. jstack

      1. Official documents
      2. The content is a bit thin
    2. JVM practical parameters (1) JVM type and compiler mode

      1. Translation is OK
      2. Old article from 2012 ...
      3. mix mode
    3. JNI learning three (Local references & Global references and JNI memory leak)

      1. Explanation of JNI
        1. I don't care about this
    4. 4.5 jstack

      1. Speak clearly
        1. jstack dump information
        2. java thread state
        3. Lock related
    5. JVM fault analysis and performance optimization series part two: Thread Dump log structure analysis generated by jstack

      1. Well written
        1. Scientifically split the content
        2. And according to the component of the thread, it is clearly classified
        3. And it's still a series ...
        4. Take a good look
    6. Three examples demonstrate Java Thread Dump log analysis

      1. Worthy of reference
    7. Full analysis of virtual machine stack

      1. Worthy of reference
    8. Java Command Learning Series (2)-Jstack

  2. Questions

    1. mix mode
    2. Thread state
      1. Thread state
      2. State transition
    3. Analyze and diagnose deadlock problems through jstack
      1. The principle of lock
      2. Understand thread state
      3. Locate deadlock thread
  3. Follow up

    1. Visualization tool

Guess you like

Origin www.cnblogs.com/xy14/p/12683383.html