Describe the issue
In SubstrateVM, JFR eagerly registers virtual threads when they are mounted and during a chunk rotation. This means large numbers of virtual threads will result in a lot of work, even if the threads don't end up emitting any events. In Hotspot, virtual threads are registered lazily upon event emission.
Steps to reproduce the issue
- Create a large number of virtual threads
- Configure JFR to emit fewer events.
Describe GraalVM and your environment:
The problem is in the latest GraalVM master and all previous versions that support virtual threads in JFR.
Solution
Adopt a lazy approach to registration similar to Hotspot.