GC 日志

VM 参数

-XX:+PrintGCDetails -Xms30M -Xmx30M -Xmn10M

代码

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;

public class Go {
    public static void main(String[] args) {
        System.out.println(Runtime.getRuntime().maxMemory());
        System.out.println(Runtime.getRuntime().totalMemory());

        while (true){
            RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
            String name = runtime.getName();
            System.out.println(name);
            System.out.println("good");
            try {

                Thread.sleep(5000);
                Object o = new Object();
                o =null;
                System.gc();

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

输出

  • jdk1.7.0_79
30408704
30408704
11852@DESKTOP-MR9A589
good
[GC [PSYoungGen: 2695K->890K(9216K)] 2695K->890K(29696K), 0.0037934 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC [PSYoungGen: 890K->0K(9216K)] [ParOldGen: 0K->847K(20480K)] 890K->847K(29696K) [PSPermGen: 3375K->3374K(21504K)], 0.0234197 secs] [Times: user=0.03 sys=0.00, real=0.02 secs]
11852@DESKTOP-MR9A589
good
[GC [PSYoungGen: 327K->96K(9216K)] 1174K->943K(29696K), 0.0009648 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC [PSYoungGen: 96K->0K(9216K)] [ParOldGen: 847K->731K(20480K)] 943K->731K(29696K) [PSPermGen: 3374K->3374K(21504K)], 0.0184578 secs] [Times: user=0.02 sys=0.00, real=0.02 secs] 
11852@DESKTOP-MR9A589
  • jdk1.8.0_111
30408704
30408704
14352@DESKTOP-MR9A589
good
[GC (System.gc()) [PSYoungGen: 2978K->1002K(9216K)] 2978K->1047K(29696K), 0.0185165 secs] [Times: user=0.00 sys=0.00, real=0.02 secs] 
[Full GC (System.gc()) [PSYoungGen: 1002K->0K(9216K)] [ParOldGen: 44K->937K(20480K)] 1047K->937K(29696K), [Metaspace: 3570K->3570K(1056768K)], 0.0103283 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
14352@DESKTOP-MR9A589
good
[GC (System.gc()) [PSYoungGen: 163K->32K(9216K)] 1101K->969K(29696K), 0.0004313 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC (System.gc()) [PSYoungGen: 32K->0K(9216K)] [ParOldGen: 937K->820K(20480K)] 969K->820K(29696K), [Metaspace: 3570K->3570K(1056768K)], 0.0058398 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
14352@DESKTOP-MR9A589

去掉while循环的输出

  • jdk1.7.0_79
30408704
30408704
4
3016@DESKTOP-MR9A589
good
[GC [PSYoungGen: 2689K->936K(9216K)] 2689K->936K(29696K), 0.0036288 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC [PSYoungGen: 936K->0K(9216K)] [ParOldGen: 0K->847K(20480K)] 936K->847K(29696K) [PSPermGen: 3375K->3374K(21504K)], 0.0210757 secs] [Times: user=0.02 sys=0.00, real=0.02 secs] 
Heap
 PSYoungGen      total 9216K, used 245K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 3% used [0x00000000ff600000,0x00000000ff63d7d0,0x00000000ffe00000)
  from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 20480K, used 847K [0x00000000fe200000, 0x00000000ff600000, 0x00000000ff600000)
  object space 20480K, 4% used [0x00000000fe200000,0x00000000fe2d3c28,0x00000000ff600000)
 PSPermGen       total 21504K, used 3381K [0x00000000f9000000, 0x00000000fa500000, 0x00000000fe200000)
  object space 21504K, 15% used [0x00000000f9000000,0x00000000f934d540,0x00000000fa500000)
  • jdk1.8.0_111
30408704
30408704
4
9712@DESKTOP-MR9A589
good
[GC (System.gc()) [PSYoungGen: 2978K->1016K(9216K)] 2978K->1042K(29696K), 0.0014384 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC (System.gc()) [PSYoungGen: 1016K->0K(9216K)] [ParOldGen: 26K->937K(20480K)] 1042K->937K(29696K), [Metaspace: 3571K->3571K(1056768K)], 0.0060659 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 9216K, used 82K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 1% used [0x00000000ff600000,0x00000000ff614920,0x00000000ffe00000)
  from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 20480K, used 937K [0x00000000fe200000, 0x00000000ff600000, 0x00000000ff600000)
  object space 20480K, 4% used [0x00000000fe200000,0x00000000fe2ea598,0x00000000ff600000)
 Metaspace       used 3578K, capacity 4536K, committed 4864K, reserved 1056768K
  class space    used 397K, capacity 428K, committed 512K, reserved 1048576K

含义

GC日志开头的 [GC[Full GC 说明了这次垃圾收集的停顿类型。如果有“Full”,说明这次GC是发生了Stop-The-World的 (不是用来区分新生代GC还是老年代GC的)。jdk1.8 中 (System.gc() :表示是调用 System.gc() 方法所触发的垃圾收集。

[PSYoungGen[ParOldGen表示GC发生的区域。区域名称与使用的GC收集器相关:

收集器新生代区域名称释义
Serial[DefNewDefault New Generation
ParNew[ParNewParallel NewGeneration
Parallel Scavenge[PSYoungGenParallel Scavenge Young Generation

[PSPermGen: 3375K->3374K(21504K)] :说明方法区(HotSpot虚拟机中的永久代,“永久”名字真是让人误解啊)是会发生垃圾回收的

[GC [PSYoungGen: 2695K->890K(9216K)] 2695K->890K(29696K), 0.0037934 secs] :【无STW【 Parallel Scavenge:GC前该内存区域已使用容量->GC后该内存区域已使用容量(该内存区域总容量)】GC前 java 堆已使用容量->GC后 java 堆已使用容量(java堆总容量),该内存区域GC所占用的时间,单位是秒】

[Times: user=0.00 sys=0.00, real=0.00 secs] :【用户态消耗的CPE时间,内核态消耗的CPU时间,操作从开始到结束所经过的总时间/墙钟时间(Wall Clock Time),单位是秒】。 有时user 或sys时间会超过real时间 ,是因为系统有多 CPU 或者多核,多线程操作会叠加这些 CPU 时间。

PSYoungGen total 9216K (def new generation total 9216K):新生代垃圾回收内存区域总大小为9216k,计算方法:eden space 8192K + from space 1024K。而 to space 1024K是用来通过复制算法存放存活对象的,不在回收区域之内。

ParOldGen total 20480K :老年代内存 20M。有时会看到 tenured generation 20480Ktenured:终身的;长期保有的;获终身聘用的;享有终身职位的这名字起的真是醉了。

Metaspace used 3578K(PSPermGen ) : 元空间(metaspace)3578K。持久代在 jdk1.8 中被彻底地删除后(jdk1.7没有彻底删除),它被一个叫元空间的区域所替代了。这样JVM会忽略PermSize和MaxPermSize这两个参数。jdk1.8 的HotSpot JVM现在使用的是本地内存来表示类的元数据,这个区域就叫做元空间。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值