Java By Kiran
Java Training Institute in Pune
Java Training Institute in Pune
Java uses Just-In-Time compiler to enable high performance. Just-In-Time compiler is a program that turns Java bytecode into instructions that can be sent directly to the processor.
Java is a portable-language because without any modification we can use Java byte-code in any platform(which supports Java). So this byte-code is portable and we can use in any other major platforms.
ou can find JVM - 32 bit or 64 bit by using System.getProperty() from Java program.
As you can see in the above image, JVM memory is divided into separate parts. At broad level, JVM Heap memory is physically divided into two parts – Young Generation and Old Generation.
Young generation is the place where all the new objects are created. When young generation is filled, garbage collection is performed. This garbage collection is called Minor GC. Young Generation is divided into three parts – Eden Memory and two Survivor Memory spaces.
Important Points about Young Generation Spaces:
• Most of the newly created objects are located in the Eden memory space.
• When Eden space is filled with objects, Minor GC is performed and all the survivor objects are moved to one of the survivor spaces.
• Minor GC also checks the survivor objects and move them to the other survivor space. So at a time, one of the survivor space is always empty.
• Objects that are survived after many cycles of GC, are moved to the Old generation memory space. Usually it’s done by setting a threshold for the age of the young generation objects before they become eligible to promote to Old generation.
Old Generation memory contains the objects that are long lived and survived after many rounds of Minor GC. Usually garbage collection is performed in Old Generation memory when it’s full. Old Generation Garbage Collection is called Major GC and usually takes longer time.
Java provides a lot of memory switches that we can use to set the memory sizes and their ratios. Some of the commonly used memory switches are:
|VM Switch||VM Switch Description|
|-Xms||For setting the initial heap size when JVM starts|
|-Xmx||For setting the maximum heap size.|
|-Xmn||For setting the size of the Young Generation, rest of the space goes for Old Generation.|
|-XX:PermGen||For setting the initial size of the Permanent Generation memory|
|-XX:MaxPermGen||For setting the maximum size of Perm Gen|
|-XX:SurvivorRatio||For providing ratio of Eden space and Survivor Space, for example if Young Generation size is 10m and VM switch is -XX:SurvivorRatio=2 then 5m will be reserved for Eden Space and 2.5m each for both the Survivor spaces. The default value is 8.|
|-XX:NewRatio||For providing ratio of old/new generation sizes. The default value is 2.|
Java Stack memory is used for execution of a thread. They contain method specific values that are short-lived and references to other objects in the heap that are getting referred from the method.
Method Area is part of space in the Perm Gen and used to store class structure (runtime constants and static variables) and code for methods and constructors..
Runtime constant pool is per-class runtime representation of constant pool in a class. It contains class runtime constants and static methods. Runtime constant pool is the part of method area.
Permanent Generation or “Perm Gen” contains the application metadata required by the JVM to describe the classes and methods used in the application. Note that Perm Gen is not part of Java Heap memory.
Perm Gen is populated by JVM at runtime based on the classes used by the application. Perm Gen also contains Java SE library classes and methods. Perm Gen objects are garbage collected in a full garbage collection.