Skip to content

Conversation

@PerfectSlayer
Copy link
Contributor

@PerfectSlayer PerfectSlayer commented Nov 27, 2025

What Does This Do

This pull request brings context tracking for the VirtualThread APIs from java.lang.
Before that, only virtual thread executor (newThreadPerTask) was supported from java.concurrency.

Motivation

Context tracking was broken when creating a virtual thread. It's runnable did not inherits from current context when created.

Additional Notes

This PR instruments VirtualThread to capture active state at creation, active it on continuation mount, and close the scope from activation on continuation unmount.

The instrumentation uses two context stores. The first from Runnable (as VirtualThread inherits from Runnable) to store the captured State to restore later. It additionally stores the AgentScope to be able to close it later as activation / close is not done around the same method (so passing the scope from OnMethodEnter / OnMethodExit using advice return value is not possible).

Instrumenting the internal VirtualThread.runContinuation() method does not work as the current thread is still the carrier thread and not a virtual thread. Activating the state when on the carrier thread (ie a platform thread) would store the active context into ThreadLocal using the platform thread as key, making the tracer unable to retrieve the stored context from the current virtual thread (ThreadLocal will not return the value associated to the underlying platform thread as they are considered to be different).

An alternative implementation could be to instrument jdk.internal.vm.Continuation and its children for state capture (at continuation creation <init>), state activation (after mount), and scope close (before unmount). I ended up instrumenting VirtualThread instead to instrument java.lang rather than jdk.internal.vm, and because thread set is done in VirtualThread itself, making it simpler to hook context tracking where thread activity happens.

Contributor Checklist

Jira ticket: APMLP-647 / APMS-17629 / #9984 / #6468

@PerfectSlayer PerfectSlayer added type: enhancement Enhancements and improvements comp: context propagation Trace context propagation inst: java Core Java language instrumentation labels Nov 27, 2025
@pr-commenter
Copy link

pr-commenter bot commented Nov 27, 2025

Benchmarks

Startup

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master bbujon/virtual-threads
git_commit_date 1764888648 1764927796
git_commit_sha 4e48384 1934b72
release_version 1.57.0-SNAPSHOT~4e48384724 1.57.0-SNAPSHOT~1934b72f79
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
ci_job_date 1764929793 1764929793
ci_job_id 1271962916 1271962916
ci_pipeline_id 84989266 84989266
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-pk27majd 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-pk27majd 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
module Agent Agent
parent None None

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 59 metrics, 6 unstable metrics.

Startup time reports for petclinic
gantt
    title petclinic - global startup overhead: candidate=1.57.0-SNAPSHOT~1934b72f79, baseline=1.57.0-SNAPSHOT~4e48384724

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (1.079 s) : 0, 1078927
Total [baseline] (10.825 s) : 0, 10824651
Agent [candidate] (1.082 s) : 0, 1081728
Total [candidate] (10.91 s) : 0, 10909776
section appsec
Agent [baseline] (1.27 s) : 0, 1270040
Total [baseline] (11.119 s) : 0, 11119137
Agent [candidate] (1.266 s) : 0, 1265851
Total [candidate] (11.175 s) : 0, 11175206
section iast
Agent [baseline] (1.225 s) : 0, 1224616
Total [baseline] (11.24 s) : 0, 11240468
Agent [candidate] (1.222 s) : 0, 1222483
Total [candidate] (11.224 s) : 0, 11223962
section profiling
Agent [baseline] (1.204 s) : 0, 1203730
Total [baseline] (10.997 s) : 0, 10997494
Agent [candidate] (1.206 s) : 0, 1205955
Total [candidate] (10.991 s) : 0, 10991449
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 1.079 s -
Agent appsec 1.27 s 191.114 ms (17.7%)
Agent iast 1.225 s 145.689 ms (13.5%)
Agent profiling 1.204 s 124.803 ms (11.6%)
Total tracing 10.825 s -
Total appsec 11.119 s 294.486 ms (2.7%)
Total iast 11.24 s 415.817 ms (3.8%)
Total profiling 10.997 s 172.843 ms (1.6%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 1.082 s -
Agent appsec 1.266 s 184.124 ms (17.0%)
Agent iast 1.222 s 140.756 ms (13.0%)
Agent profiling 1.206 s 124.227 ms (11.5%)
Total tracing 10.91 s -
Total appsec 11.175 s 265.43 ms (2.4%)
Total iast 11.224 s 314.187 ms (2.9%)
Total profiling 10.991 s 81.674 ms (0.7%)
gantt
    title petclinic - break down per module: candidate=1.57.0-SNAPSHOT~1934b72f79, baseline=1.57.0-SNAPSHOT~4e48384724

    dateFormat X
    axisFormat %s
section tracing
crashtracking [baseline] (1.185 ms) : 0, 1185
crashtracking [candidate] (1.189 ms) : 0, 1189
BytebuddyAgent [baseline] (646.487 ms) : 0, 646487
BytebuddyAgent [candidate] (648.429 ms) : 0, 648429
GlobalTracer [baseline] (282.106 ms) : 0, 282106
GlobalTracer [candidate] (282.424 ms) : 0, 282424
AppSec [baseline] (32.222 ms) : 0, 32222
AppSec [candidate] (32.314 ms) : 0, 32314
Debugger [baseline] (68.091 ms) : 0, 68091
Debugger [candidate] (68.296 ms) : 0, 68296
Remote Config [baseline] (649.076 µs) : 0, 649
Remote Config [candidate] (652.894 µs) : 0, 653
Telemetry [baseline] (8.979 ms) : 0, 8979
Telemetry [candidate] (9.096 ms) : 0, 9096
Flare Poller [baseline] (3.695 ms) : 0, 3695
Flare Poller [candidate] (3.799 ms) : 0, 3799
section appsec
crashtracking [baseline] (1.189 ms) : 0, 1189
crashtracking [candidate] (1.189 ms) : 0, 1189
BytebuddyAgent [baseline] (690.458 ms) : 0, 690458
BytebuddyAgent [candidate] (688.658 ms) : 0, 688658
GlobalTracer [baseline] (261.205 ms) : 0, 261205
GlobalTracer [candidate] (259.768 ms) : 0, 259768
IAST [baseline] (24.956 ms) : 0, 24956
IAST [candidate] (24.605 ms) : 0, 24605
AppSec [baseline] (175.784 ms) : 0, 175784
AppSec [candidate] (174.001 ms) : 0, 174001
Debugger [baseline] (67.413 ms) : 0, 67413
Debugger [candidate] (68.747 ms) : 0, 68747
Remote Config [baseline] (678.926 µs) : 0, 679
Remote Config [candidate] (756.122 µs) : 0, 756
Telemetry [baseline] (8.923 ms) : 0, 8923
Telemetry [candidate] (8.845 ms) : 0, 8845
Flare Poller [baseline] (3.944 ms) : 0, 3944
Flare Poller [candidate] (3.775 ms) : 0, 3775
section iast
crashtracking [baseline] (1.185 ms) : 0, 1185
crashtracking [candidate] (1.192 ms) : 0, 1192
BytebuddyAgent [baseline] (789.569 ms) : 0, 789569
BytebuddyAgent [candidate] (790.387 ms) : 0, 790387
GlobalTracer [baseline] (256.146 ms) : 0, 256146
GlobalTracer [candidate] (255.806 ms) : 0, 255806
IAST [baseline] (27.004 ms) : 0, 27004
IAST [candidate] (26.852 ms) : 0, 26852
AppSec [baseline] (35.862 ms) : 0, 35862
AppSec [candidate] (35.068 ms) : 0, 35068
Debugger [baseline] (66.893 ms) : 0, 66893
Debugger [candidate] (65.478 ms) : 0, 65478
Remote Config [baseline] (567.941 µs) : 0, 568
Remote Config [candidate] (567.779 µs) : 0, 568
Telemetry [baseline] (8.539 ms) : 0, 8539
Telemetry [candidate] (8.401 ms) : 0, 8401
Flare Poller [baseline] (3.486 ms) : 0, 3486
Flare Poller [candidate] (3.441 ms) : 0, 3441
section profiling
crashtracking [baseline] (1.188 ms) : 0, 1188
crashtracking [candidate] (1.196 ms) : 0, 1196
BytebuddyAgent [baseline] (701.194 ms) : 0, 701194
BytebuddyAgent [candidate] (703.136 ms) : 0, 703136
GlobalTracer [baseline] (220.922 ms) : 0, 220922
GlobalTracer [candidate] (221.085 ms) : 0, 221085
AppSec [baseline] (32.217 ms) : 0, 32217
AppSec [candidate] (32.135 ms) : 0, 32135
Debugger [baseline] (68.219 ms) : 0, 68219
Debugger [candidate] (67.969 ms) : 0, 67969
Remote Config [baseline] (630.172 µs) : 0, 630
Remote Config [candidate] (631.17 µs) : 0, 631
Telemetry [baseline] (8.988 ms) : 0, 8988
Telemetry [candidate] (8.994 ms) : 0, 8994
Flare Poller [baseline] (3.829 ms) : 0, 3829
Flare Poller [candidate] (3.789 ms) : 0, 3789
ProfilingAgent [baseline] (96.936 ms) : 0, 96936
ProfilingAgent [candidate] (97.331 ms) : 0, 97331
Profiling [baseline] (97.53 ms) : 0, 97530
Profiling [candidate] (97.921 ms) : 0, 97921
Loading
Startup time reports for insecure-bank
gantt
    title insecure-bank - global startup overhead: candidate=1.57.0-SNAPSHOT~1934b72f79, baseline=1.57.0-SNAPSHOT~4e48384724

    dateFormat X
    axisFormat %s
section tracing
Agent [baseline] (1.08 s) : 0, 1079546
Total [baseline] (8.758 s) : 0, 8757617
Agent [candidate] (1.088 s) : 0, 1088488
Total [candidate] (8.755 s) : 0, 8755295
section iast
Agent [baseline] (1.233 s) : 0, 1232710
Total [baseline] (9.491 s) : 0, 9491256
Agent [candidate] (1.222 s) : 0, 1222355
Total [candidate] (9.487 s) : 0, 9486611
Loading
  • baseline results
Module Variant Duration Δ tracing
Agent tracing 1.08 s -
Agent iast 1.233 s 153.164 ms (14.2%)
Total tracing 8.758 s -
Total iast 9.491 s 733.638 ms (8.4%)
  • candidate results
Module Variant Duration Δ tracing
Agent tracing 1.088 s -
Agent iast 1.222 s 133.867 ms (12.3%)
Total tracing 8.755 s -
Total iast 9.487 s 731.317 ms (8.4%)
gantt
    title insecure-bank - break down per module: candidate=1.57.0-SNAPSHOT~1934b72f79, baseline=1.57.0-SNAPSHOT~4e48384724

    dateFormat X
    axisFormat %s
section tracing
crashtracking [baseline] (1.192 ms) : 0, 1192
crashtracking [candidate] (1.203 ms) : 0, 1203
BytebuddyAgent [baseline] (647.573 ms) : 0, 647573
BytebuddyAgent [candidate] (652.573 ms) : 0, 652573
GlobalTracer [baseline] (282.227 ms) : 0, 282227
GlobalTracer [candidate] (284.288 ms) : 0, 284288
AppSec [baseline] (32.225 ms) : 0, 32225
AppSec [candidate] (32.581 ms) : 0, 32581
Debugger [baseline] (67.276 ms) : 0, 67276
Debugger [candidate] (68.537 ms) : 0, 68537
Remote Config [baseline] (647.386 µs) : 0, 647
Remote Config [candidate] (645.294 µs) : 0, 645
Telemetry [baseline] (9.001 ms) : 0, 9001
Telemetry [candidate] (9.144 ms) : 0, 9144
Flare Poller [baseline] (3.667 ms) : 0, 3667
Flare Poller [candidate] (3.737 ms) : 0, 3737
section iast
crashtracking [baseline] (1.215 ms) : 0, 1215
crashtracking [candidate] (1.192 ms) : 0, 1192
BytebuddyAgent [baseline] (798.049 ms) : 0, 798049
BytebuddyAgent [candidate] (790.664 ms) : 0, 790664
GlobalTracer [baseline] (257.479 ms) : 0, 257479
GlobalTracer [candidate] (255.653 ms) : 0, 255653
IAST [baseline] (27.09 ms) : 0, 27090
IAST [candidate] (26.982 ms) : 0, 26982
AppSec [baseline] (34.387 ms) : 0, 34387
AppSec [candidate] (34.877 ms) : 0, 34877
Debugger [baseline] (66.047 ms) : 0, 66047
Debugger [candidate] (65.152 ms) : 0, 65152
Remote Config [baseline] (558.01 µs) : 0, 558
Remote Config [candidate] (571.499 µs) : 0, 571
Telemetry [baseline] (8.617 ms) : 0, 8617
Telemetry [candidate] (8.44 ms) : 0, 8440
Flare Poller [baseline] (3.504 ms) : 0, 3504
Flare Poller [candidate] (3.458 ms) : 0, 3458
Loading

Load

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master bbujon/virtual-threads
git_commit_date 1764888648 1764927796
git_commit_sha 4e48384 1934b72
release_version 1.57.0-SNAPSHOT~4e48384724 1.57.0-SNAPSHOT~1934b72f79
See matching parameters
Baseline Candidate
application insecure-bank insecure-bank
ci_job_date 1764930183 1764930183
ci_job_id 1271962918 1271962918
ci_pipeline_id 84989266 84989266
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-1wvavu9n 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-1wvavu9n 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Summary

Found 0 performance improvements and 2 performance regressions! Performance is the same for 18 metrics, 16 unstable metrics.

scenario Δ mean agg_http_req_duration_p50 Δ mean agg_http_req_duration_p95 Δ mean throughput candidate mean agg_http_req_duration_p50 candidate mean agg_http_req_duration_p95 candidate mean throughput baseline mean agg_http_req_duration_p50 baseline mean agg_http_req_duration_p95 baseline mean throughput
scenario:load:insecure-bank:iast_FULL:high_load worse
[+152.957µs; +385.176µs] or [+3.048%; +7.675%]
worse
[+409.563µs; +986.699µs] or [+3.437%; +8.281%]
unstable
[-124.370op/s; +50.682op/s] or [-15.261%; +6.219%]
5.288ms 12.614ms 778.125op/s 5.019ms 11.915ms 814.969op/s
Request duration reports for petclinic
gantt
    title petclinic - request duration [CI 0.99] : candidate=1.57.0-SNAPSHOT~1934b72f79, baseline=1.57.0-SNAPSHOT~4e48384724
    dateFormat X
    axisFormat %s
section baseline
no_agent (18.22 ms) : 18032, 18407
.   : milestone, 18220,
appsec (18.55 ms) : 18361, 18739
.   : milestone, 18550,
code_origins (18.119 ms) : 17938, 18301
.   : milestone, 18119,
iast (17.574 ms) : 17399, 17749
.   : milestone, 17574,
profiling (19.141 ms) : 18945, 19336
.   : milestone, 19141,
tracing (17.735 ms) : 17560, 17911
.   : milestone, 17735,
section candidate
no_agent (17.233 ms) : 17055, 17410
.   : milestone, 17233,
appsec (18.617 ms) : 18428, 18806
.   : milestone, 18617,
code_origins (17.676 ms) : 17498, 17854
.   : milestone, 17676,
iast (17.768 ms) : 17593, 17944
.   : milestone, 17768,
profiling (19.075 ms) : 18883, 19266
.   : milestone, 19075,
tracing (17.887 ms) : 17710, 18064
.   : milestone, 17887,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 18.22 ms [18.032 ms, 18.407 ms] -
appsec 18.55 ms [18.361 ms, 18.739 ms] 330.34 µs (1.8%)
code_origins 18.119 ms [17.938 ms, 18.301 ms] -100.12 µs (-0.5%)
iast 17.574 ms [17.399 ms, 17.749 ms] -645.721 µs (-3.5%)
profiling 19.141 ms [18.945 ms, 19.336 ms] 921.109 µs (5.1%)
tracing 17.735 ms [17.56 ms, 17.911 ms] -484.19 µs (-2.7%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 17.233 ms [17.055 ms, 17.41 ms] -
appsec 18.617 ms [18.428 ms, 18.806 ms] 1.384 ms (8.0%)
code_origins 17.676 ms [17.498 ms, 17.854 ms] 443.043 µs (2.6%)
iast 17.768 ms [17.593 ms, 17.944 ms] 535.324 µs (3.1%)
profiling 19.075 ms [18.883 ms, 19.266 ms] 1.842 ms (10.7%)
tracing 17.887 ms [17.71 ms, 18.064 ms] 654.084 µs (3.8%)
Request duration reports for insecure-bank
gantt
    title insecure-bank - request duration [CI 0.99] : candidate=1.57.0-SNAPSHOT~1934b72f79, baseline=1.57.0-SNAPSHOT~4e48384724
    dateFormat X
    axisFormat %s
section baseline
no_agent (1.219 ms) : 1207, 1231
.   : milestone, 1219,
iast (3.192 ms) : 3147, 3238
.   : milestone, 3192,
iast_FULL (5.671 ms) : 5615, 5726
.   : milestone, 5671,
iast_GLOBAL (3.575 ms) : 3521, 3628
.   : milestone, 3575,
profiling (2.11 ms) : 2091, 2128
.   : milestone, 2110,
tracing (1.801 ms) : 1786, 1816
.   : milestone, 1801,
section candidate
no_agent (1.195 ms) : 1183, 1206
.   : milestone, 1195,
iast (3.222 ms) : 3178, 3267
.   : milestone, 3222,
iast_FULL (5.942 ms) : 5882, 6001
.   : milestone, 5942,
iast_GLOBAL (3.602 ms) : 3549, 3655
.   : milestone, 3602,
profiling (2.003 ms) : 1985, 2021
.   : milestone, 2003,
tracing (1.84 ms) : 1823, 1857
.   : milestone, 1840,
Loading
  • baseline results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 1.219 ms [1.207 ms, 1.231 ms] -
iast 3.192 ms [3.147 ms, 3.238 ms] 1.974 ms (161.9%)
iast_FULL 5.671 ms [5.615 ms, 5.726 ms] 4.452 ms (365.3%)
iast_GLOBAL 3.575 ms [3.521 ms, 3.628 ms] 2.356 ms (193.3%)
profiling 2.11 ms [2.091 ms, 2.128 ms] 890.788 µs (73.1%)
tracing 1.801 ms [1.786 ms, 1.816 ms] 582.194 µs (47.8%)
  • candidate results
Variant Request duration [CI 0.99] Δ no_agent
no_agent 1.195 ms [1.183 ms, 1.206 ms] -
iast 3.222 ms [3.178 ms, 3.267 ms] 2.027 ms (169.7%)
iast_FULL 5.942 ms [5.882 ms, 6.001 ms] 4.747 ms (397.4%)
iast_GLOBAL 3.602 ms [3.549 ms, 3.655 ms] 2.407 ms (201.5%)
profiling 2.003 ms [1.985 ms, 2.021 ms] 808.413 µs (67.7%)
tracing 1.84 ms [1.823 ms, 1.857 ms] 645.03 µs (54.0%)

Dacapo

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch master bbujon/virtual-threads
git_commit_date 1764888648 1764927796
git_commit_sha 4e48384 1934b72
release_version 1.57.0-SNAPSHOT~4e48384724 1.57.0-SNAPSHOT~1934b72f79
See matching parameters
Baseline Candidate
application biojava biojava
ci_job_date 1764929945 1764929945
ci_job_id 1271962919 1271962919
ci_pipeline_id 84989266 84989266
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-wfp096lu 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-wfp096lu 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 10 metrics, 2 unstable metrics.

Execution time for biojava
gantt
    title biojava - execution time [CI 0.99] : candidate=1.57.0-SNAPSHOT~1934b72f79, baseline=1.57.0-SNAPSHOT~4e48384724
    dateFormat X
    axisFormat %s
section baseline
no_agent (14.754 s) : 14754000, 14754000
.   : milestone, 14754000,
appsec (14.746 s) : 14746000, 14746000
.   : milestone, 14746000,
iast (18.169 s) : 18169000, 18169000
.   : milestone, 18169000,
iast_GLOBAL (17.956 s) : 17956000, 17956000
.   : milestone, 17956000,
profiling (14.529 s) : 14529000, 14529000
.   : milestone, 14529000,
tracing (14.719 s) : 14719000, 14719000
.   : milestone, 14719000,
section candidate
no_agent (15.399 s) : 15399000, 15399000
.   : milestone, 15399000,
appsec (14.87 s) : 14870000, 14870000
.   : milestone, 14870000,
iast (18.146 s) : 18146000, 18146000
.   : milestone, 18146000,
iast_GLOBAL (18.221 s) : 18221000, 18221000
.   : milestone, 18221000,
profiling (14.458 s) : 14458000, 14458000
.   : milestone, 14458000,
tracing (14.768 s) : 14768000, 14768000
.   : milestone, 14768000,
Loading
  • baseline results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 14.754 s [14.754 s, 14.754 s] -
appsec 14.746 s [14.746 s, 14.746 s] -8.0 ms (-0.1%)
iast 18.169 s [18.169 s, 18.169 s] 3.415 s (23.1%)
iast_GLOBAL 17.956 s [17.956 s, 17.956 s] 3.202 s (21.7%)
profiling 14.529 s [14.529 s, 14.529 s] -225.0 ms (-1.5%)
tracing 14.719 s [14.719 s, 14.719 s] -35.0 ms (-0.2%)
  • candidate results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 15.399 s [15.399 s, 15.399 s] -
appsec 14.87 s [14.87 s, 14.87 s] -529.0 ms (-3.4%)
iast 18.146 s [18.146 s, 18.146 s] 2.747 s (17.8%)
iast_GLOBAL 18.221 s [18.221 s, 18.221 s] 2.822 s (18.3%)
profiling 14.458 s [14.458 s, 14.458 s] -941.0 ms (-6.1%)
tracing 14.768 s [14.768 s, 14.768 s] -631.0 ms (-4.1%)
Execution time for tomcat
gantt
    title tomcat - execution time [CI 0.99] : candidate=1.57.0-SNAPSHOT~1934b72f79, baseline=1.57.0-SNAPSHOT~4e48384724
    dateFormat X
    axisFormat %s
section baseline
no_agent (1.474 ms) : 1462, 1485
.   : milestone, 1474,
appsec (2.475 ms) : 2424, 2527
.   : milestone, 2475,
iast (2.215 ms) : 2150, 2279
.   : milestone, 2215,
iast_GLOBAL (2.266 ms) : 2201, 2331
.   : milestone, 2266,
profiling (2.09 ms) : 2036, 2144
.   : milestone, 2090,
tracing (2.055 ms) : 2004, 2105
.   : milestone, 2055,
section candidate
no_agent (1.475 ms) : 1463, 1486
.   : milestone, 1475,
appsec (3.679 ms) : 3463, 3895
.   : milestone, 3679,
iast (2.222 ms) : 2158, 2287
.   : milestone, 2222,
iast_GLOBAL (2.262 ms) : 2197, 2327
.   : milestone, 2262,
profiling (2.495 ms) : 2334, 2657
.   : milestone, 2495,
tracing (2.06 ms) : 2009, 2110
.   : milestone, 2060,
Loading
  • baseline results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 1.474 ms [1.462 ms, 1.485 ms] -
appsec 2.475 ms [2.424 ms, 2.527 ms] 1.002 ms (68.0%)
iast 2.215 ms [2.15 ms, 2.279 ms] 740.731 µs (50.3%)
iast_GLOBAL 2.266 ms [2.201 ms, 2.331 ms] 791.909 µs (53.7%)
profiling 2.09 ms [2.036 ms, 2.144 ms] 616.098 µs (41.8%)
tracing 2.055 ms [2.004 ms, 2.105 ms] 580.978 µs (39.4%)
  • candidate results
Variant Execution Time [CI 0.99] Δ no_agent
no_agent 1.475 ms [1.463 ms, 1.486 ms] -
appsec 3.679 ms [3.463 ms, 3.895 ms] 2.204 ms (149.4%)
iast 2.222 ms [2.158 ms, 2.287 ms] 747.396 µs (50.7%)
iast_GLOBAL 2.262 ms [2.197 ms, 2.327 ms] 787.179 µs (53.4%)
profiling 2.495 ms [2.334 ms, 2.657 ms] 1.021 ms (69.2%)
tracing 2.06 ms [2.009 ms, 2.11 ms] 584.733 µs (39.6%)

@PerfectSlayer PerfectSlayer force-pushed the bbujon/virtual-threads branch 2 times, most recently from 56e90dc to 2e3f97b Compare November 27, 2025 10:21
@PerfectSlayer PerfectSlayer marked this pull request as ready for review November 27, 2025 11:20
@PerfectSlayer PerfectSlayer requested review from a team as code owners November 27, 2025 11:20
@PerfectSlayer PerfectSlayer requested a review from dougqh November 27, 2025 11:20
*/
@SuppressWarnings("unused")
@AutoService(InstrumenterModule.class)
public final class VirtualThreadInstrumentation extends InstrumenterModule.Tracing
Copy link
Contributor

@ygree ygree Dec 4, 2025

Choose a reason for hiding this comment

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

This makes TaskRunnerInstrumentation unnecessary. Perhaps we could just remove it now and move its test VirtualThreadPerTaskExecutorTest into this project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The TaskRunnerInstrumentation is still needed. Its unit tests end with disconnected traces and unfinished spans without it.
I also included the (direct) virtual thread API into the concurrent smoke test (21) to make sure both instrumentations don't mess with each other.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just double-checked, and the VirtualThreadPerTaskExecutorTest in TaskRunnerInstrumentation passes when TaskRunnerInstrumentation is disabled. Remember to add testImplementation project(':dd-java-agent:instrumentation:java:java-lang:java-lang-21.0') when running ./gradlew :dd-java-agent:instrumentation:java:java-concurrent:java-concurrent-21.0:test -PtestJvm=21

Copy link
Contributor

@ygree ygree left a comment

Choose a reason for hiding this comment

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

Looks great! Should we remove TaskRunnerInstrumentation then now?

class VirtualThreadApiTest extends InstrumentationSpecification {
def "test builder - started"() {
setup:
def threadBuilder = Thread.ofVirtual().name("builder - started")
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also add a test for Thread.startVirtualThread(). It works, I checked, but since it's another public method, it'd be nice to have a test just to be sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought of it in the first place but as the Javadoc explicitly states it is equivalent to Thread.ofVirtual().start(task);, I skipped it.
image

But you're right, better add it by safety as it's another public API 😉

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

Labels

comp: context propagation Trace context propagation inst: java Core Java language instrumentation type: enhancement Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants