Skip to content

Instantly share code, notes, and snippets.

@rednaxelafx
Created May 2, 2011 16:15
Show Gist options
  • Save rednaxelafx/951852 to your computer and use it in GitHub Desktop.
Save rednaxelafx/951852 to your computer and use it in GitHub Desktop.
A demo on GC performance impact differences between an int[] and an Integer[] (on 64-bit HotSpot VM, 19.0-b09)
# print out GC detail log
+PrintGCDetails
# make the GC logs simpler by disabling a scavenge before the System.gc()s
-ScavengeBeforeFullGC
# set heap size big enough to hold the array in the demo
InitialHeapSize=2g
MaxHeapSize=2g
rednaxelafx@fx-laptop:~/experiment/test_gc_on_array$ javac *.java
[GC [PSYoungGen: 3071K->480K(3584K)] 3071K->624K(9088K), 0.0019430 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[GC [PSYoungGen: 3552K->500K(6656K)] 3696K->900K(12160K), 0.0021050 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC [PSYoungGen: 6644K->480K(6656K)] 7044K->3256K(12160K), 0.0065920 secs] [Times: user=0.02 sys=0.01, real=0.01 secs]
Heap
PSYoungGen total 6656K, used 1377K [0x00000007d5560000, 0x00000007d6260000, 0x0000000800000000)
eden space 6144K, 14% used [0x00000007d5560000,0x00000007d5640620,0x00000007d5b60000)
from space 512K, 93% used [0x00000007d5b60000,0x00000007d5bd8010,0x00000007d5be0000)
to space 512K, 0% used [0x00000007d61e0000,0x00000007d61e0000,0x00000007d6260000)
PSOldGen total 5504K, used 2776K [0x0000000780000000, 0x0000000780560000, 0x00000007d5560000)
object space 5504K, 50% used [0x0000000780000000,0x00000007802b62a8,0x0000000780560000)
PSPermGen total 21248K, used 6710K [0x000000077ae00000, 0x000000077c2c0000, 0x0000000780000000)
object space 21248K, 31% used [0x000000077ae00000,0x000000077b48daa8,0x000000077c2c0000)
rednaxelafx@fx-laptop:~/experiment/test_gc_on_array$ java TestGCOnObjArray
[Full GC (System) [PSYoungGen: 10485K->0K(611648K)] [PSOldGen: 1048576K->1048698K(1398144K)] 1059061K->1048698K(2009792K) [PSPermGen: 2455K->2455K(21248K)], 0.4995350 secs] [Times: user=0.49 sys=0.00, real=0.51 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2455K->2455K(21248K)], 0.4879070 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2455K->2455K(21248K)], 0.4867910 secs] [Times: user=0.48 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2456K->2455K(21248K)], 0.4868760 secs] [Times: user=0.47 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2455K->2455K(21248K)], 0.4850960 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2456K->2456K(21248K)], 0.4956240 secs] [Times: user=0.49 sys=0.00, real=0.50 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2456K->2456K(21248K)], 0.4847460 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2456K->2456K(21248K)], 0.4847160 secs] [Times: user=0.48 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2456K->2456K(21248K)], 0.4844560 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2456K->2456K(21248K)], 0.4839500 secs] [Times: user=0.47 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2457K->2457K(21248K)], 0.4843830 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2457K->2457K(21248K)], 0.4846170 secs] [Times: user=0.48 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2457K->2457K(21248K)], 0.4839090 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2457K->2457K(21248K)], 0.4843670 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2458K->2458K(21248K)], 0.4839430 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2458K->2458K(21248K)], 0.4886090 secs] [Times: user=0.49 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2458K->2458K(21248K)], 0.4849800 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2458K->2458K(21248K)], 0.4845540 secs] [Times: user=0.49 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2459K->2459K(21248K)], 0.4840550 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2460K->2460K(21248K)], 0.4842400 secs] [Times: user=0.48 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2460K->2460K(21248K)], 0.4838270 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2460K->2460K(21248K)], 0.4840260 secs] [Times: user=0.47 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2460K->2460K(21248K)], 0.4844260 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2460K->2460K(21248K)], 0.4836710 secs] [Times: user=0.47 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2461K->2461K(21248K)], 0.4839770 secs] [Times: user=0.47 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2461K->2461K(21248K)], 0.4837020 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2461K->2461K(21248K)], 0.4841620 secs] [Times: user=0.47 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2461K->2461K(21248K)], 0.4839610 secs] [Times: user=0.48 sys=0.00, real=0.49 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2461K->2461K(21248K)], 0.4861230 secs] [Times: user=0.48 sys=0.00, real=0.48 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2462K->2462K(21248K)], 0.4848980 secs] [Times: user=0.48 sys=0.00, real=0.49 secs]
Heap
PSYoungGen total 611648K, used 10485K [0x00000007d5560000, 0x0000000800000000, 0x0000000800000000)
eden space 524288K, 2% used [0x00000007d5560000,0x00000007d5f9d778,0x00000007f5560000)
from space 87360K, 0% used [0x00000007faab0000,0x00000007faab0000,0x0000000800000000)
to space 87360K, 0% used [0x00000007f5560000,0x00000007f5560000,0x00000007faab0000)
PSOldGen total 1398144K, used 1048698K [0x0000000780000000, 0x00000007d5560000, 0x00000007d5560000)
object space 1398144K, 75% used [0x0000000780000000,0x00000007c001ea60,0x00000007d5560000)
PSPermGen total 21248K, used 2472K [0x000000077ae00000, 0x000000077c2c0000, 0x0000000780000000)
object space 21248K, 11% used [0x000000077ae00000,0x000000077b06a058,0x000000077c2c0000)
rednaxelafx@fx-laptop:~/experiment/test_gc_on_array$ java TestGCOnIntArray
[Full GC (System) [PSYoungGen: 10485K->0K(611648K)] [PSOldGen: 1048576K->1048698K(1398144K)] 1059061K->1048698K(2009792K) [PSPermGen: 2454K->2454K(21248K)], 0.0060180 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2454K->2454K(21248K)], 0.0066290 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2454K->2454K(21248K)], 0.0055670 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2454K->2453K(21248K)], 0.0060790 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2453K->2453K(21248K)], 0.0047910 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2453K->2453K(21248K)], 0.0084110 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2453K->2453K(21248K)], 0.0088630 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2453K->2453K(21248K)], 0.0050810 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2454K->2454K(21248K)], 0.0050360 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2454K->2454K(21248K)], 0.0051530 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2454K->2454K(21248K)], 0.0049720 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2454K->2454K(21248K)], 0.0048470 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2454K->2454K(21248K)], 0.0054160 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2455K->2455K(21248K)], 0.0047110 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2455K->2455K(21248K)], 0.0047060 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2455K->2455K(21248K)], 0.0048040 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2455K->2455K(21248K)], 0.0046170 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2455K->2455K(21248K)], 0.0051070 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2456K->2456K(21248K)], 0.0051900 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2456K->2456K(21248K)], 0.0049790 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2456K->2456K(21248K)], 0.0049050 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2457K->2457K(21248K)], 0.0046750 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2457K->2457K(21248K)], 0.0049900 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2457K->2457K(21248K)], 0.0049790 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2457K->2457K(21248K)], 0.0048840 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2458K->2458K(21248K)], 0.0048670 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2458K->2458K(21248K)], 0.0053460 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2458K->2458K(21248K)], 0.0049690 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2459K->2459K(21248K)], 0.0048600 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[Full GC (System) [PSYoungGen: 0K->0K(611648K)] [PSOldGen: 1048698K->1048698K(1398144K)] 1048698K->1048698K(2009792K) [PSPermGen: 2459K->2459K(21248K)], 0.0048350 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
PSYoungGen total 611648K, used 10485K [0x00000007d5560000, 0x0000000800000000, 0x0000000800000000)
eden space 524288K, 2% used [0x00000007d5560000,0x00000007d5f9d778,0x00000007f5560000)
from space 87360K, 0% used [0x00000007faab0000,0x00000007faab0000,0x0000000800000000)
to space 87360K, 0% used [0x00000007f5560000,0x00000007f5560000,0x00000007faab0000)
PSOldGen total 1398144K, used 1048698K [0x0000000780000000, 0x00000007d5560000, 0x00000007d5560000)
object space 1398144K, 75% used [0x0000000780000000,0x00000007c001ea60,0x00000007d5560000)
PSPermGen total 21248K, used 2470K [0x000000077ae00000, 0x000000077c2c0000, 0x0000000780000000)
object space 21248K, 11% used [0x000000077ae00000,0x000000077b069a80,0x000000077c2c0000)
public class TestGCOnIntArray {
public static final int LENGTH = 0x10000000;
public static final int TIMES = 30;
public static void main(String[] args) {
int[] array = new int[LENGTH];
for (int i = 0; i < TIMES; i++) {
System.gc();
}
}
}
public class TestGCOnObjArray {
public static final int LENGTH = 0x10000000;
public static final int TIMES = 30;
public static void main(String[] args) {
Integer[] array = new Integer[LENGTH];
for (int i = 0; i < TIMES; i++) {
System.gc();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment