JVM Internals :-
=>JVM stands for ‘Java virtual Machine’ and which is used to execute Java Byte Code.
=>The s/w component which internally having the behaviour like machine is known as Virtual Machine.
=>JVM internally having the following three partitions:
1.Class Loader SubSystem
2.Runtime Data Area
1.Class Loader SubSystem:
=>Class Loader SubSystem will load the byte code(class) on to JVM, in this process the Class Loader System will use the following :
=>Loader will load the required files into current running proces, in this process the Loader divided into three SubLoaders:
(i)BootStrap Class Loader
(ii)Extention Class Loader
(iii)Application Class Loader
(i)BootStrap Class Loader:
=>BootStrap CL will load the required files from the JavaLib.
Loading ‘String’ and ‘System’ classes from JavaLib.
(ii)Extention Class Loader:
=>Extention CL will load the required files from the ‘ext’ folder.
(iii)Application Class Loader:
=>Application CL will load the required files from ‘classpath’.
=>The Linker will link the loaded files into Current running program, in this process the linker use the following components:
=>Verify component will perform verification process,which means it checks the loaded files and the required files are same or not.
=>Once Verification is Successfull then the ‘prepare’ component will perform decoding process,which means identifying the programming components.
=>’Resolve’ component will identify the programming components are static or NonStatic based on ‘static’ keyword.
Static Programming components : main()
NonStatic programming components : a,b,c,add()
à define Static programming Components?
=>The programming components which are declared with ‘static’ keyword
are known as static programming components.
=>These Static programming components will get the memory within the class while class loading and access with class_name.
à define NonStatic Programming components?
=>The programming components which are declared without ‘static’ keyword are known as NonStatic programming components.
=>These NonStatic programming components will get the memory within the object while object creation and access with object_name.
=>Initiate component will perform initialization process,in this process ‘Runtime Data Area’ is created.
2.Runtime Data Area:
=>This Runtime Data Area is divided into the following:
(d)PC Register Area
(e)Native Method Area
=>The memory block where the class is loaded known as Method_Area.
=>while class loading static members will get the memmory within the class,in this process main() method got the memory within the class.
=>Once main() method got the memory,it is automatically copied onto JavaStackArea to start the execution process.
=>The ExecutionEngine identifies main() method and starts the execution process.
=>The memory block where the objects are created is known as Heap Area.
- Execution behaviour of ‘new’ keyword:
step1 : ‘new’ keyword specify the ExecutionControl to create one reference part of Heap_Area.
step2 : Check the required class is available on Method_Area or not.
step3 : Once the required class is available,then take the NonStatic members from the class and give memory at reference(Address).
step4 : Once all the NonStatic members are binded to reference, then the reference is copied onto ref_variable or Object_name(ob).
=>The memory block where all the methods are executed is known ‘Java Stack Area’.
=>The first method copied onto JavaStackArea is main() method,this main() method will call remaining methods for execution.
(d)PC Register Area:
=>PC(Program Counter) Regiters will record the status of method execution in Java Stack Area,in this process every method will have its own PC register and all these PC Registers are opened in a separate memory block konwn as ‘PC Register Area’.
(e)Native Method Area:
=>The methods which are declared with ‘native’ keyword,part of JavaLib are known as Native methods and these native methods internally having c or c++ code.
=>when these native method are used part of Java application,then they are separated and loaded onto separate memory block known as Native Method.
=>These Native methods are executed using JNI(Java Native method Interface).
=>while execution JNI uses Native method Libraries
=>ExecutionEngine is an executer of JVM and which starts the execution process from main() method available on JavaStackArea.
=>This ExecutionEngine internally having the following two
=>Interpreter will start the execution process and executes normal instructions.
=>when the interpreter finds the Stream instructions the n the control is transferred to the ‘JIT Compiler’.
(ii)JIT Compiler: (JIT – Just In Time)
=>This JIT-Compiler will execute Stream instructions.