Translate

Monday, October 29, 2012

Java Virtual Machine


                                      Java Virtual Machine

Java Virtual Machine Specification:
JVM Specification = Java programming language + Java Virtual Machine architecture + Java class-file format. 
We have multiple implementations of JVM Specifications defined by Sun Microsystems like:
(i) Java HotSpot VM: developed by Sun Microsystems.
There are two implementations of the Java HotSpot VM:
  • Java HotSpot Client VM
  • Java HotSpot Server VM
The main differences of the two implementations are:
  • The Client VM
     
    • Reduces application start-up time and memory footprint
       
  • The Server VM
     
    • Maximizes peak operating speed.
    • Intended for running long-running server applications.
Java programming language:
The programs written in Java or the source code translated by Java compiler into byte code and after that the JVM converts the byte code into machine code for the computer one wants to run. JVM is a part of Java Run Time Environment that is required by every operating system requires a different JRE.
The architecture of the Java programming language is given below. Firstly we write the simple java program (source code) the java compiler converts the source code into the byte code, after that JVM reads this byte code and converts this into the machine code.

Java Virtual Machine architecture:
JVM is the main component of Java architecture and it is the part of the JRE (Java Runtime Environment). It provides the cross platform functionality to java. This is a software process that converts the compiled Java byte code to machine code. Byte code is an intermediary language between Java source and the host system


Class Loader Sub System:
The Class loader is a subsystem of a JVM which is responsible, predominantly for loading classes and interfaces in the system. Apart from this, a class loader is responsible for the following activities but they are not explicitly initialized. The method tables are constructed for
Run Time Data Area:
the class.-Resolving symbolic references from type to direct references the class loaders can be of two types: a bootstrap or primordial class
Java has only two types of memory when it comes to JVM. Heap memory and Non-heap memory. All the other memory jargons you hear are logical part of either of these two.
Heap Memory:
Class instances and arrays are stored in heap memory. Heap memory is also called as shared memory. As this is the place where multiple threads will share the same data.
Non-Heap Memory:
It comprises of ‘Method Area’ and other memory required for internal processing. So here the major player is ‘Method Area’.
Method Area
As given in the last line, method area is part of non-heap memory. It stores per-class structures, code for methods and constructors. Per-class structure means runtime constants and static field.
The above three (heap memory, non-heap memory and method area) are the main jargon when it comes to memory and JVM. There are some other technical jargon you might have heard and I will summarize them below.
Memory Pool
Memory pools are created by JVM memory managers during runtime. Memory pool may belong to either heap or non-heap memory.


Runtime Constant Pool
A run time constant pool is a per-class or per-interface run time representation of the constant pool table in a class file. Each runtime constant pool is allocated from the Java virtual machine’s method area.
Java Stacks or Frames
Java stacks are created private to a thread. Every thread will have a program counter (PC) and a java stack. PC will use the java stack to store the intermediate values, dynamic linking, return values for methods and dispatch exceptions. This is used in the place of registers.
Memory Generations
HotSpot VM’s garbage collector uses generational garbage collection. It separates the JVM’s memory into and they are called young generation and old generation.
Young Generation
Young generation memory consists of two parts, Eden space and survivor space. Short-lived objects will be available in Eden space. Every object starts its life from Eden space. When GC happens, if an object is still alive and it will be moved to survivor space and other dereference objects will be removed.
Old Generation – Tenured and PermGen
Old generation memory has two parts, tenured generation and permanent generation (PermGen). PermGen is a popular term. We used to error like PermGen space not sufficient.
GC moves live objects from survivor space to tenured generation. The permanent generation contains meta data of the virtual machine, class and method objects.

1 comment:

Anonymous said...

Good information