Java VM Options

Java Hotspot VM 系列文章

先介绍一些基本概念:

1> Minor GC、Major GC和Full GC

这里写图片描述

1.1 Minor GC

从年轻代空间(包括 Eden 和 Survivor 区域)回收内存被称为 Minor GC
Collecting garbage from Young space (consisting of Eden and Survivor spaces) is called a Minor GC
但是,当发生Minor GC事件的时候,一些有趣的地方需要注意到:

(1).当 JVM 无法为一个新的对象分配空间时会触发 Minor GC,比如当 Eden 区满了。所以分配内存的频率越高,越频繁执行 Minor GC

(2).内存池被填满的时候,其中的内容全部会被复制,指针会从0开始跟踪空闲内存。Eden 和 Survivor 区进行了标记和复制操作,
取代了经典的标记、扫描、压缩、清理操作。所以 Eden 和 Survivor 区不存在内存碎片。写指针总是停留在所使用内存池的顶部。

(3).执行 Minor GC 操作时,不会影响到永久代,从永久代到年轻代的引用被当成 GC roots,从年轻代到永久代的引用在标记阶段被直接忽略掉。

(4).质疑常规的认知,所有的 Minor GC 都会触发“全世界的暂停(stop-the-world)”,停止应用程序的线程。对于大部分应用程序,停顿导致的延迟都是可以忽略不计的。其中的真相就 是,大部分 Eden 区中的对象都能被认为是垃圾,永远也不会被复制到 Survivor 区或者老年代空间。如果正好相反,Eden 区大部分新生对象不符合 GC 条件,Minor GC 执行时暂停的时间将会长很多

1.2 Major GC

Major GC is cleaning the Tenured space

One should notice that there is no formal definitions present for those terms. Neither in JVM specification nor in the Garbage Collection research papers. But on the first glance, building these definitions on top of what we know to be true about Minor GC cleaning Young space should be simple:
大家应该注意到,目前,Major GC, Full GC这些术语无论是在 JVM 规范还是在垃圾收集研究论文中都没有正式的定义

很不幸,实际上有点复杂且令人困惑。首先,许多 Major GC 是由 Minor GC 触发的,所以很多情况下将这两种 GC 分离是不太可能的。另一方面,许多现代垃圾收集机制会清理部分永久代空间,所以使用“cleaning”一词只是部分正确

1.3 Full GC

Full GC is cleaning the entire Heap – both Young and Tenured spaces

我们不用去关心到底是叫 Major GC 还是 Full GC,大家应该关注当前的 GC 是否停止了所有应用程序的线程,还是能够并发的处理而不用停掉应用程序的线程

reference from February 25, 2015 by Nikita Salnikov-Tarnovski
https://plumbr.eu/blog/garbage-collection/minor-gc-vs-major-gc-vs-full-gc

2> jstat

jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数]

vmid ==> Virtual Machine Identifier. 
A vmid takes the following form: <lvmid>[@<hostname>[:<port>]]
Where <lvmid> is the local vm identifier for the target
Java virtual machine, typically a process id; <hostname> is
the name of the host running the target Java virtual machine;
and <port> is the port number for the rmiregistry on the
target host. See the jvmstat documentation for a more complete
description of the Virtual Machine Identifier.

Example:
root@client:~# jstat -class 9581       //类加载统计
Loaded  Bytes  Unloaded  Bytes     Time   
  7605 15296.7       32    52.1       6.13
root@client:~# jstat -compiler 9581    //编译统计
Compiled Failed Invalid   Time   FailedType FailedMethod
    1666      1       0    32.72          1 java/lang/Class initAnnotationsIfNecessary
root@client:~# jstat -gccapacity  9581  //堆内存统计
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC      PGCMN    PGCMX     PGC       PC     YGC    FGC 
 87552.0 
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值