/**
* @description: 新生代Minor GC 示 例
* VM参数:-verbose:gc -XX:+PrintGCDetails -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8
* @author: xz
*/
public class Test {
private static final int _1MB = 1024 * 1024;
public static void main(String[] args) {
byte[] b1 = new byte[2*_1MB];
byte[] b2 = new byte[2*_1MB];
byte[] b3 = new byte[2*_1MB];
}
}
/**
* @description: 老年代Major GC/Full GC 示例
* VM参数:-verbose:gc -XX:+PrintGCDetails
* -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8
* -XX:PretenureSizeThreshold=3145728
* @author: xz
*/
public class Test {
private static final int _1MB = 1024 * 1024;
public static void main(String[] args) {
byte[] b1 = new byte[9*_1MB];
}
}
/**
* @description: 长期存活的对象将进入老年代的代码示例
* VM参数:-verbose:gc -XX:+PrintGCDetails
* -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8
* -XX:MaxTenuringThreshold=1
* @author: xz
*/
public class Test {
private static final int _1MB = 1024 * 1024;
public static void main(String[] args) {
byte[] b1 = new byte[_1MB/4];
//什么时候进入老年代取决于-XX:MaxTenuringThreshold 设置
byte[] b2 = new byte[4*_1MB];
byte[] b3 = new byte[4*_1MB];
byte[] b4 = null;
byte[] b5 = new byte[4*_1MB];
}
}
package com.xz.springboottest.day10;
/**
* @description: 长期存活的对象将进入老年代的代码示例
* VM参数:-verbose:gc -XX:+PrintGCDetails -Xms20M
* -Xmx20M -Xmn10M -XX:SurvivorRatio=8
* -XX:MaxTenuringThreshold=15
* @author: xz
*/
public class Test {
private static final int _1MB = 1024 * 1024;
public static void main(String[] args) {
byte[] b1 = new byte[_1MB/4];
//什么时候进入老年代取决于-XX:MaxTenuringThreshold 设置
byte[] b2 = new byte[4*_1MB];
byte[] b3 = new byte[4*_1MB];
byte[] b4 = null;
byte[] b5 = new byte[4*_1MB];
}
}
/**
* @description: 动态对象年龄判断 示例
* VM参数:-verbose:gc -XX:+PrintGCDetails -Xms20M
* -Xmx20M -Xmn10M -XX:SurvivorRatio=8
* -XX:MaxTenuringThreshold=15
* @author: xz
*/
public class Test {
private static final int _1MB = 1024 * 1024;
public static void main(String[] args) {
byte[] b1,b2,b3,b4;
b1 = new byte[_1MB/4];
//b1+b2大于Survivor空间一半
b2 = new byte[_1MB/4];
b3 = new byte[4*_1MB];
b4 = new byte[4*_1MB];
b4 = null;
b4 = new byte[4*_1MB];
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://wwwxz.blog.csdn.net/article/details/122952948
内容来源于网络,如有侵权,请联系作者删除!