add demo for object memory location

This commit is contained in:
Jason Lu 2025-03-06 14:01:51 +08:00
parent 59dbea0ecc
commit ac6fe30cc1
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package jvm.gc;
/**
* VM Args: -verbose:gc -Xmx20M -Xms20M -Xmn10M -Xlog:gc* -XX:SurvivorRatio=8
* new objects by default will go to eden first, when eden has no enough space,
* it will trigger minor gc, and move objects from eden to old generation.
*/
public class MemoryAllocationYoung {
private static final int _1MB = 1024 * 1024;
public static void testAllocation() {
byte[] a,b,c,d;
a = new byte[2 * _1MB];
b = new byte[2 * _1MB];
c = new byte[2 * _1MB];
d = new byte[4 * _1MB];
}
public static void main(String[] args) {
testAllocation();
}
}

View File

@ -0,0 +1,24 @@
package jvm.gc;
/**
* VM Args: -verbose:gc -Xmx20M -Xms20M -Xmn10M -Xlog:gc+age=trace -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=1
* -verbose:gc -Xmx20M -Xms20M -Xmn10M -Xlog:gc+age=trace -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=15
*/
@SuppressWarnings("unused")
public class TenuringThreshold {
public static final int _1MB = 1024 * 1024;
public static void testTenuringThreshold() {
byte[] allocation1, allocation2, allocation3;
allocation1 = new byte[_1MB / 4];
allocation2 = new byte[4 * _1MB];
allocation3 = new byte[4 * _1MB];
allocation3 = null;
allocation3 = new byte[4 * _1MB];
}
public static void main(String[] args) {
testTenuringThreshold();
}
}