New Post has been published on ITESSAYS
New Post has been published on http://itessays.com/java-development-technology/jvm-memory-structure-and-quickly-peeks-into-permgen.html
JVM memory structure and quickly peeks into PermGen
This post covers some basics ofĀ JVM memory structureĀ and quicklyĀ peeks intoĀ PermGenĀ to find out where it has disappeared since advent of Java SE 8
Bare Basics
The JVM is just another process running on your system and the magic begins with the java command. Like any OS process, it needs memory for its run time operations. Remember ā the JVM itself is a software abstraction of a hardware on top of which Java programs run and boast ofĀ OS independence and WORAĀ (write once run anywhere)
Quick coverage of the JVM memory structure
As per the spec, JVM is divided into 5Ā virtual memory segments.
Heap
Method (non heap)
JVM Stack
Native Stack
PC Registers
jvm-memory-segments
Heap
Every object allocated in your Java program requires to be stored in the memory. The heap isĀ the area where all the instantiated objects get stored. Yes ā blame theĀ newĀ operator for filling up your Java heapĀ ;-)
SharedĀ by allĀ threads
The JVM throwsĀ java.lang.OutOfMemoryErrorĀ when itās exhausted
Use theĀ -XmsĀ andĀ -XmxĀ JVM options to tune the Heap size
out-of-memory-error
Sub-divided into
EdenĀ (Young) ā New object or the ones with short life expectancy exist in this area and it is regulated using the -XX:NewSize and -XX:MaxNewSize parameters.Ā GC (garbage collector) minorĀ sweepsĀ this space
SurvivorĀ ā The objects which are still being referenced manage to survive garbage collection in the Eden space end up in this area. This is regulated via the -XX:SurvivorRatio JVM option
OldĀ (Tenured) ā This is for objects which survive long garbage collections in both the Eden and Survivor space (due to lingering references of course). A special garbage collector takes care of this space. Object de-alloaction in the tenured space is taken care of byĀ GC major
Method Area
Also called theĀ non heapĀ area (in HotSpot JVM implementation)
It is divided into 2 major sub spaces
PermanentĀ GenerationĀ ā This area stores class related data from class definitions, structures, methods, field, method (data and code) and constants. Can be regulated using -XX:PermSize and -XX:MaxPermSize. IT can causeĀ java.lang.OutOfMemoryError: PermGen space if it runs out if space
CodeĀ CacheĀ ā The cache area is used to store compiled code. The compiled code is nothing butĀ nativeĀ codeĀ (hardware specific) and is taken care of by theĀ JITĀ (Just In Time) compiler which is specific to the Oracle HotSpot JVM
JVM Stack
Has a lot to do with methods in the Java classes
Stores local variables and regulates method invocation, partial result and return values
Each thread in Java has itsĀ own (private) copy of the stackĀ andĀ is not accessible to other threads.
Tuned using -Xss JVM option
NativeĀ Stack
Used for native methods (non Java code)
Per thread allocation
PCĀ Registers
Program counter specific to a particular thread
Contains addresses for JVM instructions which are being exceuted (undefined in case of native methods)
So, thatās about it for the JVM memory segment basics. Coming to back to the Permanent Generation.
So where is PermGen ???
Essentially, the PermGen hasĀ been completely removed andĀ replacedĀ by another memory area known as theĀ Metaspace
MetaspaceĀ ā quick facts
Itās part of theĀ nativeĀ heap memory
Can be tuned usingĀ -XX:MetaspaceSizeĀ andĀ -XX:MaxMetaspaceSize
Clean up initiation driven byĀ XX:MetaspaceSize option i.e. when the MetaspaceSize is reached.
java.lang.OutOfMemoryError: MetadataĀ space will be received if the native space is exhausted
The PermGen related JVM options i.e. -XX:PermSize and -XX:MaxPermSize will be ignored if present
This was obviously just the tip of the iceberg. For comprehensive coverage of the JVM, there is no reference better thanĀ the specificationĀ itselfĀ :-)
.CPlase_panel display:none;
















