什么是TLAB
TLAB全称是thread local allocation buffer,本地线程缓存的意思。
有什么作用,简单来说是多线程的情况下,加速对象实例内存分配的一种方式!每个线程在java heap堆中预留的一小块内存。当线程需要堆区空间的时候,可以使用预先分配的线程缓冲!只有本地缓冲区用完了,分配新的缓存区时才需要同步锁定。参数-XX:+UseTLAB开启TLAB,默认是开启的。TLAB空间的内存非常小,缺省情况下仅占有整个Eden空间的1%,当然可以通过选项-XX:TLABWasteTargetPercent设置TLAB空间所占用Eden空间的百分比大小。
如果不用TLAB的话,还可以使用CAS失败重试的机制,在多线程情况下分配堆区对象实例内存空间!
The idea of a TLAB is to reduce the need of synchronization between threads. Using TLABs, this need is reduced as any thread has an area it can use and expect that it is the only thread using this area. Assuming that a TLAB can hold 100 objects, a thread would only need to aquire a lock for claiming more memory when allocating the 101 object. Without TLABs, this would be required for every object. The downside is of course that you potentially waste space.
Large objects are typically allocated outside of a TLAB as they void the advantage of reducing the frequency of synchronized memory allocation. Some objects might not even fit inside of a TLAB.
You can set the size of a TLAB using the -XX:TLABSize flag but generally I do not recommend you to mess with these settings unless you really discovered a problem that you can solve by that.
---------摘自https://stackoverflow.com/questions/43747221/what-is-a-tlab-thread-local-allocation-buffer

浙公网安备 33010602011771号