Slide 1

Slide 1 text

༼ つ ◕_◕ ༽つ JVM Internals ༼ つ ◕_◕ ༽つ Demystified! ( ͡° ͜ ʖ ͡°) ༼ つ ◕_◕ ༽つ ༼ つ ◕_◕ ༽つ

Slide 2

Slide 2 text

What we will NOT see here • Pure JVM boring theory • Assembly fear stuff • 0xFF • 0100111

Slide 3

Slide 3 text

What we will see here • Why internals? • Method Area • Heap • Threads • Further reading • Funny Gifs and images!

Slide 4

Slide 4 text

Bonjour

Slide 5

Slide 5 text

Hi! I’m Hanneli São Paulo, Brazil

Slide 6

Slide 6 text

Hi! I’m Hanneli Meanwhile here in Canada

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No advanced stuff Simplified way

Slide 9

Slide 9 text

If you understand computer architecture classes You understand JVM

Slide 10

Slide 10 text

Why do I Need to Understand Internals?

Slide 11

Slide 11 text

We live in a simplified era

Slide 12

Slide 12 text

All externalised

Slide 13

Slide 13 text

All externalised (Almost)Normal dressed developers (external)

Slide 14

Slide 14 text

Do I need internal details?

Slide 15

Slide 15 text

Developer showing internal details

Slide 16

Slide 16 text

Memory analyse • Help! Perm gem problems! • Search for memory leaks • Memory analyser tools • Understand how JVM works

Slide 17

Slide 17 text

What’s the relation between: JVM Memory Bytecode Assembly Low Level OpCode Operator Operation Java

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

How do I get started? • http://www.artima.com/insidejvm/ed2/jvmP.html

Slide 20

Slide 20 text

How do I get started?

Slide 21

Slide 21 text

JVM - Low level Assembly

Slide 22

Slide 22 text

I know how to write Java code

Slide 23

Slide 23 text

༼ つ ◕_◕ ༽つ classes ༼ つ ◕_◕ ༽つ

Slide 24

Slide 24 text

What happens when I invoke a method in Java

Slide 25

Slide 25 text

WAIT How many kinds of methods do you know?

Slide 26

Slide 26 text

2 types of methods Clazz.method(); object.method(); static instance

Slide 27

Slide 27 text

From Assembly classes: op code + operand operation + operand

Slide 28

Slide 28 text

operation + operand add r1, r2 public int add(int r1, int r2) operation operators == parameters

Slide 29

Slide 29 text

Method calls in JVM static instance operation + operand operation + operand invokevirtual invokestatic

Slide 30

Slide 30 text

Where are the Operands? Special place

Slide 31

Slide 31 text

Where are the Operands? Real place

Slide 32

Slide 32 text

Symbolic place called pool

Slide 33

Slide 33 text

JVM keeps this fake references It’s a strategy to deal with dynamic linking

Slide 34

Slide 34 text

While JVM does need the content of this fake box (pool), it remais unresolved

Slide 35

Slide 35 text

Each fake reference for each method is unique

Slide 36

Slide 36 text

Each fake reference for each method is unique So JVM can replace the fake calls with true invokes.

Slide 37

Slide 37 text

Back to methods Clazz.method(int a); object.method(parameter); class Lol { public int myMethod(int a){ // } } Class stuff

Slide 38

Slide 38 text

Method Area JVM Class stuff Class stuff Class stuff Non-Heap Code Cache Permanent Generation

Slide 39

Slide 39 text

Done? object

Slide 40

Slide 40 text

༼ つ ◕_◕ ༽つ object ༼ つ ◕_◕ ༽つ

Slide 41

Slide 41 text

Method Area JVM Class stuff Class stuff Class stuff Non-Heap Permanent Generation HEAP Permanent Generation object object object

Slide 42

Slide 42 text

Young gen JVM - The Heap HEAP Lol lol = new LOL(); lol object object object

Slide 43

Slide 43 text

JVM - The Heap HEAP Permanent Generation object object object object object object object object object object object object object object object object Hey, Im’m heavy

Slide 44

Slide 44 text

JVM - The Heap HEAP Permanent Generation object object object object object object object object object object object object object object object object Checks all the objects on the heap Garbage collector

Slide 45

Slide 45 text

Old gen Young generation JVM - The Heap HEAP object object Eden lol Survivor object Will be taken for GC

Slide 46

Slide 46 text

Last step Where does my application run?

Slide 47

Slide 47 text

Last step public static void main(String[] args){ …}

Slide 48

Slide 48 text

༼ つ ◕_◕ ༽つ thread ༼ つ ◕_◕ ༽つ

Slide 49

Slide 49 text

JVM - Thread Thread Heap Non-Heap

Slide 50

Slide 50 text

JVM - Thread Thread Program Counter Stack Frame Frame Frame Frame Frame Local variables [] Return Value Pointer to Method Area Pointer to Heap Area Operand Operand Operand Operand Stack

Slide 51

Slide 51 text

JVM - Sum up Program Counter Stack Frame Frame Frame Frame Heap Non-Heap Object instances Class Stuff/ Method Area Similar to Computer Architecture

Slide 52

Slide 52 text

༼ つ ◕_◕ ༽つ JVM ༼ つ ◕_◕ ༽つ

Slide 53

Slide 53 text

( ͡° ͜ ʖ ͡°) JVM ( ͡° ͜ ʖ ͡°)

Slide 54

Slide 54 text

Thanks!! Questions? @hannelita [email protected]

Slide 55

Slide 55 text

References • http://www.artima.com/insidejvm/ed2/jvmP.html • http://www.cubrid.org/blog/dev-platform/understanding-jvm-internals/ • http://architects.dzone.com/articles/understanding-jvm-internals • http://www.ourdailycodes.com/2013/09/inside-java-jvm-memory- structure-2.html • http://javarevisited.blogspot.ca/2011/04/garbage-collection-in-java.html • http://www.slideshare.net/BalamuruganSoundararajan/invoke-dynamics • http://www.javaworld.com/article/2076949/learn-java/how-the-java-virtual- machine-handles-method-invocation-and-return.html • http://blog.jamesdbloom.com/JVMInternals.html#threads