<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<div dir="auto">Did not know that graalvm supports that. It's what I am after. Thank you for the information, and the caveats. It's useful! I understand that the API may change dramatically, and will look into it instead.<br></div><div dir="auto"><br></div><div dir="auto">Hope this API can be the basis for the JEP, I am waiting this for a long time. Appreciate the effort the team and the community makes.<br></div><div dir="auto"><br></div><div dir="auto">Mar 19, 2025, 17:49 by michael.hearn@oracle.com:<br></div><blockquote class="tutanota_quote" style="border-left: 1px solid #93A3B8; padding-left: 10px; margin-left: 5px;"><div dir="auto">If you’d like to experiment with these features, including serialization of the stack frames, the Espresso JVM has an experimental API that enables them along with sample code showing how to build generators and Kryo-serialized subprogram snapshots.<br></div><div dir="auto"><br></div><div dir="auto">https://www.graalvm.org/reference-manual/espresso/continuations/<br></div><div dir="auto"><br></div><div dir="auto">https://www.graalvm.org/reference-manual/espresso/continuations/serialization/<br></div><div dir="auto"><br></div><div dir="auto">https://www.graalvm.org/reference-manual/espresso/continuations/generators/<br></div><div dir="auto"><br></div><div dir="auto">It may be enough for you to explore whatever it is you’re exploring. <br></div><div dir="auto"><br></div><div dir="auto">There are caveats!<br></div><div dir="auto"><br></div><div dir="auto">• The API will change dramatically.<br></div><div dir="auto">• Espresso is a a very new JVM with different features, performance and maturity levels to HotSpot.<br></div><div dir="auto"><br></div><div dir="auto">The planned API changes will bring it much closer to Loom philosophically, such that it might one day be the basis for a JEP. The current API is a conventional one exposes a Continuation class which lets you mount and unmount stack frames onto the current thread. Loom chooses not to expose that capability for technical reasons. We’ll go in the same direction, most likely by allowing the whole stack of a virtual thread to be copied into a LinkedList<StackFrame> or SerializableThread type structure, and also reconstituted from one. It means no net-new concepts in Java, resolves some edge cases around Thread.currentThread() stability assumptions, and because context switching virtual threads is so fast features like yielding values from a generator can be done using ordinary inter-thread constructs as you suggest.<br></div><div dir="auto"><br></div><blockquote><div dir="auto">On 18 Mar 2025, at 17:39, common1945@tutanota.com wrote:<br></div><div dir="auto"><br></div><div dir="auto">I am doing some experiments that will make use of loom's Continuation with jdk22+. I know that I can achieve java Continuation effect with following code. However, I have a few questions:<br></div><div dir="auto"><br></div><div dir="auto"> • Is it possible to pass in arguments like Lua's coroutine[1][2]?<br></div><div dir="auto"> • Is it possible to yield/ return some values like Lua's coroutine[1][2]?<br></div><div dir="auto"> • Does the way to communicate between the Continuation block i.e. Runnable and outside Runnable merely be able to achieved by embedding e.g. BlockingQueue inside the Runnable code block?<br></div><div dir="auto"> • Is it possible to capture Continuation's snapshot for later use?<br></div><div dir="auto">Many thanks<br></div><div dir="auto"><br></div><div dir="auto">import jdk.internal.vm.ContinuationScope;<br></div><div dir="auto">import jdk.internal.vm.Continuation;<br></div><div dir="auto"><br></div><div dir="auto">public class C {<br></div><div dir="auto"><br></div><div dir="auto"> public static void main(String[] args) {<br></div><div dir="auto"> var scope = new ContinuationScope("hello");<br></div><div dir="auto"> var yield = Continuation::yield;<br></div><div dir="auto"> var continuation = new Continuation(scope, () -> {<br></div><div dir="auto"> System.out.println("C1");<br></div><div dir="auto"> Continuation.yield(scope);<br></div><div dir="auto"> System.out.println("C2");<br></div><div dir="auto"> Continuation.yield(scope);<br></div><div dir="auto"> System.out.println("C3");<br></div><div dir="auto"> });<br></div><div dir="auto"> System.out.println("start");<br></div><div dir="auto"> continuation.run();<br></div><div dir="auto"> System.out.println("came back");<br></div><div dir="auto"> continuation.run();<br></div><div dir="auto"> System.out.println("back again");<br></div><div dir="auto"> continuation.run();<br></div><div dir="auto"> System.out.println("back again again");<br></div><div dir="auto"> }<br></div><div dir="auto">}<br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">[1]. https://stackoverflow.com/questions/38069751/confusion-about-lua-corountines-resume-and-yield-function/38075905#38075905<br></div><div dir="auto"><br></div><div dir="auto">[2]. https://www.lua.org/pil/9.1.html<br></div></blockquote></blockquote><div dir="auto"><br></div> </body>
</html>