java常用且很有用的问题排查工具(持续完善)
因为用的频率不是很多,老忘掉,每次都要搜下,特记录下备忘。
API查看内存情况,比Runtime更靠谱。
MemoryMXBean mxb = ManagementFactory.getMemoryMXBean();
System.out.println(mxb.getHeapMemoryUsage());
dump堆
jmap -dump:file=abc.hprof 86848
ibm openj9的dump选项可参见openj9-docs-0.17.0/xdump.html,它同时包含堆、栈及其它。
查看进程的启动jvm选项
[root@iZ23nn1p4mjZ ~]# jinfo -flags 16603
Attaching to process ID 16603, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.73-b02
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=262144000 -XX:MaxHeapSize=4181721088 -XX:MaxNewSize=1393557504 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=87031808 -XX:OldSize=175112192 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
查看当前类实例汇总情况
[root@iZbp112kwadw1qt8emked5Z logs]# jmap -histo 21094 | more num #instances #bytes class name ---------------------------------------------- 1: 61677 41842184 [B 2: 41937 38583528 [I 3: 300394 22331688 [C 4: 351629 11252128 java.util.HashMap$Node 5: 248197 5956728 java.lang.String 6: 24685 3225536 [Ljava.util.HashMap$Node; 7: 74766 2990640 java.math.BigDecimal 8: 25328 1979288 [Ljava.lang.Object; 9: 40762 1956576 java.nio.HeapByteBuffer 10: 40616 1949568 java.nio.HeapCharBuffer 11: 16747 1473736 java.lang.reflect.Method 12: 28706 1377888 java.util.HashMap 13: 8328 1199232 com.mysql.jdbc.Field 14: 17546 701840 java.math.BigInteger 15: 5746 642584 java.lang.Class 16: 34436 550976 java.lang.Integer 17: 16899 540768 java.lang.ref.WeakReference 18: 2538 534344 [Z 19: 10095 403800 java.util.TreeMap$Entry 20: 2045 359920 com.mysql.jdbc.JDBC42ResultSet 21: 11216 358912 java.util.concurrent.ConcurrentHashMap$Node
命令行运行jar应用
java -cp .;c:\classes\myClass.jar;d:\classes\A.jar;...(列出完整依赖jar) packname.mainclassname
-Xbootclasspath是早期1.2版本jdk的选项,http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4279459
-cp/classpath不支持模糊匹配
-jar 和-cp相互排斥
在目标进程上执行命令,如GC.run
[lightdb@hs-10-20-30-193 ~]$ jcmd 253518 --help 253518: java.lang.IllegalArgumentException: Unknown diagnostic command [lightdb@hs-10-20-30-193 ~]$ jcmd 253518 help 253518: The following commands are available: Compiler.CodeHeap_Analytics Compiler.codecache Compiler.codelist Compiler.directives_add Compiler.directives_clear Compiler.directives_print Compiler.directives_remove Compiler.queue GC.class_histogram GC.class_stats GC.finalizer_info GC.heap_dump GC.heap_info GC.run GC.run_finalization JFR.check JFR.configure JFR.dump JFR.start JFR.stop JVMTI.agent_load JVMTI.data_dump ManagementAgent.start ManagementAgent.start_local ManagementAgent.status ManagementAgent.stop Thread.print VM.class_hierarchy VM.classloader_stats VM.classloaders VM.command_line VM.dynlibs VM.flags VM.info VM.log VM.metaspace VM.native_memory VM.print_touched_methods VM.set_flag VM.stringtable VM.symboltable VM.system_properties VM.systemdictionary VM.uptime VM.version help For more information about a specific command use 'help <command>'. [lightdb@hs-10-20-30-193 ~]$ jcmd 253518 GC.run 253518: Command executed successfully
https://blog.csdn.net/mawming/article/details/52222092
打印关键jvm关键调试信息
参数及其默认值 | 描述 |
-XX:-CITime | 打印消耗在JIT编译的时间 |
-XX:ErrorFile=./hs_err_pid<pid>.log | 保存错误日志或者数据到文件中 |
-XX:+MaxFDLimit | 最大化文件描述符的数量限制 |
-XX:HeapDumpPath=./java_pid<pid>.hprof | 指定导出堆信息时的路径或文件名 |
-XX:-HeapDumpOnOutOfMemoryError | 当首次遭遇OOM时导出此时堆中相关信息 |
-XX:OnOutOfMemoryError="<cmd args>;<cmd args>" | 当首次遭遇OOM时执行自定义命令 |
-XX:-PrintClassHistogram | 遇到Ctrl-Break后打印类实例的柱状信息, 与jmap -histo功能相同 |
-XX:-PrintConcurrentLocks | 遇到Ctrl-Break后打印并发锁的相关信息, 与jstack -l功能相同 |
-XX:-PrintCommandLineFlags | 打印在命令行中出现过的标记 |
-XX:-PrintCompilation | 当一个方法被编译时打印相关信息 |
-XX:-PrintGC | 每次GC时打印相关信息 |
-XX:-PrintGC Details | 每次GC时打印详细信息 |
-XX:-PrintGCTimeStamps | 打印每次GC的时间戳 |
-XX:-TraceClassLoading | 跟踪类的加载信息 |
-XX:-TraceClassLoadingPreorder | 跟踪被引用到的所有类的加载信息 |
-XX:-TraceClassResolution | 跟踪常量池 |
-XX:-TraceClassUnloading | 跟踪类的卸载信息 |
-XX:-TraceLoaderConstraints | 跟踪类加载器约束的相关信息 |