JVM学习02:GC垃圾回收和内存分配

写在前面:本系列分享主要参考资料是  周志明老师的《深入理解Java虚拟机》第二版。

GC垃圾回收和内存分配知识要点Xmind梳理

 

 

 

案例分析1-(GC日志分析示例)

package com.hs.jvm;

import java.sql.Time;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class Test {

    public Object instance = null;
    private static final int _1MB = 1024 * 1024;

    //该成员属性存在的唯一目的就是占内存;
    private byte[] bigSize = new byte[2* _1MB];

    public static void main(String[] args){

        Test objA = new Test();
        Test objB = new Test();

        objA.instance = objB;
        objB.instance = objA;

        objA = null;
        objB = null;

        System.gc();

    }



/*
    [GC (System.gc()) [PSYoungGen: 9350K->4923K(76288K)] 9350K->4931K(251392K), 0.0047877 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
    [Full GC (System.gc()) [PSYoungGen: 4923K->0K(76288K)] [ParOldGen: 8K->4808K(175104K)] 4931K->4808K(251392K), [Metaspace: 3281K->3281K(1056768K)], 0.0113745 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]

    Heap
    PSYoungGen      total 76288K, used 655K [0x000000076ad80000, 0x0000000770280000, 0x00000007c0000000)
    eden space 65536K, 1% used [0x000000076ad80000,0x000000076ae23ee8,0x000000076ed80000)
    from space 10752K, 0% used [0x000000076ed80000,0x000000076ed80000,0x000000076f800000)
    to   space 10752K, 0% used [0x000000076f800000,0x000000076f800000,0x0000000770280000)
    ParOldGen       total 175104K, used 4808K [0x00000006c0800000, 0x00000006cb300000, 0x000000076ad80000)
    object space 175104K, 2% used [0x00000006c0800000,0x00000006c0cb23c0,0x00000006cb300000)
    Metaspace       used 3288K, capacity 4496K, committed 4864K, reserved 1056768K
    class space    used 359K, capacity 388K, committed 512K, reserved 1048576K
*/

    /**
     * GC :表示日志开始,如果是Full GC,表示发生了"stop the world"
     * System.gc(): 表示是通过System.gc()方法触发GC
     * PSYoungGen : 表示GC发生的区域,且区域名称和使用的GC收集器有关,比如PSYoungGen表示新生代(使用Parallel Scavenge收集器),DefNew表示新生代(使用Serial收集器)
     * 9350K->4923K(76288K):GC前该内存区域使用容量->GC后该内存区域已使用容量(该内存区域总容量)
     * 0.0047877 secs:表示该内存区域GC所占用的时间(单位秒)
     * [Times: user=0.00 sys=0.00, real=0.01 secs]:user、sys、real代表用户态小号的CPU时间、内核态消耗的CPU时间和操作从开始到结束所经过的墙钟时间
     * */

}

 

posted on 2019-04-26 14:25  我不吃番茄  阅读(196)  评论(0编辑  收藏  举报