我想在gc
时检查MaxTenuringThreshold的行为这是我的虚拟参数:
-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:+UseSerialGC -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=15 -XX:+PrintTenuringDistribution
这是我的计划:
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];
}
}
因为我已将MaxTenuringThreshold设置为15,我认为allocation1将位于from空格中,但结果是:
[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.
如你所见,从空间使用0%,为什么?我的jdk版本是:java版本" 1.7.0_79"
答案 0 :(得分:0)
MaxTenuringThreshold是暂停阈值的最大值。但是,JVM可以自由选择更短的阈值,例如1。
从空间使用0%,为什么?
你拥有的所有物品都很大,所以他们直接进入终身空间。 eden生成中的任何对象都将在JVM的正常运行/启动时创建,而不是由于您的代码直接生成。
https://stackoverflow.com/a/24620205/57695
我强烈建议将Java 7移至8或9.注意:Java 10将在3个月内发布。