1 /*
   2  * Copyright (c) 2015, Red Hat, Inc. and/or its affiliates.
   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_VM_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_HPP
  26 
  27 #include "classfile/classLoaderData.hpp"
  28 #include "code/codeCache.hpp"
  29 #include "gc/shenandoah/shenandoahHeap.hpp"
  30 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  31 #include "gc/shared/strongRootsScope.hpp"
  32 #include "gc/shared/workgroup.hpp"
  33 #include "memory/allocation.hpp"
  34 #include "runtime/mutex.hpp"
  35 #include "shenandoahCodeRoots.hpp"
  36 
  37 class CLDClosure;
  38 class CodeBlobClosure;
  39 class G1CollectedHeap;
  40 class G1GCPhaseTimes;
  41 class G1ParPushHeapRSClosure;
  42 class Monitor;
  43 class OopClosure;
  44 class SubTasksDone;
  45 
  46 
  47 class ParallelCLDRootIterator {
  48 public:
  49   ParallelCLDRootIterator();
  50   void root_cld_do(CLDClosure* strong, CLDClosure* weak);
  51 };
  52 
  53 
  54 enum Shenandoah_process_roots_tasks {
  55   SHENANDOAH_RP_PS_Universe_oops_do,
  56   SHENANDOAH_RP_PS_JNIHandles_oops_do,
  57   SHENANDOAH_RP_PS_JNIHandles_weak_oops_do,
  58   SHENANDOAH_RP_PS_ObjectSynchronizer_oops_do,
  59   SHENANDOAH_RP_PS_Management_oops_do,
  60   SHENANDOAH_RP_PS_SystemDictionary_oops_do,
  61   SHENANDOAH_RP_PS_jvmti_oops_do,
  62   // Leave this one last.
  63   SHENANDOAH_RP_PS_NumElements
  64 };
  65 
  66 class ShenandoahRootProcessor : public StackObj {
  67   SubTasksDone* _process_strong_tasks;
  68   StrongRootsScope _srs;
  69   OopStorage::ParState<false, false> _par_state_string;
  70   ShenandoahPhaseTimings::Phase _phase;
  71   ParallelCLDRootIterator   _cld_iterator;
  72   ShenandoahAllCodeRootsIterator _coderoots_all_iterator;
  73   ParallelObjectSynchronizerIterator _om_iterator;
  74   CodeBlobClosure* _threads_nmethods_cl;
  75 
  76   void process_java_roots(OopClosure* scan_non_heap_roots,
  77                           CLDClosure* scan_strong_clds,
  78                           CLDClosure* scan_weak_clds,
  79                           CodeBlobClosure* scan_strong_code,
  80                           ThreadClosure* thread_cl,
  81                           uint worker_i);
  82 
  83   void process_vm_roots(OopClosure* scan_non_heap_roots,
  84                         OopClosure* scan_non_heap_weak_roots,
  85                         OopClosure* weak_jni_roots,
  86                         uint worker_i);
  87 
  88 public:
  89   ShenandoahRootProcessor(ShenandoahHeap* heap, uint n_workers,
  90                           ShenandoahPhaseTimings::Phase phase);
  91   ~ShenandoahRootProcessor();
  92 
  93   // Apply oops, clds and blobs to all strongly reachable roots in the system
  94   void process_strong_roots(OopClosure* oops, OopClosure* weak_oops,
  95                             CLDClosure* clds,
  96                             CLDClosure* weak_clds,
  97                             CodeBlobClosure* blobs,
  98                             ThreadClosure* thread_cl,
  99                             uint worker_id);
 100 
 101   // Apply oops, clds and blobs to strongly and weakly reachable roots in the system
 102   void process_all_roots(OopClosure* oops, OopClosure* weak_oops,
 103                          CLDClosure* clds,
 104                          CodeBlobClosure* blobs,
 105                          ThreadClosure* thread_cl,
 106                          uint worker_id);
 107 
 108   // For slow debug/verification code
 109   void process_all_roots_slow(OopClosure* oops);
 110 
 111   // Number of worker threads used by the root processor.
 112   uint n_workers() const;
 113 };
 114 
 115 class ShenandoahRootEvacuator : public StackObj {
 116   StrongRootsScope _srs;
 117   ShenandoahPhaseTimings::Phase _phase;
 118   ShenandoahCsetCodeRootsIterator _coderoots_cset_iterator;
 119 
 120 public:
 121   ShenandoahRootEvacuator(ShenandoahHeap* heap, uint n_workers,
 122                           ShenandoahPhaseTimings::Phase phase);
 123   ~ShenandoahRootEvacuator();
 124 
 125   void process_evacuate_roots(OopClosure* oops,
 126                               CodeBlobClosure* blobs,
 127                               uint worker_id);
 128 
 129   // Number of worker threads used by the root processor.
 130   uint n_workers() const;
 131 };
 132 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_HPP