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 _heap->is_degenerated_gc_in_progress(), 94 "Only do this in root processing phase"); 95 96 T o = RawAccess<>::oop_load(p); 97 if (! CompressedOops::is_null(o)) { 98 oop obj = CompressedOops::decode_not_null(o); 99 if (_heap->in_collection_set(obj)) { 100 assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress"); 101 shenandoah_assert_marked(p, obj); 102 oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); 103 if (resolved == obj) { 104 resolved = _heap->evacuate_object_recursively(obj, p, _thread); 105 } 106 RawAccess<IS_NOT_NULL | MO>::oop_store(p, resolved); 107 } 108 } 109 } 110 template <DecoratorSet MO> 111 void ShenandoahEvacuateUpdateRootsClosure<MO>::do_oop(oop* p) { 112 do_oop_work(p); 113 } 114 115 template <DecoratorSet MO> 116 void ShenandoahEvacuateUpdateRootsClosure<MO>::do_oop(narrowOop* p) { 117 do_oop_work(p); 118 } 119 120 ShenandoahEvacUpdateOopStorageRootsClosure::ShenandoahEvacUpdateOopStorageRootsClosure() : 121 _heap(ShenandoahHeap::heap()), _thread(Thread::current()) { 122 } 123 124 void ShenandoahEvacUpdateOopStorageRootsClosure::do_oop(oop* p) { 125 assert(_heap->is_concurrent_weak_root_in_progress() || 126 _heap->is_concurrent_strong_root_in_progress(), 127 "Only do this in root processing phase"); 128 129 oop obj = RawAccess<>::oop_load(p); 130 if (! CompressedOops::is_null(obj)) { 131 if (_heap->in_collection_set(obj)) { 132 assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress"); 133 shenandoah_assert_marked(p, obj); 134 oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); 135 if (resolved == obj) { 136 resolved = _heap->evacuate_object_recursively(obj, p, _thread); 137 } 138 139 Atomic::cmpxchg(p, obj, resolved); 140 } 141 } 142 } 143 144 void ShenandoahEvacUpdateOopStorageRootsClosure::do_oop(narrowOop* p) { 145 ShouldNotReachHere(); 146 } 147 148 ShenandoahCodeBlobAndDisarmClosure::ShenandoahCodeBlobAndDisarmClosure(OopClosure* cl) : 149 CodeBlobToOopClosure(cl, true /* fix_relocations */), 150 _bs(BarrierSet::barrier_set()->barrier_set_nmethod()) { 151 } 152 153 void ShenandoahCodeBlobAndDisarmClosure::do_code_blob(CodeBlob* cb) { 154 nmethod* const nm = cb->as_nmethod_or_null(); 155 if (nm != NULL && nm->oops_do_try_claim()) { 156 assert(!ShenandoahNMethod::gc_data(nm)->is_unregistered(), "Should not be here"); 157 CodeBlobToOopClosure::do_code_blob(cb); 158 _bs->disarm(nm); 159 } 160 } 161 162 #ifdef ASSERT 163 template <class T> 164 void ShenandoahAssertNotForwardedClosure::do_oop_work(T* p) { 165 T o = RawAccess<>::oop_load(p); 166 if (!CompressedOops::is_null(o)) { 167 oop obj = CompressedOops::decode_not_null(o); 168 shenandoah_assert_not_forwarded(p, obj); 169 } 170 } 171 172 void ShenandoahAssertNotForwardedClosure::do_oop(narrowOop* p) { do_oop_work(p); } 173 void ShenandoahAssertNotForwardedClosure::do_oop(oop* p) { do_oop_work(p); } 174 #endif 175 176 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP