- If you are on Linux :
you can try to grep the java process by:
you can try to grep the java process by:
====
[nikhil@nikhil bin]$ ps auxwww |grep java
nikhil 22412 1 18 10:43 pts/4 00:00:02 /home/nikhil/jdk1.6.0_31/bin/java -Djava.util.logging.config.file=/home/nikhil/Studies/apache-tomcat-7.0.26/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/home/nikhil/Studies/apache-tomcat-7.0.26/endorsed -classpath /home/nikhil/Studies/apache-tomcat-7.0.26/bin/bootstrap.jar:/home/nikhil/Studies/apache-tomcat-7.0.26/bin/tomcat-juli.jar -Dcatalina.base=/home/nikhil/Studies/apache-tomcat-7.0.26 -Dcatalina.home=/home/nikhil/Studies/apache-tomcat-7.0.26 -Djava.io.tmpdir=/home/nikhil/Studies/apache-tomcat-7.0.26/temp org.apache.catalina.startup.Bootstrap start
====
- Navigate to jdk bin dir or setup the the system classpath like below :
export CLASSPATH=/home/nikhil/jdk1.6.0_31/bin/:$CLASSPATH:.:
- execute jmap command :
for heap jmap -heap <process id>, you will get output like below :
====
[nikhil@nikhil bin]$ jmap -heap 22412
Attaching to process ID 22412, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 20.6-b01
using thread-local object allocation.
Parallel GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2034237440 (1940.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 21757952 (20.75MB)
MaxPermSize = 85983232 (82.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 31850496 (30.375MB)
used = 28962800 (27.621078491210938MB)
free = 2887696 (2.7539215087890625MB)
90.93359174061214% used
From Space:
capacity = 5242880 (5.0MB)
used = 0 (0.0MB)
free = 5242880 (5.0MB)
0.0% used
To Space:
capacity = 5242880 (5.0MB)
used = 0 (0.0MB)
free = 5242880 (5.0MB)
0.0% used
PS Old Generation
capacity = 84738048 (80.8125MB)
used = 1802824 (1.7193069458007812MB)
free = 82935224 (79.09319305419922MB)
2.1275259963505415% used
PS Perm Generation
capacity = 21757952 (20.75MB)
used = 15853608 (15.119178771972656MB)
free = 5904344 (5.630821228027344MB)
72.86351215408509% used
====
The above output shows the memory usage by java process, let's go little deep with the details:
Jmap is a utility that connects to the JVM on default jmx port i.e:1099 by default and may vary from vendor to vendor.
1.
==
using thread-local object allocation.
Parallel GC with 4 thread(s)
==
suggests that there are 4 GC threads running with parallel GC algoritham.
2.
==
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2034237440 (1940.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 21757952 (20.75MB)
MaxPermSize = 85983232 (82.0MB)
==
suggests the heap config and sizes of different chunk. To get details of these check my article JVM memory configuration.
3.
==
Heap Usage:
PS Young Generation
Eden Space:
capacity = 31850496 (30.375MB)
used = 28962800 (27.621078491210938MB)
free = 2887696 (2.7539215087890625MB)
90.93359174061214% used
From Space:
capacity = 5242880 (5.0MB)
used = 0 (0.0MB)
free = 5242880 (5.0MB)
0.0% used
To Space:
capacity = 5242880 (5.0MB)
used = 0 (0.0MB)
free = 5242880 (5.0MB)
0.0% used
PS Old Generation
capacity = 84738048 (80.8125MB)
used = 1802824 (1.7193069458007812MB)
free = 82935224 (79.09319305419922MB)
2.1275259963505415% used
PS Perm Generation
capacity = 21757952 (20.75MB)
used = 15853608 (15.119178771972656MB)
free = 5904344 (5.630821228027344MB)
72.86351215408509% used
==
Above suggests the memory usage by different chunks of the process heap.
Note : Process heap is process size not the java heap.
Now if you want to dump the info of the objects, classes and references residing over heap, you can take a heap dump by following :
jmap -J-d64 -heap:format=b <proces id>
above is for 64 bit jvms, if you have a 32 bit java, try below:
jmap -heap:format=b <process id>
here format=b suggests that ,it is in binary form. You can also produce an ASCII one, but most of the time it is of no use, because majority of heap dump analyzers support binary or hprof format.
OK, now I want to know about my classloader instances. here we go :
jmap -permstat <process id>
======
[nikhil@nikhil bin]$ jmap -permstat 22412
Attaching to process ID 22412, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 20.6-b01
7387 intern Strings occupying 666440 bytes.
finding class loader instances ..Finding object size using Printezis bits and skipping over...
done.
computing per loader stat ..done.
please wait.. computing liveness............................................liveness analysis may be inaccurate ...
class_loader classes bytes parent_loader alive? type
<bootstrap> 1424 8722704 null live <internal>
0x00000000d9f63548 0 0 0x0000000086c001c0 live org/apache/catalina/loader/WebappClassLoader@0x000000008276adf8
0x00000000d9f1efa8 0 0 0x0000000086c001c0 live org/apache/catalina/loader/WebappClassLoader@0x000000008276adf8
0x0000000086c47000 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086d17fa0 0 0 0x0000000086c00230 dead java/util/ResourceBundle$RBClassLoader@0x00000000821f4cb0
0x00000000d9e16c48 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46e18 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46de0 1 3088 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x00000000d9e16c80 1 3144 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46e50 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46da8 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x00000000d9d8a470 0 0 0x0000000086c001c0 live org/apache/catalina/loader/WebappClassLoader@0x000000008276adf8
0x0000000086c00ad0 12 78648 null live sun/misc/Launcher$ExtClassLoader@0x0000000081bd0df0
0x00000000d9e16bb0 1 3144 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x00000000d9e16ab8 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46ec0 1 3088 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c47098 1 3088 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x00000000d9e16be8 1 3088 null dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c47140 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x00000000d9e16948 17 100592 0x0000000086c001c0 live org/apache/catalina/loader/WebappClassLoader@0x000000008276adf8
0x00000000d9e16b28 1 3088 null dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c47108 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x00000000d9e16af0 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46e88 1 3128 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46d70 1 3088 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c470d0 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46f68 1 3128 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46fa0 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c47060 1 3128 null dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c471b0 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x00000000d9e16a80 1 3088 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c46ef8 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x00000000d9f30118 0 0 0x0000000086c001c0 live org/apache/catalina/loader/WebappClassLoader@0x000000008276adf8
0x0000000086c47178 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x00000000d9e16a48 1 3088 null dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c471e8 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c00230 97 931728 0x0000000086c00ad0 live sun/misc/Launcher$AppClassLoader@0x0000000081c3f970
0x0000000086c46f30 1 3120 0x0000000086c001c0 dead sun/reflect/DelegatingClassLoader@0x0000000081a675e8
0x0000000086c001c0 699 5813752 0x0000000086c00230 live org/apache/catalina/loader/StandardClassLoader@0x0000000081d63dd0
total = 39 2278 15737720 N/A alive=9, dead=30 N/A
======
OK Baj, I just want to see the objects that are alive on my heap :
jmap -histo <process id>
I am not going to paste the output here, because it would be very large :) :P
Note : jconsole is also a powerful tool from which you can determine the jvm runtime details. See the page
jconsole
If you are on Windows : get the process id from Task manger that appears on screen after pressing ctrl+alt+delete, by default it doesn't show the pid, however you can custmize this from the view settings, rest steps would be the same.
No comments:
Post a Comment