GC시 구세대 공간 크기에 대한 의문.
-Xms18m
-Xmx18m
-Xmn16m
-XX:+UseSerialGC -XX:-UseAdaptiveSizePolicy
-XX:SurvivorRatio=6
-verbose:gc
-XX:+PrintGC
-XX:+PrintGCDetails
위의 JVM 매개 변수를 사용하여 아래 코드를 실행할 때 GC 로그의 구세대 총 용량은 4096K(4M)로 설정된 2M(18-16)과 다르다
[Tenured: 3072K->3072K(4096K), 0.0143395 secs]
여기에 주의해라. 괄호 안의 4096K는 구생대의 모든 공간이 2M이 아니라 4M이라는 것을 나타낸다.
-Xms24m-Xmx24m를 설정하면 정상입니다([Tenured: 6144K->6144K(8192K), 0.0129542 secs]).
이게 도대체 이유는요?
출력은 다음과 같습니다.
Minor GC should happen
[GC [DefNew (promotion failed): 11509K->11659K(14336K), 0.0123390 secs][Tenured: 3072K->3072K(4096K), 0.0143395 secs] 11509K->11413K(18432K), [Perm : 2075K->2075K(12288K)], 0.0333981 secs] [Times: user=0.01 sys=0.00, real=0.03 secs]
[Full GC [Tenured: 3072K->3072K(4096K), 0.0097443 secs] 13461K->13461K(18432K), [Perm : 2081K->2081K(12288K)], 0.0097931 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
[Full GC [Tenured: 3072K->3072K(4096K), 0.0177553 secs] 13461K->13448K(18432K), [Perm : 2081K->2075K(12288K)], 0.0178095 secs] [Times: user=0.01 sys=0.00, real=0.02 secs]
java.lang.OutOfMemoryError: Java heap space
Dumping heap to D:/D/myeclipse_dump.bin ...
Exception in thread "main"java.lang.OutOfMemoryError: Java heap space
at jvm.MultiMajorGCLog$MemoryObject.
at jvm.MultiMajorGCLog.testMain(MultiMajorGCLog.java:34)
at jvm.MultiMajorGCLog.main(MultiMajorGCLog.java:39)
Unable to create D:/D/myeclipse_dump.bin: File exists
Heap
def new generation total 14336K, used 10748K [0x02a00000, 0x03a00000, 0x03a00000)
eden space 12288K, 87% used [0x02a00000, 0x0347f088, 0x03600000)
from space 2048K, 0% used [0x03800000, 0x03800000, 0x03a00000)
to space 2048K, 0% used [0x03600000, 0x03600000, 0x03800000)
tenured generation total 4096K, used 3072K [0x03a00000, 0x03e00000, 0x03e00000)
the space 4096K, 75% used [0x03a00000, 0x03d00010, 0x03d00200, 0x03e00000)
compacting perm gen total 12288K, used 2082K [0x03e00000, 0x04a00000, 0x07e00000)
the space 12288K, 16% used [0x03e00000, 0x04008840, 0x04008a00, 0x04a00000)
No shared spaces configured.
package jvm;
public class MultiMajorGCLog
{
public static void testMain()
{
try
{
Thread.sleep(40);
}
catch (Exception e)
{
e.printStackTrace();
}
MemoryObject object1 = new MemoryObject(1024 * 1024 * 3);
MemoryObject object2 = new MemoryObject(1024 * 1024 * 3);
MemoryObject object3 = new MemoryObject(1024 * 1024 * 3);
MemoryObject object4 = new MemoryObject(1024 * 1024 * 2);
System.out.println("Minor GC should happen");
MemoryObject object5 = new MemoryObject(1024 * 1024 * 2);
MemoryObject object6 = new MemoryObject(1024 * 1024 * 2);
}
public static void main(String[] args)
{
testMain();
}
private static class MemoryObject
{
private byte[] bytes;
public MemoryObject(int objectSize)
{
this.bytes = new byte[objectSize];
}
}
}