JVM Flashcards
What is JVM and usage
1). Java virtual machine
2) Load and execute the app
java file -> complie –> .class file
What are the main components of JVM and their usage
1)class loader subsystem - load all the app’s .class files load all the java API . class files
2) Run time data area
3) Execution engine - execute byte code instructions combine with native method interface
Class loader - What are the 3 phases of class loading
1) load
2) link
3) initializing
Class loader - What process happened in the load stage?
1) bootstrap class loader - load internal file - rt.jar(all the important classes/packages
2) Extension class loader (jre/lib/ext)
3) application class loader
- load all the application code
- load all classes under CLASSPATH env varible,
- cp parameter in java command
Class loader - What process happened in the linking stage?
1) verifying - byte code loaded
2) preparing - only memory allocated static(Class) variables, initialized to default values
3) resolve - all the symbolic in the class are resolved(changed to actual reference), - classDefNotFoundException
Class loader - What process happened in the initializing stage?
1) static initializer of class - static block, set static variable values
Class loader - what is the work flow
1) Delegation Hierarchy Principle.
2) Whenever JVM comes across a class
- it checks whether that class is already loaded or not in the method area.
- already loaded -> JVM proceeds with execution.
- not loaded -> JVM asks the
Java ClassLoader Sub-System —(delegates)–>
Application ClassLoader —(delegates)–>
Extension ClassLoader –(delegates)–>
Bootstrap ClassLoader.
Bootstrap ClassLoader search in the Bootstrap classpath(JDK/JRE/LIB).
available:load the class,
not available:delegated request to Extension ClassLoader.
Extension ClassLoader searches for the class in the Extension Classpath(JDK/JRE/LIB/EXT). available:load the class, not available:delegated request to Application ClassLoader.
Application ClassLoader searches for the class in the Application Classpath. available:load the class, not available:ClassNotFoundException
Run Time Area - What it contains?
1) method area(PermGen/Metaspace)
- metadata for classes: static variables, constant pool, byte code
- also called PermGen space(64MB) -XX:MaxPermSize
- since java 8, called : metaSpace(default no limits, just move metadata to a native OS space)
2) heap
- object Data
- -Xms -Xmx
3)stacks Stack frame for current unfinished method, Per thread local variables stackOverflowError -Xss
4)PC registers
Program counter - pointer of next instruction to be execute, created per thread
5)native method stack
When we invoking a native method
Execution Engine
Once PC is ready on next execution instructions
1)Interpreter
bytecode-> Native method interface-> Native method library
2)JIT complier
For repeated used instructions, will kept machine code ready
3)Hotspot profiler
help Jit complier find frequent used instructions
Why Jit compilter called just in time?
1) A JIT compiler compiles the byte code into the machine code
2) Runs after the program has started
3) traditional compiler that compiles all the code to machine language before the program is first run.
2) First only necessary part of byte code are converted for app to start, then when a method is called it will be converted on demand
4) Provide ready compiled machine code to JVM, JVM can execute directly without re-interpre
5) Analysis on hot method and perform some optimization on the code(Inline final method, Eliminate dead code)