run() 메서드를 호출합니다. run() 메서드가 반환되는 경우 포착되지 않은 예외가 처리되며 OS 스레드는 종료되는 스레드가 마지막 스레드인지 판단해 JVM 종료 여부를 결정합니다(종료되는 스레드가 데몬 스레드가 아닌지를 의미합니다).Program Counter(PC)
Stack
Native Stack

Frame
ldc #3, invokevirtual #4 와 같은 메서드나 변수에 대한 참조는 실제 메모리 주소가 아닌 클래스 상수 풀에 있는 심볼릭 링크입니다. 아래 예시 코드와 바이트코드를 확인하면 실제 메모리 주소 없이 모두 클래스 파일의 상수 풀에 대한 심볼릭 참조로 대체되어 있습니다.
javap -v -p -s -sysinfo -constants classes/org/jvminternals/SimpleClass.class 명령어로 확인한 바이트 코드입니다.

이전 PermGen은 JVM에 의해서 크기가 강제되던 영역이었습니다. 하지만 Metatspace는 Native Memory로 OS가 자동으로 혹은 옵션을 통해 크기를 조절하도록 변경됐습니다. 이를 통해 예전 PermGen에서 발생하던 OOM 에러의 가능성이 더 낮아졌습니다.
Method area
interend strings
PermGen과 Metaspace가 저장하는 데이터의 종류
| Java 7의 PermGen (Hotspot 관리대상 O) | Java 8의 Metaspace(Native Memory(Off heap), Hotspot 관리대상 X) | |
|---|---|---|
| Class Metadata | O | O |
| Method Metadata | O | O |
| Interend String | O (GC 대상) | PermGen에서 Java Heap 영역으로 이동 (GC 대상) |
| Static Object 변수, 상수 | O | PermGen에서 Java Heap 영역으로 이동 (GC 대상) |
*Hotspot's representation of Java classes (referred to here as class meta-data) is currently stored in a portion of the Java heap referred to as the permanent generation. In addition, interned Strings and class static variables are stored in the permanent generation. The permanent generation is managed by Hotspot and must have enough room for all the class meta-data, interned Strings and class statics used by the Java application. Class metadata and statics are allocated in the permanent generation when a class is loaded and are garbage collected from the permanent generation when the class is unloaded. Interned Strings are also garbage collected when the permanent generation is GC'ed. (클래스 메타데이터라고 불리는) HotSpot이 자바 클래스를 표현하는 것은 현재(Java 7) Permanent generation(PermGen)이라고 불리는 자바 힙의 일부분에 저장되고 있습니다. 추가적으로 인턴된 String과 스태틱 변수들도 PermGen에 저장되죠. PermGen은 Hotspit에 의해 관리되며 자바 애플리케이션에 사용되는 모든 클래스 메타 데이터, 인턴된 String과 스태틱 변수들을 저장하기 위해 반드시 충분한 공간을 보유해야 합니다. 클래스 메타데이터와 스태틱 데이터들은 클래스가 로드될 때 PermGen에 할당되어 있다가 클래스가 언로드되면 PermGen에서 GC됩니다. Intern된 String 역시 PermGen이 GC될 때 같이 수집되죠.
The proposed implementation will allocate class meta-data in native memory and move interned Strings and class statics to the Java heap. Hotspot will explicitly allocate and free the native memory for the class meta-data. Allocation of new class meta-data would be limited by the amount of available native memory rather than fixed by the value of -XX:MaxPermSize, whether the default or specified on the command line. 이번에 제안된 구현은 네이티브 메모리에 클래스 메타데이터를 할당하고 인턴된 String과 클래스 스태틱들을 자바 힙으로 옮기는 것입니다. Hotspot은 이제 명시적으로 클래스 메타데이터를 위한 네이티브 메모리를 할당하고 해제할 겁니다. 새로운 클래스 메타 데이터의 할당은 -XX:MaxPermSize 옵션 값에 고정되지 않고 기본값으로 설정되어 있든, 커맨드 라인에서 지정하든 사용 가능한 메모리 양으로 제한되게 됩니다.
Allocation of native memory for class meta-data will be done in blocks of a size large enough to fit multiple pieces of class meta-data. Each block will be associated with a class loader and all class meta-data loaded by that class loader will be allocated by Hotspot from the block for that class loader. Additional blocks will be allocated for a class loader as needed. The block sizes will vary depending on the behavior of the application. The sizes will be chosen so as to limit internal and external fragmentation. Freeing the space for the class meta-data would be done when the class loader dies by freeing all the blocks associated with the class loader. Class meta-data will not be moved during the life of the class. 클레스 메타데이터를 네이티브 메모리에 할당하는 것은 클래스 메타데이터들의 여러 조각들에 알맞을만큼 충분한 크기에 블럭들 안에서 처리될 겁니다. 각 블럭들은 클래스 로더와 연결될 것이며, 해당 클래스 로더들에 의해 로드된 모든 클래스 메타데이터들은 클래스 로더에 대한 블록에서 핫스팟에 의해 할당되게 될겁니다. 필요하다면 클래스 로더에 추가적으로 블록들이 할당될 겁니다. 블록 사이즈는 애플리케이션의 동작에 따라 달라집니다. 그 크기는 내외부의 메모리 단편화를 제한하기 위해 선택됩니다. 클래스 메타데이터를 위한 메모리 공간을 해제하는 것은 클래스 로더와 관련된 모든 블록들이 해제되어 클래스 로더가 소멸될 때 수행됩니다. 클래스 메타데이터는 클래스의 라이프사이클 동안은 이동되지 않습니다.