--- old/src/hotspot/share/memory/heapInspection.cpp 2020-08-14 20:20:03.478397055 +0200 +++ new/src/hotspot/share/memory/heapInspection.cpp 2020-08-14 20:20:02.978388069 +0200 @@ -575,13 +575,26 @@ // Try parallel first. if (parallel_thread_num > 1) { ResourceMark rm; - ParallelObjectIterator* poi = Universe::heap()->parallel_object_iterator(parallel_thread_num); - if (poi != NULL) { - ParHeapInspectTask task(poi, cit, filter); - Universe::heap()->run_task(&task); - delete poi; - if (task.success()) { - return task.missed_count(); + + WorkGang* gang = Universe::heap()->get_safepoint_workers(); + if (gang != NULL) { + // The GC provided a WorkGang to be used during a safepoint. + + // Can't run with more threads than provided by the WorkGang. + WithUpdatedActiveWorkers update_and_restore(gang, parallel_thread_num); + + ParallelObjectIterator* poi = Universe::heap()->parallel_object_iterator(gang->active_workers()); + if (poi != NULL) { + // The GC supports parallel object iteration. + + ParHeapInspectTask task(poi, cit, filter); + // Run task with the active workers. + gang->run_task(&task); + + delete poi; + if (task.success()) { + return task.missed_count(); + } } } }