The jmap of the JDK with its own tools

Source: Internet
Author: User

Jmap is a lightweight gadget that comes with the JDK. Located in the Java Bin directory, it is able to print out all the ' objects ' in memory of a Java process (using PID) (e.g., the number of objects that are produced). It can output not only the tools of all in-memory objects, but even the heap in the VM, with binary output as text. Use the method Jmap-histo pid. You can also save it to text, and after a while, using the text Comparison tool, you can compare which objects the GC recycles. It can also be used with jhat (Java Heap analysis Tool) to visually visualize current memory problems in the form of an image.

1 , Jmap command format

jmap [option] pid

2 , common parameters

Note: Most features of Jmap can only be run under Linux, only the-dump and-histo options are available under Windows

-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

3 , source code

Package com.jdktools;

Import java.util.ArrayList;

Import Java.util.Random;

/**

 * Simple application with a large number of loops and objects created for testing the JDK's own jmap use

 *  parameter:-xms30m-xmx60m

*

* @author Fan Fangming

*/

public class Easyjmap {

Public byte[] PlaceHolder = newbyte[1 * 1024x768];// placeholder

public static void Main (String[]args) throws Exception {

while (true) {

Random random = Newrandom ();

int loops =random.nextint (10000);

Easyjmap Jstat = Neweasyjmap ();

System.out.println ("... Building object: "+ Loops +" ( One) ");

Jstat.getloop (loops);// multiple loops, resulting in a large number of objects

Thread.Sleep (10);

}

}

public void Getloop (int size) {

Arraylist<easyjmap>list = new arraylist<easyjmap> ();

for (int i = 0; i < size;i++) {

Easyjmap Jstat = Neweasyjmap ();

List.add (Jstat);

}

}

}

4 , operating parameters

* parameters:-xms30m-xmx60m , this parameter is used to start the JVM virtual machine

5 , running results

C:\Program files\java\jdk1.6.0_25\bin>jmap-dump:format=b,file=d:/ffm83/jmaplog.txt1668

Dumping heap to D:\ffm83\jmaplog.txt ...

Heap dump file created

View-histo[:live] The object statistics of the print heap, including the number of objects, memory size, and so on

C:\Program Files\java\jdk1.6.0_25\bin>jmap-histo 1668

Num #instances #bytes class name

----------------------------------------------

1:7561 7536976 [B

2:4970 496896 <constMethodKlass>

3:8147 441176 <symbolKlass>

4:4970 400192 <methodKlass>

5:1458 198624 [C

6:320 188400 <constantPoolKlass>

7:298 128672 <constantPoolCacheKlass>

8:320 127832 <instanceKlassKlass>

9:7174 114784 Com.jdkTools.EasyJmap

10:314 64696 [Ljava.lang.Object;

11:380 41904 [I

12:388 37248 Java.lang.Class

13:1485 35640 java.lang.String

...

The jmap of the JDK with its own 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.