zzh

zzh

JVM Local Memory

Concept#

Local memory = Direct memory + Metaspace

Direct memory#

  • Concept: Direct memory is not part of the virtual machine's runtime data area. It is a memory area that is directly allocated from the system outside of the Java heap. Direct memory uses NIO and operates on native memory through DirectByteBuffer stored in the heap, resulting in high read and write performance.
  • Reason: Direct memory is a physical memory specifically used for JVM and IO device interaction. Since the JVM operates based on automatic garbage collection, data in memory is constantly moved during garbage collection. If you call a system API to write the memory at a certain location to disk, and at the same time, GC moves that portion of data, the operating system would end up writing incorrect data after the GC is finished.

Metaspace#

  • Concept: The concept of Metaspace was introduced in JDK 1.8, previously known as the method area/permanent generation. It stores loaded class information, constants, static variables, constant pool, and compiled code generated by Just-In-Time compilation.

Working memory and local memory#

In JMM, each thread has its own working memory to store shared variables in JVM memory. Each thread can only operate on variables in its own working memory. Working memory is an abstract concept, not actual memory, but rather CPU registers and caches.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.