Skip to main content

Java memory model

Schema

RAM
HEAP
heap0
Heap is shared between threads
sg_tlab_0
Thread-Local Allocation Buffer Thread 0
sg_tlab_1
Thread-Local Allocation Buffer Thread 1
Thread #0
Thread_Stack_0
Local variables (primitives) and method params:
byte
short
char
int
long
float
double
THREAD_TLAB0
TLAB
Thread #1
Thread_Stack_1
Local variables (primitives) and method params:
byte
short
char
int
long
float
double
THREAD_TLAB1
TLAB

Memory model image

Thread-Local Allocation Buffer section in EDEN space Memory model image

JVM memory allocation

JVM memory allocation

THREAD_TLAB0 --> sg_tlab_0 THREAD_TLAB1 --> sg_tlab_1

UseTLAB setting this will stop the JVM from using TLAB

-XX-UseTLAB

To not allow resizing (if it's filled - all allocations would be in main sync heap)

-XX:-ResizeTLAB

For size settings (per thread)

-XX:TLABSize -XX:MinTLABSize -XX:MaxTLABSize

-Xlog:gc+tlab=trace flag