Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JVM Internals Demystified

hannelita
February 19, 2015

JVM Internals Demystified

Confoo 2015

hannelita

February 19, 2015
Tweet

More Decks by hannelita

Other Decks in Technology

Transcript

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  5. Hi! I’m Hanneli
    Meanwhile here in Canada

    View full-size slide

  6. No advanced stuff
    Simplified way

    View full-size slide

  7. If you understand computer architecture
    classes
    You understand JVM

    View full-size slide

  8. Why do I Need to
    Understand Internals?

    View full-size slide

  9. We live in a simplified era

    View full-size slide

  10. All externalised

    View full-size slide

  11. All externalised
    (Almost)Normal dressed
    developers (external)

    View full-size slide

  12. Do I need internal details?

    View full-size slide

  13. Developer showing internal
    details

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  17. How do I get started?

    View full-size slide

  18. JVM - Low level
    Assembly

    View full-size slide

  19. I know how to write Java
    code

    View full-size slide

  20. ༼ つ ◕_◕ ༽つ classes ༼ つ ◕_◕ ༽つ

    View full-size slide

  21. What happens when I
    invoke a method in Java

    View full-size slide

  22. WAIT
    How many kinds of
    methods do you know?

    View full-size slide

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

    View full-size slide

  24. From Assembly classes:
    op code + operand
    operation + operand

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  27. Where are the Operands?
    Special
    place

    View full-size slide

  28. Where are the Operands?
    Real place

    View full-size slide

  29. Symbolic place called pool

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  32. Each fake reference for
    each method is unique

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  36. ༼ つ ◕_◕ ༽つ object ༼ つ ◕_◕ ༽つ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  39. 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

    View full-size slide

  40. 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

    View full-size slide

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

    View full-size slide

  42. Last step
    Where does my application
    run?

    View full-size slide

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

    View full-size slide

  44. ༼ つ ◕_◕ ༽つ thread ༼ つ ◕_◕ ༽つ

    View full-size slide

  45. JVM - Thread
    Thread
    Heap Non-Heap

    View full-size slide

  46. 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

    View full-size slide

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

    View full-size slide

  48. ༼ つ ◕_◕ ༽つ JVM ༼ つ ◕_◕ ༽つ

    View full-size slide

  49. ( ͡° ͜
    ʖ ͡°) JVM ( ͡° ͜
    ʖ ͡°)

    View full-size slide

  50. Thanks!!
    Questions?
    @hannelita
    [email protected]

    View full-size slide

  51. 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

    View full-size slide