- Heap Memory
- Non Heap Memory
Heap Memory (also called Shared Memory)
This is the place where multiple Thread will share the instances. So, all the Class Instances (Objects) and Arrays stored in this.
Non-Heap Memory
It comprises of 'Mehtod area' and other memory required for internal processing.
Mehtod area : As it is a part of non-heap area, it stores per-class structures, code for methods and constructors. Per-class structure means runtime constants and static fields.
So basically these above 3 type are the main jargon when it comes for JVM memory. But there are some other technical term also comes, whenever we talks about JVM.
Memory Pool : This is created by JVM Memory Manager at the runtime. It may belong to Heap or non-Heap.
Runtime Constant Pool : Its a per-class or per-interface run time representation of the constant_pool table in a class file. Its got allocated from JVM Method area.
Java Stack: This is created privately for each thread. Each Thread will have Program Counter (PC) and Java Stack. PC stores the intermediate value, dynamic linking, return value of any method and dispatched exception. This is basically used in place of register.
Memory Generation : JVM garbage collector uses these generation wise collection into mainly two category :- Young Genration and Old Generation.
Young Generation
-> Eden Space - Shortlived objects and any newly created objects will be available.
-> Survivor Space -When GC happens, if an object is still alive and it will be moved to survivor space.
Old Generation
-> Tenured Space - GC moves live objects from survivor space to tenured generation.
-> PermGen Space - This is called permanent generation. It contains meta data of the virtual machine, class and method objects.
Key TakeAways:-
- Local Variables are stored in Frames during runtime.
- Static Variables are stored in Method Area.
- Arrays are stored in heap memory.
- MemoryPoolMXBean provides you api to explore the memory usage, threshold notifications, peak memory usage and memory usage monitoring.
- Threads and Locks chapter of Java Language Specification talks lot about java memory
- Chapter 5 of Inside the Java Virtual Machine, The Java Virtual Machine by Bill Venners
No comments:
Post a Comment