On Thu, 13 Mar 2025 10:48:14 GMT, Alan Bateman <[email protected]> wrote:
> Follow up to JDK-8319447 to change the VirtualThread implementation to use
> FJP's delayed task handling.
>
> The SPTE based implementation is not removed. It will continue to be used by
> tests. If custom schedulers are exposed in the future then they will use this
> implementation.
>
> For timed-Object.wait, waitTimeoutExpired is changed to use lazySubmit to
> avoid signalling and increase the chance that the unparked virtual thread
> will continue on the current carrier. For timed-park, the timeout task is
> changed to reduced form of unpark that also uses lazySubmit, for the same
> reason.
>
> `jcmd Thread.vthread_scheduler` is changed to no longer print the delay
> schedulers. Instead, the delayed task count will appear in the default
> scheduler output.
src/java.base/share/classes/java/lang/VirtualThread.java line 889:
> 887: private void parkTimeoutExpired() {
> 888: assert !VirtualThread.currentThread().isVirtual();
> 889: if (!getAndSetParkPermit(true)
@AlanBateman Would it make sense to test whether the park-permit is false
before the LOCK XCHG?
src/java.base/share/classes/java/lang/VirtualThread.java line 1455:
> 1453: return pool.schedule(command, delay, unit);
> 1454: } else {
> 1455: return DelayedTaskSchedulers.schedule(command, delay, unit);
@AlanBateman Would it make sense to test if the Scheduler implements
ScheduledExecutorService?
src/java.base/share/classes/java/lang/VirtualThread.java line 1462:
> 1460: * Supports scheduling a runnable task to run after a delay. It
> uses a number
> 1461: * of ScheduledThreadPoolExecutor instances to reduce contention on
> the delayed
> 1462: * work queue used. This class is used when using a custom
> scheduler.
@AlanBateman It might make sense to instead require a custom Scheduler to
implement ScheduledExecutorService? 🤔
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24030#discussion_r2033942539
PR Review Comment: https://git.openjdk.org/jdk/pull/24030#discussion_r2033943663
PR Review Comment: https://git.openjdk.org/jdk/pull/24030#discussion_r2033944680