ClassLoader
1.Loading:
When a Java program is converted into .class file by Java compiler which is collection of byte code. ClassLoader is responsible to load that
class file from file system, network or any other location.
Our Java class is depends up on any other class let’s say
JdbcDriver.class, it will search by following ClassLoaders.
·
Bootstrap ClassLoader
- JRE/lib/rt.jar
First bootstrap class loader tries to find the class. It
scans the rt.jar file in
JRE lib folder
·
Extension ClassLoader
- JRE/lib/ext or any
directory denoted by java.ext.dirs
If class is not found then extension class loader searches
the class file in inside jre\lib\ext folder
·
Application ClassLoader - CLASSPATH environment
variable, -classpath or -cp option
Again if class is not found
then application classloader searches all the Jar files and classes in
CLASSPATH environment variable of system.
2.Linking:
·
Bytecode verifier will verify
whether the generated bytecode is proper or not.
·
Prepare(memory
allocation): allocates memory to
static variables & methods.
3.Initialization: In prepare only memory is allocated, here all static variable will be
assigned with the original values and the static blocks will be executed.
Runtime area
Fields(Data members) and methods are
also known as class members
·
Method Area : all Class level Data members, Method definitions stored here
·
Heap All Objects & instance variable Data stored Here.
·
Stacks : All Methods executions & Thread Executions done here. store local
variables, and intermediate results. Each thread has its own JVM stack, created
simultaneously as the thread is created. So all such local variable are
called thread-local variables.
·
PC register store the physical
memory address of the statements which is currently executing. In Java, each
thread has its separate PC register.
·
Java supports and uses native code as
well. Many low level code is written in languages like C and C++. Native method
stacks hold the instruction of native code.
Execution Engine
All code assigned to JVM is executed by an execution
engine. The execution engine reads the byte code and executes one by one.
It uses two inbuilt interpreter and JIT compiler to
convert the bytecode to machine code and execute it.
1.Interpreter A JVM interpreter pretty much
converts each byte-code instruction to corresponding native instruction.
It directly executes the bytecode only one instruction at a
time and does not perform any
optimization.
2.JIT Compiler JIT compiler takes a block of code (not one statement at a time as
interpreter), optimize the code and then translate it to optimized machine
code. To improve performance, it will Optimizes the bytecode
Differences between JDK, JRE and JVM
JVM = Just a Specification. HotSpot VM is implementation of
IT
JRE = JVM + libraries to run Java application.



0 comments:
Post a Comment