-1

How currently TLAB is handling in Virtual Thread introduced by Project Loom in Java? Is TLAB available in virtual threads?

Matrix12
  • 446
  • 8
  • 19
  • Why do you think they are not available? Please note that I expect this to be not per virtual thread but per physical thread that can run virtual threads. (A virtual thread that is not executed by a physical thread cannot allocate memory and therefore also doesn't need a TLAB). – Thomas Kläger Aug 30 '22 at 10:21
  • What do you mean cannot allocate memory? In virtual thread we can allocate objects it question is how is coordinate with TLAB? I am not sure but I am wondering that virtual thread allocates outside of TLAB – Matrix12 Aug 30 '22 at 12:08
  • I am wondering about this because TLAB is reserved space for thread but we can create thousands of them so I assumed that it is not possible for create thousands of TLAB because they are quickly creating and terminating – Matrix12 Aug 30 '22 at 12:10

1 Answers1

1

Virtual threads don't have a TLAB - they don't need it.

From 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
Thomas Kläger
  • 17,754
  • 3
  • 23
  • 34