深入理解java虚拟机
第四章:java虚拟机命令行工具
1:jps命令行进程状况工具 jps [options] [hostid]
C:\Users\lenovo>jps -l
13824 sun.tools.jps.Jps
14224 org.jetbrains.jps.cmdline.Launcher
8528 org.jetbrains.idea.maven.server.RemoteMavenServer
12660 org.jetbrains.jps.cmdline.Launcher
7316
11544
236 com.li.SpringBootLabApplication //主类
2:jstat 用于监视虚拟机各种运行状态信息的命令行工具。包括类装载,内存,垃圾收集,JIT编译等数据
jstat [option vmid [interval [s|ms][count]]]
option 代表用户希望查询的虚拟机信息
例如每250毫秒查询一次进程236的垃圾回收信息,查询20次
3:jinfo 打印java配置信息
打印进程
jinfo 236的信息
C:\Users\lenovo>jinfo 236 Attaching to process ID 236, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.161-b12 Java System Properties: java.runtime.name = Java(TM) SE Runtime Environment java.vm.version = 25.161-b12 sun.boot.library.path = D:\software\jdk\jdk8\jdk1.8.0_161\jre\bin java.vendor.url = http://java.oracle.com/ java.vm.vendor = Oracle Corporation path.separator = ; file.encoding.pkg = sun.io java.vm.name = Java HotSpot(TM) 64-Bit Server VM sun.os.patch.level = sun.java.launcher = SUN_STANDARD user.script = user.country = CN user.dir = D:\software\github\github下载\laboratoryWeb java.vm.specification.name = Java Virtual Machine Specification PID = 236 java.runtime.version = 1.8.0_161-b12 java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment os.arch = amd64 java.endorsed.dirs = D:\software\jdk\jdk8\jdk1.8.0_161\jre\lib\endorsed org.jboss.logging.provider = slf4j line.separator = java.io.tmpdir = C:\Users\lenovo\AppData\Local\Temp\ java.vm.specification.vendor = Oracle Corporation user.variant = os.name = Windows 10 sun.jnu.encoding = GBK java.library.path = D:\software\jdk\jdk8\jdk1.8.0_161\bin;C:\Users\lenovo\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm\5.0.3\dcc2193db20e19e1feca8b1240dbbc4e190824fa\asm-5.0.3.jar;D:\software\ideaj\ideaIC-2017.3.4.win\lib\idea_rt.jar java.vm.specification.version = 1.8 sun.arch.data.model = 64 sun.java.command = com.li.SpringBootLabApplication java.home = D:\software\jdk\jdk8\jdk1.8.0_161\jre user.language = zh java.specification.vendor = Oracle Corporation awt.toolkit = sun.awt.windows.WToolkit java.vm.info = mixed mode java.version = 1.8.0_161 java.ext.dirs = D:\software\jdk\jdk8\jdk1.8.0_161\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext sun.boot.class.path = D:\software\jdk\jdk8\jdk1.8.0_161\jre\lib\resources.jar;D:\software\jdk\jdk8\jdk1.8.0_161\jre\classes java.awt.headless = true java.vendor = Oracle Corporation catalina.base = C:\Users\lenovo\AppData\Local\Temp\tomcat.6690132104814217884.9002 file.separator = \ java.vendor.url.bug = http://bugreport.sun.com/bugreport/ sun.io.unicode.encoding = UnicodeLittle sun.cpu.endian = little sun.desktop = windows sun.cpu.isalist = amd64 VM Flags: Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=134217728 -XX:MaxHeapSize=2122317824 -XX:MaxNewSize=707264512 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=44564480 -XX:OldSize=89653248 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC Command line: -javaagent:D:\software\ideaj\ideaIC-2017.3.4.win\lib\idea_rt.jar=50372:D:\software\ideaj\ideaIC-2017.3.4.win\bin -Dfile.encoding=UTF-8
4:jmap: java内存映像工具
例如显示 java堆详细信息
jmap -heap 236
C:\Users\lenovo>jmap -heap 236 Attaching to process ID 236, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.161-b12 using thread-local object allocation. Parallel GC with 4 thread(s) Heap Configuration: MinHeapFreeRatio = 0 MaxHeapFreeRatio = 100 MaxHeapSize = 2122317824 (2024.0MB) NewSize = 44564480 (42.5MB) MaxNewSize = 707264512 (674.5MB) OldSize = 89653248 (85.5MB) 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 = 195035136 (186.0MB) used = 71367536 (68.06138610839844MB) free = 123667600 (117.93861389160156MB) 36.592143069031415% used From Space: capacity = 17825792 (17.0MB) used = 17497968 (16.687362670898438MB) free = 327824 (0.3126373291015625MB) 98.16095688763787% used To Space: capacity = 14155776 (13.5MB) used = 0 (0.0MB) free = 14155776 (13.5MB) 0.0% used PS Old Generation capacity = 112197632 (107.0MB) used = 23719728 (22.620895385742188MB) free = 88477904 (84.37910461425781MB) 21.1410237249927% used 24236 interned Strings occupying 2896624 bytes. C:\Users\lenovo>
5:jhat 虚拟机堆转储快照分析工具
6:jstack: java堆栈跟踪工具
7: hsdis JIT生成代码反汇编
可视化工具:
通过jdk/bin目录下的 jconsole.exe启动jconsole,将搜索出所有本地运行的虚拟机进程。
选择一个进程进行监控: 可查看各个状态的信息
本博客为非营利性个人原创,除部分有明确署名的作品外,所刊登的所有作品的著作权均为本人所拥有,本人保留所有法定权利。违者必究