Java HotSpot(TM) 64-Bit Server VM (25.152-b16) for bsd-amd64 JRE (1.8.0_152-b16), built on Sep 14 2017 02:31:13 by "java_re" with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Memory: 4k page, physical 8388608k(189488k free)
/proc/meminfo:
CommandLine flags: -XX:InitialHeapSize=20971520 -XX:MaxHeapSize=20971520 -XX:MaxNewSize=10485760 -XX:NewSize=10485760 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:SurvivorRatio=8 -XX:-UseCompressedClassPointers -XX:-UseCompressedOops -XX:+UseSerialGC
0.191: [GC (Allocation Failure) 0.191: [DefNew: 6443K->679K(9216K), 0.0067661 secs] 6443K->4775K(19456K), 0.0069140 secs] [Times: user=0.00 sys=0.01, real=0.01 secs]
Heap
def new generation total 9216K, used 7145K [0x0000000103c00000, 0x0000000104600000, 0x0000000104600000)
eden space 8192K, 78% used [0x0000000103c00000, 0x0000000104250748, 0x0000000104400000)
from space 1024K, 66% used [0x0000000104500000, 0x00000001045a9f78, 0x0000000104600000)
to space 1024K, 0% used [0x0000000104400000, 0x0000000104400000, 0x0000000104500000)
tenured generation total 10240K, used 4096K [0x0000000104600000, 0x0000000105000000, 0x0000000105000000)
the space 10240K, 40% used [0x0000000104600000, 0x0000000104a00030, 0x0000000104a00200, 0x0000000105000000)
Metaspace used 3187K, capacity 4112K, committed 4352K, reserved 8192K
packageidv.java.jvm.gc.memoryallocate.pretenure;/** * @author Carl Lu * VM args: -Xloggc:gclog-PretenureDemo.log -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:+UseSerialGC -XX:PretenureSizeThreshold=3145728 -XX:-UseCompressedClassPointers -XX:-UseCompressedOops * Here we use 3145728(byte) to represent 3MB since this can not be written as 3M for "PretenureSizeThreshold". * 3145728/1024/1024 = 3(MB) */publicclassPretenureDemo {privatestaticfinalint _1MB =1024*1024;publicstaticvoidmain(String[] args) {byte[] allocatetion; allocatetion =newbyte[4* _1MB]; }}
GC log如下:
Java HotSpot(TM) 64-Bit Server VM (25.152-b16) for bsd-amd64 JRE (1.8.0_152-b16), built on Sep 14 2017 02:31:13 by "java_re" with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Memory: 4k page, physical 8388608k(211428k free)
/proc/meminfo:
CommandLine flags: -XX:InitialHeapSize=20971520 -XX:MaxHeapSize=20971520 -XX:MaxNewSize=10485760 -XX:NewSize=10485760 -XX:PretenureSizeThreshold=3145728 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:SurvivorRatio=8 -XX:-UseCompressedClassPointers -XX:-UseCompressedOops -XX:+UseSerialGC
Heap
def new generation total 9216K, used 2550K [0x0000000104800000, 0x0000000105200000, 0x0000000105200000)
eden space 8192K, 31% used [0x0000000104800000, 0x0000000104a7daf0, 0x0000000105000000)
from space 1024K, 0% used [0x0000000105000000, 0x0000000105000000, 0x0000000105100000)
to space 1024K, 0% used [0x0000000105100000, 0x0000000105100000, 0x0000000105200000)
tenured generation total 10240K, used 4096K [0x0000000105200000, 0x0000000105c00000, 0x0000000105c00000)
the space 10240K, 40% used [0x0000000105200000, 0x0000000105600018, 0x0000000105600200, 0x0000000105c00000)
Metaspace used 3296K, capacity 4112K, committed 4352K, reserved 8192K
Java HotSpot(TM) 64-Bit Server VM (25.152-b16) for bsd-amd64 JRE (1.8.0_152-b16), built on Sep 14 2017 02:31:13 by "java_re" with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Memory: 4k page, physical 8388608k(206472k free)
/proc/meminfo:
CommandLine flags: -XX:InitialHeapSize=20971520 -XX:MaxHeapSize=20971520 -XX:MaxNewSize=10485760 -XX:MaxTenuringThreshold=15 -XX:NewSize=10485760 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:SurvivorRatio=8 -XX:-UseCompressedClassPointers -XX:-UseCompressedOops -XX:+UseSerialGC
0.281: [GC (Allocation Failure) 0.281: [DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 15)
- age 1: 1048576 bytes, 1048576 total
: 7158K->1024K(9216K), 0.0073013 secs] 7158K->5326K(19456K), 0.0074506 secs] [Times: user=0.01 sys=0.01, real=0.00 secs]
0.290: [GC (Allocation Failure) 0.290: [DefNew
Desired survivor size 524288 bytes, new threshold 15 (max 15)
: 5120K->0K(9216K), 0.0034517 secs] 9422K->5326K(19456K), 0.0035425 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
Heap
def new generation total 9216K, used 4178K [0x0000000110800000, 0x0000000111200000, 0x0000000111200000)
eden space 8192K, 51% used [0x0000000110800000, 0x0000000110c14970, 0x0000000111000000)
from space 1024K, 0% used [0x0000000111000000, 0x0000000111000000, 0x0000000111100000)
to space 1024K, 0% used [0x0000000111100000, 0x0000000111100000, 0x0000000111200000)
tenured generation total 10240K, used 5326K [0x0000000111200000, 0x0000000111c00000, 0x0000000111c00000)
the space 10240K, 52% used [0x0000000111200000, 0x00000001117339c8, 0x0000000111733a00, 0x0000000111c00000)
Metaspace used 3303K, capacity 4112K, committed 4352K, reserved 8192K
沒發生promotion的情況(把程式的13跟14行註解掉就可以看到這個結果了):
Java HotSpot(TM) 64-Bit Server VM (25.152-b16) for bsd-amd64 JRE (1.8.0_152-b16), built on Sep 14 2017 02:31:13 by "java_re" with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Memory: 4k page, physical 8388608k(232432k free)
/proc/meminfo:
CommandLine flags: -XX:InitialHeapSize=20971520 -XX:MaxHeapSize=20971520 -XX:MaxNewSize=10485760 -XX:MaxTenuringThreshold=15 -XX:NewSize=10485760 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:SurvivorRatio=8 -XX:-UseCompressedClassPointers -XX:-UseCompressedOops -XX:+UseSerialGC
0.305: [GC (Allocation Failure) 0.305: [DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 15)
- age 1: 976104 bytes, 976104 total
: 6902K->953K(9216K), 0.0034486 secs] 6902K->953K(19456K), 0.0036413 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
Heap
def new generation total 9216K, used 5215K [0x000000011b400000, 0x000000011be00000, 0x000000011be00000)
eden space 8192K, 52% used [0x000000011b400000, 0x000000011b8299b0, 0x000000011bc00000)
from space 1024K, 93% used [0x000000011bd00000, 0x000000011bdee4e8, 0x000000011be00000)
to space 1024K, 0% used [0x000000011bc00000, 0x000000011bc00000, 0x000000011bd00000)
tenured generation total 10240K, used 0K [0x000000011be00000, 0x000000011c800000, 0x000000011c800000)
the space 10240K, 0% used [0x000000011be00000, 0x000000011be00000, 0x000000011be00200, 0x000000011c800000)
Metaspace used 3298K, capacity 4112K, committed 4352K, reserved 8192K