Java Code:
package lime.jvm._003._006._002;
/**
* @Author : Liangmy
* @Description :
* @Date : Created in 2020/1/1 下午10:58
* @Modified By :
*/
/**
* VM Args : -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8
* java -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=3145728 -XX:+PrintGCDetails -verbose:gc -XX:+UseSerialGC lime.jvm._003._006._002.TestPretenureSizeThreshold
*/
public class TestPretenureSizeThreshold {
private static final int _1MB = 1024 * 1024;
public static void main(String[] args) {
testPretenureSizeThreshold();
}
private static void testPretenureSizeThreshold() {
byte[] allocation;
allocation = new byte[4 * _1MB]; // 直接分配在老年代中
}
}
Console :
liangmydeMacBook-Pro:_002 liangmy$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
liangmydeMacBook-Pro:_002 liangmy$ java -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=3145728 -XX:+PrintGCDetails -verbose:gc -XX:+UseSerialGC lime.jvm._003._006._002.TestPretenureSizeThreshold
Heap
def new generation total 9216K, used 835K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000)
eden space 8192K, 10% used [0x00000007bec00000, 0x00000007becd0f20, 0x00000007bf400000)
from space 1024K, 0% used [0x00000007bf400000, 0x00000007bf400000, 0x00000007bf500000)
to space 1024K, 0% used [0x00000007bf500000, 0x00000007bf500000, 0x00000007bf600000)
tenured generation total 10240K, used 4096K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000)
the space 10240K, 40% used [0x00000007bf600000, 0x00000007bfa00010, 0x00000007bfa00200, 0x00000007c0000000)
Metaspace used 2646K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 286K, capacity 386K, committed 512K, reserved 1048576K