RFR: 8331553: Windows JVM leaks Event and Thread handles when multiple threads are used

Daniel Jeliński djelinski at openjdk.org
Tue Jun 18 21:10:29 UTC 2024


We use 2 ParkEvent instances per thread. The ParkEvent objects are never freed, but they are recycled when a thread dies, so the number of live ParkEvent instances is proportional to the maximum number of threads that were live at any time.

On Windows, the ParkEvent object wraps a kernel Event object. Kernel objects are a limited and costly resource. In this PR, I replace the use of kernel events with user-space synchronization.

The new implementation uses WaitOnAddress and WakeByAddressSingle methods to implement synchronization. The methods are available since Windows 8. We only support Windows 10 and newer, so OS support should not be a problem.

WaitOnAddress was observed to return spuriously, so I added the necessary code to recalculate the timeout and continue waiting.

Tier1-5 tests passed. Performance tests were... inconclusive. For example, `ThreadOnSpinWaitProducerConsumer` reported 30% better results, while `LockUnlock.testContendedLock` results were 50% worse. 

Thoughts?

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

Commit messages:
 - Implement PlatformEvent using WaitOnAddress

Changes: https://git.openjdk.org/jdk/pull/19778/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19778&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8331553
  Stats: 75 lines in 3 files changed: 9 ins; 54 del; 12 mod
  Patch: https://git.openjdk.org/jdk/pull/19778.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19778/head:pull/19778

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


More information about the build-dev mailing list