On Thu, 24 Oct 2024 22:13:27 GMT, David Holmes <dhol...@openjdk.org> wrote:

>> We don't unmount the virtual thread here, we just temporarily change the 
>> thread identity. You could think of this method as 
>> switchIdentityToCarrierThread if that helps.
>
> Sorry to belabour this but why are we temporarily changing the  thread 
> identity? What is the bigger operation that in underway here?

We've had these temporary transitions from day 1. The changes in this PR remove 
one usage, they don't add any new usages. The intention is to make this 
nuisance go away. The last usage requires changes to the timer support, working 
on it. For now, it's easiest to think of it as a "java on java" issue where 
critical code is in Java rather than the VM. The timer issue arises when a 
virtual thread does a timed park needs to schedule and cancel a timer. This 
currently requires executing Java code that may contend on a timer or trigger a 
timer thread to start. This has implications for thread state, the park 
blocker, and the parking permit. Adding support for nested parking gets very 
messy, adds overhead, and is confusing for serviceability observers.  The 
exiting behavior is to just temporarily switch the thread identity (as in 
Thread::currentThread) so it executes in the context of the carrier rather than 
the virtual thread. As I said, we are working to make this go away, it would 
have 
 been nice to have removed in advance of the changes here.

Update: The temporary transitions are now removed in the fibers branch (loom 
repo). This removes the switchToCarrierThread and switchToVirtualThread 
methods, and removes the need to introduce setCurrentLockId that is hard to 
explain in the discussions here. Need to decide if we should include it in this 
PR or try to do it before or after.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21565#discussion_r1816425590

Reply via email to