༼ つ ◕_◕ ༽つ JVM Internals ༼ つ ◕_◕ ༽つ
Demystified! ( °͡ ʖ͜ °͡)
༼ つ ◕_◕ ༽つ ༼ つ ◕_◕ ༽つ
What we will NOT see here
• Pure JVM boring theory
• Assembly fear stuff
• 0xFF
• 0100111
What we will see here• Why internals?
• Method Area
• Heap
• Threads
• Further reading
• Funny Gifs and images!
Hi! I’m Hanneli
São Paulo, Brazil
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)
If you understand computer architecture classes
You understand JVM
Why do I Need to Understand Internals?
We live in a simplified era
All externalised(Almost)Normal dressed
developers (external)
Do I need internal details?
Developer showing internal details
Memory analyse
• Help! Perm gem problems!
• Search for memory leaks
• Memory analyser tools
• Understand how JVM works
What’s the relation between:
JVM
Memory
Bytecode
Assembly
Low Level
OpCode
Operator
Operation
Java
How do I get started?• http://www.artima.com/insidejvm/ed2/jvmP.html
How do I get started?
JVM - Low level
Assembly
I know how to write Java code
༼ つ ◕_◕ ༽つ classes ༼ つ ◕_◕ ༽つ
What happens when I invoke a method in Java
WAIT
How many kinds of methods do you know?
2 types of methodsClazz.method();
object.method();
static
instance
From Assembly classes:
op code + operandoperation + operand
operation + operand
add r1, r2
public int add(int r1, int r2)
operation operators == parameters
Method calls in JVMstaticinstance
operation+
operand
operation +
operandinvokevirtual invokestatic
Where are the Operands?
Special place
Where are the Operands?
Real place
Symbolic place called pool
JVM keeps this fake references
It’s a strategy to deal with dynamic linking
While JVM does not need the content of this fake box (pool), it remais
unresolved
Each fake reference for each method is unique
Each fake reference for each method is uniqueSo JVM can replace the
fake calls with true invokes.
Back to methods
Clazz.method(int a);
object.method(parameter);class Lol { public int myMethod(int a){ // } }
Class stuff
Method Area
JVMClass stuff Class stuff Class stuff
Non-HeapCode Cache
Permanent G
eneration
༼ つ ◕_◕ ༽つ object ༼ つ ◕_◕ ༽つ
Method Area
JVM
Class stuff Class stuff Class stuff
Non-Heap
Permanent G
eneration
HEAPPerm
anent Generation
objectobject
object
Young gen
JVM - The Heap
HEAP
Lol lol = new LOL();
lol
object object
object
JVM - The Heap
HEAP
Permanent G
eneration
object
object
objectobject
object
object
objectobject
object
object
objectobject
object
object
objectobject
Hey, Im’m heavy
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
Old gen
Young generation
JVM - The Heap
HEAPobject object
Eden
lolSurvivor
object
Will be taken for GC
Last stepWhere does my application
run?
Last step
public static void main(String[] args){ …}
༼ つ ◕_◕ ༽つ thread ༼ つ ◕_◕ ༽つ
JVM - Thread
Thread
Heap Non-Heap
JVM - Thread
Thread
Program Counter Stack
Frame
Frame
Frame
Frame
Frame
Local variables []Return ValuePointer to Method AreaPointer to Heap Area
OperandOperandOperand
Operand Stack
JVM - Sum upProgram Counter Stack
Frame
Frame
Frame
Frame
Heap Non-Heap
Object instances Class Stuff/ Method Area
Similar to Computer
Architecture
What are those weird parameters?
-XX -Xms
HEAP
HEAP
JVM Optimization Techniques
Why should I study JVM?
New languagesOptimizationsArchitecture ideasHardware and AI
༼ つ ◕_◕ ༽つ JVM ༼ つ ◕_◕ ༽つ
( °͡ ʖ͜ °͡) JVM ( °͡ ʖ͜ °͡)
Thanks!!
Questions?
@[email protected]
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