1 /*
  2  * Copyright (c) 2019, 2022, 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 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP
 25 #define SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP
 26 
 27 #include "code/nmethod.hpp"
 28 #include "memory/iterator.hpp"
 29 #include "oops/accessDecorators.hpp"
 30 #include "runtime/handshake.hpp"
 31 
 32 class BarrierSetNMethod;
 33 class ShenandoahBarrierSet;
 34 class ShenandoahHeap;
 35 class ShenandoahMarkingContext;
 36 class ShenandoahHeapRegionSet;
 37 class Thread;
 38 
 39 class ShenandoahForwardedIsAliveClosure: public BoolObjectClosure {
 40 private:
 41   ShenandoahMarkingContext* const _mark_context;
 42 public:
 43   inline ShenandoahForwardedIsAliveClosure();
 44   inline bool do_object_b(oop obj);
 45 };
 46 
 47 class ShenandoahIsAliveClosure: public BoolObjectClosure {
 48 private:
 49   ShenandoahMarkingContext* const _mark_context;
 50 public:
 51   inline ShenandoahIsAliveClosure();
 52   inline bool do_object_b(oop obj);
 53 };
 54 
 55 class ShenandoahIsAliveSelector : public StackObj {
 56 private:
 57   ShenandoahIsAliveClosure _alive_cl;
 58   ShenandoahForwardedIsAliveClosure _fwd_alive_cl;
 59 public:
 60   inline BoolObjectClosure* is_alive_closure();
 61 };
 62 
 63 class ShenandoahKeepAliveClosure : public OopClosure {
 64 private:
 65   ShenandoahBarrierSet* const _bs;
 66 public:
 67   inline ShenandoahKeepAliveClosure();
 68   inline void do_oop(oop* p);
 69   inline void do_oop(narrowOop* p);
 70 private:
 71   template <typename T>
 72   void do_oop_work(T* p);
 73 };
 74 
 75 class ShenandoahOopClosureBase : public MetadataVisitingOopIterateClosure {
 76 public:
 77   inline void do_nmethod(nmethod* nm);
 78 };
 79 
 80 class ShenandoahUpdateRefsClosure: public ShenandoahOopClosureBase {
 81 private:
 82   ShenandoahHeap* _heap;
 83 public:
 84   inline ShenandoahUpdateRefsClosure();
 85   inline void do_oop(oop* p);
 86   inline void do_oop(narrowOop* p);
 87 private:
 88   template <class T>
 89   inline void do_oop_work(T* p);
 90 };
 91 
 92 template <bool concurrent, bool stable_thread>
 93 class ShenandoahEvacuateUpdateRootClosureBase : public ShenandoahOopClosureBase {
 94 protected:
 95   ShenandoahHeap* const _heap;
 96   Thread* const _thread;
 97 public:
 98   inline ShenandoahEvacuateUpdateRootClosureBase();
 99   inline void do_oop(oop* p);
100   inline void do_oop(narrowOop* p);
101 protected:
102   template <class T>
103   inline void do_oop_work(T* p);
104 };
105 
106 using ShenandoahEvacuateUpdateMetadataClosure = ShenandoahEvacuateUpdateRootClosureBase<false, true>;
107 using ShenandoahEvacuateUpdateRootsClosure = ShenandoahEvacuateUpdateRootClosureBase<true, false>;
108 using ShenandoahContextEvacuateUpdateRootsClosure = ShenandoahEvacuateUpdateRootClosureBase<true, true>;
109 
110 template <bool CONCURRENT, typename IsAlive, typename KeepAlive>
111 class ShenandoahCleanUpdateWeakOopsClosure : public OopClosure {
112 private:
113   IsAlive*    _is_alive;
114   KeepAlive*  _keep_alive;
115 
116 public:
117   inline ShenandoahCleanUpdateWeakOopsClosure(IsAlive* is_alive, KeepAlive* keep_alive);
118   inline void do_oop(oop* p);
119   inline void do_oop(narrowOop* p);
120 };
121 
122 class ShenandoahCodeBlobAndDisarmClosure: public CodeBlobToOopClosure {
123 private:
124   BarrierSetNMethod* const _bs;
125 
126 public:
127   inline ShenandoahCodeBlobAndDisarmClosure(OopClosure* cl);
128   inline void do_code_blob(CodeBlob* cb);
129 };
130 
131 #ifdef ASSERT
132 class ShenandoahAssertNotForwardedClosure : public OopClosure {
133 private:
134   template <class T>
135   inline void do_oop_work(T* p);
136 
137 public:
138   inline void do_oop(narrowOop* p);
139   inline void do_oop(oop* p);
140 };
141 #endif // ASSERT
142 
143 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP