JMAP 
打印出某个java进程内存内所有对象的情况(产生的对象以及数量) 
jmap -histo pid 打印jvm heap的直方图。其输出信息包括类名,对象数量,对象占用大小。 内容会比较多 不方便查看可以将其保存到文本中去。

(jmap -histo pid&;gt;histo.log) (注:其实就是将jmap结果重定向到文件中)
该命令检查内存泄漏 是很有用哦。 
[xxxxxxxx ~]$ more histo.log 
  
num     #instances         #bytes  class name 
———————————————- 
   1:        251510       39395232  [C 
   2:         53304       37733944  [I 
   3:         90608       12763752  
   4:         90608       10883664  
   5:        256090       10243600  java.lang.String 
   6:          8209        9233040  
   7:         74133        9109848  [B 
   8:        129787        6779512  
   9:          8209        6552912  
  10:        111943        6268808  java.util.HashMap$ValueIterator 
  11:         94562        6051968  java.util.TreeMap$Entry 
  12:          7083        5493440  
  13:        109800        5270400  org.apache.catalina.LifecycleEvent 
  14:         28087        5116800  [Ljava.lang.Object; 
  15:         34532        4681168  [Ljava.util.HashMap$Entry; 
  16:         27458        4173616  java.lang.reflect.Method 
  17:        109800        3498960  [Lorg.apache.catalina.Container; 
  18:         66949        3213552  java.util.HashMap$Entry 
  19:        109970        2771112  [Lorg.apache.catalina.LifecycleListener; 
  20:         32831        2101184  java.util.HashMap 
  21:         34327        1828320  [Ljava.lang.String; 
  22:         21356        1708480  java.util.TreeMap 
  23:          8785        1616440  java.lang.Class 
.................. 
通过多次jmap 可以发现某些class 的大小在上升,最终消耗的内存也在涨,那就是有内存泄漏问题
.................. 
jmap -dump:format=b,file=heap.log 12191 可以将12191 进程的内存heap输出出来到heap.log 文件里。 
jmap -heap pid(该命令我用的比较多) 打印出heap情况,可以观察到New Generation(Eden Space,From Space,To Space),tenured generation,Perm Generation的内存使用情况。 
[xxxxxxxx ~]$ jmap -heap 12191 
Attaching to process ID 12191, please wait… 
Debugger attached successfully. 
Server compiler detected. 
JVM version is 11.0-b16 
  
using parallel threads in the new generation. 
using thread-local object allocation. 
Concurrent Mark-Sweep GC 
  
Heap Configuration: 
   MinHeapFreeRatio = 40 
   MaxHeapFreeRatio = 70 
   MaxHeapSize      = 2147483648 (2048.0MB) 
   NewSize          = 268435456 (256.0MB) 
   MaxNewSize       = 268435456 (256.0MB) 
   OldSize          = 805306368 (768.0MB) 
   NewRatio         = 7 
   SurvivorRatio    = 8 
   PermSize         = 134217728 (128.0MB) 
   MaxPermSize      = 134217728 (128.0MB) 
  
Heap Usage: 
New Generation (Eden + 1 Survivor Space): 
   capacity = 241631232 (230.4375MB) 
   used     = 94646792 (90.26221466064453MB) 
   free     = 146984440 (140.17528533935547MB) 
   39.16993313182296% used 
Eden Space: 
   capacity = 214827008 (204.875MB) 
   used     = 67842568 (64.69971466064453MB) 
   free     = 146984440 (140.17528533935547MB) 
   31.580092573835035% used 
From Space: 
   capacity = 26804224 (25.5625MB) 
   used     = 26804224 (25.5625MB) 
   free     = 0 (0.0MB) 
   100.0% used 
To Space: 
   capacity = 26804224 (25.5625MB) 
   used     = 0 (0.0MB) 
   free     = 26804224 (25.5625MB) 
   0.0% used 
concurrent mark-sweep generation: 
   capacity = 1879048192 (1792.0MB) 
   used     = 74001208 (70.57305145263672MB) 
   free     = 1805046984 (1721.4269485473633MB) 
   3.9382283176694597% used 
Perm Generation: 
   capacity = 134217728 (128.0MB) 
   used     = 61586560 (58.7335205078125MB) 
   free     = 72631168 (69.2664794921875MB) 
   45.885562896728516% used 
  
jmap -permstat pid 打印permanent generation heap情况 
  
更多信息查看man jmap 
   OPTIONS 
          
             When  no  option  is used jmap prints shared object mappings. For each shared object loaded in the target 
             VM, start address, the size of the mapping, and the full path of the shared object file are printed. This 
             is similar to the Solaris pmap utility. 
  
          -dump:[live,]format=b,file= 
             Dumps  the  Java  heap  in hprof binary format to filename. The live suboption is optional. If specified, 
             only the live objects in the heap are dumped. To browse the heap dump, you can  use  jhat(1)  (Java  Heap 
             Analysis Tool) to read the generated file. 
  
          -finalizerinfo 
             Prints information on objects awaiting finalization. 
  
          -heap 
             Prints  a heap summary. GC algorithm used, heap configuration and generation wise heap usage are printed. 
  
          -histo[:live] 
             Prints a histogram of the heap. For each Java class, number of objects, memory size in bytes,  and  fully 
             qualified  class names are printed. VM internal class names are printed with ‘*’ prefix. If the live sub- 
             option is specified, only live objects are counted. 
  
          -permstat 
             Prints class loader wise statistics of permanent generation of Java heap.  For  each  class  loader,  its 
             name,  liveness,  address,  parent  class  loader,  and  the number and size of classes it has loaded are 
             printed. In addition, the number and size of interned Strings are printed. 
  
          -F Force. Use with jmap -dump or jmap -histo option if the pid does not respond. The live suboption  is  not 
             supported in this mode. 
  
          -h Prints a help message. 
  
          -help 
             Prints a help message. 
  
          -J 
             Passes  to the Java virtual machine on which jmap is run. 

posted on 2018-09-28 00:04  进_进  阅读(569)  评论(0)    收藏  举报