On Fri, 18 Sep 2020 08:03:13 GMT, Aleksey Shipilev <sh...@openjdk.org> wrote:
>> Lin Zang has refreshed the contents of this pull request, and previous >> commits have been removed. The incremental views >> will show differences compared to the previous content of the PR. > > src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp line 1470: > >> 1468: for (uint j = 0; j < roots_num; j++) { >> 1469: uint stack_id = j % _num_workers; >> 1470: oop obj = _roots_stack.pop(); > > I am not sure we can `pop()` the stack from multiple threads without any sort > of synchronization. It might be better to > just walk the same roots from multiple threads, and then let the bitmap help > us figure out if we have visited the root > already. See how `ShenandoahVerifierReachableTask` does it? Hi @shipilev, Thanks for your effort for reviewing this change! The method prepare_worker_queue() here is invoked in the constructor of ShenandoahParallelObjectIterator, which is designed to run in single thread. The logic of using ParallelObjectIterator is as follows: (refer to code in hotspot/share/memory/heapInspection.cpp) - create instance of ParallelObjectIterator in shenandoahHeap: ParallelObjectIterator* poi = Universe::heap()->parallel_object_iterator(gang->active_workers()) - create heap iteration task and run (invoke ParallelObjectIterator's method object_iterator()) ParHeapInspectTask task(**poi**, cit, filter); // Run task with the active workers. gang->run_task(&task); ======= So the ShenandoahParallelObjectIterator iterate all roots in the single thread, collecting all roots in the roots_stack, then prepare the queues for every workers. -- processed in constructor. And the workers start their processing from their queue, and then iterate all reachable objects. -- processed in work(uint worker_id) I have checked that ShenandoahVerifierReachableTask supports iterating roots parallelly, I didn't choose that way because I want to make every workers to start with nearly the same number of roots in their queue, hope it could help on inital work load balance. Lin ------------- PR: https://git.openjdk.java.net/jdk/pull/67