經過jmap查看jvm採用的垃圾收集器

1  tomcat PID得到

 ps -ef|grep tomcatjava

    

1 [root@iZ2zeapch8kbaw4bxnz8vxZ tomcat7]# ps -ef|grep tomcat
2 root     13296     1  0 10:35 pts/1    00:00:00 /usr/sbin/cronolog /usr/local/tomcat7/logs/catalina.%Y-%m-%d.out
3 root     13297 13295 87 10:35 pts/1    00:00:12 /usr/local/jdk1.8.0_77/bin/java -Djava.util.logging.config.file=/usr/local/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms1024m -Xmx1024m -Xss512K -XX:+UseConcMarkSweepGC -Djdk.tls.ephemeralDHKeySize=2048 -Djava.endorsed.dirs=/usr/local/tomcat7/endorsed -classpath /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat7 -Dcatalina.home=/usr/local/tomcat7 -Djava.io.tmpdir=/usr/local/tomcat7/temp org.apache.catalina.startup.Bootstrap start
4 root     13434 12792  0 10:35 pts/1    00:00:00 grep tomcat

 

 

2 查看java垃圾收集器 jmap -heap pid

    其中 using thread-local object allocation下面就是採用的java垃圾收集器算法

   下圖事例中爲:Concurrent Mark-Sweep GCapache

 

[root@iZ2zeapchxZ tomcat7]# jmap -heap 13297
Attaching to process ID 13297, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 1073741824 (1024.0MB)
   NewSize                  = 87228416 (83.1875MB)
   MaxNewSize               = 87228416 (83.1875MB)
   OldSize                  = 986513408 (940.8125MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 78512128 (74.875MB)
   used     = 17016048 (16.227767944335938MB)
   free     = 61496080 (58.64723205566406MB)
   21.673145835507096% used
Eden Space:
   capacity = 69795840 (66.5625MB)
   used     = 10923608 (10.417564392089844MB)
   free     = 58872232 (56.144935607910156MB)
   15.650800964642018% used
From Space:
   capacity = 8716288 (8.3125MB)
   used     = 6092440 (5.810203552246094MB)
   free     = 2623848 (2.5022964477539062MB)
   69.89718559093045% used
To Space:
   capacity = 8716288 (8.3125MB)
   used     = 0 (0.0MB)
   free     = 8716288 (8.3125MB)
   0.0% used
concurrent mark-sweep generation:
   capacity = 986513408 (940.8125MB)
   used     = 41311272 (39.397499084472656MB)
   free     = 945202136 (901.4150009155273MB)
   4.187603702594583% used

19916 interned Strings occupying 2422360 bytes.

  Concurrent Mark-Sweep GC :CMS回收器bootstrap

     Mark Sweep Compact GC:    串行GC(Serial GC)tomcat

     Parallel GC with 2 thread(s): 並行GC(ParNew)bash

    如何修改GC回收器: 設置 JAVA_OPTSeclipse

3JMAP介紹

 

打印出某個java進程(使用pid)內存內的,全部‘對象’的狀況(如:產生那些對象,及其數量)。jvm

 

能夠輸出全部內存中對象的工具,甚至能夠將VM 中的heap,以二進制輸出成文本。使用方法 jmap -histo pid。若是連用SHELL jmap -histo pid>a.log能夠將其保存到文本中去,在一段時間後,使用文本對比工具,能夠對比出GC回收了哪些對象。jmap -dump:format=b,file=outfile 3024能夠將3024進程的內存heap輸出出來到outfile文件裏,再配合MAT(內存分析工具(Memory Analysis Tool),使用參見:http://blog.csdn.net/fenglibing/archive/2011/04/02/6298326.aspx)或與jhat (Java Heap Analysis Tool)一塊兒使用,可以以圖像的形式直觀的展現當前內存是否有問題。工具

64位機上使用須要使用以下方式:ui

jmap -J-d64 -heap pid

2、命令格式

SYNOPSIS

       jmap [ option ] pid

       jmap [ option ] executable core

       jmap [ option ] [server-id@]remote-hostname-or-IP

3、參數說明

1)options 

executable Java executable from which the core dump was produced.

(多是產生core dumpjava可執行程序)

core 將被打印信息的core dump文件

remote-hostname-or-IP 遠程debug服務的主機名或ip

server-id 惟一id,假如一臺主機上多個遠程debug服務 

2)、基本參數:

-dump:[live,]format=b,file=<filename> 使用hprof二進制形式,輸出jvmheap內容到文件=. live子選項是可選的,假如指定live選項,那麼只輸出活的對象到文件

-finalizerinfo 打印正等候回收的對象的信息.

-heap 打印heap的概要信息,GC使用的算法,heap的配置及wise heap的使用狀況.

-histo[:live] 打印每一個class的實例數目,內存佔用,類全名信息. VM的內部類名字開頭會加上前綴」*若是live子參數加上後,只統計活的對象數量

-permstat 打印classloadjvm heap長久層的信息包含每一個classloader的名字,活潑性,地址,classloader和加載的class數量另外,內部String的數量和佔用內存數也會打印出來

-F 強迫.pid沒有相應的時候使用-dump或者-histo參數在這個模式下,live子參數無效

-h | -help 打印輔助信息 

-J 傳遞參數給jmap啓動的jvm. 

pid 須要被打印配相信息的java進程id,能夠用jps查問.

4、使用示例

   jmap -histo 4939

[輸出較多這裏不貼了]

2jmap -dump:format=b,file=test.bin 4939

Dumping heap to /home/fenglb/test.bin ...

Heap dump file created

 

4   jmap -histo pid|head -n 30

  

 num     #instances         #bytes  class name
----------------------------------------------
   1:        117098      170232696  [B
   2:        204755      121325072  [I
   3:        651042       82624448  [C
   4:        414175        9940200  java.lang.String
   5:        141560        8732760  [Ljava.lang.Object;
   6:         40748        3585824  java.lang.reflect.Method
   7:         78318        2506176  java.util.HashMap$Node
   8:         30303        2477016  [S
   9:         21451        1962016  [Ljava.util.HashMap$Node;
  10:         54391        1855488  [Ljava.lang.String;
  11:         23772        1521408  java.util.regex.Matcher
  12:         53136        1275264  java.util.ArrayList
  13:         29266        1170640  java.util.LinkedHashMap$Entry
  14:         23997        1151856  java.util.StringTokenizer
  15:         34861        1115552  java.awt.Color
  16:         31430        1005760  java.lang.ref.WeakReference
  17:         17900        1002400  org.apache.jasper.compiler.Mark
  18:         41636         999264  java.lang.StringBuilder
  19:         30441         974112  java.util.concurrent.ConcurrentHashMap$Node
  20:         19761         948528  java.util.HashMap
  21:          8217         931240  java.lang.Class
  22:         41439         892720  [Ljava.lang.Class;
  23:         13799         772744  java.util.LinkedHashMap
  24:         10456         752832  java.util.regex.Pattern
  25:          9480         682560  org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo
  26:         19754         632128  java.util.Stack
  27:         14611         621080  [[C

  其中:

 

[C is a char[] [S is a short[] [I is a int[] [B is a byte[] [[I is a int[][]

相關文章
相關標籤/搜索