工具是运用知识处理数据的手段。
JDK的命令行工具
名称 | 主要作用 |
---|---|
jps | JVM Process Status Tool,显示指定系统内所有的HotSpot虚拟机进程 |
jstat | JVM Statistics Monitoring Tool,用于收集HotSpot虚拟机各方面的运行数据 |
jinfo | Configuration Info for Java,显示虚拟机配置信息 |
jmap | Memory map for Java,生成虚拟机的内存转储快照(heapdump文件) |
jhat | JVM Heap Dump Browser,用于分许heapdump文件,它会建立一个HTTP/HTML服务器,让用户可以在浏览器上查看分析结果 |
jstack | Stack Trace for Java,显示虚拟机的线程快照 |
jps:虚拟机进程状况工具
可以列出正在运行的虚拟机进程,并显示虚拟机执行主类(Main Class,main()函数所在的类)的名称,以及这些进程的本地虚拟机的唯一ID(LVMID,Local Virtual Machine Identifier)。
对于本地虚拟机进程来说,LVMID与操作系统的进程ID(PID,Process Identifier)是一致的。
The jps command supports a number of options that modify the output of the command. These options are subject to change or removal in the future.
-q Suppress the output of the class name, JAR file name, and arguments passed to the main method, producing only a list of local VM identifiers.
-m Output the arguments passed to the main method. The output may be null for embedded JVMs.
-l Output the full package name for the application’s main class or the full path name to the application’s JAR file.
-v Output the arguments passed to the JVM.
-V Output the arguments passed to the JVM through the flags file (the .hotspotrc file or the file specified by the -XX:Flags=
argument). -Joption Pass option to the java launcher called by javac. For example, -J-Xms48m sets the startup memory to 48 megabytes. It is a common convention for -J to pass options to the underlying VM executing applications written in Java.
jstat:虚拟机统计信息监视工具
用于监视虚拟机各种运行状态信息的命令行工具。它可以显示本地或远程虚拟机进程中的类装载、内存、垃圾收集、JIT编译等运行数据。它是运行期定位虚拟机性能问题的首选工具
jinfo:Java配置信息工具
作用是实时地查看和调整虚拟机的各项参数。
jinfo [ option ] pid
jinfo [ option ] executable core
jinfo [ option ][ server-id@ ] remote-hostname-or-IP
jmap:Java内存映射工具
用于生成堆转储快照(一般称为headdump或者dump文件)。还可以查询finalize执行队列,Java堆和永久代的详细信息,如空间使用率、当前用的是哪种收集器等。
选项 | 作用 |
---|---|
-dump | 生成Java堆转储快照。格式为:-dump:[live,]format-b,file= |
-finalizerinfo | 显示在F-Queue中等待Finalizer线程执行finalize方法的对象 |
-heap | 显示Java堆详细信息,如使用哪些回收器、参数配置、分代状况等。 |
-histo | 显示堆中对象统计信息,包括类、实例数量和合计容量 |
-permstat | 以ClassLoader为统计口径显示永久代内存状态 |
-F | 当虚拟机进程堆-dump选项没有响应时,可使用这个选项强制生成dump快照 |
jhat:虚拟机堆转储快照分析工具
分析jmap生成的堆转储快照
jstack:Java堆栈跟踪工具
用于生成虚拟机当前时刻的线程快照(一般称为threaddump或javacore文件)。线程快照就是当前虚拟机内每一条线程正在执行的方法堆栈的集合,生成线程快照的主要目的是定位线程主线长时间停顿的原因,如线程间死锁、死循环、请求外部资源导致的长时间等待等都是导致线程长时间停顿的常见原因。
选项 | 作用 |
---|---|
-F | 当正常输出的请求不被响应时,强制输出线程堆栈 |
-l | 除堆栈外,显示关于锁的附加信息 |
-m | 如果调用到本地方法的话,可以显示C/C++的堆栈 |
JDK的可视化工具
JConsole:Java监视和管理控制台
Reference
深入理解Java虚拟机:JVM高级特性与最佳实践