1 /*
   2  * Copyright (c) 2007, 2012, Oracle and/or its affiliates. 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_VM_GC_IMPLEMENTATION_PARNEW_PAROOPCLOSURES_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PAROOPCLOSURES_HPP
  27 
  28 #include "memory/genOopClosures.hpp"
  29 
  30 // Closures for ParNewGeneration
  31 
  32 class ParScanThreadState;
  33 class ParNewGeneration;
  34 typedef Padded<OopTaskQueue> ObjToScanQueue;
  35 typedef GenericTaskQueueSet<ObjToScanQueue, mtGC> ObjToScanQueueSet;
  36 class ParallelTaskTerminator;
  37 
  38 class ParScanClosure: public OopsInKlassOrGenClosure {
  39  protected:
  40   ParScanThreadState* _par_scan_state;
  41   ParNewGeneration*   _g;
  42   HeapWord*           _boundary;
  43   template <class T> void inline par_do_barrier(T* p);
  44   template <class T> void inline do_oop_work(T* p,
  45                                              bool gc_barrier,
  46                                              bool root_scan);
  47  public:
  48   ParScanClosure(ParNewGeneration* g, ParScanThreadState* par_scan_state);
  49 };
  50 
  51 class ParScanWithBarrierClosure: public ParScanClosure {
  52  public:
  53   ParScanWithBarrierClosure(ParNewGeneration* g,
  54                             ParScanThreadState* par_scan_state) :
  55     ParScanClosure(g, par_scan_state) {}
  56   virtual void do_oop(oop* p);
  57   virtual void do_oop(narrowOop* p);
  58   inline void do_oop_nv(oop* p);
  59   inline void do_oop_nv(narrowOop* p);
  60 };
  61 
  62 class ParScanWithoutBarrierClosure: public ParScanClosure {
  63  public:
  64   ParScanWithoutBarrierClosure(ParNewGeneration* g,
  65                                ParScanThreadState* par_scan_state) :
  66     ParScanClosure(g, par_scan_state) {}
  67   virtual void do_oop(oop* p);
  68   virtual void do_oop(narrowOop* p);
  69   inline void do_oop_nv(oop* p);
  70   inline void do_oop_nv(narrowOop* p);
  71 };
  72 
  73 class ParRootScanWithBarrierTwoGensClosure: public ParScanClosure {
  74  public:
  75   ParRootScanWithBarrierTwoGensClosure(ParNewGeneration* g,
  76                                        ParScanThreadState* par_scan_state) :
  77     ParScanClosure(g, par_scan_state) {}
  78   virtual void do_oop(oop* p);
  79   virtual void do_oop(narrowOop* p);
  80 };
  81 
  82 class ParRootScanWithoutBarrierClosure: public ParScanClosure {
  83  public:
  84   ParRootScanWithoutBarrierClosure(ParNewGeneration* g,
  85                                    ParScanThreadState* par_scan_state) :
  86     ParScanClosure(g, par_scan_state) {}
  87   virtual void do_oop(oop* p);
  88   virtual void do_oop(narrowOop* p);
  89 };
  90 
  91 class ParScanWeakRefClosure: public ScanWeakRefClosure {
  92  protected:
  93   ParScanThreadState* _par_scan_state;
  94   template <class T> inline void do_oop_work(T* p);
  95  public:
  96   ParScanWeakRefClosure(ParNewGeneration* g,
  97                         ParScanThreadState* par_scan_state);
  98   virtual void do_oop(oop* p);
  99   virtual void do_oop(narrowOop* p);
 100   inline void do_oop_nv(oop* p);
 101   inline void do_oop_nv(narrowOop* p);
 102 };
 103 
 104 class ParEvacuateFollowersClosure: public VoidClosure {
 105  private:
 106   ParScanThreadState* _par_scan_state;
 107   ParScanThreadState* par_scan_state() { return _par_scan_state; }
 108 
 109   // We want to preserve the specific types here (rather than "OopClosure")
 110   // for later de-virtualization of do_oop calls.
 111   ParScanWithoutBarrierClosure* _to_space_closure;
 112   ParScanWithoutBarrierClosure* to_space_closure() {
 113     return _to_space_closure;
 114   }
 115   ParRootScanWithoutBarrierClosure* _to_space_root_closure;
 116   ParRootScanWithoutBarrierClosure* to_space_root_closure() {
 117     return _to_space_root_closure;
 118   }
 119 
 120   ParScanWithBarrierClosure* _old_gen_closure;
 121   ParScanWithBarrierClosure* old_gen_closure () {
 122     return _old_gen_closure;
 123   }
 124   ParRootScanWithBarrierTwoGensClosure* _old_gen_root_closure;
 125   ParRootScanWithBarrierTwoGensClosure* old_gen_root_closure () {
 126     return _old_gen_root_closure;
 127   }
 128 
 129   ParNewGeneration* _par_gen;
 130   ParNewGeneration* par_gen() { return _par_gen; }
 131 
 132   ObjToScanQueueSet*  _task_queues;
 133   ObjToScanQueueSet*  task_queues() { return _task_queues; }
 134 
 135   ParallelTaskTerminator* _terminator;
 136   ParallelTaskTerminator* terminator() { return _terminator; }
 137  public:
 138   ParEvacuateFollowersClosure(
 139     ParScanThreadState* par_scan_state_,
 140     ParScanWithoutBarrierClosure* to_space_closure_,
 141     ParScanWithBarrierClosure* old_gen_closure_,
 142     ParRootScanWithoutBarrierClosure* to_space_root_closure_,
 143     ParNewGeneration* par_gen_,
 144     ParRootScanWithBarrierTwoGensClosure* old_gen_root_closure_,
 145     ObjToScanQueueSet* task_queues_,
 146     ParallelTaskTerminator* terminator_);
 147   virtual void do_void();
 148 };
 149 
 150 #endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PAROOPCLOSURES_HPP