JVM Flashcards

1
Q

What is JVM and usage

A

1). Java virtual machine
2) Load and execute the app
java file -> complie –> .class file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the main components of JVM and their usage

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Class loader - What are the 3 phases of class loading

A

1) load
2) link
3) initializing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Class loader - What process happened in the load stage?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Class loader - What process happened in the linking stage?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Class loader - What process happened in the initializing stage?

A

1) static initializer of class - static block, set static variable values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Class loader - what is the work flow

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Run Time Area - What it contains?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Execution Engine

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why Jit compilter called just in time?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly