<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 22 Jul 2022, at 20:59, <a href="mailto:eric@kolotyluk.net" class="">
eric@kolotyluk.net</a> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span class="">Ooooh … “</span>cooperating with the compiler and making sure such transitions only occur inside methods that the compiler knows to treat specially.”<o:p class=""></o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
I know there are no ‘language’ changes, but I did not imagine there would be any cooperation with the compiler?<o:p class=""></o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Out of curiosity what does this look like, or can you refer us to some other discussions?<o:p class=""></o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Is this just normal Java reflection, or something deeper and more intimate with the compiler?<o:p class=""></o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Cheers, Eric</div>
</div>
</div>
</blockquote>
<br class="">
</div>
<div>I meant the JIT compiler(s). Look here: <a href="https://github.com/openjdk/jdk/blob/987656d69065b5b61d658cec3704a181a4aef18b/src/java.base/share/classes/java/lang/VirtualThread.java#L270" class="">https://github.com/openjdk/jdk/blob/987656d69065b5b61d658cec3704a181a4aef18b/src/java.base/share/classes/java/lang/VirtualThread.java#L270</a></div>
<div><br class="">
</div>
<div>The special @ChangesCurrentThread annotation on that method and a couple of others tells the compiler (i.e. the JIT compiler) to turn off some optimisations that rely on the assumption that the current thread cannot change in the middle of a method.</div>
<div><br class="">
</div>
<div>Neglecting that annotation could rely in miscompilation and very strange bugs, and we can’t statically infer that property, so that is why the Continuation class is not safe when used directly. Virtual threads take care to interact with the compiler in
 this way, but other constructs based on continuations must be thread-confined to be safe.</div>
<div><br class="">
</div>
<div>— Ron</div>
</body>
</html>