KEMBAR78
Java Memory Structure | PDF
Haim Yadid
JVM Memory Structure
About Me
• Developing software since 1984
• Basic -> Pascal -> C -> C++ -> Java -> Kotlin
• Developer , architect, group manager
• Independent performance expert for 8 years
• Group manager in
• Java.IL
• Founded in the Beginning of 2016
• Disrupt the small businesses insurance field
• Providing online experience which is simple, fast and
transparent
• HQ@Palo Alto / RnD@Kfar Saba (Israel) / Austin-TX
• We started to write real code on May 2016
Heap
• -Xms
• -Xmx
Xms Xmx
Max
Init
Physical vs Process Memory
0 2^32/2^48Process Address Space
Physical memory0
Page
Swap
Page
Page
Page
Reserved/Virtual
Page
Page
Page
Page
Committed - activeCommitted - inactive
Heap structure
• JMX: java.lang.Memory::HeapMemoryUsage
• Continuous address space
Used VirtualCommited
Max
Init
JVisualVM Heap
Not Only Heap
• Heap
• Code cache
• Meta spaces (Native)
• Native memory
Heap
Code
Cache
0 2^32/2^48
Native
Native
Native
Meta
Meta
Meta Space
• Classes byte code
• Part of native memory.
• Need not be continuous in memory or pre reserved.
• Limit by -XX:MaxMetaspaceSize=
JVisualVM
JMX : java.lang.MemoryPool.Metaspace::usage
Code cache
• JIT’ed hotspot methods (machine code)
• -XX:InitialCodeCacheSize=2555904 (2.5MB)
• -XX:ReservedCodeCacheSize=251658240 (240MB)
• codecache flushing -XX:+UseCodeCacheFlushing
JVisualVM
JMX : java.lang.MemoryPool.Code Cache::usage
Native Memory
• Thread stacks (1MB for 64 bit OS)
• Native allocations
• Direct byte buffer java.nio.DirectByteBuffer
• Limit by : -XX:MaxDirectMemorySize=
• unsafe.allocateMemory
• JNI malloc()
Calculating it All
• Heap Max = 1 GB
• 100 threads = 100 MB
• Code cache 256 MB
• Meta space 100 MB
Native Memory Tracking
java -XX:+UnlockDiagnosticVMOptions

-XX:NativeMemoryTracking=summary

-XX:+PrintNMTStatistics
jcmd <pid> VM.native_memory summary
Native Memory Tracking:

Total: reserved=5808103KB, committed=1987515KB

- Java Heap (reserved=4194304KB, committed=1647104KB)

(mmap: reserved=4194304KB, committed=1647104KB) 



- Class (reserved=1118666KB, committed=77258KB)

(classes #12468)

(malloc=10698KB #17369) 

(mmap: reserved=1107968KB, committed=66560KB) 



- Thread (reserved=44541KB, committed=44541KB)

(thread #45)

(stack: reserved=44192KB, committed=44192KB)

(malloc=137KB #230) 

(arena=212KB #89)

…..

-
Docker
-XX:+UnlockExperimentalVMOptions

-XX:+UseCGroupMemoryLimitForHeap

-XX:MaxRAMFraction=
Lorem Ipsum Dolor
Questions?

Java Memory Structure