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 VALUE_OBJ_CLASS_SPEC {
  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_FlatProfiler_oops_do,
  60   SHENANDOAH_RP_PS_Management_oops_do,
  61   SHENANDOAH_RP_PS_SystemDictionary_oops_do,
  62   SHENANDOAH_RP_PS_ClassLoaderDataGraph_oops_do,
  63   SHENANDOAH_RP_PS_jvmti_oops_do,
  64   SHENANDOAH_RP_PS_CodeCache_oops_do,
  65   // Leave this one last.
  66   SHENANDOAH_RP_PS_NumElements
  67 };
  68 
  69 class ShenandoahRootProcessor : public StackObj {
  70   SubTasksDone* _process_strong_tasks;
  71   StrongRootsScope _srs;
  72   ShenandoahPhaseTimings::Phase _phase;
  73   ParallelCLDRootIterator   _cld_iterator;
  74   ShenandoahAllCodeRootsIterator _coderoots_all_iterator;
  75   ParallelObjectSynchronizerIterator _om_iterator;
  76   CodeBlobClosure* _threads_nmethods_cl;
  77 
  78   void process_java_roots(OopClosure* scan_non_heap_roots,
  79                           CLDClosure* scan_strong_clds,
  80                           CLDClosure* scan_weak_clds,
  81                           CodeBlobClosure* scan_strong_code,
  82                           CodeBlobClosure* nmethods_cl,
  83                           ThreadClosure* thread_cl,
  84                           uint worker_i);
  85 
  86   void process_vm_roots(OopClosure* scan_non_heap_roots,
  87                         OopClosure* scan_non_heap_weak_roots,
  88                         OopClosure* weak_jni_roots,
  89                         uint worker_i);
  90 
  91 public:
  92   ShenandoahRootProcessor(ShenandoahHeap* heap, uint n_workers,
  93                           ShenandoahPhaseTimings::Phase phase);
  94   ~ShenandoahRootProcessor();
  95 
  96   // Apply oops, clds and blobs to all strongly reachable roots in the system
  97   void process_strong_roots(OopClosure* oops, OopClosure* weak_oops,
  98                             CLDClosure* clds,
  99                             CLDClosure* weak_clds,
 100                             CodeBlobClosure* blobs,
 101                             ThreadClosure* thread_cl,
 102                             uint worker_id);
 103 
 104   // Apply oops, clds and blobs to strongly and weakly reachable roots in the system
 105   void process_all_roots(OopClosure* oops, OopClosure* weak_oops,
 106                          CLDClosure* clds,
 107                          CodeBlobClosure* blobs,
 108                          ThreadClosure* thread_cl,
 109                          uint worker_id);
 110 
 111   // For slow debug/verification code
 112   void process_all_roots_slow(OopClosure* oops);
 113 
 114   // Number of worker threads used by the root processor.
 115   uint n_workers() const;
 116 };
 117 
 118 class ShenandoahRootEvacuator : public StackObj {
 119   SubTasksDone* _process_strong_tasks;
 120   StrongRootsScope _srs;
 121   ShenandoahPhaseTimings::Phase _phase;
 122   ShenandoahCsetCodeRootsIterator _coderoots_cset_iterator;
 123   CodeBlobClosure* _threads_nmethods_cl;
 124 
 125 public:
 126   ShenandoahRootEvacuator(ShenandoahHeap* heap, uint n_workers,
 127                           ShenandoahPhaseTimings::Phase phase);
 128   ~ShenandoahRootEvacuator();
 129 
 130   void process_evacuate_roots(OopClosure* oops,
 131                               CodeBlobClosure* blobs,
 132                               uint worker_id);
 133 
 134   // Number of worker threads used by the root processor.
 135   uint n_workers() const;
 136 };
 137 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_HPP