rev 59439 : 8245825: Shenandoah: Remove diagnostic flag ShenandoahConcurrentScanCodeRoots

   1 /*
   2  * Copyright (c) 2019, 2020, Red Hat, Inc. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_INLINE_HPP
  26 #define SHARE_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_INLINE_HPP
  27 
  28 #include "classfile/classLoaderDataGraph.hpp"
  29 #include "classfile/stringTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "gc/shared/oopStorageParState.inline.hpp"
  32 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
  33 #include "gc/shenandoah/shenandoahConcurrentRoots.hpp"
  34 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  35 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  36 #include "gc/shenandoah/shenandoahRootProcessor.hpp"
  37 #include "gc/shenandoah/shenandoahUtils.hpp"
  38 #include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "prims/resolvedMethodTable.hpp"
  41 #include "runtime/safepoint.hpp"
  42 
  43 template <bool CONCURRENT>
  44 inline ShenandoahVMRoot<CONCURRENT>::ShenandoahVMRoot(OopStorage* storage,
  45         ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase) :
  46   _itr(storage), _phase(phase), _par_phase(par_phase) {
  47 }
  48 
  49 template <bool CONCURRENT>
  50 template <typename Closure>
  51 inline void ShenandoahVMRoot<CONCURRENT>::oops_do(Closure* cl, uint worker_id) {
  52   ShenandoahWorkerTimingsTracker timer(_phase, _par_phase, worker_id);
  53   _itr.oops_do(cl);
  54 }
  55 
  56 template <bool CONCURRENT>
  57 inline ShenandoahWeakRoot<CONCURRENT>::ShenandoahWeakRoot(OopStorage* storage,
  58   ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase) :
  59   ShenandoahVMRoot<CONCURRENT>(storage, phase, par_phase) {
  60 }
  61 
  62 inline ShenandoahWeakRoot<false>::ShenandoahWeakRoot(OopStorage* storage,
  63   ShenandoahPhaseTimings::Phase phase,  ShenandoahPhaseTimings::ParPhase par_phase) :
  64   _itr(storage), _phase(phase), _par_phase(par_phase) {
  65 }
  66 
  67 template <typename IsAliveClosure, typename KeepAliveClosure>
  68 void ShenandoahWeakRoot<false /* concurrent */>::weak_oops_do(IsAliveClosure* is_alive, KeepAliveClosure* keep_alive, uint worker_id) {
  69   ShenandoahWorkerTimingsTracker timer(_phase, _par_phase, worker_id);
  70   _itr.weak_oops_do(is_alive, keep_alive);
  71 }
  72 
  73 template <bool CONCURRENT>
  74 ShenandoahWeakRoots<CONCURRENT>::ShenandoahWeakRoots() :
  75   _jni_roots(OopStorageSet::jni_weak(), ShenandoahPhaseTimings::JNIWeakRoots),
  76   _string_table_roots(OopStorageSet::string_table_weak(), ShenandoahPhaseTimings::StringTableRoots),
  77   _resolved_method_table_roots(OopStorageSet::resolved_method_table_weak(), ShenandoahPhaseTimings::ResolvedMethodTableRoots),
  78   _vm_roots(OopStorageSet::vm_weak(), ShenandoahPhaseTimings::VMWeakRoots) {
  79 }
  80 
  81 template <bool CONCURRENT>
  82 template <typename Closure>
  83 void ShenandoahWeakRoots<CONCURRENT>::oops_do(Closure* cl, uint worker_id) {
  84   _jni_roots.oops_do(cl, worker_id);
  85   _string_table_roots.oops_do(cl, worker_id);
  86   _resolved_method_table_roots.oops_do(cl, worker_id);
  87   _vm_roots.oops_do(cl, worker_id);
  88 }
  89 
  90 inline ShenandoahWeakRoots<false /* concurrent */>::ShenandoahWeakRoots(ShenandoahPhaseTimings::Phase phase) :
  91   _jni_roots(OopStorageSet::jni_weak(), phase, ShenandoahPhaseTimings::JNIWeakRoots),
  92   _string_table_roots(OopStorageSet::string_table_weak(), phase, ShenandoahPhaseTimings::StringTableRoots),
  93   _resolved_method_table_roots(OopStorageSet::resolved_method_table_weak(), phase, ShenandoahPhaseTimings::ResolvedMethodTableRoots),
  94   _vm_roots(OopStorageSet::vm_weak(), phase, ShenandoahPhaseTimings::VMWeakRoots) {
  95 }
  96 
  97 template <typename IsAliveClosure, typename KeepAliveClosure>
  98 void ShenandoahWeakRoots<false /* concurrent*/>::weak_oops_do(IsAliveClosure* is_alive, KeepAliveClosure* keep_alive, uint worker_id) {
  99   _jni_roots.weak_oops_do(is_alive, keep_alive, worker_id);
 100   _string_table_roots.weak_oops_do(is_alive, keep_alive, worker_id);
 101   _resolved_method_table_roots.weak_oops_do(is_alive, keep_alive, worker_id);
 102   _vm_roots.weak_oops_do(is_alive, keep_alive, worker_id);
 103 }
 104 
 105 template <typename Closure>
 106 void ShenandoahWeakRoots<false /* concurrent */>::oops_do(Closure* cl, uint worker_id) {
 107   AlwaysTrueClosure always_true;
 108   weak_oops_do<AlwaysTrueClosure, Closure>(&always_true, cl, worker_id);
 109 }
 110 
 111 template <bool CONCURRENT>
 112 ShenandoahVMRoots<CONCURRENT>::ShenandoahVMRoots(ShenandoahPhaseTimings::Phase phase) :
 113   _jni_handle_roots(OopStorageSet::jni_global(), phase, ShenandoahPhaseTimings::JNIRoots),
 114   _vm_global_roots(OopStorageSet::vm_global(), phase, ShenandoahPhaseTimings::VMGlobalRoots) {
 115 }
 116 
 117 template <bool CONCURRENT>
 118 template <typename T>
 119 void ShenandoahVMRoots<CONCURRENT>::oops_do(T* cl, uint worker_id) {
 120   _jni_handle_roots.oops_do(cl, worker_id);
 121   _vm_global_roots.oops_do(cl, worker_id);
 122 }
 123 
 124 template <bool CONCURRENT, bool SINGLE_THREADED>
 125 ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::ShenandoahClassLoaderDataRoots(ShenandoahPhaseTimings::Phase phase) :
 126   _phase(phase) {
 127   if (!SINGLE_THREADED) {
 128     ClassLoaderDataGraph::clear_claimed_marks();
 129   }
 130   if (CONCURRENT) {
 131     ClassLoaderDataGraph_lock->lock();
 132   }
 133 }
 134 
 135 template <bool CONCURRENT, bool SINGLE_THREADED>
 136 ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::~ShenandoahClassLoaderDataRoots() {
 137   if (CONCURRENT) {
 138     ClassLoaderDataGraph_lock->unlock();
 139   }
 140 }
 141 
 142 
 143 template <bool CONCURRENT, bool SINGLE_THREADED>
 144 void ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::always_strong_cld_do(CLDClosure* clds, uint worker_id) {
 145   if (SINGLE_THREADED) {
 146     assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
 147     assert(Thread::current()->is_VM_thread(), "Single threaded CLDG iteration can only be done by VM thread");
 148     ClassLoaderDataGraph::always_strong_cld_do(clds);
 149   } else {
 150     ShenandoahWorkerTimingsTracker timer(_phase, ShenandoahPhaseTimings::CLDGRoots, worker_id);
 151     ClassLoaderDataGraph::always_strong_cld_do(clds);
 152   }
 153 }
 154 
 155 template <bool CONCURRENT, bool SINGLE_THREADED>
 156 void ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::cld_do(CLDClosure* clds, uint worker_id) {
 157   if (SINGLE_THREADED) {
 158     assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
 159     assert(Thread::current()->is_VM_thread(), "Single threaded CLDG iteration can only be done by VM thread");
 160     ClassLoaderDataGraph::cld_do(clds);
 161   } else {
 162     ShenandoahWorkerTimingsTracker timer(_phase, ShenandoahPhaseTimings::CLDGRoots, worker_id);
 163     ClassLoaderDataGraph::cld_do(clds);
 164   }
 165 }
 166 
 167 template <typename ITR>
 168 ShenandoahCodeCacheRoots<ITR>::ShenandoahCodeCacheRoots(ShenandoahPhaseTimings::Phase phase) : _phase(phase) {
 169   nmethod::oops_do_marking_prologue();
 170 }
 171 
 172 template <typename ITR>
 173 void ShenandoahCodeCacheRoots<ITR>::code_blobs_do(CodeBlobClosure* blob_cl, uint worker_id) {
 174   ShenandoahWorkerTimingsTracker timer(_phase, ShenandoahPhaseTimings::CodeCacheRoots, worker_id);
 175   _coderoots_iterator.possibly_parallel_blobs_do(blob_cl);
 176 }
 177 
 178 template <typename ITR>
 179 ShenandoahCodeCacheRoots<ITR>::~ShenandoahCodeCacheRoots() {
 180   nmethod::oops_do_marking_epilogue();
 181 }
 182 
 183 class ShenandoahParallelOopsDoThreadClosure : public ThreadClosure {
 184 private:
 185   OopClosure* _f;
 186   CodeBlobClosure* _cf;
 187   ThreadClosure* _thread_cl;
 188 public:
 189   ShenandoahParallelOopsDoThreadClosure(OopClosure* f, CodeBlobClosure* cf, ThreadClosure* thread_cl) :
 190     _f(f), _cf(cf), _thread_cl(thread_cl) {}
 191 
 192   void do_thread(Thread* t) {
 193     if (_thread_cl != NULL) {
 194       _thread_cl->do_thread(t);
 195     }
 196     t->oops_do(_f, _cf);
 197   }
 198 };
 199 
 200 template <typename ITR>
 201 ShenandoahRootScanner<ITR>::ShenandoahRootScanner(uint n_workers, ShenandoahPhaseTimings::Phase phase) :
 202   ShenandoahRootProcessor(phase),
 203   _serial_roots(phase),
 204   _thread_roots(phase, n_workers > 1),
 205   _code_roots(phase),
 206   _vm_roots(phase),
 207   _dedup_roots(phase),
 208   _cld_roots(phase) {
 209 }
 210 
 211 template <typename ITR>
 212 void ShenandoahRootScanner<ITR>::roots_do(uint worker_id, OopClosure* oops) {
 213   CLDToOopClosure clds_cl(oops, ClassLoaderData::_claim_strong);
 214   MarkingCodeBlobClosure blobs_cl(oops, !CodeBlobToOopClosure::FixRelocations);
 215   roots_do(worker_id, oops, &clds_cl, &blobs_cl);
 216 }
 217 
 218 template <typename ITR>
 219 void ShenandoahRootScanner<ITR>::strong_roots_do(uint worker_id, OopClosure* oops) {
 220   CLDToOopClosure clds_cl(oops, ClassLoaderData::_claim_strong);
 221   MarkingCodeBlobClosure blobs_cl(oops, !CodeBlobToOopClosure::FixRelocations);
 222   strong_roots_do(worker_id, oops, &clds_cl, &blobs_cl);
 223 }
 224 
 225 template <typename ITR>
 226 void ShenandoahRootScanner<ITR>::roots_do(uint worker_id, OopClosure* oops, CLDClosure* clds, CodeBlobClosure* code, ThreadClosure *tc) {
 227   assert(!ShenandoahSafepoint::is_at_shenandoah_safepoint() ||
 228          !ShenandoahHeap::heap()->unload_classes(),
 229           "Expect class unloading when Shenandoah cycle is running");
 230   ResourceMark rm;
 231 
 232   _serial_roots.oops_do(oops, worker_id);
 233   _vm_roots.oops_do(oops, worker_id);
 234 
 235   assert(clds != NULL, "Only possible with CLD closure");
 236   _cld_roots.cld_do(clds, worker_id);
 237 
 238   // With ShenandoahConcurrentScanCodeRoots, we avoid scanning the entire code cache here,
 239   // and instead do that in concurrent phase under the relevant lock. This saves init mark
 240   // pause time.
 241   if (code != NULL && !ShenandoahConcurrentScanCodeRoots) {
 242     _code_roots.code_blobs_do(code, worker_id);
 243     ShenandoahParallelOopsDoThreadClosure tc_cl(oops, NULL, tc);
 244     _thread_roots.threads_do(&tc_cl, worker_id);
 245   } else {
 246     ShenandoahParallelOopsDoThreadClosure tc_cl(oops, code, tc);
 247     _thread_roots.threads_do(&tc_cl, worker_id);
 248   }
 249 
 250   AlwaysTrueClosure always_true;
 251   _dedup_roots.oops_do(&always_true, oops, worker_id);
 252 }
 253 
 254 template <typename ITR>
 255 void ShenandoahRootScanner<ITR>::strong_roots_do(uint worker_id, OopClosure* oops, CLDClosure* clds, CodeBlobClosure* code, ThreadClosure* tc) {
 256   assert(ShenandoahHeap::heap()->unload_classes(), "Should be used during class unloading");
 257   ShenandoahParallelOopsDoThreadClosure tc_cl(oops, code, tc);
 258   ResourceMark rm;
 259 
 260   _serial_roots.oops_do(oops, worker_id);
 261   _vm_roots.oops_do(oops, worker_id);
 262   _cld_roots.always_strong_cld_do(clds, worker_id);
 263   _thread_roots.threads_do(&tc_cl, worker_id);
 264 }
 265 
 266 template <typename IsAlive, typename KeepAlive>
 267 void ShenandoahRootUpdater::roots_do(uint worker_id, IsAlive* is_alive, KeepAlive* keep_alive) {
 268   CodeBlobToOopClosure update_blobs(keep_alive, CodeBlobToOopClosure::FixRelocations);
 269   ShenandoahCodeBlobAndDisarmClosure blobs_and_disarm_Cl(keep_alive);
 270   CodeBlobToOopClosure* codes_cl = ShenandoahConcurrentRoots::can_do_concurrent_class_unloading() ?
 271                                   static_cast<CodeBlobToOopClosure*>(&blobs_and_disarm_Cl) :
 272                                   static_cast<CodeBlobToOopClosure*>(&update_blobs);
 273 
 274   CLDToOopClosure clds(keep_alive, ClassLoaderData::_claim_strong);
 275 
 276   _serial_roots.oops_do(keep_alive, worker_id);
 277   _vm_roots.oops_do(keep_alive, worker_id);
 278 
 279   _cld_roots.cld_do(&clds, worker_id);
 280   _code_roots.code_blobs_do(codes_cl, worker_id);
 281   _thread_roots.oops_do(keep_alive, NULL, worker_id);
 282 
 283   _serial_weak_roots.weak_oops_do(is_alive, keep_alive, worker_id);
 284   _weak_roots.weak_oops_do(is_alive, keep_alive, worker_id);
 285   _dedup_roots.oops_do(is_alive, keep_alive, worker_id);
 286 }
 287 
 288 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_INLINE_HPP
--- EOF ---