[feature]: Experimental VirtualThreads support#4793
Conversation
|
Bravo! |
|
Unsure of where your roadmap is for Java IO/NIO integration of VirtualThreads but all those API that traditionally block without you even thinking about it (like Edit: or as possibly suggested via JEP proposal - all sockets/files/etc are now in non-blocking mode by default and the "blocking" jdk apis are all rewritten to be in terms of a non blocking event loop that is "hidden" that parks/wakes-up threads at every I/O op |
Not to ask for too much of your time. Do you know of models or examples of what you describe. Are they likely I've read the Java documentation for there various versions which had/have preview & release versions I can also always take a look at the 'delimited continuations' code in SN itself. That is two years In a similar vein, I've been monitoring various Scala 'async' efforts for a number of years, including SN PR #3978. Thank you For background, I am a SN contributor and one of the people who might be doing enabling SN library work. |
|
Here is the JDK 25 API doc for the from JEP 425:
im not sure if this is what is actually implemented but that seems to imply all sockets in JDK are now secretly in non-blocking mode, or can you temporarily change the socket to non-blocking while VT checks and then reset it to blocking? |
|
Thank you for the info. In following the evolution of Virtual Threads from preview thru JDK 25, I had seen |
|
Suggestion, since this work is Draft. perhaps it might be wise/prudent to make the first few releases of Background: Part of the reason that I am a big fan of SN Virtual Threads is that I had a private |
|
Virtual threads are always opt in, even on the JDK as these require usage of new Threads API to construct them. Adding additional blocker on the build side would seem redundant. |
|
OK, IIUC Thread#isVirtual' allows library calls to dispatch. JDK >= 21 allows entire program to choose 'Thread.ofVirtual()' or not, as suitable for each thread. I understand that a good goal is JDK 25 parity with no pinning surprises and synchronized blocks working. If SN has remaining gotchas, the announcement of virtual thread support announcement needs to be carefully worded so that early adopters are not turned off by falling into known, to some, defects or not-yet-implemented holes. Yes, a worry-wart concern. |
|
Whilst on a many hundred kilometer drive and contemplating this PR and #4798, IIRC, the current implementation of 'java.net' does not funnel through 'SocketChannel'. Of course, the test matrix doubles, which probably means re-writing many ancient & fragile Not jumping to solution, but contemplating what a solution might look like and what |
|
Support for custom Schedulers would be a great area to explore, as combining virtual threads with IOUring would be very promising. |
|
Hi @WojciechMazur, So sorry to ping you here. Please mark this comment as off-topic to hide it after reading. I left similar more context in the comment at bazel-contrib/rules_scala#1809 (comment), you might have already unsubscribed from that thread. And I don't want to give up yet since the GSoC 2026 application deadline (Mar 16~30) is approaching again. So I found your most active thread recently to reach out again: I applied for the 2025 GSoC project Scala Bazel Rules for Scala.js and Scala Native https://github.com/scalacenter/GoogleSummerOfCode?#scala-native--scalajs-projects last year. It's possible that my application might have been missed. I resent an application letter two weeks ago for 2026 GSoC project, could you please take a look at? Don't forget to check the spam or junk folder, just in case my email is incorrectly filtered. My sending address is Besides, I also tried to DM you on the Discord Scala Channel last week. Could you take a look at it when you get a chance? No hurry! Regards I've double checked your email from mutiple sources, I think I shouldn't mess up the address? Don't forget to hide this comment once you've read it! PS: I'm also excited to see Virtual Threads support on Scala Native! Cheers. |
6e11df5 to
5e15c33
Compare
|
In this implementation, can we customize the Scheduler? As far as I know, this implementation integrates very well with IO_Uring. |
eed7218 to
5a49ef9
Compare
There is an |
66c880b to
83657c6
Compare
|
https://github.com/franz1981/Netty-VirtualThread-Scheduler is a nice one hope this can help scala native for high performance networking @franz1981 |
|
This is needed too |
Based on the contibutions guide and the license agreements we're not to inspect the OpenJDK sources https://scala-native.org/en/latest/contrib/contributing.html#very-important-notice-about-javalib The approach from Netty won't work for us, becouse |
Right now it is usable only in the OpenJDK which is to run Netty's eventloops as long running virtual thread: it uses stock JDK +24 since previously NIO wasn't Loom friendly. |
83657c6 to
7aa4f9f
Compare
5c9e73c to
643e995
Compare
643e995 to
e3e6943
Compare
…le and hard to test
|
|
||
| import scala.scalanative.annotation.alwaysinline | ||
| import scala.scalanative.libc.stdatomic.{AtomicBool, AtomicInt, AtomicLong, AtomicRef} | ||
| import scala.scalanative.libc.stdatomic.{AtomicBool, AtomicInt, AtomicLongLong, AtomicRef} |
There was a problem hiding this comment.
The universe of fancy C types:
int - typically 4 bytes
long - maybe 4, maybe 8 bytes, effectively ssize_t
long long 8 bytes
|
Wow! |
|
yay! |
VirtualThreads support work has started in 2024 but was never finished. This branch contains work-in-progress implementation to track current progress. Some of these changes would be extracted
VirtualThreads are going to initially be a Scala 3 only feature due to the lack of Continuations API in Scala 2
This PR focuses only on the scheduling of lightweight threads, does not contains scoped-concurrency primitives.
Currently supports only MacOS (x86_64/aarch64) and Linux (x86_64) - no stable continuations on Windows yet
Known issue: on LLVM 14/ 15 the continuations result in broken state at runtime. Issue not present after upgrade to LLVM 16 (latest version 22 recommended)