在阅读《深入理解Java虚拟机》中长期存活对象进入年老代这部分内容时,将书中代码运行了一遍,结果如下(运行环境:jdk1.8.0_172):
①当-XX:MaxTenuringThreshold=1时,运行结果与书中描述一致,allocation1对象在第二次GC发生时进入老年代。
[GC (Allocation Failure) [DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 1)
- age 1: 790240 bytes, 790240 total
: 5335K->771K(9216K), 0.0031656 secs] 5335K->4867K(19456K), 0.0032127 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 1)
: 4867K->0K(9216K), 0.0008847 secs] 8963K->4866K(19456K), 0.0009065 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 9216K, used 4178K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
eden space 8192K, 51% us