Friday, 28 February 2014

Java Virtual Machine(JVM)

In this blog we learn about JVM(Java Virtual Machine).
JVM is considered as the heart of the Java program.It takes .class file and converts each byte code instructions into the machine language instruction that can be executed by microprocessor
The block diagram of JVM architecture can be represented as below:-

When we save our java program it is saved as .java file.when we compile it ,it is get converted into .class file which consists byte code instructions by the java compiler. This compiler is outside the JVM.After compilation .class file is send to the JVM. In JVM there is a module(or program) called class loader subsystem, which performs following actions:-

  • this .class file is loaded into memory.
  • then it checks whether the byte code is correct or not.If any error is detected, it rejects the execution immediately.
  • if byte is correct it allocates necessary memory to execute the program.
This memory is again divided into five parts, which are also known as runtime data areas.It contains data and results while running the program. These areas are as follows:-

  • Method area-Method area is the memory block which stores the class code and code of variables and code of methods(function) in java program.
  • Heap-In this area objects are created.whenever JVM loads a class ,a method and heap areas ate created immediately in it.
  •  Java stacks-while running a method ,it needs some more memory to store data and results. This additional memory is allotted on Java stacks.while executing a method , a separate frame will be created in java stack, where the method is executed. JVM uses separate thread to execute each method.
  • PC(program counter) registers-these are also the memory area which contains the memory address of the instructions of the methods.
  • Native method stacks-Native methods(C/C++ functions )are executed on native methods stack.to execute native method ,native method library is required.These libraries are located  and connected to JVM by a program, called Native method interface.
Execution engine contains interpreter and JIT(Just in time )compiler, which are responsible for converting byte code instruction into machine language so that processor can execute them. Most of the JVM implementations use both the interpreter and JIT compiler simultaneously to convert the byte code. This technique is called adaptive optimizer.

No comments:

Post a Comment