Figure below explains the Runtime data areas that JVM has:
JVM has only two Runtime memory area types.:
- Heap
- Non-Heap
- PC register
- JVM stack
- JVM Heap:
- shared across all the Threads
- Created on JVM start-up
- Memory is reclaimed using the Garbage Collection.
- Heap can be of fixed size or dynamically expandable. Users can expand the memory between permissible limits.
- If JVM Heap is configured for dynamic expansion and sufficient memory is not available then JVM will throw OutOfMemoryError Error
- PC(program Counter) Register: PC is created per Thread. At one time, it executes code of one method for the associated thread.
- If that method is not native, It contains the address of the JVM instruction currently being executed.
- If the method currently being executed by the thread is native, the value of the Java virtual machine's pc register is undefined.
- JVM stack: Each JVM thread has a private Java virtual machine stack, created at the same time as the thread
- It stores frames.frames
- Stacks are similar to conventional language(example,) stacks
- These store local variables, partial results and plays part in method invocation and return
- Size of JVM stack can be fix or expandable. If the size is fixed and for some operation memory required is more than the size then JVM throws StackOverFlowError. If Stack size is dynamically expandable and now if the required memory is more then the available then JVM will throw OutOfMemoryError Error
- Method Area: It is shared among all Java virtual machine threads.It is created on virtual machine start-up.
- It stores per-class structures such as the runtime 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 logically part of the heap but Specification doesn't restrict this.So it can be independent part also
- if JVM runs short of Method Area memory for a request then OutOfMemoryError Error will be thrown.
- Runtime Constant Pool: Runtime constant Pool memory is allocated from the Method Area. The runtime constant pool for a class or interface is constructed when the class or interface is created by the Java virtual machine.
- It is a per-class or per-interface runtime representation of the constant_pool table in a class file. Similar to symbol table in conventional languages
- 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.
- Native Method Stacks: These stacks are provided by JVMs that support native methods (methods written in languages other than Java). They are created per thread.
- Local variables's stack
- Operand stack
- Frame Data
- Instance variables are stored in Heap
- Local variables are stored on stack
- Static variables are stored in Method Area
- Arrays are stored on heap
This is a clear explanation of the JVM memory which has helped to explain why the max Java heap is <2GB on 32-bit Windows. See http://bit.ly/cJ3Zfn but it's rather inaccurate now, I see
ReplyDeleteIt's prompted me to do some more exploration of Java memory. I've updated by old post about Java heap size, but this is clearly very dated now. I need to do a proper overhaul, which I'll do once I upgrade to 64-bit Windows in the next month or so.
awesome explanation
ReplyDeleteImpressed with the simple and clear explanation.
ReplyDeleteI found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing..
ReplyDeleteBelieve me I did wrote an post about tutorials for beginners with reference of your blog.
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind.Hadoop Training in Bangalore
ReplyDeleteI like that blog. such a nice content your blog.
ReplyDeletePython Training in Chennai | Certification | Online Training Course | Python Training in Bangalore | Certification | Online Training Course | Python Training in Hyderabad | Certification | Online Training Course | Python Training in Coimbatore | Certification | Online Training Course | Python Training in Online | Python Certification Training Course
Good Post! , it was so good to read and useful to improve my knowledge as an updated one, keep blogging. After seeing your article I want to say that also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
ReplyDeleteData Science Course in Pune
https://www.3ritechnologies.com/course/data-science-online-training/
data science online training
thanks for sharing it and do share more posts like this.
ReplyDeletedata science online training
ReplyDeleteGood Post! it was so good to read and useful to improve my knowledge as an updated one, keep blogging. After seeing your article, I want to say that also a well-written article with some very good information which is very useful for the AWS Online Training