I wanna check the behavior for MaxTenuringThreshold when gc
this is my vm arguments:
-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:+UseSerialGC -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=15 -XX:+PrintTenuringDistribution
and this is my program:
public class TestTenuringThreshold {
private static final int _1MB = 1024 * 1024;
public static void main(String[] args) {
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];
}
}
as I have set MaxTenuringThreshold to 15, I think the allocation1 will be in the from space, but the result is:
[GC[DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 15)
- age 1: 750416 bytes, 750416 total
: 5188K->732K(9216K), 0.0041173 secs] 5188K->4828K(19456K), 0.0041663 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC[DefNew
Desired survivor size 524288 bytes, new threshold 15 (max 15)
- age 1: 136 bytes, 136 total
: 4913K->0K(9216K), 0.0018490 secs] 9009K->4827K(19456K), 0.0018711 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 9216K, used 4260K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
eden space 8192K, 52% used [0x00000000f9a00000, 0x00000000f9e28fd0, 0x00000000fa200000)
from space 1024K, 0% used [0x00000000fa200000, 0x00000000fa200088, 0x00000000fa300000)
to space 1024K, 0% used [0x00000000fa300000, 0x00000000fa300000, 0x00000000fa400000)
tenured generation total 10240K, used 4827K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
the space 10240K, 47% used [0x00000000fa400000, 0x00000000fa8b6dd8, 0x00000000fa8b6e00, 0x00000000fae00000)
compacting perm gen total 21248K, used 2718K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
the space 21248K, 12% used [0x00000000fae00000, 0x00000000fb0a78a0, 0x00000000fb0a7a00, 0x00000000fc2c0000)
No shared spaces configured.
as you see, the from space is 0% used, why? My jdk version is: java version "1.7.0_79"
The MaxTenuringThreshold is a maximum for the tenuring threshold. However the JVM is free to choose a much shorter threshold such as 1.
the from space is 0% used, why?
All the object you have are large so they go straight into the tenured space. Any objects in the eden generation will be created in the normal running/startup of the JVM, not due to your code directly.
https://stackoverflow.com/a/24620205/57695
I would strongly recommend moving off Java 7 to 8 or 9. Note: Java 10 will be released in 3 months.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.