This PR removes the type stable memory aspect of `ParkEvent`. The concept of type stable memory means that once it's been allocated, it will forever be of a certain type (like a `ParkEvent`). Forever means that it will not be freed for as long as the VM lives.
Keeping the park events in type stable memory had the unfortunate consequence that we needed to hold on to memory after a thread population spike. Since the JVMTI raw monitor supports non-JavaThread users, we can not use the Thread-SMR (Safe Memory Reclamation) mechanism to make sure the park event is kept live while operating on it. Because the Thread-SMR mechanism can only protect JavaThreads in its captured list. I have instead placed an atomic usage counter (`_in_use_cnt`) in each park event that tracks the current number of users of the park event. The counter is set to one in the park event's constructor. Anyone that wants to operate on the park event can call the park event's `retain_usage()`. This should be done at a time when it can be guaranteed that the thread associated with the park event is still alive. Then call `drop_usage()` after the operation is fulfilled. Calling `retain_usage()` will increase the value of `_in_use_cnt` by one, and `drop_usage()` usage will decrease the value by one. After `drop_usage()` has decreased the value it will also check if the value is down to zero, and if so it will delete the park event. This way we can make sure that a "retained" reference to the park event is still valid, even though the park event has outlived the associated thread. A nice side effect of this PR is that it eliminates a common reason for spurious wakeups for threads, caused by the fact that we used to recycle `ParkEvent`s (e.g. allocate from a free-list). I've used the submitted [ThreadSpike.java](https://bugs.openjdk.org/secure/attachment/122155/ThreadSpike.java) test to measure the reduced memory consumption. `linux-x64/jdk/bin/java -XX:NativeMemoryTracking=summary -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics -Dthreads=20000 ThreadSpike.java | egrep '(Internal|Synchronization|Thread).*committed='` This shows that committed `Synchronization` memory goes from ~6.7 MB to ~0.3 MB, which is a ~95% reduction in memory consumption. `Thread` memory only increases by 1.4 KB and `Internal` memory stays the same. Running a thread-churn test for one hour, did not show any leakage of `Synchronization` memory. Running `test/micro/org/openjdk/bench/vm/lang/MonitorBench.java` doesn't show any concerning regression. Successfully passes tier1-5 tests. Also ran `DaCapo23`, `Renaissance` and `SPECjbb2015` benchmarks without any concerning regression. --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - Merge branch 'master' into 8393647_reconsider_immortal_park_events - 8393647: Immortal ParkEvents inflate memory footprint after thread spike - Embedded _SleepEvent into JavaThread Changes: https://git.openjdk.org/jdk/pull/33770/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=33770&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8393647 Stats: 252 lines in 10 files changed: 68 ins; 125 del; 59 mod Patch: https://git.openjdk.org/jdk/pull/33770.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/33770/head:pull/33770 PR: https://git.openjdk.org/jdk/pull/33770
