JVM 与 jstat

 

JVM jstat

准备知识

Sun的   Java   HotSpot(热区)   虚拟机将堆划分成三块区域同时用了三种垃圾收集技术。将堆进行拆分的目的是允许为新建立的对象和旧对象使用不同的算法。   这种技术是因为大多数的Java对象是生命周期较短的对象。堆的三个块区域为:

  1. permanent space持久空间: 用于类和方法对象的存储

  2. old space 旧对象空间:用于建立一段时间的对象

  3. eden space 新对象空间:用于新建立的对象

新对象空间被进一步划分成3个子区域:  
      1Eden:所有的新建立的对象存储处。  
      2Survivor   Space   0   或   1:在新对象成为旧对象之前的对象存储处。

在服务启动时没有指定启动参数-verbose:gc,可通过jstat Java应用程序的资源和性能进行实时的命令行的监控,包括了对Heap size和垃圾回收状况的监控等等

使用jstat

执行jstat-gc 得到GC回收过程,要运行多次,通过比较来查看是否有内存泄露的可能.

Jstat –gc pid 间隔时间(默认是毫秒) 次数 (查看jstat --help)

S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT

320.0 320.0 128.0 0.0 22400.0 869.1 502144.0 491115.6 56064.0 33139.4 93108 1209.757 8 10.132 1219.889

320.0 320.0 128.0 0.0 22400.0 9067.6 502144.0 491115.6 56064.0 33139.4 93108 1209.757 8 10.132 1219.889

320.0 320.0 128.0 0.0 22400.0 18480.5 502144.0 491115.6 56064.0 33139.4 93108 1209.757 8 10.132 1219.889

320.0 320.0 128.0 0.0 22400.0 21662.6 502144.0 491115.6 56064.0 33139.4 93108 1209.757 8 10.132 1219.889

320.0 320.0 0.0 96.0 22400.0 4712.3 502144.0 491143.6 56064.0 33139.4 93109 1209.771 8 10.132 1219.903

320.0 320.0 0.0 96.0 22400.0 13482.3 502144.0 491143.6 56064.0 33139.4 93109 1209.771 8 10.132 1219.903

320.0 320.0 0.0 96.0 22400.0 21006.6 502144.0 491143.6 56064.0 33139.4 93109 1209.771 8 10.132 1219.903

320.0 320.0 136.0 0.0 22400.0 3065.5 502144.0 491167.6 56064.0 33139.4 93110 1209.786 8 10.132 1219.918

320.0 320.0 136.0 0.0 22400.0 10034.8 502144.0 491167.6 56064.0 33139.4 93110 1209.786 8 10.132 1219.918

320.0 320.0 136.0 0.0 22400.0 15687.6 502144.0 491167.6 56064.0 33139.4 93110 1209.786 8 10.132 1219.918

320.0 320.0 136.0 0.0 22400.0 22046.2 502144.0 491167.6 56064.0 33139.4 93110 1209.786 8 10.132 1219.918

320.0 320.0 0.0 144.0 22400.0 6664.2 502144.0 491191.6 56064.0 33139.4 93111 1209.799 8 10.132 1219.930

320.0 320.0 0.0 144.0 22400.0 12998.2 502144.0 491191.6 56064.0 33139.4 93111 1209.799 8 10.132 1219.930

320.0 320.0 0.0 144.0 22400.0 21305.5 502144.0 491191.6 56064.0 33139.4 93111 1209.799 8 10.132 1219.930

320.0 320.0 112.0 0.0 22400.0 9634.2 502144.0 491247.6 56064.0 33139.4 93112 1209.813 8 10.132 1219.945

320.0 320.0 112.0 0.0 22400.0 17039.8 502144.0 491247.6 56064.0 33139.4 93112 1209.813 8 10.132 1219.945

320.0 320.0 0.0 128.0 22400.0 7411.9 502144.0 491267.6 56064.0 33139.4 93113 1209.829 8 10.132 1219.960

320.0 320.0 0.0 128.0 22400.0 16995.1 502144.0 491267.6 56064.0 33139.4 93113 1209.829 8 10.132 1219.960

320.0 320.0 96.0 0.0 22400.0 4477.4 502144.0 491291.6 56064.0 33139.4 93114 1209.845 8 10.132 1219.977

320.0 320.0 96.0 0.0 22400.0 8164.9 502144.0 491291.6 56064.0 33139.4 93114 1209.845 8 10.132 1219.977

-gc Option

Garbage-collected heap statistics

Column

Description

S0C

Current survivor space 0 capacity (KB).

S1C

Current survivor space 1 capacity (KB).

S0U

Survivor space 0 utilization (KB).

S1U

Survivor space 1 utilization (KB).

EC

Current eden space capacity (KB).

EU

Eden space utilization (KB).

OC

Current old space capacity (KB).

OU

Old space utilization (KB).

PC

Current permanent space capacity (KB).

PU

Permanent space utilization (KB).

YGC

Number of young generation GC Events.

YGCT

Young generation garbage collection time.

FGC

Number of full GC events.

FGCT

Full garbage collection time.

GCT

Total garbage collection time.

XxxC:xxx容量

xxxU:xxx使用

 

 

 

u02 log/Developer> jstat -gcutil 26800 20000 20

S0 S1 E O P YGC YGCT FGC FGCT GCT

91.67 0.00 17.16 42.18 62.26 95012 1232.768 9 11.342 1244.109

0.00 75.00 37.25 42.21 62.26 95017 1232.838 9 11.342 1244.180

0.00 75.00 92.21 42.22 62.26 95021 1232.881 9 11.342 1244.223

87.52 0.00 35.94 42.25 62.26 95026 1232.943 9 11.342 1244.285

 

S0Heap上的 Survivor space 0 段已使用空间的百分比

S1Heap上的 Survivor space 1 段已使用空间的百分比

EHeap上的 Eden space 段已使用空间的百分比

OHeap上的 Old space 段已使用空间的百分比

PPerm space 已使用空间的百分比

YGC:从程序启动到采样时发生Young GC的次数

YGCTYoung GC所用的时间(单位秒)

FGC:从程序启动到采样时发生Full GC的次数

FGCTFull GC所用的时间(单位秒)

GCT:用于垃圾回收的总时间(单位秒)

 

-gcutil Option

Summary of Garbage Collection Statistics

Column

Description

S0

Survivor space 0 utilization as a percentage of the space's current capacity.

S1

Survivor space 1 utilization as a percentage of the space's current capacity.

E

Eden space utilization as a percentage of the space's current capacity.

O

Old space utilization as a percentage of the space's current capacity.

P

Permanent space utilization as a percentage of the space's current capacity.

YGC

Number of young generation GC events.

YGCT

Young generation garbage collection time.

FGC

Number of full GC events.

FGCT

Full garbage collection time.

GCT

Total garbage collection time.

 

 

通过指定虚拟机启动参数-verbose:gc,使得GC把回收垃圾的信息打印到控制台

Java –verbose:gc

[Full GC 168K->97K(1984K)0.0253873 secs]

箭头之前:168K是代表GC回收前对象占用的内存空间

箭头之后:97代表GC回收后对旬占用内存空间

说明有168K-97K=71K的对象容量被回收

括号里的1984代表堆heap内存总容量, 收集所需要的时间是0.0253873

 

参考文献

jstat - Java Virtual Machine Statistics Monitoring Tool

http://java.sun.com/javase/6/docs/technotes/tools/share/jstat.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值