JetBrains / lincheck

Framework for testing concurrent data structures
Mozilla Public License 2.0
576 stars 33 forks source link

Fix Java 11 performance bug #316

Closed eupp closed 4 months ago

eupp commented 5 months ago

Closes #308

This PR fixes the performance problem accidentally introduced in #296 , that manifested on our Java 11 CI builds. The root cause of the problem and the solution are described below.

The problem was related to the JVM classes re-transformation, performed by the Java agent. For model checking instrumentation mode, the class re-transformation was performed lazily on demand. However, for the stress strategy, all the loaded classes were re-transformed eagerly for each Lincheck test. During a long JVM run (e.g. in case of our CI builds), a lot of classes can be loaded to the JVM, and for each Lincheck test run, the Lincheck JVM agent in the stress model would try to re-transform them.

However, for the stress strategy we actually only need to intercept the suspension points, that is calls to certain internal coroutine methods. The observation is that most of the loaded classes would not contain these calls, so there is no need to constantly re-transform them.

So the solution, implemented in this PR, is to remember all the loaded classes that actually have coroutine calls inside them, and only re-transform these classes (or newly loaded classes) on subsequent Lincheck agent installations.