Out of the heap, native heap, direct memory and own memory

I recently came across these concepts while studying the internal structure of the JVM. I know that they already have a lot of questions about SO, but I still can’t understand the relationship between them or just what they are.

Now I describe them as such:

  • Native memory means an area of ​​memory outside the normal JVM heap, but is still in the user’s shared memory saved by the OS for the JVM process (for example, on 32-bit Windows it is 2 GB by default). This space is reserved by the JVM for storing some internal data, such as an area of ​​continuous generation / method, etc.
  • Direct memory means you are using the internal memory using java.nio.DirectByteBuffer .

  • The native heap means that you use the built-in memory with unsafe.allocateMemory or just execute malloc in the JNI code.

  • Off-heap is the same as the original memory.

And one more question: is it possible to allocate memory directly outside the total memory space (4 GB on a 32-bit OS) saved for the JVM process?

Please indicate errors in my understanding and, if possible, give them a clear description.

+6
source share
2 answers

1) Heap memory: memory in the JVM process managed by the JVM to represent Java objects

2) Internal memory / Inactive memory : this is memory allocated in the process address space that is not on the heap.

3) Direct memory : similar to native, but also implies that the shared buffer in the hardware is shared. For example, a buffer inside a network adapter or graphic display. The goal here is to reduce the number of copies that copy the same bytes in memory.

Finally, depending on the OS, additional internal allocations (assignment of memory address space) can be performed through Unsafe alloc and / or by matching memory with a file. Of particular interest is the mapping of memory to a file, since it can easily allocate more memory than the machine currently has as physical RAM. Also note that the limitation of the total address space is limited by the size of the pointer used, the 32-bit pointer cannot go beyond 4 GB. Period.

+6
source

And one more question: is it possible to allocate memory directly outside the total memory space (4 GB on a 32-bit OS) saved for the JVM process?

4 GB is a general limitation of the virtual address space for a process on a 32-bit OS. 4-byte pointers simply cannot address anymore.

The only thing you can do is open a large file and interact with it through a limited number of buffers with memory mapping, display and free them as needed, and hoping that the OS cache page stores them in physical memory.

If you need more than 2 GB of memory, you really need to work with a 64-bit OS and JVM.

+1
source

Source: https://habr.com/ru/post/988457/


All Articles