JVM学习笔记1

1.运行时数据结构

2.堆分代

3.垃圾收集器

  • Parallel Scavenge收集器:新生代称为PSYoungGen,老年代称为ParOldGen,永久代称为Metaspace
  • ParNew收集器:新生代为ParNew
  • Serial收集器:新生代为DefNew

4.gc日志

package jvm;

public class GcTest {
	public static void main(String[] args) {
		System.out.println("垃圾回收前........");
		System.gc();
		System.out.println("垃圾回收后........");
	}

}

 控制台:

垃圾回收前........
[GC (System.gc()) [PSYoungGen: 1996K->816K(38400K)] 1996K->824K(125952K), 0.0010917 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC (System.gc()) [PSYoungGen: 816K->0K(38400K)] [ParOldGen: 8K->526K(87552K)] 824K->526K(125952K), [Metaspace: 2594K->2594K(1056768K)], 0.0072251 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
垃圾回收后........
Heap
 PSYoungGen      total 38400K, used 998K [0x00000000d5d00000, 0x00000000d8780000, 0x0000000100000000)
  eden space 33280K, 3% used [0x00000000d5d00000,0x00000000d5df9b20,0x00000000d7d80000)
  from space 5120K, 0% used [0x00000000d7d80000,0x00000000d7d80000,0x00000000d8280000)
  to   space 5120K, 0% used [0x00000000d8280000,0x00000000d8280000,0x00000000d8780000)
 ParOldGen       total 87552K, used 526K [0x0000000081600000, 0x0000000086b80000, 0x00000000d5d00000)
  object space 87552K, 0% used [0x0000000081600000,0x0000000081683a30,0x0000000086b80000)
 Metaspace       used 2600K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 288K, capacity 386K, committed 512K, reserved 1048576K

 4.判断对象是否可回收

(1)引用计数法

package jvm;

/**
 * 引用计数法:
 * 循环引用无法回收
 */
public class ReferenceCountgorithms {
	
	public Object instance;

	public static void main(String[] args) {
		ReferenceCountgorithms m1 = new ReferenceCountgorithms();
		ReferenceCountgorithms m2 = new ReferenceCountgorithms();
		
		m1.instance = m2;
		m2.instance = m1;
		
		m1 = null;
		m2 = null;
		
		System.gc();

	}

}

 (2)可达性分析法

5.垃圾收集算法

(1)标记-清除算法

(2)复制算法

主要针对新生代

(3)标记-整理-清除算法

主要针对老年代

(4)分代算法

6.垃圾收集器

(1)serial

单线程垃圾收集器

(2)ParNew

 

posted @ 2019-10-16 21:12  hy叶子  阅读(141)  评论(0编辑  收藏  举报