Skip to content

Add JFR metrics for virtual thread pinning and submit failures#19092

Open
tsawada wants to merge 2 commits into
open-telemetry:mainfrom
tsawada:tsawada/jfr-virtual-threads
Open

Add JFR metrics for virtual thread pinning and submit failures#19092
tsawada wants to merge 2 commits into
open-telemetry:mainfrom
tsawada:tsawada/jfr-virtual-threads

Conversation

@tsawada

@tsawada tsawada commented Jun 28, 2026

Copy link
Copy Markdown
  • Add VirtualThreadPinnedHandler to collect jdk.VirtualThreadPinned as jvm.thread.virtual.pinned histogram (seconds)
  • Add VirtualThreadSubmitFailedHandler to collect jdk.VirtualThreadSubmitFailed as jvm.thread.virtual.submit_failed counter
  • Add VIRTUAL_THREAD_METRICS feature to JfrFeature (experimental, disabled by default) - Add testJava21 source set for tests requiring Java 21+ APIs

Both events exist since Java 19. The implementation lives in the java17 source set since only the event name strings depend on JVM version.

No test for VirtualThreadSubmitFailed, as I couldn't come up with a reliable way to trigger it.

VirtualThreadPinned threshold defaults to 20 ms, which may be worth making configurable. Other handlers such as LongLockHandler also rely on the JFR default threshold, so I've kept the same approach here.

Related: #14949

@tsawada tsawada requested a review from a team as a code owner June 28, 2026 13:20
Copilot AI review requested due to automatic review settings June 28, 2026 13:20
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 28, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: tsawada / name: Takeo Sawada (e40d254)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds two new JFR-based runtime-telemetry metrics for virtual threads: jvm.thread.virtual.pinned (a histogram of pinning durations from jdk.VirtualThreadPinned) and jvm.thread.virtual.submit_failed (a counter from jdk.VirtualThreadSubmitFailed). Both are gated behind a new experimental, default-disabled VIRTUAL_THREAD_METRICS JfrFeature. The handlers live in the existing java17 source set (the events exist since Java 19), and a new testJava21 source set is introduced to host tests that need GA virtual-thread APIs. The new handlers closely mirror the existing LongLockHandler pattern and are wired into HandlerRegistry.

Changes:

  • Add VirtualThreadPinnedHandler and VirtualThreadSubmitFailedHandler, plus the VIRTUAL_THREAD_METRICS feature, and register both handlers.
  • Add a testJava21 source set, configurations, compile/test task wiring, and a JfrVirtualThreadPinnedTest.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
.../internal/threads/VirtualThreadPinnedHandler.java New handler recording pinning duration as a seconds histogram.
.../internal/threads/VirtualThreadSubmitFailedHandler.java New handler counting submit-failed events.
.../internal/JfrFeature.java Adds the experimental, default-disabled VIRTUAL_THREAD_METRICS feature.
.../internal/HandlerRegistry.java Registers the two new handlers.
.../build.gradle.kts Adds testJava21 source set, configurations, compile/test tasks, and check wiring.
.../testJava21/.../JfrVirtualThreadPinnedTest.java New Java 21+ test exercising virtual-thread pinning.

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome.

For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question.

Automation flags a PR for human review once every review thread has a reply or is marked as resolved.

Status across open PRs is visible on the pull request dashboard.

Comment on lines +32 to +33
int feature = Runtime.version().feature();
Assumptions.assumeTrue(feature >= 21 && feature < 24, "Requires Java 21-23");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could consider @EnabledOnJre(JRE.JAVA_21)

@laurit laurit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants