JVM一些命令

https://apistore.top 开源电商支付系统,欢迎加入转发。

jinfo [pid]

Attaching to process ID 43, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.251-b08
Java System Properties:

java.vendor = Oracle Corporation
sun.java.launcher = SUN_STANDARD
catalina.base = /tmp/tomcat.1606937383102952494.8452
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
sun.nio.ch.bugLevel =
catalina.useNaming = false
dk.class.preload.timeout = 250
os.name = Linux

VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=6291456000 -XX:MaxHeapSize=6291456000 -XX:MaxNewSize=209715
2000 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=2097152000 -XX:OldSize=4194304000 -XX:ThreadStackSize=1024 -XX:+UseCompressed
ClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC
Command line:  -javaagent:/opt/javaagent/jmx_prometheus_javaagent.jar=5555:/opt/javaagent/config.yaml -Xmx6000M -Xms6000M -
Xmn2000M -Xss1024k -javaagent:/opt/sandbox/lib/sandbox-agent.jar -Ddk.logging.path=.
jmap -histo [pid] | less
num     #instances         #bytes  class name
----------------------------------------------
   1:      14559331     1099574024  [C
   2:       6127154      294103392  java.nio.HeapCharBuffer
   3:         68899       84911968  [I
   4:       2889346       69344304  java.lang.String
   5:         43769       41487816  [B
   6:        538150       41299056  [Ljava.lang.Object;
   7:       1427020       34248480  java.lang.StringBuilder
   8:        606854       12047912  [Ljava.lang.Class;
   9:        117127       10307176  java.lang.reflect.Method
  10:        245042        9801680  java.util.LinkedHashMap$Entry
  11:        338192        8116608  java.util.ArrayList
  12:        245385        7852320  java.util.LinkedHashMap$LinkedEntryIterator
  13:         86184        7827040  [Ljava.util.HashMap$Node;
  14:        243192        7782144  java.util.HashMap$Node
  15:         64828        6346464  [S
  16:        189525        6064800  java.util.ArrayList$Itr
  17:        224848        5777232  [Ljava.lang.reflect.Method;
  18:        112641        5406768  io.prometheus.jmx.shaded.io.prometheus.jmx.MatchedRule
  19:        166481        5327392  java.util.concurrent.ConcurrentHashMap$Node
查看实例数量,占用大小

查看堆的配置以及使用情况

jmap -heap [pid] 
JVM version is 25.251-b08
using thread-local object allocation.
Parallel GC with 8 thread(s)
Heap Configuration:
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 6291456000 (6000.0MB)
   NewSize                  = 2097152000 (2000.0MB)
   MaxNewSize               = 2097152000 (2000.0MB)
   OldSize                  = 4194304000 (4000.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 = 2034237440 (1940.0MB)
   used     = 806484528 (769.1235809326172MB)
   free     = 1227752912 (1170.8764190673828MB)
   39.645545408897796% used
From Space:
   capacity = 23592960 (22.5MB)
   used     = 23373720 (22.290916442871094MB)
   free     = 219240 (0.20908355712890625MB)
   99.07073974609375% used
To Space:
   capacity = 33030144 (31.5MB)
   used     = 0 (0.0MB)
   free     = 33030144 (31.5MB)
   0.0% used
PS Old Generation
   capacity = 4194304000 (4000.0MB)
   used     = 561750232 (535.7267684936523MB)
   free     = 3632553768 (3464.2732315063477MB)
   13.39316921234131% used
jcmd [pid] help
The following commands are available:
JFR.stop
JFR.start
JFR.dump
JFR.check
VM.native_memory
VM.check_commercial_features
VM.unlock_commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
VM.classloader_stats
GC.rotate_log
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.finalizer_info
GC.heap_info
GC.run_finalization
GC.run
VM.uptime
VM.dynlibs
VM.flags
VM.system_properties
VM.command_line
VM.version
help
jcmd [pid] GC.heap_info

PSYoungGen      total 2042368K, used 156541K [0x0000000743000000, 0x00000007c0000000, 0x00000007c0000000)
  eden space 2036736K, 7% used [0x0000000743000000,0x000000074c5df030,0x00000007bf500000)
  from space 5632K, 54% used [0x00000007bfa80000,0x00000007bfd806a0,0x00000007c0000000)
  to   space 5632K, 0% used [0x00000007bf500000,0x00000007bf500000,0x00000007bfa80000)
 ParOldGen       total 4096000K, used 162804K [0x0000000649000000, 0x0000000743000000, 0x0000000743000000)
  object space 4096000K, 3% used [0x0000000649000000,0x0000000652efd378,0x0000000743000000)
 Metaspace       used 148697K, capacity 156544K, committed 156800K, reserved 1185792K
  class space    used 18130K, capacity 19499K, committed 19584K, reserved 1048576K
arthas memory

JVM 生成 Heap Dump 的时候,虚拟机是暂停一切服务的。如果是线上系统执行 Heap Dump 时需要注意。

生成hprof文件:

jmap -dump:format=b,file=/appruntime/java/yourapp/logs/jmap_heapdump.hprof pid

延伸出一个问题:日常巡检内存使用量时要拉大时间跨度,如果总是选择几个小时,可能置身其中无法关注到大的变化量。

jps -vml

1250 sun.tools.jps.Jps -lvm -Dapplication.home=/opt/jdk1.8.0_251 -Xms8m
43 app.jar -javaagent:/opt/javaagent/jmx_prometheus_javaagent.jar=5555:/opt/javaagent/confi
g.yaml -Xmx6000M -Xms6000M -Xmn2000M -Xss1024k -javaagent:/opt/sandbox/lib/sandbox-agent.jar -Ddk.logging.path=.
jstack [pid]
可以打印当前JVM所有线程,可以排查创建的线程数量是否与指定的相等。
"kafka-producer-network-thread | producer-1" #94 daemon prio=10 os_prio=0 tid=0x00007f62f0899000 nid=0x8a runnable [0x00007
f635c5dd000]
   java.lang.Thread.State: RUNNABLE
        at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
        at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
        at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
        at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
        - locked <0x000000064e625808> (a sun.nio.ch.Util$3)
        - locked <0x000000064e6257f8> (a java.util.Collections$UnmodifiableSet)
        - locked <0x000000064e624758> (a sun.nio.ch.EPollSelectorImpl)
        at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
        at org.apache.kafka.common.network.Selector.select(Selector.java:674)
        at org.apache.kafka.common.network.Selector.poll(Selector.java:396)
        at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:460)
        at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:239)
        at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:163)
        at java.lang.Thread.run(Thread.java:748)

"nioEventLoopGroup-2-8" #93 prio=10 os_prio=0 tid=0x00007f62f04a2000 nid=0x89 runnable [0x00007f635c6de000]
   java.lang.Thread.State: RUNNABLE
        at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
        at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
        at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
        at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
        - locked <0x000000064e43a670> (a io.netty.channel.nio.SelectedSelectionKeySet)
jstat -gcutil [pid] 1000
S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
  0.00  59.97  22.30   3.98  94.84  92.58    107    1.356     4    0.449    1.805
  0.00  59.97  22.31   3.98  94.84  92.58    107    1.356     4    0.449    1.805
  0.00  59.97  22.32   3.98  94.84  92.58    107    1.356     4    0.449    1.805
  0.00  59.97  22.32   3.98  94.84  92.58    107    1.356     4    0.449    1.805
  0.00  59.97  22.32   3.98  94.84  92.58    107    1.356     4    0.449    1.805
  0.00  59.97  23.85   3.98  94.84  92.58    107    1.356     4    0.449    1.805
  0.00  59.97  23.85   3.98  94.84  92.58    107    1.356     4    0.449    1.805
  0.00  59.97  23.85   3.98  94.84  92.58    107    1.356     4    0.449    1.805
  0.00  59.97  23.85   3.98  94.84  92.58    107    1.356     4    0.449    1.805
  0.00  59.97  25.47   3.98  94.84  92.58    107    1.356     4    0.449    1.805
jstat -gccause [pid] 1s 10
S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
  0.00  59.97  40.70   3.98  94.84  92.58    107    1.356     4    0.449    1.805 Allocation Failure   No GC
  0.00  59.97  40.71   3.98  94.84  92.58    107    1.356     4    0.449    1.805 Allocation Failure   No GC
  0.00  59.97  40.71   3.98  94.84  92.58    107    1.356     4    0.449    1.805 Allocation Failure   No GC
  0.00  59.97  40.72   3.98  94.84  92.58    107    1.356     4    0.449    1.805 Allocation Failure   No GC
  0.00  59.97  42.34   3.98  94.84  92.58    107    1.356     4    0.449    1.805 Allocation Failure   No GC
  0.00  59.97  42.34   3.98  94.84  92.58    107    1.356     4    0.449    1.805 Allocation Failure   No GC
  0.00  59.97  42.36   3.98  94.84  92.58    107    1.356     4    0.449    1.805 Allocation Failure   No GC
  0.00  59.97  42.36   3.98  94.84  92.58    107    1.356     4    0.449    1.805 Allocation Failure   No GC
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值