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 class SATBMarkQueueSet; 39 40 class ShenandoahFlushSATBHandshakeClosure : public HandshakeClosure { 41 private: 42 SATBMarkQueueSet& _qset; 43 public: 44 inline explicit ShenandoahFlushSATBHandshakeClosure(SATBMarkQueueSet& qset); 45 inline void do_thread(Thread* thread) override; 46 }; 47 48 class ShenandoahForwardedIsAliveClosure: public BoolObjectClosure { 49 private: 50 ShenandoahMarkingContext* const _mark_context; 51 public: 52 inline ShenandoahForwardedIsAliveClosure(); 53 inline bool do_object_b(oop obj); 54 }; 55 56 class ShenandoahIsAliveClosure: public BoolObjectClosure { 57 private: 58 ShenandoahMarkingContext* const _mark_context; 59 public: 60 inline ShenandoahIsAliveClosure(); 61 inline bool do_object_b(oop obj); 62 }; 63 64 class ShenandoahIsAliveSelector : public StackObj { 65 private: 66 ShenandoahIsAliveClosure _alive_cl; 67 ShenandoahForwardedIsAliveClosure _fwd_alive_cl; 68 public: 69 inline BoolObjectClosure* is_alive_closure(); 70 }; 71 72 class ShenandoahKeepAliveClosure : public OopClosure { 73 private: 74 ShenandoahBarrierSet* const _bs; 75 public: 76 inline ShenandoahKeepAliveClosure(); 77 inline void do_oop(oop* p); 78 inline void do_oop(narrowOop* p); 79 private: 80 template <typename T> 81 void do_oop_work(T* p); 82 }; 83 84 class ShenandoahOopClosureBase : public MetadataVisitingOopIterateClosure { 85 public: 86 inline void do_nmethod(nmethod* nm); 87 }; 88 89 class ShenandoahUpdateRefsClosure: public ShenandoahOopClosureBase { 90 private: 91 ShenandoahHeap* _heap; 92 public: 93 inline ShenandoahUpdateRefsClosure(); 94 inline void do_oop(oop* p); 95 inline void do_oop(narrowOop* p); 96 private: 97 template <class T> 98 inline void do_oop_work(T* p); 99 }; 100 101 template <bool concurrent, bool stable_thread> 102 class ShenandoahEvacuateUpdateRootClosureBase : public ShenandoahOopClosureBase { 103 protected: 104 ShenandoahHeap* const _heap; 105 Thread* const _thread; 106 public: 107 inline ShenandoahEvacuateUpdateRootClosureBase(); 108 inline void do_oop(oop* p); 109 inline void do_oop(narrowOop* p); 110 protected: 111 template <class T> 112 inline void do_oop_work(T* p); 113 }; 114 115 using ShenandoahEvacuateUpdateMetadataClosure = ShenandoahEvacuateUpdateRootClosureBase<false, true>; 116 using ShenandoahEvacuateUpdateRootsClosure = ShenandoahEvacuateUpdateRootClosureBase<true, false>; 117 using ShenandoahContextEvacuateUpdateRootsClosure = ShenandoahEvacuateUpdateRootClosureBase<true, true>; 118 119 template <bool CONCURRENT, typename IsAlive, typename KeepAlive> 120 class ShenandoahCleanUpdateWeakOopsClosure : public OopClosure { 121 private: 122 IsAlive* _is_alive; 123 KeepAlive* _keep_alive; 124 125 public: 126 inline ShenandoahCleanUpdateWeakOopsClosure(IsAlive* is_alive, KeepAlive* keep_alive); 127 inline void do_oop(oop* p); 128 inline void do_oop(narrowOop* p); 129 }; 130 131 class ShenandoahCodeBlobAndDisarmClosure: public CodeBlobToOopClosure { 132 private: 133 BarrierSetNMethod* const _bs; 134 135 public: 136 inline ShenandoahCodeBlobAndDisarmClosure(OopClosure* cl); 137 inline void do_code_blob(CodeBlob* cb); 138 }; 139 140 #ifdef ASSERT 141 class ShenandoahAssertNotForwardedClosure : public OopClosure { 142 private: 143 template <class T> 144 inline void do_oop_work(T* p); 145 146 public: 147 inline void do_oop(narrowOop* p); 148 inline void do_oop(oop* p); 149 }; 150 #endif // ASSERT 151 152 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP