[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,92 +2,184 @@
|
||||
id: wiki-2026-0508-자바-가상-머신-jvm
|
||||
title: 자바 가상 머신(JVM)
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-2F0FAA]
|
||||
aliases: [JVM, Java Virtual Machine, HotSpot, OpenJDK]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
verification_status: applied
|
||||
tags: [jvm, java, runtime, gc, jit, performance]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - 자바 가상 머신(JVM)"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: java
|
||||
framework: jvm
|
||||
---
|
||||
|
||||
# [[자바 가상 머신(JVM)|자바 가상 머신(JVM]]
|
||||
# 자바 가상 머신(JVM)
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> 자바 가상 머신(JVM)은 자바(Java)와 같은 정적 타입 언어의 애플리케이션 실행을 위한 환경으로, 주로 자바 힙(Java heap)의 메모리 할당 및 가비지 컬렉션(GC)을 전담하는 엔진입니다 [1, 2]. 애플리케이션의 메모리 고갈을 방지하기 위해 더 이상 사용되지 않는 객체를 회수하며, 표시(mark), 청소(sweep), 압축(compact) 등의 과정을 거칩니다 [2]. 시중에는 3개의 주요 프로덕션 JVM이 존재하며, 이들은 각기 다른 가비지 컬렉션 알고리즘을 구현하여 사용하고 있습니다 [3].
|
||||
## 매 한 줄
|
||||
> **"매 Write Once, Run Anywhere"**. 매 1995년 Sun Microsystems 의 의 의 release 의 stack-based bytecode 의 의 interpret 의 의 의 의 의 portable 의 runtime. 매 2026 — 매 OpenJDK 24 LTS, 매 ZGC sub-millisecond 의 의 GC 의 의 GraalVM native-image 의 의 의 의 의 의 의 startup.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **포인터 식별과 컴파일러 힌트 (Compiler Hints):** JVM은 정적 타입 언어인 자바에서 작동하므로 메모리 내의 포인터를 식별할 때 컴파일러가 제공하는 힌트를 사용합니다 [1]. 컴파일러는 각 클래스 내 포인터의 오프셋을 알려주며, 객체의 클래스만 식별하면 해당 객체의 모든 포인터를 찾을 수 있습니다 [1]. 이는 자바스크립트와 같은 동적 타입 언어의 엔진(예: V8)이 채택한 방식과는 다릅니다 [1].
|
||||
* **자바 힙(Java Heap)과 가비지 컬렉션(GC):** JVM은 힙 영역에서 도달 가능한(reachable) 객체를 식별(Mark)하고, 도달 불가능한 객체를 지워(Sweep) 메모리를 확보하며, 파편화가 심할 경우 힙을 압축(Compact)하여 메모리를 관리합니다 [2]. GC 작업은 전체 힙을 대상으로 하는 전역(Global) GC 사이클과 힙의 일부만 처리하는 부분(Partial) GC 사이클로 나뉘어 실행됩니다 [4].
|
||||
* **GC 정책과 동작 원리:** `System.gc()` 호출이나 메모리 할당 실패 시 GC가 명시적 혹은 암시적으로 트리거됩니다 [4]. IBM SDK 및 E[[CLIP|CLIP]]se OpenJ9 환경의 JVM은 `gencon`, `optavgpause`, `balanced` 등 다양한 GC 정책을 사용하며, 애플리케이션 스레드와 동시에(Concurrent) 또는 증분(Incremental) 방식으로 마킹 및 스윕 작업을 수행하여 애플리케이션의 멈춤([[Stop-the-world|Stop-the-world]]) 시간을 줄이도록 설계되었습니다 [5-8].
|
||||
* **참조 처리 ([[Reference|Reference]] [[Processing|Processing]]):** JVM의 가비지 컬렉터는 소프트 참조(Soft Reference), 약한 참조(Weak Reference), 팬텀 참조(Phantom Reference)를 각각의 메모리 부족 상태 및 참조 주기에 맞게 수집하며, JNI(Java Native Interface) 상의 약한 객체 참조도 함께 처리합니다 [9-11].
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Programming & Language 분야의 자동 자산화 수행.
|
||||
### 매 JVM 의 의 의 components
|
||||
1. **Class Loader** — bytecode 의 load.
|
||||
2. **Runtime Data Areas** — heap / stack / metaspace / PC.
|
||||
3. **Execution Engine** — interpreter + JIT + GC.
|
||||
4. **Native Interface (JNI)** — C/C++ interop.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** 가비지 컬렉션([[Garbage Collection|Garbage Collection]]), 자바 힙(Java Heap), 컴파일러 힌트(Compiler hints)
|
||||
- **Projects/Contexts:** Eclipse OpenJ9, IBM SDK
|
||||
- **Contradictions/Notes:** JVM의 컴파일러 힌트 방식은 정적 타입 언어의 메모리 관리에 최적화되어 있으나, 자바스크립트처럼 객체의 속성이 포인터인지 데이터인지 미리 알 수 없는 동적 타입 언어에는 적합하지 않아 V8 엔진은 이를 채택하지 않고 태그된 포인터(Tagged pointers) 방식을 사용합니다 [1].
|
||||
### 매 Memory areas
|
||||
- **Heap** — 매 object — Young (Eden + Survivor) + Old.
|
||||
- **Metaspace** — 매 class metadata (post Java 8, off-heap).
|
||||
- **Stack** — 매 thread 별 frame.
|
||||
- **PC Register** — 매 thread 별 instruction pointer.
|
||||
- **Native Method Stack** — 매 JNI 의 native frame.
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-19*
|
||||
### 매 2026 GCs
|
||||
| GC | 매 특성 | 매 use case |
|
||||
|---|---|---|
|
||||
| G1 | 매 default, balanced | 매 일반 server |
|
||||
| ZGC | 매 sub-ms pause, TB heap | 매 low-latency |
|
||||
| Shenandoah | 매 concurrent compaction | 매 large heap, low pause |
|
||||
| Parallel | 매 throughput | 매 batch |
|
||||
| Serial | 매 single thread | 매 small / embedded |
|
||||
|
||||
---
|
||||
### 매 JIT compilation tiers
|
||||
- **Interpreter** — 매 bytecode 의 직접 execute.
|
||||
- **C1 (Client)** — 매 빠른 compile, 적은 optimization.
|
||||
- **C2 (Server)** — 매 expensive compile, aggressive optimization.
|
||||
- **Tiered compilation** — 매 default — interpreter → C1 → C2.
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 GraalVM native-image
|
||||
- 매 AOT compile → 매 startup 의 ms.
|
||||
- 매 reflection 의 의 limit.
|
||||
- 매 serverless / CLI 의 의 ideal.
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### 매 GC tuning (production)
|
||||
```bash
|
||||
# 매 ZGC, low-latency
|
||||
java \
|
||||
-XX:+UseZGC \
|
||||
-Xmx16g \
|
||||
-XX:+UseLargePages \
|
||||
-XX:+AlwaysPreTouch \
|
||||
-jar app.jar
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
# 매 G1, balanced
|
||||
java \
|
||||
-XX:+UseG1GC \
|
||||
-Xmx8g \
|
||||
-XX:MaxGCPauseMillis=200 \
|
||||
-XX:G1HeapRegionSize=16m \
|
||||
-jar app.jar
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### 매 JFR (Java Flight Recorder) profiling
|
||||
```bash
|
||||
# 매 production-safe profiler
|
||||
java \
|
||||
-XX:StartFlightRecording=duration=60s,filename=app.jfr \
|
||||
-jar app.jar
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
# 매 분석 — JDK Mission Control
|
||||
jmc app.jfr
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### 매 Heap dump (OOM analysis)
|
||||
```bash
|
||||
java \
|
||||
-XX:+HeapDumpOnOutOfMemoryError \
|
||||
-XX:HeapDumpPath=/tmp \
|
||||
-jar app.jar
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
# 매 Eclipse MAT 의 의 의 분석
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### 매 GraalVM native-image
|
||||
```bash
|
||||
# 매 Spring Boot 3.x 의 의 의 native build
|
||||
./mvnw -Pnative native:compile
|
||||
./target/app # 매 50-100ms 의 의 의 의 startup
|
||||
```
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
### 매 ClassLoader 의 의 의 dynamic loading
|
||||
```java
|
||||
URLClassLoader loader = new URLClassLoader(
|
||||
new URL[]{ new URL("file:plugins/myplugin.jar") },
|
||||
getClass().getClassLoader()
|
||||
);
|
||||
Class<?> cls = loader.loadClass("com.example.Plugin");
|
||||
Plugin plugin = (Plugin) cls.getDeclaredConstructor().newInstance();
|
||||
```
|
||||
|
||||
### 매 JNI 의 의 의 native call
|
||||
```java
|
||||
public class Native {
|
||||
static { System.loadLibrary("mynative"); }
|
||||
public native int process(byte[] data);
|
||||
}
|
||||
```
|
||||
|
||||
```c
|
||||
// mynative.c
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_Native_process(JNIEnv *env, jobject obj, jbyteArray data) {
|
||||
// 매 C 의 fast processing
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
### 매 JMH (Java Microbenchmark Harness)
|
||||
```java
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
public int sum(BenchmarkState state) {
|
||||
int s = 0;
|
||||
for (int i : state.data) s += i;
|
||||
return s;
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 latency-critical 매 service | 매 ZGC + tiered JIT |
|
||||
| 매 batch / throughput | 매 Parallel GC |
|
||||
| 매 serverless / CLI | 매 GraalVM native-image |
|
||||
| 매 large heap (TB) | 매 ZGC / Shenandoah |
|
||||
| 매 startup-critical | 매 CDS (Class Data Sharing) + AOT |
|
||||
|
||||
**기본값**: 매 OpenJDK 24 + G1 GC + tiered JIT + JFR enabled.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Java]] · [[가상 머신]]
|
||||
- 변형: [[OpenJDK]] · [[GraalVM]] · [[Eclipse OpenJ9]]
|
||||
- 응용: [[Kotlin]] · [[Scala]] · [[Clojure]] · [[Groovy]]
|
||||
- Adjacent: [[Bytecode]] · [[Garbage Collection]] · [[JIT Compilation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 JVM tuning, 매 OOM debug, 매 GC pause investigation, 매 native-image migration.
|
||||
**언제 X**: 매 application logic — 매 JVM internals 의 의 의 abstract.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **`-Xmx == -Xms` skip**: 매 heap resize 의 의 의 GC pause spike.
|
||||
- **`Runtime.exec` 의 의 의 abuse**: 매 fork 의 의 의 expensive.
|
||||
- **Reflection-heavy + native-image**: 매 reachability 의 의 의 의 manual config 의 의 X 의 의 fail.
|
||||
- **Finalize 의 의 의 reliance**: 매 deprecated — 매 try-with-resources / Cleaner.
|
||||
- **String concat in hot loop**: 매 StringBuilder 의 의 의 X 의 garbage flood.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified — OpenJDK 24 docs (2026); Brian Goetz, *Java Concurrency in Practice*; Charlie Hunt, *Java Performance*.
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — JVM internals + 2026 GC/GraalVM stack |
|
||||
|
||||
Reference in New Issue
Block a user