JAVA

JVM 메모리 구조

icedstone 2025. 4. 19. 19:14
반응형

  1. Method Area
    • 클래스 정보(메서드, 필드, static 변수 등)를 저장
    • ClassLoader에 의해 로딩된 클래스들의 메타데이터가 올라간다.
    • Java 8 이전에는 PermGen, 이후에는 Metaspace로 대체됨
    • 모든 thread가 함께 사용
    • 해당 영역 안에 Runtime Constant Pool이 존재
  2. Heap Area
    • 모든 객체 인스턴스(new)가 생성되는 영역
    • GC의 주요 대상
    • 모든 thread가 함께 사용
  3. Stack Area
    • 메서드 호출 시 로컬 변수, 매개 변수, 리턴 주소 저장
  4. PC register
    • 현재 실행 중인 JVM 명령의 주소를 저장
  5. Native Method Stack
    • JVM이 아닌 Native code(C, C++ 등)를 실행할 때 사용하는 Stack
반응형

 

public class Example {
	// Member Variable => class 생성시 Heap Area에 저장
	String s1=  "Hello";

	// Class Variable => class 변수들은 classLoader에 의해 Class가 로드될 때 Method Area에 저장
	static String s2= "World";

	// final로 선언하면 Class Variable은 상수로 치환되어 Method Area내부 Constant Pool
	static final String s3= "JVM";

	public static void t1(int a) {// parameter Variable
	    // local Variable
		int b;
	}
}
  • stack area - local Variable , Parameter Variable
  • class(Methoed) area - Class Variable (static Variable)
  • heap area -Member Variable(Instance Variable)

함께 알아두면 좋을 정보

initial heap size: Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum. Before J2SE 5.0, the default initial heap size was a reasonable minimum, which varies by platform. You can override this default using the -Xms command-line option. maximum heap size: Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the default maximum heap size was 64MB. You can override this default using the -Xmx command-line option.

오라클 문서에 따르면 heap memory의 default 값에 대해서 다음과 같이 설명하고 있다.

최소 메모리 공간은

실제 장착된 메모리 크기의 1/64 or 64MB 중 큰 값

최대 메모리 공간은

실제 장착된 메모리 크기의 1/4 or 1GB 중 작은 값(J2SE 5.0 이전버전에서는 64MB)

-- 위 설명을 보면 J2SE 5.0 버전 기준으로 되어있는데 최신 버전(오라클 기준)에서도 특별한 변경사항은 없는 것으로 보여집니다.(JVM 24 기준)

 

반응형