Inside the jvm

Preview:

Citation preview

Inside the JVMSTRUCTURE OF JAVA VIRTUAL MACHINE

Development Center @ Pikicast.com김병부 ( Benjamin )

Benjamin : about me

Pikicast Netmarble U-Angel Joins.com and etc

因果關係 : 인과관계

System Crash, Service Crash. Application Crash 서비스가 죽는 것은 항상 원인이 있습니다 시스템이 원인인지 , 어플리케이션이 원인인지 , 데이터 베이스가 원인인지 알아야 같은 현상을 막을 수 있습니다 . 서비스는 한번에 죽지 않습니다 . 서서히 죽어갈 뿐입니다 .

건강 검진 or 사후 검증 Thread dump Heap dump

List of JVM

List of JVM?? The Java Virtual Machine Specification

Hotspot JVM Open JVM IBM JVM TinyVM Dalvik JM ??

Stack Machine vs Register Machine

JVM : Java Virtual Machine #1

Class File Bytecode 의 집합 Interpreter / JIT Compiler

Java Stack Heap

Thread 들이 공유하는 메모리 영역 Method Area

Thread 들이 공유하는 메모리 영역 Class 변수 , 상수 , Class 정보 , Method 정보

Thread1st Keyword inside of the JVM

Thread State : java.lang.Thread.State

NEW RUNNABLE TIMED_WAITING WAITING BLOCKED TERMINATED

Since Java 1.5

Thread :list of thread in the Hotspot JVM

Thread 종류 Non – Daemon Thread :

E.g. Thread, VM Thread Daemon Thread :

Garbage Collector Thread, JMX Monitoring Thread System Threads

VM thread GC threads Periodic task thread – timer events i.e. interrupts for schedule Compiler thread – compiles byte code to native code in runtime

Thread: Multi-Thread

Each thread has .. Program Counter (PC) Stack Native stack Stack Frame

Multi Thread – Context Switching & Scheduling Thread-Safe

Keyword – synchronized

JVM Stack

JVM Stack per Thread!!! Stack Frame per Method

Local Variable Array Operand Stack Reference to Constant Pool

Thread dump: How to dump JVM Thread

jstack [pid] or kill –3 [pid]Thread Dump Date JVM Type, Mode

Thread name

Thread Priority Thread ID Native

Thread ID

Thread STATUS

Thread STACK info

Thread Dump Tool : IBM Thread and Monitor Dump Analyzer for Java

Heap Area2nd Keyword inside of the JVM

JVM Memory Structure: with JVM options

Basic Structure Depends on GC options Promotion Minor GC vs Major GC

Young Generation Old and Perm Generation STW – Stop the world

From Java8, No more PERM gen. Metaspace (Native Heap)

What is difference between Method Area and PERM GEN?

Actually the Method Area is a part of the PERM GEN

A third generation closely related to the tenured generation is the permanent generation. The permanent generation is special because it holds data needed by the virtual machine to describe objects that do not have an equivalence at the Java language level. For example objects describing classes and methods are stored in the permanent generation.

Thread and Heap: Reference from Stack to Heap

Stream API?

Garbage Collection

GC options Serial GC, Parallel GC – Mark, Sweep, Compact Incremental GC CMS G1GC

CMS vs G1GC

CMS GC Concurrent – Mark – Sweep GC more CPU,

G1GC Garbage-First GC Region Recommend over 4G memory

Heap Dump: How to dump JVM Heap

jmap –dump:format=b,file=[file name].hprof [PID] JVM 메모리 사이즈 만큼의 binary 파일이 생성된다 . Binary 파일이므로 분석툴이 필요함 .

Heap Dump Tool : IBM HeapAnalyzer Or Eclipse Memory Analyzer

OOME Case : Out Of Memory Exception

java.lang.OutOfMemoryError : Java heap space java.lang.OutOfMemoryError : PermGen space java.lang.OutOfMemoryError : Request array size exceeds VM

limit

ConclusionConclusion inside of the JVM

Note

Dump 는 10 초 간격으로 3 번씩 뜬다 . Perm 영역에서도 OOM 이 발생할 수도 있다 . Hotspot JVM > Open JVM Async Process 가 만능은 아님

MultiThread 도 Pool 로 관리하자 Thread-safe and Pool Management

우리에겐 G1GC 가 가장 맞는 케이스 Throughput based tuning Response time based tuning 튜닝의 끝은 순정

Thank you

Recommended