Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ThreadLocal allocated in TLAB?

I suppose, that ThreadLocal variables are allocated in Thread Local allocation Buffer(s) or TLABs, am I right ?

I was not successful in finding any document stating what exactly makes some class stored in TLAB. If you know some, please post a link.

like image 884
Rostislav Matl Avatar asked Dec 05 '22 23:12

Rostislav Matl


1 Answers

I was not successfull to find any document stating what exactly makes some class stored in TLAB. If you know some, please post a link.

Actually, the explanation is right there in the blog post you lnked to:

A Thread Local Allocation Buffer (TLAB) is a region of Eden that is used for allocation by a single thread. It enables a thread to do object allocation using thread local top and limit pointers, which is faster than doing an atomic operation on a top pointer that is shared across threads.

Every thread allocates memory from its own chunk of Eden, the "Generation 0" part of the heap. Pretty much everything is stored in the TLAB for a period of time - quite possibly your ThreadLocals, too - but they get moved away from there after a gen0 garbage collection. TLABs are there to make allocations faster, not to make the memory unaccessible from other threads. A more accessible description from the same blog you linked to is A little thread privacy, please.

like image 71
gustafc Avatar answered Dec 08 '22 05:12

gustafc