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