83
/83 The JVM 2015.06 Gun Lee 1

The JVM - Internal ( 스터디 자료 )

Embed Size (px)

Citation preview

Page 1: The JVM - Internal ( 스터디 자료 )

/83

The JVM

2015.06 Gun Lee

1

Page 2: The JVM - Internal ( 스터디 자료 )

/83 2

JVM에 대해 스터디하던 내용을

정리하여 공유합니다.

많은 부분이 엑셈에서 출판된

Java Performance Fundmental(김한도 저)

에서 발췌하였습니다.

제 슬라이드는 단지 이에 대한 소개이므로

더 깊은 내용은 위 도서를 직접 보시는 것을 강추!! 드립니다. ^^

Page 3: The JVM - Internal ( 스터디 자료 )

/83

What is the JVM?

3

Page 4: The JVM - Internal ( 스터디 자료 )

/83

What is the JVM?

4

… is Java virtual Machine…

Page 5: The JVM - Internal ( 스터디 자료 )

/83

What is the JVM?

5

Write Once, run everywhere

Page 6: The JVM - Internal ( 스터디 자료 )

/83

What is the JVM?

6

JVM Architecture

Page 7: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

7

Page 8: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

8

bytecode

Page 9: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

9

source

Page 10: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

10

javap –c

bytecode

Page 11: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

11

javap –verbose

Page 12: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

12

Constant pool

Page 13: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

13

opcode, operand

Page 14: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

14

classloader

Page 15: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

15

Namespace

- classloader 마다 존재

- class의 구분 namespace + full qualified name

Page 16: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

16

Namespace

Page 17: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

17

delegation model

class visibility

Parent first

Page 18: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

18

ClassNotFoundException

!

Page 19: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

19

Classloader Tree in WAS

Isolating the Application from other Applications

Sharing Class between deployed module

Page 20: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

20

Classloader Tree in WAS

Page 21: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

21

parent-first, child-last?

Page 22: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

22

parent-first, child-last?

Not always

Page 23: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

23

parent-first, child-last?

- Tomcat Bootstrap System WEB-INF/classes/* WEB-INF/lib/* Common Vendor specific extensions!

Page 24: The JVM - Internal ( 스터디 자료 )

/83

Class, Classloader

24

Class

Classloader

constant pool bytecode local variable table

namespace delegation model - parent first

Page 25: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

25

Page 26: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

26

execute bytecodes

Page 27: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

27

Interpreter

JIT(Just In Time) Compiler

Page 28: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

28

Interpreter

read the bytecode line by line

no optimization

parsing & executing

해석시간은 짧으나 실행시간은 길다!

Page 29: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

29

JIT Compiler

loads the whole method

generates native code

optimization

Native로 컴파일 하는 시간이 긺

여러 번 호출시 이득

Page 30: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

30

JIT Compiler

Page 31: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

31

Hotspot Compiler

Mixed mode system

Page 32: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

32

Hotspot Compiler

Page 33: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

33

Server VM vs Client VM

Page 34: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

34

Server VM vs Client VM

Server VM – advanced adaptive compiler runtime performance profiling, optimizing

Client VM - better for GUI run faster smaller memory footprint

Page 35: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

35

Profiling & Optimization

Page 36: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

36

Profiling & Optimization

Page 37: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

37

Profiling & Optimization

Page 38: The JVM - Internal ( 스터디 자료 )

/83

Execution Engine

38

JVM Options

-Xint

-XX:CompileThreshold=<value> Client:1,500, Server:10,000

-Xcomp

Page 39: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

39

Page 40: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

40

Runtime Data Area

Page 41: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

41

Runtime Data Area

Page 42: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

42

Method area and Heap shared among all threads

Page 43: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

43

Method area

Page 44: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

44

Method area Type Information (Runtime) Constant Pool field Information Method Information

(& bytecode) Class Variables …

Page 45: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

45

Method area Type Information (Runtime) Constant Pool field Information Method Information

(& bytecode) Class Variables …

Class??

Page 46: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

46

Heap

a = new myObj();

b = new myObj();

Heap

Method Area Class

obj

obj

Page 47: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

47

Heap

Check it out later…

The chapter. Garbage Collection

Page 48: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

48

exclusive to each thread

Page 49: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

49

PC register(Program counter)

contains the address of the Java Virtual Machine instruction currently being executed

Page 50: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

50

JVM Stacks

Stack Trace

Page 51: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

51

stack trace

stackframe

Page 53: The JVM - Internal ( 스터디 자료 )

/83

Runtime Data Area

53

Runtime Data Area

Page 54: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

54

Page 55: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

55

GC ????

Stop the World !!

Out of Memory !!

Page 56: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

56

GC of Hotspot JVM

Weak Generation Hypothesis - High Infant Mortality

Page 57: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

57

Heap of Hotspot JVM

Page 58: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

58

GC & Reachability

Page 59: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

59

GC & Reachability

Page 60: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

60

Bump the pointer & TLAB (Thread Local Allocation Barrier)

Page 61: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

61

Mark alive object

--> Reachable from Rootset.

reference from Old Gen???

Page 62: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

62

Card Table & Write Barrier

1 byte card per 512 byte Old gen.

Page 63: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

63

Card Table & Write Barrier

Page 64: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

64

Minor GC - young Gen. Mark & Copy

Page 65: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

65

Full GC - Old Gen. Mark & sweep & compaction

Page 66: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

66

Parallel Collector – young gen.

Page 67: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

67

Parallel Collector – young gen.

Options

-XX:+UseParallelGC

-XX:ParallelGCThreds=<value>

Page 68: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

68

Parallel Compacting Collector - old Gen.

Page 69: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

69

Parallel Compacting Collector

Options

-XX:+UseParallelOldGC (+Java6)

Page 70: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

70

Parallel Compacting Collector

Options

-XX:+UseParallelOldGC (+Java6)

Page 71: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

71

CMS Collector – Old Gen

Page 72: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

72

CMS Collector – Old Gen

short pausing time No Compaction

-> disadvantage for fast allocation in promotion.

if the compaction task is needed, the STW time can be longer than any

other GC types.

Page 73: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

73

CMS Collector – Old Gen

Options

-XX:+UseConcMarkSweepGC

-XX:+UseParNewGC

Page 74: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

74

GC log Options

-XX:+DisableExplicitGC

-XX:+PrintGCDetails

-XX:+PrintGCTimeStamps

-Xloggc

Page 75: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

75

IBM JVM

Page 76: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

76

Pinned Class problem

[AF] Allocation Failure action=0

Page 77: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

77

IBM JVM – GC Options

-Xgcpolicy:<options> optthruput optavgpause gencon subpool

Page 78: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

78

Visual GC animation http://haks1999.github.io/haklab-gc/serial.html

Page 79: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

79

Heap memory tuning test

Page 80: The JVM - Internal ( 스터디 자료 )

/83

Garbage Collector

80

verbose GC analysis

HPJmeter, IBM GC Analyzer…

Page 81: The JVM - Internal ( 스터디 자료 )

/83

and more…

81

Trouble shootings

Thread Dump Analysis Heap Dump Analysis

GC Log Analysis

Page 82: The JVM - Internal ( 스터디 자료 )

/83

References ( contents, images )

http://www.oracle.com/technetwork/java/whitepaper-135217.html http://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf http://www.artima.com/insidejvm/ed2/jvm.html http://javapapers.com/core-java/java-jvm-run-time-data-areas/ http://blog.ragozin.info/2011/06/understanding-gc-pauses-in-jvm-hotspots.html http://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html http://epicdevs.com/16 http://blog.naver.com/bumsukoh/110113098160 http://helloworld.naver.com/helloworld/1230 http://helloworld.naver.com/helloworld/1329 http://helloworld.naver.com/helloworld/329631 http://www.slideshare.net/novathinker/1-java-key http://www.slideshare.net/novathinker/2-runtime-data-areas http://www.slideshare.net/novathinker/3-garbage-collection http://www.slideshare.net/novathinker/4-class-loader http://www.slideshare.net/novathinker/5-execution-engine https://www.ibm.com/developerworks/community/blogs/738b7897-cd38-4f24-9f05-48dd69116837/entry/troubleshooting_and_memory_leak_analysis_with_java_data_objects_framework18?lang=en Java Performance(by Charlie Hunt , Binu John) / Addison-Wesley JAVA PERFORMANCE FUNDAMENTAL(김한도 저) / 엑셈

82

Page 83: The JVM - Internal ( 스터디 자료 )

/83 83

Thank you !

Q&A or later

[email protected]

http://facebook.com/gunlee01