News for hackers. Stuff that matters.
Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by kevincox on Monday May 02, 2022 @04:34PM (#31240549)
Can you explain how this is done? Is the current stack copied onto the heap (to the size it currently is)? How are new frames allocated once a thread is suspended?
Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by pron on Monday May 02, 2022 @04:55PM (#31240808)
A portion of the stack is copied to the heap when the virtual thread is suspended, and upon successive yields those "stack chunks" are either reused or new ones allocated and form a linked list. When resuming a virtual thread, however, we don't copy its entire stack back from the heap to the stack, but we do it lazily, by installing a "return barrier" by patching the return address, so as you return from a method, its caller (or several callers) is lazily "thawed" back from the heap. This copying of small chunks of memory into a region that's likely in the cache is very efficient.

The entire mechanism is rather efficient because in Java we don't have pointers into the stack, so we don't need to pin anything to a specific address, and stacks can be freely moved around.

Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by SemanticStrengh on Monday May 02, 2022 @07:00PM (#31242241)
I wonder the implications and opportunities for https://github.com/microsoft/openjdk-proposals/blob/main/sta...
Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by U1F984 on Monday May 02, 2022 @08:05PM (#31242700)
Apparently it's already being taken into consideration:

> The optimization should work with Project Loom when it becomes available.