JDK8 几个常见内置命令工具

https://docs.oracle.com/javase/8/docs/technotes/tools/index.html#basic

javap

javap [options] classfile…

javap命令反汇编一个或多个类文件。输出取决于所使用的选项。如果不使用任何选项,则javap命令将打印程序包,受保护的字段和公共字段以及传递给它的类的方法。javap命令将其输出打印到stdout

命令用法
javap -help打印javap命令的帮助消息。
javap --help同上
javap -?同上
javap -version版本信息
javap -c [classfile]为该类中的每个方法打印反汇编的代码
javap -verbose [classfile]输出附加信息
javap -l [classfile]打印行和局部变量表
javap -s [classfile]打印内部类型签名
javap -public [classfile]仅显示公共班级和成员
javap -protected [classfile]仅显示受保护的和公开的班级和成员
javap -private [classfile]显示所有班级和成员
javap -p [classfile]同上
javap -sysinfo [classfile]显示正在处理的类的系统信息(路径,大小,日期,MD5哈希)
javap -constants path显示 static final 常数。
javap -classpath path指定javap命令用于查找类的路径。设置默认值或CLASSPATH环境变量时,将覆盖它
javap -bootclasspath [classfile]指定加载引导类的路径。默认情况下,引导程序类是实现位于jre / lib / rt.jar和其他几个JAR文件中的核心Java平台的类

jps

JVM Process Status Tool - Lists instrumented HotSpot Java virtual machines on a target system.

JVM进程状态工具-列出目标系统上已检测到的HotSpot Java虚拟机

命令用法
jps -q禁止类名称,JAR文件名和传递给main方法的参数的输出,仅生成本地JVM标识符的列表
jps -m显示传递给main方法的参数,对于嵌入式JVM,输出可能为null
jps -l显示应用程序主类的完整软件包名称或应用程序JAR文件的完整路径名称
jps -v显示传递给JVM的参数
jps -V压低类名,JAR文件名和传递给main方法的参数的输出,仅生成本地JVM标识符的列表
jps -J[option]将option传递给JVM,其中option是Java应用程序启动器的参考页上描述的选项之一。例如,-J-Xms48m将启动内存设置为48 MB

使用 jps -mlvV 可以获取到这个进程的 pid、jar 包的名字以及 JVM 参数等。

jstat

Usage: jstat -help|-options
       jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
-<option> required

Definitions:
  <option>      An option reported by the -options option
  <vmid>        Virtual Machine Identifier. A vmid takes the following form:
                     <lvmid>[@<hostname>[:<port>]]
                Where <lvmid> is the local vm identifier for the target
                Java virtual machine, typically a process id; <hostname> is
                the name of the host running the target Java virtual machine;
                and <port> is the port number for the rmiregistry on the
                target host. See the jvmstat documentation for a more complete
                description of the Virtual Machine Identifier.
  <lines>       Number of samples between header lines.
  <interval>    Sampling interval. The following forms are allowed:
                    <n>["ms"|"s"]
                Where <n> is an integer and the suffix specifies the units as 
                milliseconds("ms") or seconds("s"). The default units are "ms".
  <count>       Number of samples to take before terminating.
  -J<flag>      Pass <flag> directly to the runtime system.

监视Java虚拟机(JVM)统计信息,主要是 GC 信息,在性能优化中经常用到。此命令是实验性的不受支持。

在这里插入图片描述
通过 jps 查到的进程号 31007,我们使用 jstat -gc 31007 来查看该进程的 GC 信息

 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
31744.0 28672.0  0.0    0.0   744448.0 334937.1  281600.0   91480.1   98380.0 94025.2 12504.0 11717.8     19    0.414   4      0.971    1.385

S0C 表示当前 Survivor0 的容量
S1C 表示当前 Survivor1 的容量
S0U 表示当前 Survivor0 的利用率
S1U 表示当前 Survivor1 的利用率
EC 表示 Eden 的容量
EU 表示 Eden 的利用率
OC 表示老年代的容量
OU 表示老年代的利用率
MC 表示 Metaspace 的容量
MU 表示 Metaspace 的利用率
CCSC 表示类指针压缩空间容量
CCSU 表示使用的类指针压缩空间
YGC 表示新生代 GC 的次数
YGCT 表示新生代 GC 的时间
FGC 表示 Full Gc 的次数
FGCT 表示 Full GC 的时间
GCT 表示 GC 总时间

每个对象都有一个指向它自身类的指针,_klass: 指向类的 4 字节指针,64 位平台上 _klass: 指向类的 8 字节的指针,为了节约这些空间,引入了类指针压缩空间。

jcmd

JVM诊断命令工具-将诊断命令请求发送到正在运行的Java虚拟机,可以查看 JVM 信息

jcmd [-l|-h|-help]

jcmd pid | main-class PerfCounter.print

jcmd pid | main-class -f filename

jcmd pid | main-class command[ arguments]

在这里插入图片描述

先使用 jps 获取 [pid]

使用 jcmd [pid] help 来查看都支持什么命令

> jcmd 31007 help 
31007:
The following commands are available:
VM.native_memory
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

For more information about a specific command use 'help <command>'.

选一个参数,比如打印堆的信息,使用 jcmd 31007 GC.heap_info 命令

jcmd 31007 GC.heap_info
31007:
 PSYoungGen      total 773120K, used 374889K [0x000000076ab00000, 0x00000007a3000000, 0x00000007c0000000)
  eden space 744448K, 50% used [0x000000076ab00000,0x000000078191a610,0x0000000798200000)
  from space 28672K, 0% used [0x0000000798200000,0x0000000798200000,0x0000000799e00000)
  to   space 31744K, 0% used [0x00000007a1100000,0x00000007a1100000,0x00000007a3000000)
 ParOldGen       total 281600K, used 91480K [0x00000006c0000000, 0x00000006d1300000, 0x000000076ab00000)
  object space 281600K, 32% used [0x00000006c0000000,0x00000006c5956040,0x00000006d1300000)
 Metaspace       used 95324K, capacity 99822K, committed 100056K, reserved 1136640K
  class space    used 11895K, capacity 12686K, committed 12760K, reserved 1048576K

还可以进一步查看命令的班帮助信息 jcmd 31007 help GC.heap_dump

> jcmd 31007 help GC.heap_dump
31007:
GC.heap_dump
Generate a HPROF format dump of the Java heap.

Impact: High: Depends on Java heap size and content. Request a full GC unless the '-all' option is specified.

Permission: java.lang.management.ManagementPermission(monitor)

Syntax : GC.heap_dump [options] <filename>

Arguments:
        filename :  Name of the dump file (STRING, no default value)

Options: (options must be specified using the <key> or <key>=<value> syntax)
        -all : [optional] Dump all objects, including unreachable objects (BOOLEAN, false)

jmap

打印进程,核心文件或远程调试服务器的共享对象内存映射或堆内存详细信息。此命令是实验性的,不受支持。

jhat

分析Java堆。此命令是实验性的,不受支持。

jstack

打印Java进程,核心文件或远程调试服务器的Java线程堆栈跟踪。此命令是实验性的,不受支持。


参考资料:
https://mp.weixin.qq.com/s/mdohLcNkzl1EpoETkEhM_w

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值