On Mon, 17 Jun 2024 12:56:03 GMT, Alan Bateman <al...@openjdk.org> wrote:
>> src/hotspot/share/runtime/threads.cpp line 1334: >> >>> 1332: if (p->is_vthread_mounted()) { >>> 1333: const oop vt = p->vthread(); >>> 1334: if (vt != thread_oop) { >> >> We need a comment explaining why we have to check for this as without >> knowing the implementation quirks it seems non-sensical for a thread to have >> mounted itself! > >> We need a comment explaining why we have to check for this as without >> knowing the implementation quirks it seems non-sensical for a thread to have >> mounted itself! > > Just to note that JavaThread._vthread is always the "current thread". It's > the virtual thread when mounted, the carrier (as in itself) when there is no > virtual thread mounted. It's done this way so that the C2 instrinic for > currentThread doesn't need a branch/test. I wasn't aware of that, and I was going to suggest to add that information as documentation, but it seems to be already documented here: https://github.com/openjdk/jdk/blob/ad0b54d429fdbd806c09aa06bb42f1ed4a0297e8/src/hotspot/share/runtime/javaThread.hpp#L95 ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/19744#discussion_r1642798969