Issue
How currently TLAB is handling in Virtual Thread introduced by Project Loom in Java? Is TLAB available in virtual threads?
Solution
Virtual threads don't have a TLAB - they don't need it.
From href="https://blogs.oracle.com/javamagazine/post/going-inside-javas-project-loom-and-virtual-threads" rel="nofollow noreferrer">Going inside Java’s Project Loom and virtual threads:
Obviously, at some point, virtual threads must be attached to an actual OS thread to execute. These OS threads upon which a virtual thread executes are called carrier threads .
If a virtual thread is not attached to a carrier thread is not executing any instructions and therefore cannot allocate memory - it doesn't need a TLAB.
If it is attached to a carrier thread it is executing instructions and therefore can allocate memory. For this memory allocations it can safely use the TLAB of the carrier thread.
No contention here:
- at any point in time a carrier thread is executing exactly one virtual thread
- at any point in time a virtual thread is executed by at most one carrier thread
Answered By - Thomas Kläger
Answer Checked By - Gilberto Lyons (JavaFixing Admin)