This problem is encountered when a JVMTI agent is loaded into running VM. The 
JvmtiExport::get_jvmti_interface() is called from the agent's Agent_OnAttach 
entrypoint. To support virtual threads it enables JVMTI notifications from the 
VirtualThread class with a call to:
  `JvmtiEnvBase::enable_virtual_threads_notify_jvmti()`.
The problem is that there is no JVMTI environments at this point yet. This 
assert is hit when a virtual thread is created concurrently after the JVMTI 
notifications have been enabled but the requested JVMTI environment has not 
been created yet.
The fix is to create a JVMTI env first and only then to enable the JVMTI 
notifications.

This issue is very hard to reproduce. I had to use some tricks with adding 
`os::naked_short_nanosleep()` and also by refactoring the test 
`VThreadTLSTest.java`. At least, I was able to verify this test does not fail 
with my fix anymore.

Testing:
 - submitted hundreds of `VThreadTLSTest.java` mach5 runs on several platforms 
in the `fastdebug` mode
 - in progress: mach5 tiers 1-6

-------------

Commit messages:
 - 8300051: assert(JvmtiEnvBase::environments_might_exist()) failed: to enter 
event controller, JVM TI environments must exist

Changes: https://git.openjdk.org/jdk/pull/14945/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14945&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8300051
  Stats: 26 lines in 2 files changed: 14 ins; 12 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/14945.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14945/head:pull/14945

PR: https://git.openjdk.org/jdk/pull/14945

Reply via email to