--- old/src/hotspot/share/gc/z/zHeap.cpp 2020-04-25 22:41:18.593497934 +0800 +++ new/src/hotspot/share/gc/z/zHeap.cpp 2020-04-25 22:41:18.421498701 +0800 @@ -35,6 +35,7 @@ #include "gc/z/zResurrection.hpp" #include "gc/z/zStat.hpp" #include "gc/z/zThread.inline.hpp" +#include "gc/z/zTask.hpp" #include "gc/z/zVerify.hpp" #include "gc/z/zWorkers.inline.hpp" #include "logging/log.hpp" @@ -45,6 +46,7 @@ #include "runtime/thread.hpp" #include "utilities/debug.hpp" +class ZTask; static const ZStatSampler ZSamplerHeapUsedBeforeMark("Memory", "Heap Used Before Mark", ZStatUnitBytes); static const ZStatSampler ZSamplerHeapUsedAfterMark("Memory", "Heap Used After Mark", ZStatUnitBytes); static const ZStatSampler ZSamplerHeapUsedBeforeRelocation("Memory", "Heap Used Before Relocation", ZStatUnitBytes); @@ -206,6 +208,28 @@ _workers.print_threads_on(st); } +// A delegate class for AbstractGangTask to Ztask. +class DelegatedZAbstractGangTask : public ZTask { + private: + AbstractGangTask* _task; + + public: + DelegatedZAbstractGangTask(AbstractGangTask* task) : + ZTask(task->name()), + _task(task) { } + + virtual void work() { + _task->work(ZThread::worker_id()); + } +}; + +Tickspan ZHeap::run_task(AbstractGangTask* task) { + Ticks start = Ticks::now(); + DelegatedZAbstractGangTask dtask(task); + _workers.run_parallel(&dtask); + return Ticks::now() - start; +} + void ZHeap::out_of_memory() { ResourceMark rm;