Quick revision
The short answer
A TLAB is a private chunk of eden that HotSpot hands to each thread, so the thread can allocate by bumping its own pointer without any synchronisation. When the TLAB runs out, the thread either retires it and takes a new one or, if the object is large compared with the TLAB, allocates that object directly in shared eden on a slower path. In G1, an object of half a region or more is humongous and bypasses eden altogether.
What to remember
In this answer, we saw that a TLAB is a private slice of eden that lets each thread allocate with a pointer bump and no synchronisation. When it runs out, the thread either retires it and takes a new one or allocates the object directly in eden, depending on the refill waste limit. In G1, objects of half a region or more skip both and go into dedicated humongous regions, which has its own costs. Finally, JFR records allocations on these slow paths, which gives a byte-weighted sample of allocation with very low overhead.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A TLAB is a private chunk of eden that HotSpot hands to each thread, so the thread can allocate by bumping its own pointer without any synchronisation. When the TLAB runs out, the thread either retires it and takes a new one or, if the object is large compared with the TLAB, allocates that object directly in shared eden on a slower path. In G1, an object of half a region or more is humongous and bypasses eden altogether.
Why this question is asked
Allocation is the most frequent thing a Java program does, so HotSpot works hard to make it fast, and TLABs are the main reason it is fast. Interviewers ask about them at this level because the slow paths explain real observations: why a few large buffers can hurt G1, why JFR can profile allocation cheaply, and why allocation profiles look the way they do. In this answer, we will recap what a TLAB is, walk through the fast path and the refill path, see what happens to an object that does not fit, look at humongous objects in G1, and finish with how JFR uses all this for low-overhead profiling.
1A Quick Recap of Eden and TLABs
New objects are allocated in eden, the part of the young generation where objects start their lives. If every thread allocated directly in eden, they would all update one shared top pointer, and each allocation would need an atomic compare-and-swap instruction. With dozens of threads allocating millions of objects per second, that shared pointer would become a hot spot.
So HotSpot gives each thread its own thread-local allocation buffer, a TLAB. A TLAB is just a range of eden, described by a start, a current top and an end, that only one thread may allocate into. Getting the TLAB from eden needs synchronisation, but allocating inside it does not.
2The Fast Path: a Pointer Bump
When a thread executes new Order(), compiled code checks whether the object fits between the TLAB's top and end. If it does, the object's address is the current top, and top moves forward by the object's size. The JVM then writes the object header and makes sure the fields are zero. That is the whole fast path, a few machine instructions, and it is inlined into the compiled method.
Notice that nothing here touches shared memory. The thread owns its TLAB, so two threads allocating at the same moment never interfere with each other.
3When the TLAB Runs Out
Sooner or later the object does not fit. Now the thread leaves the fast path and calls into the JVM runtime. There are two choices, and HotSpot picks between them with a rule called the refill waste limit.
If the space left in the TLAB is small, below the waste limit, the thread retires the TLAB. It fills the unused tail with a dummy filler object so the heap stays parsable for the collector, asks eden for a fresh TLAB, and allocates the object there. Getting a new TLAB means updating eden's shared top with an atomic operation, so this path is slower, but it happens once per TLAB rather than once per object.
If the space left is still large, throwing it away would waste memory. So instead the thread keeps its TLAB and allocates this one object directly in shared eden, outside any TLAB, using the shared atomic pointer. It also raises its waste limit a little, so that if this keeps happening, it eventually retires the TLAB anyway. The default limit is a fraction of the TLAB size (TLABRefillWasteFraction, 64 by default, meaning one sixty-fourth; check your version).
- Does s fit in the current TLAB?YesPointer bump, doneNoGo to the slow path
- Is s humongous for G1?YesAllocate in dedicated humongous regionsNoContinue
- Is the TLAB's free space below the waste limit?YesRetire TLAB, take a new one, allocate thereNoAllocate s in eden outside the TLAB
- If eden has no roomtrigger a young collection, then retry
4 steps in order. Play them, or step through them one at a time.
Only the first step is the common case; the rest are slow paths.
4How Big Is a TLAB?
TLABs are not a fixed size. HotSpot sizes them per thread based on how much each thread allocated between recent collections and how many threads are allocating, aiming for each thread to refill its TLAB a set number of times per young collection. A busy request thread gets a large TLAB, often hundreds of kilobytes or more, while an idle thread gets a small one, so idle threads do not hold big chunks of eden hostage.
So whether an object is too large for the current TLAB depends both on its size and on how full the TLAB already is. A 10 KB array might fit easily into a fresh TLAB, trigger a refill when the TLAB is nearly full, or be allocated outside the TLAB when the TLAB still has a lot of space but not quite enough.
5Humongous Objects in G1
G1 divides the heap into equal regions, typically between 1 MB and 32 MB depending on heap size. An object of half a region or more is called humongous. G1 never puts it in eden or in a TLAB. Instead it finds one or more contiguous free regions and allocates the object there directly, as part of the old generation.
The reason is that copying a multi-megabyte object between survivor spaces on every young collection would be expensive. But humongous allocation has its own costs. It needs contiguous free regions, it wastes the unused tail of the last region, and a high rate of humongous allocation can trigger concurrent marking cycles or, in the worst case, a full collection when no contiguous space is left. G1 can reclaim dead humongous objects early during young collections in many cases, but code that allocates large temporary buffers in a loop is still a classic G1 problem.
A common fix is to reuse large buffers, read data in smaller chunks, or raise the region size with -XX:G1HeapRegionSize so that the objects stop being humongous.
6How JFR Uses TLABs for Cheap Profiling
Profiling every allocation would be far too expensive, because the fast path is only a few instructions. JFR avoids this by hooking only the slow paths. The event jdk.ObjectAllocationInNewTLAB is recorded when a thread takes a new TLAB, and it reports the object that caused the refill together with its stack trace. The event jdk.ObjectAllocationOutsideTLAB is recorded when an object is allocated directly in eden or as a humongous object.
Since a TLAB refill happens roughly once every so many kilobytes of allocation, the object that triggers it is effectively a sample weighted by bytes allocated. A stack that allocates ten times more bytes triggers about ten times more refills. Newer JDKs add jdk.ObjectAllocationSample, which throttles these samples to a configurable rate and is enabled in the default JFR profile. That is how JFR gives a realistic picture of who allocates the most, with overhead low enough for production.
7Follow-up questions
Are TLABs used for every allocation?
No. Objects that are allocated outside the TLAB because they are large relative to the remaining space, humongous objects in G1, and allocations made while the JVM itself is in certain runtime paths go elsewhere. But for typical application code, the overwhelming majority of objects come from TLABs.
Can we turn TLABs off?
There is a flag, -XX:-UseTLAB, but turning them off makes every allocation contend on eden's shared pointer and is only useful for experiments. Tuning flags such as the minimum TLAB size exist too, but the adaptive sizing is good enough that changing them is rarely worth it.
Why does an allocation profile sometimes blame an innocent small object?
Because the sample is the object that happened to trigger the refill. Over many samples the blame is fair in proportion to bytes allocated, but a single sample can land on any object. We should read allocation profiles in aggregate, not trust one stack trace.
8Conclusion
In this answer, we saw that a TLAB is a private slice of eden that lets each thread allocate with a pointer bump and no synchronisation. When it runs out, the thread either retires it and takes a new one or allocates the object directly in eden, depending on the refill waste limit. In G1, objects of half a region or more skip both and go into dedicated humongous regions, which has its own costs. Finally, JFR records allocations on these slow paths, which gives a byte-weighted sample of allocation with very low overhead.
Open with
A TLAB, a thread-local allocation buffer, is a chunk of eden that HotSpot gives to one thread. Inside it, allocation is a pointer bump: check that the object fits before the end, return the current top, move top forward, write the header.
Then, if they want more
No lock and no atomic operation, because only that thread uses the buffer. Getting a TLAB from eden does need an atomic update of eden's shared top, so that is the slower path, but it happens once per TLAB. When an object does not fit, HotSpot looks at how much space is left.
If the remainder is below the refill waste limit, a fraction of the TLAB size, it retires the TLAB, fills the gap with a filler object, takes a new TLAB and allocates there. If a lot of space is still left, it allocates that one object directly in eden outside the TLAB and raises the waste limit.
TLAB sizes adapt per thread to allocation rate. In G1 there is one more case: an object of half a region or more is humongous and goes straight into contiguous dedicated regions, which can waste space and trigger extra GC work.
JFR hooks exactly these slow paths, with events for allocation in a new TLAB and outside a TLAB, which gives a byte-weighted sample of allocations at very low overhead.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain thread-local allocation buffers (TLABs) in HotSpot, and what happens when an...": https://scrivio-interview-library.netlify.app/java/java-performance/1d8a0cbe88/