--- old/src/hotspot/share/gc/g1/g1CollectedHeap.cpp 2020-03-16 16:47:35.155020015 +0800 +++ new/src/hotspot/share/gc/g1/g1CollectedHeap.cpp 2020-03-16 16:47:34.975020833 +0800 @@ -87,6 +87,7 @@ #include "logging/log.hpp" #include "memory/allocation.hpp" #include "memory/iterator.hpp" +#include "memory/heapInspection.hpp" #include "memory/resourceArea.hpp" #include "memory/universe.hpp" #include "oops/access.inline.hpp" @@ -5013,3 +5014,40 @@ GrowableArray G1CollectedHeap::memory_pools() { return _g1mm->memory_pools(); } + +class G1ParHeapInspectTask: public ParHeapInspectTask { + private: + HeapRegionClaimer _claimer; + public: + G1ParHeapInspectTask(G1CollectedHeap* heap, KlassInfoTable* shared_cit, + BoolObjectClosure* filter, size_t* shared_missed_count, + size_t thread_num) : + ParHeapInspectTask(heap, shared_cit, filter, shared_missed_count, thread_num), + _claimer(thread_num == 0 ? heap->workers()->active_workers() : thread_num) { } + void do_object_iterate_parallel(ObjectClosure* cl, uint worker_id) { + ((G1CollectedHeap*)getHeap())->object_iterate_parallel(cl, worker_id, &_claimer); + } +}; + +bool G1CollectedHeap::run_par_heap_inspect_task(KlassInfoTable* cit, + BoolObjectClosure* filter, + size_t* missed_count, size_t thread_num) { + G1ParHeapInspectTask task(this, cit, filter, missed_count, thread_num); + return object_iterate_try_parallel(&task, thread_num) && task.is_success(); +} + +void G1CollectedHeap::object_iterate_parallel(ObjectClosure* cl, uint worker_id, HeapRegionClaimer* claimer) { + IterateObjectClosureRegionClosure blk(cl); + heap_region_par_iterate_from_worker_offset(&blk, claimer, worker_id); +} + +bool G1CollectedHeap::object_iterate_try_parallel(AbstractGangTask* task, size_t par_thread_num) { + if (task == NULL) { + return false; + } + par_thread_num = MIN2((uint)par_thread_num, workers()->total_workers()); + workers()->run_task(task, par_thread_num); + return true; +} + +