JVM工具篇-jcmd
[root@promote ~]# jcmd help Error parsing arguments: No command specified Usage: jcmd <pid | main class> <command ...|PerfCounter.print|-f file> or: jcmd -l or: jcmd -h command must be a valid jcmd command for the selected jvm. Use the command "help" to see which commands are available. If the pid is 0, commands will be sent to all Java processes. The main class argument will be used to match (either partially or fully) the class used to start Java. If no options are given, lists Java processes (same as -p). PerfCounter.print display the counters exposed by this process -f read and execute commands from the file -l list JVM processes on the local machine -h this help
jcmd后面 pid后面具体可以使用哪些参数,可以通过jcmd pid help提示出来
[root@promote ~]# jcmd 2079 help 2079: 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 --打印thread dump,后面可带 -l GC.class_stats GC.class_histogram GC.heap_dump --导出head dump,示例:jcmd pid GC.heap_dump /root/a.hprof GC.finalizer_info GC.heap_info GC.run_finalization --调用 java.lang.System.runFinalization() GC.run --调用java.lang.System.gc() VM.uptime --查看该进程的运行持续时间,单位秒 VM.dynlibs VM.flags --查看该进程的虚拟机启动参数 VM.system_properties --打印当前jvm读到的system_properties,配合grep工具快速查看 VM.command_line VM.version --查看虚拟机的版本 help
[root@promote ~]# jcmd 2079 GC.heap_info 2079: def new generation total 9280K, used 0K [0x00000000e3400000, 0x00000000e3e10000, 0x00000000ecd50000) eden space 8256K, 0% used [0x00000000e3400000, 0x00000000e3400000, 0x00000000e3c10000) from space 1024K, 0% used [0x00000000e3c10000, 0x00000000e3c10000, 0x00000000e3d10000) to space 1024K, 0% used [0x00000000e3d10000, 0x00000000e3d10000, 0x00000000e3e10000) tenured generation total 20480K, used 458K [0x00000000ecd50000, 0x00000000ee150000, 0x0000000100000000) the space 20480K, 2% used [0x00000000ecd50000, 0x00000000ecdc2ad0, 0x00000000ecdc2c00, 0x00000000ee150000) Metaspace used 3358K, capacity 4628K, committed 4864K, reserved 1056768K class space used 372K, capacity 453K, committed 512K, reserved 1048576K
[root@promote ~]# jcmd 2079 VM.classloader_stats 2079: ClassLoader Parent CLD* Classes ChunkSz BlockSz Type 0x000000010000f958 0x000000010000fd00 0x00007f56cc0c0cf0 1 6144 3408 sun.misc.Launcher$AppClassLoader 2 12288 3520 + unsafe anonymous classes 0x000000010000fd00 0x0000000000000000 0x0000000000000000 0 0 0 sun.misc.Launcher$ExtClassLoader 0x0000000000000000 0x0000000000000000 0x00007f56cc01ddb0 562 4587520 3351392 <boot class loader> 65 133120 74968 + unsafe anonymous classes Total = 3 630 4739072 3433288 ChunkSz: Total size of all allocated metaspace chunks BlockSz: Total size of all allocated metaspace blocks (each chunk has several blocks)
[root@promote ~]# jcmd 2079 GC.class_histogram 2079: num #instances #bytes class name ---------------------------------------------- 1: 1345 111760 [C 2: 639 73232 java.lang.Class 3: 296 57296 [I 4: 767 35112 [Ljava.lang.Object; 5: 1332 31968 java.lang.String 6: 10 25232 [B 7: 188 10528 java.lang.invoke.MemberName 8: 261 8352 java.util.concurrent.ConcurrentHashMap$Node 9: 174 6960 java.lang.ref.SoftReference 10: 194 6208 java.lang.invoke.LambdaForm$Name 11: 256 6144 java.lang.Long 12: 94 5640 [Ljava.lang.ref.SoftReference; 13: 173 5536 java.lang.invoke.MethodType$ConcurrentWeakInternSet$WeakEntry 14: 128 5120 java.lang.invoke.MethodType 15: 256 4096 java.lang.Byte 16: 256 4096 java.lang.Integer 17: 256 4096 java.lang.Short 18: 117 4048 [Ljava.lang.Class; 19: 109 3488 java.util.Hashtable$Entry 20: 67 3040 [Ljava.lang.invoke.LambdaForm$Name; 21: 8 3008 java.lang.Thread 22: 62 2976 java.lang.invoke.LambdaForm 23: 28 2912 [Ljava.lang.invoke.MethodHandle; 24: 49 2744 java.lang.invoke.MethodTypeForm 25: 97 2328 java.lang.invoke.LambdaForm$NamedFunction 26: 62 2248 [Ljava.lang.String; 27: 69 2208 java.lang.invoke.DirectMethodHandle 28: 128 2048 java.lang.Character 29: 9 1936 [Ljava.util.concurrent.ConcurrentHashMap$Node; 30: 38 1824 sun.util.locale.LocaleObjectCache$CacheEntry 31: 21 1344 java.net.URL 32: 1 1040 [Ljava.lang.Byte; 33: 1 1040 [Ljava.lang.Integer; 34: 1 1040 [Ljava.lang.Long; 35: 1 1040 [Ljava.lang.Short; 36: 26 1040 java.io.ObjectStreamField 37: 63 1008 java.lang.Object 38: 6 992 [Ljava.util.Hashtable$Entry; 39: 31 992 java.util.HashMap$Node 40: 11 912 [Ljava.util.HashMap$Node; 41: 19 760 sun.util.locale.BaseLocale$Key 42: 17 680 java.util.LinkedHashMap$Entry 43: 9 656 [S 44: 10 640 java.util.concurrent.ConcurrentHashMap 45: 3 624 [Ljava.lang.invoke.LambdaForm; 46: 13 624 java.util.HashMap 47: 19 608 java.util.Locale 48: 19 608 sun.util.locale.BaseLocale 49: 10 560 sun.invoke.util.Wrapper 50: 10 560 sun.misc.URLClassPath$JarLoader 51: 1 528 [Ljava.lang.Character; 52: 12 480 java.lang.invoke.MethodHandleImpl$IntrinsicMethodHandle 53: 6 480 java.lang.reflect.Constructor 54: 12 480 java.security.AccessControlContext 55: 6 456 [Lsun.invoke.util.Wrapper; 56: 19 456 java.util.Locale$LocaleKey 57: 17 408 java.io.ExpiringCache$Entry 58: 10 400 java.lang.invoke.DirectMethodHandle$Accessor 59: 12 384 java.lang.invoke.SimpleMethodHandle 60: 1 384 java.lang.ref.Finalizer$FinalizerThread 61: 6 384 java.nio.DirectByteBuffer 62: 1 376 java.lang.ref.Reference$ReferenceHandler 63: 11 352 java.io.File 64: 14 336 java.lang.invoke.LambdaFormEditor$Transform$Kind 65: 6 336 java.nio.DirectLongBufferU 66: 10 320 java.lang.OutOfMemoryError 67: 11 304 [Ljava.io.ObjectStreamField; 68: 12 288 java.lang.invoke.Invokers 69: 9 288 jdk.internal.org.objectweb.asm.Type 70: 11 264 java.lang.RuntimePermission 71: 8 256 java.lang.ref.ReferenceQueue 72: 8 248 [Ljava.lang.invoke.LambdaForm$BasicType; 73: 6 240 [Ljava.lang.invoke.BoundMethodHandle$SpeciesData; 74: 3 240 [Ljava.util.WeakHashMap$Entry; 75: 10 240 sun.misc.MetaIndex 76: 7 208 [Ljava.lang.invoke.LambdaForm$NamedFunction; 77: 5 200 java.lang.invoke.BoundMethodHandle$SpeciesData 78: 5 200 java.util.WeakHashMap$Entry 79: 6 192 java.lang.invoke.LambdaForm$BasicType 80: 8 192 java.lang.invoke.MethodHandleImpl$Intrinsic 81: 8 192 java.net.NetPermission 82: 4 192 java.util.Hashtable 83: 6 192 java.util.Vector 84: 4 160 java.lang.ref.Finalizer 85: 10 160 java.lang.ref.ReferenceQueue$Lock 86: 4 160 java.security.ProtectionDomain 87: 6 144 java.util.ArrayList 88: 3 144 java.util.WeakHashMap 89: 6 144 sun.misc.PerfCounter 90: 2 128 java.io.ExpiringCache$1 91: 3 120 java.lang.invoke.BoundMethodHandle$Species_LL 92: 2 112 [Ljava.lang.invoke.MethodType; 93: 2 112 sun.nio.cs.UTF_8$Encoder 94: 3 96 java.io.FileDescriptor 95: 2 96 java.lang.ThreadGroup 96: 3 96 java.lang.invoke.BoundMethodHandle$Species_L 97: 2 96 java.nio.HeapByteBuffer 98: 3 96 java.security.CodeSource 99: 2 96 java.util.Properties 100: 3 96 java.util.Stack 101: 1 96 sun.misc.Launcher$AppClassLoader 102: 2 96 sun.misc.URLClassPath 103: 2 96 sun.nio.cs.StreamEncoder 104: 1 88 sun.misc.Launcher$ExtClassLoader 105: 2 80 java.io.BufferedWriter 106: 2 80 java.io.ExpiringCache 107: 2 80 java.lang.invoke.MethodHandleImpl$AsVarargsCollector 108: 1 72 [Ljava.lang.invoke.LambdaFormEditor$Transform$Kind; 109: 3 72 java.security.SecurityPermission 110: 3 72 java.util.concurrent.atomic.AtomicLong 111: 3 72 sun.misc.Signal 112: 3 72 sun.reflect.NativeConstructorAccessorImpl 113: 2 64 [J 114: 2 64 [Ljava.lang.Thread; 115: 4 64 [Ljava.security.Principal; 116: 2 64 java.io.FileOutputStream 117: 2 64 java.io.PrintStream 118: 2 64 java.lang.ClassValue$Entry 119: 2 64 java.lang.VirtualMachineError 120: 2 64 java.lang.ref.ReferenceQueue$Null 121: 2 64 java.security.Permissions 122: 4 64 java.security.ProtectionDomain$Key 123: 1 56 [[I 124: 1 56 java.net.SocketPermission 125: 1 48 [Ljava.lang.invoke.MethodHandleImpl$Intrinsic; 126: 2 48 [Ljava.security.ProtectionDomain; 127: 2 48 java.io.BufferedOutputStream 128: 2 48 java.io.File$PathStatus 129: 2 48 java.io.OutputStreamWriter 130: 3 48 java.lang.ThreadLocal 131: 1 48 java.lang.invoke.BoundMethodHandle$Species_L4 132: 2 48 java.lang.invoke.MethodHandles$Lookup 133: 2 48 java.lang.reflect.ReflectPermission 134: 2 48 java.nio.charset.CoderResult 135: 3 48 java.nio.charset.CodingErrorAction 136: 3 48 java.util.concurrent.atomic.AtomicInteger 137: 2 48 sun.misc.NativeSignalHandler 138: 3 48 sun.reflect.DelegatingConstructorAccessorImpl 139: 1 40 [[Ljava.lang.invoke.LambdaForm$Name; 140: 1 40 java.io.BufferedInputStream 141: 1 40 java.lang.ClassLoader$NativeLibrary 142: 1 40 sun.nio.cs.StandardCharsets$Aliases 143: 1 40 sun.nio.cs.StandardCharsets$Cache 144: 1 40 sun.nio.cs.StandardCharsets$Classes 145: 1 32 [Ljava.lang.OutOfMemoryError; 146: 2 32 [Ljava.lang.StackTraceElement; 147: 1 32 [Ljava.lang.ThreadGroup; 148: 1 32 java.io.FileInputStream 149: 1 32 java.io.FilePermission 150: 1 32 java.io.UnixFileSystem 151: 1 32 java.lang.ArithmeticException 152: 2 32 java.lang.Boolean 153: 1 32 java.lang.NullPointerException 154: 2 32 java.nio.ByteOrder 155: 1 32 java.security.BasicPermissionCollection 156: 1 32 java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl 157: 2 32 sun.net.www.protocol.jar.Handler 158: 1 32 sun.nio.cs.StandardCharsets 159: 1 24 [Ljava.io.File$PathStatus; 160: 1 24 [Ljava.lang.ClassValue$Entry; 161: 1 24 [Lsun.launcher.LauncherHelper; 162: 1 24 DeadLockDemo$$Lambda$1/834600351 163: 1 24 DeadLockDemo$$Lambda$2/531885035 164: 1 24 java.io.FilePermissionCollection 165: 1 24 java.lang.ClassValue$Version 166: 1 24 java.lang.Double 167: 1 24 java.lang.StringBuilder 168: 1 24 java.lang.invoke.MethodHandleImpl$4 169: 1 24 java.lang.invoke.MethodType$ConcurrentWeakInternSet 170: 1 24 java.security.AllPermissionCollection 171: 1 24 java.util.BitSet 172: 1 24 java.util.Collections$EmptyMap 173: 1 24 java.util.Collections$SetFromMap 174: 1 24 java.util.Collections$SynchronizedSet 175: 1 24 java.util.Collections$UnmodifiableRandomAccessList 176: 1 24 java.util.Locale$Cache 177: 1 24 sun.launcher.LauncherHelper 178: 1 24 sun.misc.URLClassPath$FileLoader 179: 1 24 sun.nio.cs.UTF_8 180: 1 24 sun.util.locale.BaseLocale$Cache 181: 1 16 [D 182: 1 16 [F 183: 1 16 [Ljava.lang.Throwable; 184: 1 16 [Ljava.security.cert.Certificate; 185: 1 16 [Z 186: 1 16 java.io.FileDescriptor$1 187: 1 16 java.lang.CharacterDataLatin1 188: 1 16 java.lang.ClassValue$Identity 189: 1 16 java.lang.Float 190: 1 16 java.lang.Runtime 191: 1 16 java.lang.String$CaseInsensitiveComparator 192: 1 16 java.lang.System$2 193: 1 16 java.lang.Terminator$1 194: 1 16 java.lang.invoke.MemberName$Factory 195: 1 16 java.lang.invoke.MethodHandleImpl$2 196: 1 16 java.lang.invoke.MethodHandleImpl$3 197: 1 16 java.lang.ref.Reference$1 198: 1 16 java.lang.ref.Reference$Lock 199: 1 16 java.lang.reflect.ReflectAccess 200: 1 16 java.net.URLClassLoader$7 201: 1 16 java.nio.Bits$1 202: 1 16 java.nio.charset.CoderResult$1 203: 1 16 java.nio.charset.CoderResult$2 204: 1 16 java.security.AllPermission 205: 1 16 java.security.ProtectionDomain$2 206: 1 16 java.security.ProtectionDomain$JavaSecurityAccessImpl 207: 1 16 java.util.Collections$EmptyList 208: 1 16 java.util.Collections$EmptySet 209: 1 16 java.util.Hashtable$EntrySet 210: 1 16 java.util.WeakHashMap$KeySet 211: 1 16 java.util.zip.ZipFile$1 212: 1 16 sun.misc.Launcher 213: 1 16 sun.misc.Launcher$Factory 214: 1 16 sun.misc.Perf 215: 1 16 sun.misc.Unsafe 216: 1 16 sun.net.www.protocol.file.Handler 217: 1 16 sun.reflect.ReflectionFactory Total 8254 469712