Jmap of "deep JVM" JVM tools

Source: Internet
Author: User

I. Introduction of TOOLS

If you configure the Java\bin directory to an environment variable, the cmd input jmap will be prompted as follows:



Translation: Prints out the case of a Java process (using PID) in memory, all ' objects ' (e.g., the number of objects that were produced).

A tool that can output all in-memory objects, and even the heap in the VM can be exported as text in binary.


second, the use of tools

jmap [option] pid
jmap [option] executable core
jmap [option] [[Email Protected]]remote-hostname-or-ip

2.1), Options:
Executable Java executable from which, the core dump was produced.
(Probably the Java executable that generated the core dump)
Core dump file that will be printed with the information
Remote-hostname-or-ip the host name or IP of the Remote Debug service
Server-id Unique ID, if multiple Remote debug services on a single host
2.2. Basic parameters:
-dump:[live,]format=b,file=<filename> uses the Hprof binary form to output the JVM's heap content to File =. The live sub-option is optional, and if you specify the live option, only the live object is exported to the file.
-finalizerinfo prints information about objects that are waiting to be reclaimed.
-heap prints the summary of the heap, the algorithm used by the GC, the configuration of the heap, and the use of the wise heap.
-histo[:live] Prints the number of instances per class, memory consumption, class full name information. The internal class name of the VM is prefixed with "*". If the live child parameter is added, only the number of live objects is counted.
-permstat Prints the classload and JVM heap for a long layer of information. Contains the name of each classloader, the liveliness, the address, the parent ClassLoader, and the number of classes loaded. In addition, the number of internal strings and the amount of memory consumed are also printed.
-F coercion. Use the-dump or-histo parameters when the PID is not appropriate. In this mode, the live sub-argument is invalid.
-H | -HELP Printing Auxiliary Information
-j Pass parameters to Jmap-initiated JVM.
The PID needs to be printed with the information of the Java process ID, the difference between entrepreneurship and work-blog preview, you can use JPS to inquire.


third, the test code

Import Java.io.bufferedreader;import Java.io.ioexception;import Java.io.inputstreamreader;import Java.lang.management.managementfactory;public class Jmapstudy {public static void main (string[] args) {//gets the Currentprocess ' s namestring name = Managementfactory.getruntimemxbean (). GetName ();//result format:[email  protected]string pid = Name.split ("@") [0];  String command = "tasklist/fi \" pid eq "+ pid +" \ ""; executecmd (command); new Jmapthread (). Start (); command = "Jmap-histo "+ pid;executecmd (command);} /** * Executes the special command by means of runtime, and output the result * to console * * @param command */public St atic void Executecmd (String command) {try {string S; Process process = Runtime.getruntime (). exec (command); BufferedReader BufferedReader =new BufferedReader (New InputStreamReader (Process.getinputstream ())); while ((s = Bufferedreader.readline ()) = null) System.out.println (s);p rocess.waitfor ();} catch (Interruptedexception e) {e.printstacktrace ();} catch (IoexceptiOn e) {e.printstacktrace ();}}} Class Jmapthread extends thread{/** * This method was used for creating a process to be tested memory. */public void Run () {for (int i = 0; i <; i++) {try {Thread.Sleep]} catch (Interruptedexception e) {e.printstacktrace ();} System.out.println ("Now I:" + i);}}}


iv. Results of Operation

Image name PID session name Session # Memory use ========================= ======== ================ =======     = = ============javaw.exe 12928 Console 1 13,864 Know i:0now i:1now i:2 num  #instances #bytes class name----------------------------------------------1:1518 280472          [C 2:1020 182192 <symbolKlass> 3:107 110032 [B 4:30 96184 [I 5:1398 33552 java.lang.String 6:259 27200 &LT;CONSTMETHODKLASS&G   T            7:774 24768 java.util.treemap$entry 8:259 20976 <methodKlass> 9:  15344 <constantPoolKlass> 10:332 14280 [Ljava.lang.Object;   11:39 12792 <objArrayKlassKlass> 12:21 8864 <instanceKlassKlass> 13:21 6440  <constantPoolCacheKlass> 14:192 6128 [Ljava.lang.String;           15:76 6080 Java.lang.reflect.Method 16:60 5760 java.lang.Class 17: 103 4944 java.nio.HeapCharBuffer 18:47 3968 [S 19:60 2880 ja Va.nio.HeapByteBuffer 20:40 2880 java.lang.reflect.Field 21:115 2288 [Ljava . lang.  Class;  22:23 2096 [Ljava.util.hashmap$entry;           23:51 2088 [[I 24:83 1992 Java.util.hashtable$entry 25:13  1400 [Ljava.util.hashtable$entry;            26:83 1328 Java.lang.StringBuilder 27:53 1272 java.util.hashmap$entry 28: 1024x768 java.util.concurrent.concurrenthashmap$segment 29:15 840 java.net.u RL 30:32 768 Java.util.concurrent.loCks.  Reentrantlock$nonfairsync 31:35 752 [Ljava.util.concurrent.concurrenthashmap$hashentry;            32:45 720 java.io.File 33:10 640 Java.lang.reflect.Constructor 34:            640 Java.util.HashMap 35:19 608 java.util.linkedhashmap$entry 36:            608 Java.util.Locale 37:18 576 java.lang.ref.Finalizer 38:36             576 java.lang.processenvironment$checkedentry 39:5 520 Java.lang.Thread 40:20 480 java.util.concurrent.concurrenthashmap$hashentry 41:14 448 java.lang.ref.SoftRef Erence 42:7 392 Sun.nio.cs.ext.gbk$decoder 43:21 336 java.lang.StringBu Ffer 44:10 Java.io.ObjectStreamField 45:2 [ljava.lang.reflect.m  Ethod;   46:13         312 java.io.expiringcache$entry 47:13 312 java.io.FileDescriptor 48:17            272 sun.security.action.GetPropertyAction 49:11 Java.net.Parts 50:10            Java.security.AccessControlContext 51:5 Java.util.TreeMap 52:6 Java.util.Hashtable 53:9 216 java.util.ArrayList 54:5 20  0 Sun.misc.urlclasspath$jarloader 55:4 184 [Ljava.lang.reflect.Field;             56:7 168 Java.util.Vector 57:3 168 Sun.nio.cs.ext.gbk$encoder 58:  2 [Ljava.util.concurrent.concurrenthashmap$segment; 59:4 Java.util.StringTokenizer 60:8 [Ljava.io.ObjectStreamField  ; 61:3 144 Java.io.BufferedReader 62:9 144  Java.io.FileInputStream 63:4 Java.io.BufferedInputStream 64:5 120             Sun.reflect.NativeConstructorAccessorImpl 65:3 Sun.nio.cs.StreamDecoder 66:2  Java.io.expiringcache$1 67:1 104 Jmapthread 68:1 104            Java.lang.ref.finalizer$finalizerthread 69:13 104 Java.lang.Object 70:1             104 Java.lang.ref.reference$referencehandler 71:2 java.net.Inet6Address 72:1 Sun.net.www.protocol.file.FileURLConnection 73:2 7 Sun.nio.cs.StreamEncoder 4:3 java.lang.classloader$nativelibrary 75:4 Java.io.FileOutput   Stream 76:6 sun.misc.urlclasspath$3 77:2 java.lang.ThreadGroup     78:4        Java.lang.OutOfMemoryError 79:2 80:2 java.util.Properties             Java.util.LinkedHashMap 81:4 82:5 Java.io.BufferedOutputStream  [Ljava.lang.reflect.Constructor;             83:5 Java.lang.Boolean 84:5 sun.misc.MetaIndex 85:  1 [Ljava.lang.threadlocal$threadlocalmap$entry; 86:5 Sun.reflect.DelegatingConstructorAccessorImpl 87:2 Java.ut Il.concurrent.ConcurrentHashMap 88:2 Java.io.BufferedWriter 89:2 8 0 Java.lang.ProcessImpl 90:5 java.lang.class$1 91:3 java.util . Stack 92:3 java.lang.RuntimePermission 93:3 java.lang.ref.Weak        Reference 94:3     Java.lang.NoSuchMethodError 95:1 Sun.misc.launcher$appclassloader 96:             1 Sun.misc.launcher$extclassloader 97:3 Sun.nio.cs.surrogate$parser 98:             2 java.lang.ClassNotFoundException 99:2 Java.io.PrintStream 100: 2 sun.misc.urlclasspath$fileloader$1 101:2 java.io.FilePermission 1             02:2 [Ljava.lang.Thread; 103:4 Java.lang.Integer 104:  2 Java.security.CodeSource 105:2 Java.lang.threadlocal$threadlocalmap$entry 106:4 java.net.urlclassloader$1 107:1 Java.util.regex.Pattern 1 08:2 Java.util.linkedhashmap$keyiterator 109:2 Sun.misc.URLClass Path 110:2            Java.security.PrivilegedActionException 111:2 11 Java.util.linkedlist$listitr             2:2 Java.io.ExpiringCache 113:1 java.util.regex.Matcher 114:             1 [Ljava.util.regex.pattern$grouphead; 115:3 [Ljava.io.File; 116:             3 java.lang.ThreadLocal 117:2 Java.lang.ref.ReferenceQueue 118:             2 [Ljava.net.URL; 119:3 java.lang.classloader$3 120:1 [J 121:2 java.lang.ProcessBuilder 122:3 Java.nio. CharSet. Codingerroraction 123:2 java.net.inetaddress$cacheentry 124:2-ja Va.util.linkedlist$entry 125:2 java.security.Permissions 126:2-J Ava.lang.ref.RefErencequeue$null 127:2 java.util.LinkedList 128:2 java.net.Inet4 Address 129:2 java.lang.management.ManagementPermission 130:2-ja Va.io.InputStreamReader 131:2 Java.io.OutputStreamWriter 132:1 J             Ava.lang.ProcessEnvironment 133:1 134:1 sun.nio.cs.standardcharsets$classes             Sun.nio.cs.standardcharsets$cache 135:1 Java.util.properties$linereader 136:             2 [Ljava.net.InetAddress; 137:5 java.lang.class$3 138:1              Sun.nio.cs.standardcharsets$aliases 139:1 Java.security.ProtectionDomain 140: 2 Java.nio.charset.CoderResult 141:2 Sun.security.action.LoadLib         Raryaction 142:    1 Sun.misc.SoftCache 143:2 sun.misc.Signal 144:1             Sun.nio.cs.ext.ExtendedCharsets 145:2 146:1 java.lang.processimpl$1             Java.util.collections$synchronizedmap 147:2 148:4 Java.nio.ByteOrder             Java.lang.ref.referencequeue$lock 149:2 150:1 Java.util.HashSet             [Ljava.lang.ThreadGroup; 151:2 Java.net.inetaddress$cache 152:2              java.io.filepermission$1 153:1 154:2 java.util.RandomAccessSubList             Java.net.inetaddress$cache$type 155:1 Java.util.abstractlist$listitr 156: 2 Sun.misc.NativeSignalHandler 157:1 [Ljava.lang.OutOfMemoryError;      158:1       Java.util.hashmap$entryiterator 159:1 Java.util.concurrent.atomic.AtomicReferenceF Ieldupdater$atomicreferencefieldupdaterimpl 160:4 sun.reflect.reflectionfactory$getreflection Factoryaction 161:1 Sun.management.VMManagementImpl 162:1 java.s Ecurity.             Basicpermissioncollection 163:1 Java.lang.stringcoding$stringdecoder 164:1             Sun.misc.launcher$appclassloader$1 165:1 Java.io.WinNTFileSystem 166: 1 java.lang.reflect.ReflectPermission 167:1 [ljava.net.inetaddress$cache$type ; 168:3 sun.reflect.reflectionfactory$1 169:1 Java.util.regex.Patt Ern$treeinfo 170:1 java.lang.NumberFormatException 171:1 sun.sec Urity.action.gEtintegeraction 172:1 sun.nio.cs.StandardCharsets 173:1 Java.uti L.sublist$1 174:1 java.lang.threadlocal$threadlocalmap 175:1 Sun  . Nio.cs.ext.GBK 176:1 Java.lang.stringcoding$stringencoder 177:1 24 Sun.management.RuntimeImpl 178:1 Java.util.BitSet 179:1 sun.net . www. MessageHeader 180:1 Java.io.FileReader 181:1 java.lang.ref.Refer ence 182:1 java.util.collections$unmodifiablemap 183:1 sun.misc.  Launcher$extclassloader$1 184:1 [Ljava.security.Principal; 185:1 16             Java.lang.SystemClassLoaderAction 186:1 Java.security.protectiondomain$key 187: 1 JAva.security.policy$unsupportedemptycollection 188:1 Java.util.hashmap$entryset 189: 1 sun.security.action.GetBooleanAction 190:1 Java.io.FilePermissionCollec tion 191:1 [Ljava.lang.StackTraceElement; 192:2 Sun.net.www.prot Ocol.jar.Handler 193:1 java.util.regex.pattern$5 194:1 java.util . Regex. Pattern$start 195:1 java.util.regex.pattern$single 196:1 java.ut             Il.concurrent.atomic.AtomicInteger 197:1 Java.util.regex.pattern$node 198:1             Sun.misc.Launcher 199:1 Sun.misc.urlclasspath$fileloader 200:1              Java.util.regex.pattern$lastnode 201:1 Java.util.hashmap$keyset 202:1  16Java.util.collections$emptymap 203:1 [Ljava.security.cert.Certificate; 204:1 Java.nio.charset.coderresult$1 205:1 Java.lang.processenvironment$checkedentryse T 206:1 java.util.collections$emptylist 207:1 java.nio.charset.c Oderresult$2 208:1 Java.net.Inet6AddressImpl 209:1 SUN.JKERNEL.D ownloadmanager$1 210:1 Java.net.Inet4AddressImpl 211:1 [ljava.se Curity. Protectiondomain; 212:1 java.lang.processenvironment$checkedentryset$1 213:1 8 SUN.N  Et.www.protocol.file.Handler 214:1 8 java.net.inetaddress$1 215:1 8 Sun.misc.Unsafe 216:1 8 Java.util.collections$emptyset 217:1 8 java. Net.  Inetaddressimplfactory 218:1 8 Java.lang.ref.reference$lock 219:1 8             Java.util.collections$reversecomparator 220:1 8 sun.net.inetaddresscachepolicy$2 221:             1 8 sun.misc.launcher$factory 222:1 8 sun.jkernel.downloadmanager$2 223: 1 8 java.lang.processenvironment$namecomparator 224:1 8 Java.lang.ProcessE              Nvironment$entrycomparator 225:1 8 Java.util.hashtable$emptyenumerator 226:1              8 java.lang.compiler$1 227:1 8 java.lang.terminator$1 228:1 8 java.nio.charset.charset$3 229:1 8 java.lang.system$2 230:1 8 JAV A.lang.runtime 231:1 8 Java.net.UnknownContentHandler 232:1 8 SUN.MI Sc. AsciicaseinsensiTivecomparator 233:1 8 java.net.urlclassloader$7 234:1 8 JAVA.LANG.R Eflect. Reflectaccess 235:1 8 java.security.protectiondomain$2 236:1 8 SUN.R Eflect. Reflectionfactory 237:1 8 sun.net.inetaddresscachepolicy$1 238:1 8 J              Ava.util.hashtable$emptyiterator 239:1 8 java.security.security$1 240:1 8 java.lang.string$caseinsensitivecomparatortotal 7599 899640now i:3now i:4now i:5now i:6now i:7 Now I:8now I:9

RELATED links:

http://blog.csdn.net/fenglibing/article/details/6411953


http://blog.csdn.net/zhaozheng7758/article/details/8623530

Jmap of "deep JVM" JVM tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.