Till today I knew that java has heap and that is created by JVM. Further, this memory is allocated by OS to JVM instance, i.e. heap resides inside JVM instance.
But today I saw a picture,
which shows, JVM and heap far apart.
So, I am confused right now, Can anyone let me know, whether I was wrong before or I am not able to understand the picture?
Two kinds of memory. The JVM divides its memory into two main categories: heap memory and non-heap memory. Heap memory is the part with which people are typically the most familiar. It's where objects that are created by the application are stored.
The Java heap is the area of memory used to store objects instantiated by applications running on the JVM. When the JVM is started, heap memory is created and any objects in the heap can be shared between threads as long as the application is running.
Java Heap space is used by java runtime to allocate memory to Objects and JRE classes. Whenever we create an object, it's always created in the Heap space. Garbage Collection runs on the heap memory to free the memory used by objects that don't have any reference.
All Stack and heap memory is part of the ram memory.
There is a lot to discuss on this question. I always like the articles from IBM since it contains very good information. For this specific question, here is an excerpt.
From The native and Java heaps article on IBM:
The JVM maintains two memory areas, the Java™ heap, and the native (or system) heap. These two heaps have different purposes and are maintained by different mechanisms.
The Java heap contains the instances of Java objects and is often referred to as 'the heap'. It is the Java heap that is maintained by Garbage Collection, and it is the Java heap that is changed by the command-line heap settings. The Java heap is allocated using mmap, or shmat if large page support is requested. The maximum size of the Java heap is preallocated during JVM startup as one contiguous area, even if the minimum heap size setting is lower. This allocation allows the artificial heap size limit imposed by the minimum heap size setting to move toward the actual heap size limit with heap expansion.
The native, or system heap, is allocated by using the underlying malloc and free mechanisms of the operating system, and is used for the underlying implementation of particular Java objects; for example:
- Motif objects required by AWT and Swing
- Buffers for data compression routines, which are the memory space that the Java Class Libraries require to read or write compressed data like .zip or .jar files.
- Malloc allocations by application JNI code
- Compiled code generated by the Just In Time (JIT) Compiler
- Threads to map to Java threads
Hope it helps you understand.
The JVM in green is most likely not a JVM instance but the JVM code which resides in the system memory, inside the Java Heap(s) there are the JVM instances you expected.
If you look at this image below it is clearer, the JVM in green in your image would be inside the Host Operating system blue area
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With