Fast Allocation
As you will see from the garbage collector descriptions below, in many cases there are large contiguous blocks
of memory available from which to allocate objects. Allocations from such blocks are efficient, using a simple
bump-the-pointer technique. That is, the end of the previously allocated object is always kept track of. When a
new allocation request needs to be satisfied, all that needs to be done is to check whether the object will fit in
the remaining part of the generation and, if so, to update the pointer and initialize the object.
For multithreaded applications, allocation operations need to be multithread-safe. If global locks were used to
ensure this, then allocation into a generation would become a bottleneck and degrade performance. Instead,
the HotSpot JVM has adopted a technique called Thread-Local Allocation Buffers (TLABs). This improves
multithreaded allocation throughput by giving each thread its own buffer (i.e., a small portion of the
generation) from which to allocate. Since only one thread can be allocating into each TLAB, allocation can take
place quickly by utilizing the bump-the-pointer technique, without requiring any locking. Only infrequently,
when a thread fills up its TLAB and needs to get a new one, must synchronization be utilized. Several techniques
to minimize space wastage due to the use of TLABs are employed. For example, TLABs are sized by the allocator
to waste less than 1% of Eden, on average. The combination of the use of TLABs and linear allocations using the
bump-the-pointer technique enables each allocation to be efficient, only requiring around 10 native instructions.
See more details from Memory Management in the Java HotSpot™ Virtual Machine