--- old/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp 2020-06-01 12:25:23.301028046 +0200 +++ new/src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp 2020-06-01 12:25:22.985028456 +0200 @@ -226,9 +226,18 @@ template class ShenandoahClassLoaderDataRoots { private: + ShenandoahSharedSemaphore _semaphore; ShenandoahPhaseTimings::Phase _phase; + + static uint worker_count(uint n_workers) { + // Limit concurrency a bit, otherwise it wastes resources when workers are tripping + // over each other. This also leaves free workers to process other parts of the root + // set, while admitted workers are busy with doing the CLDG walk. + return MAX2(1u, MIN2(ShenandoahSharedSemaphore::max_tokens(), n_workers / 2)); + } + public: - ShenandoahClassLoaderDataRoots(ShenandoahPhaseTimings::Phase phase); + ShenandoahClassLoaderDataRoots(ShenandoahPhaseTimings::Phase phase, uint n_workers); ~ShenandoahClassLoaderDataRoots(); void always_strong_cld_do(CLDClosure* clds, uint worker_id);