rev 55429 : 8226413: Shenandoah: Separate root scanner for SH::object_iterate()

   1 /*
   2  * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_INLINE_HPP
  25 #define SHARE_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_INLINE_HPP
  26 
  27 #include "classfile/classLoaderDataGraph.hpp"
  28 #include "gc/shared/oopStorageParState.inline.hpp"
  29 #include "gc/shenandoah/shenandoahHeuristics.hpp"
  30 #include "gc/shenandoah/shenandoahRootProcessor.hpp"
  31 #include "gc/shenandoah/shenandoahTimingTracker.hpp"
  32 #include "gc/shenandoah/shenandoahUtils.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "runtime/safepoint.hpp"
  35 
  36 template <bool CONCURRENT>
  37 ShenandoahJNIHandleRoots<CONCURRENT>::ShenandoahJNIHandleRoots() :
  38   _itr(JNIHandles::global_handles()) {
  39 }
  40 
  41 template <bool CONCURRENT>
  42 template <typename T>
  43 void ShenandoahJNIHandleRoots<CONCURRENT>::oops_do(T* cl, uint worker_id) {
  44   if (CONCURRENT) {
  45     _itr.oops_do(cl);
  46   } else {
  47     ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
  48     ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::JNIRoots, worker_id);
  49     _itr.oops_do(cl);
  50   }
  51 }
  52 
  53 template <typename IsAlive, typename KeepAlive>
  54 void ShenandoahWeakRoots::oops_do(IsAlive* is_alive, KeepAlive* keep_alive, uint worker_id) {
  55   _task.work<IsAlive, KeepAlive>(worker_id, is_alive, keep_alive);
  56 }
  57 
  58 template <bool SINGLE_THREADED>
  59 ShenandoahClassLoaderDataRoots<SINGLE_THREADED>::ShenandoahClassLoaderDataRoots() {
  60   if (!SINGLE_THREADED) {
  61     ClassLoaderDataGraph::clear_claimed_marks();
  62   }
  63 }
  64 
  65 template <bool SINGLE_THREADED>
  66 void ShenandoahClassLoaderDataRoots<SINGLE_THREADED>::clds_do(CLDClosure* strong_clds, CLDClosure* weak_clds, uint worker_id) {
  67   if (SINGLE_THREADED) {
  68     assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
  69     assert(Thread::current()->is_VM_thread(), "Single threaded CLDG iteration can only be done by VM thread");
  70 
  71     ClassLoaderDataGraph::roots_cld_do(strong_clds, weak_clds);
  72   } else {
  73     ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
  74     ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::CLDGRoots, worker_id);
  75     ClassLoaderDataGraph::roots_cld_do(strong_clds, weak_clds);
  76   }
  77 }
  78 
  79 template <typename ITR>
  80 ShenandoahCodeCacheRoots<ITR>::ShenandoahCodeCacheRoots() {
  81   nmethod::oops_do_marking_prologue();
  82 }
  83 
  84 template <typename ITR>
  85 void ShenandoahCodeCacheRoots<ITR>::code_blobs_do(CodeBlobClosure* blob_cl, uint worker_id) {
  86   ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
  87   ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::CodeCacheRoots, worker_id);
  88   _coderoots_iterator.possibly_parallel_blobs_do(blob_cl);
  89 }
  90 
  91 template <typename ITR>
  92 ShenandoahCodeCacheRoots<ITR>::~ShenandoahCodeCacheRoots() {
  93   nmethod::oops_do_marking_epilogue();
  94 }
  95 
  96 class ShenandoahParallelOopsDoThreadClosure : public ThreadClosure {
  97 private:
  98   OopClosure* _f;
  99   CodeBlobClosure* _cf;
 100   ThreadClosure* _thread_cl;
 101 public:
 102   ShenandoahParallelOopsDoThreadClosure(OopClosure* f, CodeBlobClosure* cf, ThreadClosure* thread_cl) :
 103     _f(f), _cf(cf), _thread_cl(thread_cl) {}
 104 
 105   void do_thread(Thread* t) {
 106     if (_thread_cl != NULL) {
 107       _thread_cl->do_thread(t);
 108     }
 109     t->oops_do(_f, _cf);
 110   }
 111 };
 112 
 113 template <typename ITR>
 114 ShenandoahRootScanner<ITR>::ShenandoahRootScanner(uint n_workers, ShenandoahPhaseTimings::Phase phase) :
 115   ShenandoahRootProcessor(phase),
 116   _thread_roots(n_workers > 1) {
 117 }
 118 
 119 template <typename ITR>
 120 void ShenandoahRootScanner<ITR>::roots_do(uint worker_id, OopClosure* oops) {
 121   CLDToOopClosure clds_cl(oops, ClassLoaderData::_claim_strong);
 122   MarkingCodeBlobClosure blobs_cl(oops, !CodeBlobToOopClosure::FixRelocations);
 123   roots_do(worker_id, oops, &clds_cl, &blobs_cl);
 124 }
 125 
 126 template <typename ITR>
 127 void ShenandoahRootScanner<ITR>::strong_roots_do(uint worker_id, OopClosure* oops) {
 128   CLDToOopClosure clds_cl(oops, ClassLoaderData::_claim_strong);
 129   MarkingCodeBlobClosure blobs_cl(oops, !CodeBlobToOopClosure::FixRelocations);
 130   strong_roots_do(worker_id, oops, &clds_cl, &blobs_cl);
 131 }
 132 
 133 template <typename ITR>
 134 void ShenandoahRootScanner<ITR>::roots_do(uint worker_id, OopClosure* oops, CLDClosure* clds, CodeBlobClosure* code, ThreadClosure *tc) {
 135   assert(!ShenandoahSafepoint::is_at_shenandoah_safepoint() ||
 136          !ShenandoahHeap::heap()->unload_classes() ||
 137           ShenandoahHeap::heap()->heuristics()->can_do_traversal_gc(),
 138           "Expect class unloading or traversal when Shenandoah cycle is running");
 139   ShenandoahParallelOopsDoThreadClosure tc_cl(oops, code, tc);
 140   ResourceMark rm;
 141 
 142   _serial_roots.oops_do(oops, worker_id);
 143   _jni_roots.oops_do(oops, worker_id);
 144   _cld_roots.clds_do(clds, clds, worker_id);
 145   _thread_roots.threads_do(&tc_cl, worker_id);
 146 
 147   // With ShenandoahConcurrentScanCodeRoots, we avoid scanning the entire code cache here,
 148   // and instead do that in concurrent phase under the relevant lock. This saves init mark
 149   // pause time.
 150   if (code != NULL && !ShenandoahConcurrentScanCodeRoots) {
 151     _code_roots.code_blobs_do(code, worker_id);
 152   }



























 153 }
 154 
 155 template <typename ITR>
 156 void ShenandoahRootScanner<ITR>::strong_roots_do(uint worker_id, OopClosure* oops, CLDClosure* clds, CodeBlobClosure* code, ThreadClosure* tc) {
 157   assert(ShenandoahHeap::heap()->unload_classes(), "Should be used during class unloading");
 158   ShenandoahParallelOopsDoThreadClosure tc_cl(oops, code, tc);
 159   ResourceMark rm;
 160 
 161   _serial_roots.oops_do(oops, worker_id);
 162   _jni_roots.oops_do(oops, worker_id);
 163   _cld_roots.clds_do(clds, NULL, worker_id);
 164   _thread_roots.threads_do(&tc_cl, worker_id);
 165 }
 166 
 167 template <typename IsAlive, typename KeepAlive>
 168 void ShenandoahRootUpdater::roots_do(uint worker_id, IsAlive* is_alive, KeepAlive* keep_alive) {
 169   CodeBlobToOopClosure update_blobs(keep_alive, CodeBlobToOopClosure::FixRelocations);
 170   CLDToOopClosure clds(keep_alive, ClassLoaderData::_claim_strong);
 171   CLDToOopClosure* weak_clds = ShenandoahHeap::heap()->unload_classes() ? NULL : &clds;
 172 
 173   _serial_roots.oops_do(keep_alive, worker_id);
 174   _jni_roots.oops_do(keep_alive, worker_id);
 175 
 176   _thread_roots.oops_do(keep_alive, NULL, worker_id);
 177   _cld_roots.clds_do(&clds, weak_clds, worker_id);
 178 
 179   if(_update_code_cache) {
 180     _code_roots.code_blobs_do(&update_blobs, worker_id);
 181   }
 182 
 183   _weak_roots.oops_do<IsAlive, KeepAlive>(is_alive, keep_alive, worker_id);
 184   _dedup_roots.oops_do(is_alive, keep_alive, worker_id);
 185 }
 186 
 187 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_INLINE_HPP
--- EOF ---