1 /*
   2  * Copyright (c) 2015, 2018, 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_VM_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_HPP
  26 
  27 #include "code/codeCache.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahHeap.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahCollectorPolicy.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahCodeRoots.hpp"
  31 #include "gc_implementation/shenandoah/shenandoahPhaseTimings.hpp"
  32 #include "gc_implementation/shenandoah/shenandoahSynchronizerIterator.hpp"
  33 #include "memory/allocation.hpp"
  34 #include "utilities/workgroup.hpp"
  35 
  36 class ParallelCLDRootIterator VALUE_OBJ_CLASS_SPEC {
  37 public:
  38   ParallelCLDRootIterator();
  39   void root_cld_do(CLDClosure* strong, CLDClosure* weak);
  40 };
  41 
  42 enum Shenandoah_process_roots_tasks {
  43   SHENANDOAH_RP_PS_Universe_oops_do,
  44   SHENANDOAH_RP_PS_JNIHandles_oops_do,
  45   SHENANDOAH_RP_PS_JNIHandles_weak_oops_do,
  46   SHENANDOAH_RP_PS_FlatProfiler_oops_do,
  47   SHENANDOAH_RP_PS_Management_oops_do,
  48   SHENANDOAH_RP_PS_SystemDictionary_oops_do,
  49   SHENANDOAH_RP_PS_jvmti_oops_do,
  50   // Leave this one last.
  51   SHENANDOAH_RP_PS_NumElements
  52 };
  53 
  54 class ShenandoahRootProcessor : public StackObj {
  55   SubTasksDone* _process_strong_tasks;
  56   SharedHeap::StrongRootsScope _srs;
  57   ShenandoahPhaseTimings::Phase _phase;
  58   ParallelCLDRootIterator   _cld_iterator;
  59   ShenandoahAllCodeRootsIterator _coderoots_all_iterator;
  60   ShenandoahSynchronizerIterator _om_iterator;
  61 
  62   void process_java_roots(OopClosure* scan_non_heap_roots,
  63                           CLDClosure* thread_clds,
  64                           CLDClosure* scan_strong_clds,
  65                           CLDClosure* scan_weak_clds,
  66                           CodeBlobClosure* scan_strong_code,
  67                           uint worker_i);
  68 
  69   void process_vm_roots(OopClosure* scan_non_heap_roots,
  70                         OopClosure* scan_non_heap_weak_roots,
  71                         OopClosure* weak_jni_roots,
  72                         uint worker_i);
  73 
  74 public:
  75   ShenandoahRootProcessor(ShenandoahHeap* heap, uint n_workers,
  76                           ShenandoahPhaseTimings::Phase phase);
  77   ~ShenandoahRootProcessor();
  78 
  79   // Apply oops, clds and blobs to all strongly reachable roots in the system
  80   void process_strong_roots(OopClosure* oops,
  81                             CLDClosure* clds,
  82                             CLDClosure* weak_clds,
  83                             CodeBlobClosure* blobs,
  84                             ThreadClosure* thread_cl,
  85                             uint worker_id);
  86 
  87   // Apply oops, clds and blobs to strongly and weakly reachable roots in the system
  88   void process_all_roots(OopClosure* oops,
  89                          CLDClosure* clds,
  90                          CodeBlobClosure* blobs,
  91                          ThreadClosure* thread_cl,
  92                          uint worker_id);
  93 
  94   // For slow debug/verification code
  95   void process_all_roots_slow(OopClosure* oops);
  96 
  97   // Number of worker threads used by the root processor.
  98   uint n_workers() const;
  99 };
 100 
 101 class ShenandoahRootEvacuator : public StackObj {
 102   SubTasksDone* _evacuation_tasks;
 103   SharedHeap::StrongRootsScope _srs;
 104   ShenandoahPhaseTimings::Phase _phase;
 105   ParallelCLDRootIterator   _cld_iterator;
 106   ShenandoahCsetCodeRootsIterator _coderoots_cset_iterator;
 107   ShenandoahSynchronizerIterator _om_iterator;
 108 
 109   enum Shenandoah_evacuate_roots_tasks {
 110     SHENANDOAH_EVAC_Universe_oops_do,
 111     SHENANDOAH_EVAC_JNIHandles_oops_do,
 112     SHENANDOAH_EVAC_JNIHandles_weak_oops_do,
 113     SHENANDOAH_EVAC_FlatProfiler_oops_do,
 114     SHENANDOAH_EVAC_Management_oops_do,
 115     SHENANDOAH_EVAC_SystemDictionary_oops_do,
 116     SHENANDOAH_EVAC_jvmti_oops_do,
 117     // Leave this one last.
 118     SHENANDOAH_EVAC_NumElements
 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