Recently I came across these concepts while learning JVM internals. I am aware that there are already a lot of questions on SO about them individually, but I still cannot grasp the relationship between them or, simply what they are.
Now I describe them as such:
Native memory means the memory area outside normal JVM heap, but still within the total user space memory spared by OS for JVM process (for example on 32-bit Windows it is by default 2 GB). This space is reserved by JVM to store some internal data, such as Permanent Generation / Method Area etc.
Direct memory means you use native memory by means of
java.nio.DirectByteBuffer
.Native heap means you use native memory by means of
unsafe.allocateMemory
or simply do amalloc
in your JNI code.Off-heap is the same as native memory.
And one additional question, is it possible to allocate memory directly outside the total memory space (4GB on 32-bit OS) spared for JVM process?
Please point out the mistakes in my understanding and if possible, give a clear description about them.