Top Banner
_JVM Internals _Demystified! ( ͡ ° ͜ ʖ ͡ °) __
55

JVM Internals Demystified

Aug 04, 2015

Download

Technology

Hanneli Tavante
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JVM Internals Demystified

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

Demystified! ( °͡ ʖ͜ °͡)

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

Page 2: JVM Internals Demystified

What we will NOT see here

• Pure JVM boring theory

• Assembly fear stuff

• 0xFF

• 0100111

Page 3: JVM Internals Demystified

What we will see here• Why internals?

• Method Area

• Heap

• Threads

• Further reading

• Funny Gifs and images!

Page 4: JVM Internals Demystified

Hi! I’m Hanneli

São Paulo, Brazil

Page 5: JVM Internals Demystified
Page 6: JVM Internals Demystified

No advanced stuffSimplified way

Started learning Java for Web AppsNever had looked at JVM

It was difficult to learn the internals(at least for me)

Page 7: JVM Internals Demystified

If you understand computer architecture classes

You understand JVM

Page 8: JVM Internals Demystified

Why do I Need to Understand Internals?

Page 9: JVM Internals Demystified

We live in a simplified era

Page 10: JVM Internals Demystified

All externalised

Page 11: JVM Internals Demystified

All externalised(Almost)Normal dressed

developers (external)

Page 12: JVM Internals Demystified

Do I need internal details?

Page 13: JVM Internals Demystified

Developer showing internal details

Page 14: JVM Internals Demystified

Memory analyse

• Help! Perm gem problems!

• Search for memory leaks

• Memory analyser tools

• Understand how JVM works

Page 15: JVM Internals Demystified

What’s the relation between:

JVM

Memory

Bytecode

Assembly

Low Level

OpCode

Operator

Operation

Java

Page 16: JVM Internals Demystified
Page 17: JVM Internals Demystified

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

Page 18: JVM Internals Demystified

How do I get started?

Page 19: JVM Internals Demystified

JVM - Low level

Assembly

Page 20: JVM Internals Demystified

I know how to write Java code

Page 21: JVM Internals Demystified

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

Page 22: JVM Internals Demystified

What happens when I invoke a method in Java

Page 23: JVM Internals Demystified

WAIT

How many kinds of methods do you know?

Page 24: JVM Internals Demystified

2 types of methodsClazz.method();

object.method();

static

instance

Page 25: JVM Internals Demystified

From Assembly classes:

op code + operandoperation + operand

Page 26: JVM Internals Demystified

operation + operand

add r1, r2

public int add(int r1, int r2)

operation operators == parameters

Page 27: JVM Internals Demystified

Method calls in JVMstaticinstance

operation+

operand

operation +

operandinvokevirtual invokestatic

Page 28: JVM Internals Demystified

Where are the Operands?

Special place

Page 29: JVM Internals Demystified

Where are the Operands?

Real place

Page 30: JVM Internals Demystified

Symbolic place called pool

Page 31: JVM Internals Demystified

JVM keeps this fake references

It’s a strategy to deal with dynamic linking

Page 32: JVM Internals Demystified

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

unresolved

Page 33: JVM Internals Demystified

Each fake reference for each method is unique

Page 34: JVM Internals Demystified

Each fake reference for each method is uniqueSo JVM can replace the

fake calls with true invokes.

Page 35: JVM Internals Demystified

Back to methods

Clazz.method(int a);

object.method(parameter);class Lol { public int myMethod(int a){ // } }

Class stuff

Page 36: JVM Internals Demystified

Method Area

JVMClass stuff Class stuff Class stuff

Non-HeapCode Cache

Permanent G

eneration

Page 37: JVM Internals Demystified

Done?object

Page 38: JVM Internals Demystified

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

Page 39: JVM Internals Demystified

Method Area

JVM

Class stuff Class stuff Class stuff

Non-Heap

Permanent G

eneration

HEAPPerm

anent Generation

objectobject

object

Page 40: JVM Internals Demystified

Young gen

JVM - The Heap

HEAP

Lol lol = new LOL();

lol

object object

object

Page 41: JVM Internals Demystified

JVM - The Heap

HEAP

Permanent G

eneration

object

object

objectobject

object

object

objectobject

object

object

objectobject

object

object

objectobject

Hey, Im’m heavy

Page 42: JVM Internals Demystified

JVM - The Heap

HEAP

Permanent G

eneration

object

object

objectobject

object

object

objectobject

object

object

objectobject

object

object

objectobject

Checks all the objects on the heap

Garbage collector

Page 43: JVM Internals Demystified

Old gen

Young generation

JVM - The Heap

HEAPobject object

Eden

lolSurvivor

object

Will be taken for GC

Page 44: JVM Internals Demystified

Last stepWhere does my application

run?

Page 45: JVM Internals Demystified

Last step

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

Page 46: JVM Internals Demystified

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

Page 47: JVM Internals Demystified

JVM - Thread

Thread

Heap Non-Heap

Page 48: JVM Internals Demystified

JVM - Thread

Thread

Program Counter Stack

Frame

Frame

Frame

Frame

Frame

Local variables []Return ValuePointer to Method AreaPointer to Heap Area

OperandOperandOperand

Operand Stack

Page 49: JVM Internals Demystified

JVM - Sum upProgram Counter Stack

Frame

Frame

Frame

Frame

Heap Non-Heap

Object instances Class Stuff/ Method Area

Similar to Computer

Architecture

Page 50: JVM Internals Demystified

What are those weird parameters?

-XX -Xms

HEAP

HEAP

JVM Optimization Techniques

Page 51: JVM Internals Demystified

Why should I study JVM?

New languagesOptimizationsArchitecture ideasHardware and AI

Page 52: JVM Internals Demystified

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

Page 53: JVM Internals Demystified

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

Page 54: JVM Internals Demystified

Thanks!!

Questions?

@[email protected]

Page 55: JVM Internals Demystified

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

• http://www.amazon.com.br/Java-Virtual-Machine-Definition-Verification-ebook/dp/B000V9G6QW/ref=sr_1_1?ie=UTF8&qid=1435028967&sr=8-1&keywords=java+virtual+machine