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

FTD JVM Internals

FTD JVM Internals

Felipe Mamud

October 16, 2014
Tweet

More Decks by Felipe Mamud

Other Decks in Programming

Transcript

  1. Java Virtual Machine • The Java Virtual Machine Specification •

    Written in C/C++ • Stack based VM • Different implementations • Symbolic reference • Garbage Collected • Java Bytecode • JIT (Just-In-Time)
  2. Java bytecode is the instruction set of the Java virtual

    machine opcode = 1 or 2 bytes 256 possible opcodes 198 are currently in use 51 are reserved for future use 3 are set aside as permanently unimplemented list of all opcodes: http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html
  3. variable declaration int i; 0: iconst_0 // push 0 to

    top of the operand stack 1: istore_1 // Pop value from top of operand stack and store as local variable 1
  4. object instantiation Object ftd = new Object(); 0: new #2

    // Class java/lang/Object 1: dup // duplicate the value on top of the stack 2: invokespecial #3 // Method java/lang/Object “<init>()V”
  5. Runtime Constant Pool The constant pool contains the following types:

    • Integer, Long, Float, Double • String, Uft8 • Class • NameAndType • Fieldref, Methodref, InterfaceMethodref
  6. Java Bytecode Type Description B byte signed byte C char

    Unicode character D double double-precision floating-point value F float single-precision floating-point value I int integer J long long integer L<classname> reference an instance of class <classname> S short signed short Z boolean true or false [ reference one array dimension
  7. Java Code Java Bytecode Expression double d[][][]; [[[D Object mymethod(int

    I, double d, Thread t) (IDLjava/lang/Thread;)Ljava/lang/Object;
  8. Code Cache used for compilation and storage of methods that

    have been compiled to native code by the JIT compiler
  9. Java memory consumption 8 bytes Object Header 8 bytes Object

    reference (x86 may use XX:+UseCompressedOops) 8 bytes alignment (WAT?)
  10. String explanation Field Type Size (bytes) HEADER 16 value “Java”

    char[] (16 + 8) + (4 * 2) = 32 offset int 4 count int 4 hash int 4 PADDING = 60 + 4 TOTAL 64 bytes
  11. Class File Format ClassFile { u4 magic; u2 minor_version; u2

    major_version; u2 constant_pool_count; cp_info contant_pool[constant_pool_count – 1]; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 interfaces[interfaces_count]; u2 fields_count; field_info fields[fields_count]; u2 methods_count; method_info methods[methods_count]; u2 attributes_count; attribute_info attributes[attributes_count]; }
  12. 1. Create a initial class using Bootstrap classloader; 2. links

    the initial class; 3. initializes it; 4. and invokes the public class method void main(String[]) JVM initialization order
  13. find, check headers class file, super loading, binary created 3

    steps, verifying and preparing the type and its direct supers structurally correct, and obeys the semantic requirements allocation of memory foe data structures executing initialization method <clinit> (optional) checking corrected symbolic references
  14. FTD Group THANK YOU! JOIN US! “And be not conformed

    to this world: but be ye transformed by the renewing of your mind, that ye may prove what {is} that good, and acceptable, and perfect, will of God.” (Romans 12:2)