Skip to content

Route all VT creation through scheduler.newThread() for custom schedulers#225

Draft
franz1981 wants to merge 1 commit into
openjdk:fibersfrom
franz1981:newthread-routing
Draft

Route all VT creation through scheduler.newThread() for custom schedulers#225
franz1981 wants to merge 1 commit into
openjdk:fibersfrom
franz1981:newthread-routing

Conversation

@franz1981

@franz1981 franz1981 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

When a custom scheduler is installed via implClass, all VT creation routes through scheduler.newThread(String, int, Thread, Runnable) — the new raw-params overload.
The existing builder overload delegates to it, extracting name and characteristics from the builder.

Single routing point in newVirtualThread(): when scheduler is null and CUSTOM_SCHEDULER is true, routes through the default scheduler's raw newThread(). No cycle — the raw default creates VirtualThread directly.

For paths without a builder (startVirtualThread, factory), uses no builder allocation — raw params are passed directly.


This is a PoC which show 2 things:

  1. if the (custom) scheduler overrides the newThread method can wrap its Runnable with a ScopedValue which can help with Add VirtualThreadScheduler.currentVirtualThreadTask() default method #224: still duplication (as it is now, which is not great), but enable every VT to run with such context.
  2. using the preferredCarrier != null info, a custom scheduler can "treat" differently (by forcing some specific scheduling policy) such VirtualThread e.g. JDK pollers

Other 2 things:

  • I dislike to pass/intercepts raw VT parameters
  • Since we have some "legacy" thread builder scheduler field, this looks more messy than it could, sorry for that: with the unified "custom scheduler" API probably there's no reason to have per-builder scheduler fields

Progress

  • Change must not contain extraneous whitespace

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/loom.git pull/225/head:pull/225
$ git checkout pull/225

Update a local copy of the PR:
$ git checkout pull/225
$ git pull https://git.openjdk.org/loom.git pull/225/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 225

View PR using the GUI difftool:
$ git pr show -t 225

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/loom/pull/225.diff

@bridgekeeper

bridgekeeper Bot commented Jun 15, 2026

Copy link
Copy Markdown

👋 Welcome back franz1981! A progress list of the required criteria for merging this PR into fibers will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented Jun 15, 2026

Copy link
Copy Markdown

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

…lers

When a custom scheduler is installed via implClass, all VT creation
routes through scheduler.newThread(String, int, Thread, Runnable) —
the new raw-params overload. The existing builder overload delegates
to it, extracting name and characteristics from the builder.

Single routing point in newVirtualThread(): when scheduler is null
and CUSTOM_SCHEDULER is true, routes through the default scheduler's
raw newThread(). No cycle — the raw default creates VirtualThread
directly.

For paths without a builder (startVirtualThread, factory), uses
no builder allocation — raw params are passed directly.

CUSTOM_SCHEDULER is static final, JIT constant-folds for builtin.
* @see <a href="Thread.html#inheritance">Inheritance when creating threads</a>
*/
default VirtualThreadTask newThread(Builder.OfVirtual builder,
default VirtualThreadTask newThread(String name, int characteristics,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

characteristics is JDK internal implementation default so cannot be exposed with the API like this.

@franz1981 franz1981 Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I mentioned it in the first desc

I dislike to pass/intercepts raw VT parameters

That's what I meant 🙏

This is just a PoC to show the idea: currently there are different routes (builders/factories and raw VT start), and unify them to all go through the scheduler::newThread which uses a builder is not still right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants