JVM Memory Structure


Java 7
Young Generation
Eden
Survivors: S0, S1
- When Eden is full, Minor GC
- minor GC
Old Generation
Major GC
string pool was relocated to the heap
String pool values are garbage collected

Internal architecture of the Java virtual machine:

Heap
One JVM instance has only one heap, it is created on JVM start-up and shared among all Java virtual machine threads.
The heap is the runtime data area from which memory for all class instances and arrays is allocated.
Its memory is reclaimed using the Garbage Collection.
Heap is also used to store Method Area.
Method Area
Method Area is logically part of the heap.
It stores information about loaded types, and per-class structures such as class static variables, constant pool, field and method data, and the code for methods and constructors, including the special methods used in class and instance initialization and interface type initialization
It is created on virtual machine start-up and shared among all Java virtual machine threads.
Runtime Constant Pool
Runtime constant Pool memory is allocated from the Method Area.
It is created when the class or interface is loaded by the Java virtual machine.
It stores different kinds of constants, ranging from numeric literals known at compile time to method and field references that must be resolved at run time.
JVM stack
Another runtime memory area types is JVM stack.
JVM stack is created when a new thread is launched. Data stored in the JVM stack in private and only accessible to that thread.
A Java stack stores a thread's state in discrete stack frames.
JVM stack holds local variables and partial results, and plays a part in method invocation and return.
The Stack Frame
The stack frame stores local variables, operand stack, and frame data.
When a thread invokes a Java method, the virtual machine creates and pushes a new frame onto the thread's Java stack. This new frame then becomes the current frame. As the method executes, it uses the frame to store parameters, local variables, intermediate computations, and other data.
Native Method Stacks
These stacks are provided by JVM that support native methods. They are created per thread.
Instance variables are stored in Heap
Static variables are stored in Method Area
Arrays are stored on heap
For local primitive variables are stored on stack, for non-primitive variables, its memory is allocated in heap, stack only stores a reference to that object.
When you instantiate an object in Java you are actually allocating two pieces of memory - one on the stack and one on the heap.
The memory of the stack is used to store a reference and the memory on the heap is used to store the actual object. The primitive data types (int, long, char etc.) are only stored on the stack.
Resources

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)