1 /* 2 * Copyright (c) 2019, 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 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_INLINE_HPP 24 #define SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_INLINE_HPP 25 26 #include "gc/shared/barrierSetNMethod.hpp" 27 #include "gc/shenandoah/shenandoahAsserts.hpp" 28 #include "gc/shenandoah/shenandoahClosures.hpp" 29 #include "gc/shenandoah/shenandoahHeap.inline.hpp" 30 #include "gc/shenandoah/shenandoahNMethod.inline.hpp" 31 #include "gc/shenandoah/shenandoahTraversalGC.hpp" 32 #include "oops/compressedOops.inline.hpp" 33 #include "runtime/atomic.hpp" 34 #include "runtime/thread.hpp" 35 36 ShenandoahForwardedIsAliveClosure::ShenandoahForwardedIsAliveClosure() : 37 _mark_context(ShenandoahHeap::heap()->marking_context()) { 38 } 39 40 bool ShenandoahForwardedIsAliveClosure::do_object_b(oop obj) { 41 if (CompressedOops::is_null(obj)) { 42 return false; 43 } 44 obj = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); 45 shenandoah_assert_not_forwarded_if(NULL, obj, 46 (ShenandoahHeap::heap()->is_concurrent_mark_in_progress() || 47 ShenandoahHeap::heap()->is_concurrent_traversal_in_progress())); 48 return _mark_context->is_marked(obj); 49 } 50 51 ShenandoahIsAliveClosure::ShenandoahIsAliveClosure() : 52 _mark_context(ShenandoahHeap::heap()->marking_context()) { 53 } 54 55 bool ShenandoahIsAliveClosure::do_object_b(oop obj) { 56 if (CompressedOops::is_null(obj)) { 57 return false; 58 } 59 shenandoah_assert_not_forwarded(NULL, obj); 60 return _mark_context->is_marked(obj); 61 } 62 63 BoolObjectClosure* ShenandoahIsAliveSelector::is_alive_closure() { 64 return ShenandoahHeap::heap()->has_forwarded_objects() ? 65 reinterpret_cast<BoolObjectClosure*>(&_fwd_alive_cl) : 66 reinterpret_cast<BoolObjectClosure*>(&_alive_cl); 67 } 68 69 ShenandoahUpdateRefsClosure::ShenandoahUpdateRefsClosure() : 70 _heap(ShenandoahHeap::heap()) { 71 } 72 73 template <class T> 74 void ShenandoahUpdateRefsClosure::do_oop_work(T* p) { 75 T o = RawAccess<>::oop_load(p); 76 if (!CompressedOops::is_null(o)) { 77 oop obj = CompressedOops::decode_not_null(o); 78 _heap->update_with_forwarded_not_null(p, obj); 79 } 80 } 81 82 void ShenandoahUpdateRefsClosure::do_oop(oop* p) { do_oop_work(p); } 83 void ShenandoahUpdateRefsClosure::do_oop(narrowOop* p) { do_oop_work(p); } 84 85 ShenandoahTraversalUpdateRefsClosure::ShenandoahTraversalUpdateRefsClosure() : 86 _heap(ShenandoahHeap::heap()), 87 _traversal_set(ShenandoahHeap::heap()->traversal_gc()->traversal_set()) { 88 assert(_heap->is_traversal_mode(), "Why we here?"); 89 } 90 91 template <class T> 92 void ShenandoahTraversalUpdateRefsClosure::do_oop_work(T* p) { 93 T o = RawAccess<>::oop_load(p); 94 if (!CompressedOops::is_null(o)) { 95 oop obj = CompressedOops::decode_not_null(o); 96 if (_heap->in_collection_set(obj) || _traversal_set->is_in((HeapWord*)obj)) { 97 obj = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); 98 RawAccess<IS_NOT_NULL>::oop_store(p, obj); 99 } else { 100 shenandoah_assert_not_forwarded(p, obj); 101 } 102 } 103 } 104 105 void ShenandoahTraversalUpdateRefsClosure::do_oop(oop* p) { do_oop_work(p); } 106 void ShenandoahTraversalUpdateRefsClosure::do_oop(narrowOop* p) { do_oop_work(p); } 107 108 ShenandoahEvacuateUpdateRootsClosure::ShenandoahEvacuateUpdateRootsClosure() : 109 _heap(ShenandoahHeap::heap()), _thread(Thread::current()) { 110 } 111 112 template <class T> 113 void ShenandoahEvacuateUpdateRootsClosure::do_oop_work(T* p) { 114 assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress"); 115 116 T o = RawAccess<>::oop_load(p); 117 if (! CompressedOops::is_null(o)) { 118 oop obj = CompressedOops::decode_not_null(o); 119 if (_heap->in_collection_set(obj)) { 120 shenandoah_assert_marked(p, obj); 121 oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); 122 if (resolved == obj) { 123 resolved = _heap->evacuate_object(obj, _thread); 124 } 125 RawAccess<IS_NOT_NULL>::oop_store(p, resolved); 126 } 127 } 128 } 129 void ShenandoahEvacuateUpdateRootsClosure::do_oop(oop* p) { 130 do_oop_work(p); 131 } 132 133 void ShenandoahEvacuateUpdateRootsClosure::do_oop(narrowOop* p) { 134 do_oop_work(p); 135 } 136 137 ShenandoahEvacUpdateOopStorageRootsClosure::ShenandoahEvacUpdateOopStorageRootsClosure() : 138 _heap(ShenandoahHeap::heap()), _thread(Thread::current()) { 139 } 140 141 void ShenandoahEvacUpdateOopStorageRootsClosure::do_oop(oop* p) { 142 assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress"); 143 144 oop obj = RawAccess<>::oop_load(p); 145 if (! CompressedOops::is_null(obj)) { 146 if (_heap->in_collection_set(obj)) { 147 shenandoah_assert_marked(p, obj); 148 oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); 149 if (resolved == obj) { 150 resolved = _heap->evacuate_object(obj, _thread); 151 } 152 153 Atomic::cmpxchg(p, obj, resolved); 154 } 155 } 156 } 157 158 void ShenandoahEvacUpdateOopStorageRootsClosure::do_oop(narrowOop* p) { 159 ShouldNotReachHere(); 160 } 161 162 ShenandoahCodeBlobAndDisarmClosure::ShenandoahCodeBlobAndDisarmClosure(OopClosure* cl) : 163 CodeBlobToOopClosure(cl, true /* fix_relocations */), 164 _bs(BarrierSet::barrier_set()->barrier_set_nmethod()) { 165 } 166 167 void ShenandoahCodeBlobAndDisarmClosure::do_code_blob(CodeBlob* cb) { 168 nmethod* const nm = cb->as_nmethod_or_null(); 169 if (nm != NULL && nm->oops_do_try_claim()) { 170 assert(!ShenandoahNMethod::gc_data(nm)->is_unregistered(), "Should not be here"); 171 CodeBlobToOopClosure::do_code_blob(cb); 172 _bs->disarm(nm); 173 } 174 } 175 176 #ifdef ASSERT 177 template <class T> 178 void ShenandoahAssertNotForwardedClosure::do_oop_work(T* p) { 179 T o = RawAccess<>::oop_load(p); 180 if (!CompressedOops::is_null(o)) { 181 oop obj = CompressedOops::decode_not_null(o); 182 shenandoah_assert_not_forwarded(p, obj); 183 } 184 } 185 186 void ShenandoahAssertNotForwardedClosure::do_oop(narrowOop* p) { do_oop_work(p); } 187 void ShenandoahAssertNotForwardedClosure::do_oop(oop* p) { do_oop_work(p); } 188 #endif 189 190 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP