The jmap of the JDK self-belt tool

Source: Internet
Author: User
Tags int size

Jmap is a lightweight gadget with JDK. In the Java Bin directory, it is able to print out the case of all ' objects ' in memory of a Java process (using PID) (e.g., the resulting objects, and their number). It can output not only the tools of all in-memory objects, but even the heap of the VM in binary output to text. Use the method Jmap-histo pid. You can also save it to text, and after a while, use the text Contrast tool to compare which objects the GC reclaims. It can also be used with jhat (Java Heap analysis Tool) to visually display current memory problems in the form of images.

1, jmap command format

jmap [option] pid

2, commonly used parameters

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

-dump:[live,]format=b,file=<filename> uses the Hprof binary form to output the heap content of the JVM to the file =. Live sub options are optional, and if the live option is specified, only live objects are exported to the file.

-finalizerinfo Print the information for the object that is waiting to be reclaimed.

-heap prints Heap's profile, the algorithm used by GC, the configuration of heap, and the use of wise heap.

-histo[:live] Prints the number of instances per class, memory footprint, class full name information. The VM's inner class name begins with a prefix of "*". If the live child parameter is added, only the number of live objects is counted.

-permstat Prints Classload and JVM heap information for a long time. Contains the name, liveliness, address, parent ClassLoader, and number of classes loaded for each classloader. In addition, the number of internal strings and the amount of memory consumed are printed.

-F forced. Use-dump or-histo parameters when the PID does not correspond. In this mode, the live child parameter 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 create objects for testing the JDK's own jmap use

* Parameter:-xms30m-xmx60m

*

* @author Fan Fangming

*/

public class Easyjmap {

Public byte[] Placeholder = newbyte[1 * 1024]; 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 objects: "+ Loops +" (a));

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. Operation Result

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 the object statistics for the-histo[:live] 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

...

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.