f8b21af4be
10_Wiki/Topics 대규모 정리: - 오류 캡처/미완성 stub 문서 227개 제거 - 교차폴더 중복 43클러스터 병합 (63파일 → redirect) - 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건 - 카테고리 MOC 6개 신규 생성 - Graph 섹션 미해결 related-keyword 링크 10,058건 제거 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
184 lines
5.2 KiB
Markdown
184 lines
5.2 KiB
Markdown
---
|
|
id: wiki-2026-0508-자바-가상-머신-jvm
|
|
title: 자바 가상 머신(JVM)
|
|
category: 10_Wiki/Topics
|
|
status: verified
|
|
canonical_id: self
|
|
aliases: [JVM, Java Virtual Machine, HotSpot, OpenJDK]
|
|
duplicate_of: none
|
|
source_trust_level: A
|
|
confidence_score: 0.9
|
|
verification_status: applied
|
|
tags: [jvm, java, runtime, gc, jit, performance]
|
|
raw_sources: []
|
|
last_reinforced: 2026-05-10
|
|
github_commit: pending
|
|
tech_stack:
|
|
language: java
|
|
framework: jvm
|
|
---
|
|
|
|
# 자바 가상 머신(JVM)
|
|
|
|
## 매 한 줄
|
|
> **"매 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.
|
|
|
|
## 매 핵심
|
|
|
|
### 매 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.
|
|
|
|
### 매 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.
|
|
|
|
### 매 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.
|
|
|
|
### 매 GraalVM native-image
|
|
- 매 AOT compile → 매 startup 의 ms.
|
|
- 매 reflection 의 의 limit.
|
|
- 매 serverless / CLI 의 의 ideal.
|
|
|
|
## 💻 패턴
|
|
|
|
### 매 GC tuning (production)
|
|
```bash
|
|
# 매 ZGC, low-latency
|
|
java \
|
|
-XX:+UseZGC \
|
|
-Xmx16g \
|
|
-XX:+UseLargePages \
|
|
-XX:+AlwaysPreTouch \
|
|
-jar app.jar
|
|
|
|
# 매 G1, balanced
|
|
java \
|
|
-XX:+UseG1GC \
|
|
-Xmx8g \
|
|
-XX:MaxGCPauseMillis=200 \
|
|
-XX:G1HeapRegionSize=16m \
|
|
-jar app.jar
|
|
```
|
|
|
|
### 매 JFR (Java Flight Recorder) profiling
|
|
```bash
|
|
# 매 production-safe profiler
|
|
java \
|
|
-XX:StartFlightRecording=duration=60s,filename=app.jfr \
|
|
-jar app.jar
|
|
|
|
# 매 분석 — JDK Mission Control
|
|
jmc app.jfr
|
|
```
|
|
|
|
### 매 Heap dump (OOM analysis)
|
|
```bash
|
|
java \
|
|
-XX:+HeapDumpOnOutOfMemoryError \
|
|
-XX:HeapDumpPath=/tmp \
|
|
-jar app.jar
|
|
|
|
# 매 Eclipse MAT 의 의 의 분석
|
|
```
|
|
|
|
### 매 GraalVM native-image
|
|
```bash
|
|
# 매 Spring Boot 3.x 의 의 의 native build
|
|
./mvnw -Pnative native:compile
|
|
./target/app # 매 50-100ms 의 의 의 의 startup
|
|
```
|
|
|
|
### 매 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
|
|
- 변형: [[OpenJDK]]
|
|
- 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 |
|