HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🌚
[New] 우기팀
/
득윤
득윤
/
🤖
JVM Internal
🤖

JVM Internal

JVM structure
JVM structure

Runtime Data Area

  • The pc Register
    • Each Java Virtual Machine thread has its own pc (program counter) register
    • 어느 시점에라도 각 JVM thread 는 하나의 메서드를 실행하고 있음
    • 그 메서드가 native 가 아니라면 pc 레지스터는 실행중인 JVM instruction의 주소를 가르킴
    • 그 메서드가 native 라면 pc 레지스터의 값은 정의되지 않음
    • pc 레지스터는 returnAddress 혹은 platform의 native pointer 를 담을 만큼 큼
 
  • JVM Stack
    • 모든 thread는 private 한 JVM stack을 가진다.
    • JVM stack은 frames를 저장한다.
    • JVM stack은 contiguous 하게 저장될 필요는 없다.
    • JVM stack의 size는 설정으로 제한될 수 있으며 심지어 동적으로 변경하여 최소 사이즈를 가지게 할 수도 있다.
    • JVM stack이 터지면 StackOverflowError 가 발생한다.
    • JVM stack을 동적으로 변경하여 확장하는 것을 시도하였으나 메모리가 부족한 경우 OutOfMemoryError 가 발생한다.
 
  • Heap
    • JVM은 모든 JVM threads간에 공유되는 heap을 하나 가진다.
    • heap은 run-time data 영역으로서 모든 class instances 와 arrays의 주소가 할당된다.
    • heap은 jvm start-up 단계에서 생성된다.
    • 객체의 heap저장 영역은 garbage collector 라고 불리는 automatic storage management system 에의해 reclaimed된다.
    • heap의 메모리는 contiguous 할 필요 없다.
    • heap의 크기는 고정되어 있을 수 도 있고 동적으로 변경될 수도 있다.
    • gc와 같은 automatic storage management system이 감당할 수 없을 정도로 많은 computation을 요구하게 heap이 구성된다면 JVM은 OutOfMemoryError을 던진다.
 
  • Method Area
    • JVM은 모든 JVM threads간에 공유되는 method area를 하나 가진다.
    • Method Area에는 per-class structures가 저장된다.
      • run-time constant pool
      • fields
      • method data
      • code for methods and construtors
    • Method Area는 jvm start-up 단계에서 생성된다.
    • Method Area의 메모리는 contiguous 할 필요 없다.
    • Method Area의 크기는 고정되어 있을 수 도 있고 동적으로 변경될 수도 있다.
    • 할당 받은 메모리 요청에대해 memory를 제공할 수 없을때 JVM은 OutOfMemoryError를 던진다.
 
  • Run-time Constant Pool
    • run-time constant pool은 per-class 혹은 per-interface인 constant_pool의 표현이다.
    • compile-time 에 알 수 있는 numeric literals 부터 run-time 에 resolve되어야하는 method 나 field에 대한 참조까지 처리한다.
    • 전통적인 cs에서의 symbol table과 비슷한 역할을 한다.
    • 각 run-time contant pool은 JVM의 method area에 할당된다.
    • run-time contant pool은 class 혹은 interface의 생성시 만들어진다.
    • class 혹은 interface 를 생성할때 성생의 run-time constant pool이 JVM method area에 이용가능한 것을 초과한다면 JVM은 OutOfMemoryError를 던진다.
 
typical symbol table in conventional programming languaes
typical symbol table in conventional programming languaes
 
  • Native Method Stacks
    • Native method 를 담기위한 stack이다.
      • Native Method - 자바가 아닌 언어에서 제공되는 메소드 e.g. C,C++
    • 일반적으로 JVM threads 별로 가지고 있으며 thread 의 생성, 소멸 시 함께 생성, 소멸됨
 
notion image
 
 
@) 참고 - 오라클 Run-time Data Areas