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 *
42 #include "runtime/javaThread.hpp"
43
44 //
45 // ========= Super
46 //
47
48 ShenandoahSuperClosure::ShenandoahSuperClosure() :
49 MetadataVisitingOopIterateClosure(), _heap(ShenandoahHeap::heap()) {}
50
51 ShenandoahSuperClosure::ShenandoahSuperClosure(ShenandoahReferenceProcessor* rp) :
52 MetadataVisitingOopIterateClosure(rp), _heap(ShenandoahHeap::heap()) {}
53
54 void ShenandoahSuperClosure::do_nmethod(nmethod* nm) {
55 nm->run_nmethod_entry_barrier();
56 }
57
58 //
59 // ========= Marking
60 //
61
62 ShenandoahMarkRefsSuperClosure::ShenandoahMarkRefsSuperClosure(ShenandoahObjToScanQueue* q, ShenandoahReferenceProcessor* rp) :
63 ShenandoahSuperClosure(rp),
64 _queue(q),
65 _mark_context(ShenandoahHeap::heap()->marking_context()),
66 _weak(false) {}
67
68 template<class T, ShenandoahGenerationType GENERATION>
69 inline void ShenandoahMarkRefsSuperClosure::work(T* p) {
70 ShenandoahMark::mark_through_ref<T, GENERATION>(p, _queue, _mark_context, _weak);
71 }
72
73 ShenandoahForwardedIsAliveClosure::ShenandoahForwardedIsAliveClosure() :
74 _mark_context(ShenandoahHeap::heap()->marking_context()) {}
75
76 bool ShenandoahForwardedIsAliveClosure::do_object_b(oop obj) {
77 if (CompressedOops::is_null(obj)) {
78 return false;
79 }
80 obj = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
81 shenandoah_assert_not_forwarded_if(nullptr, obj, ShenandoahHeap::heap()->is_concurrent_mark_in_progress());
82 return _mark_context->is_marked(obj);
83 }
84
85 ShenandoahIsAliveClosure::ShenandoahIsAliveClosure() :
86 _mark_context(ShenandoahHeap::heap()->marking_context()) {}
87
88 bool ShenandoahIsAliveClosure::do_object_b(oop obj) {
89 if (CompressedOops::is_null(obj)) {
90 return false;
91 }
92 shenandoah_assert_not_forwarded(nullptr, obj);
93 return _mark_context->is_marked(obj);
94 }
95
96 BoolObjectClosure* ShenandoahIsAliveSelector::is_alive_closure() {
97 return ShenandoahHeap::heap()->has_forwarded_objects() ?
98 reinterpret_cast<BoolObjectClosure*>(&_fwd_alive_cl) :
99 reinterpret_cast<BoolObjectClosure*>(&_alive_cl);
100 }
101
102 ShenandoahKeepAliveClosure::ShenandoahKeepAliveClosure() :
103 _bs(ShenandoahBarrierSet::barrier_set()) {}
104
105 template <typename T>
106 void ShenandoahKeepAliveClosure::do_oop_work(T* p) {
107 assert(ShenandoahHeap::heap()->is_concurrent_mark_in_progress(), "Only for concurrent marking phase");
108 assert(!ShenandoahHeap::heap()->has_forwarded_objects(), "Not expected");
109
110 T o = RawAccess<>::oop_load(p);
111 if (!CompressedOops::is_null(o)) {
112 oop obj = CompressedOops::decode_not_null(o);
113 _bs->enqueue(obj);
114 }
115 }
116
117
118 //
119 // ========= Evacuating + Roots
120 //
121
122 template <bool CONCURRENT, bool STABLE_THREAD>
123 void ShenandoahEvacuateUpdateRootClosureBase<CONCURRENT, STABLE_THREAD>::do_oop(oop* p) {
124 if (CONCURRENT) {
125 ShenandoahEvacOOMScope scope;
126 do_oop_work(p);
127 } else {
128 do_oop_work(p);
198 }
199
200 ShenandoahNMethodAndDisarmClosure::ShenandoahNMethodAndDisarmClosure(OopClosure* cl) :
201 NMethodToOopClosure(cl, true /* fix_relocations */),
202 _bs(BarrierSet::barrier_set()->barrier_set_nmethod()) {
203 }
204
205 void ShenandoahNMethodAndDisarmClosure::do_nmethod(nmethod* nm) {
206 assert(nm != nullptr, "Sanity");
207 assert(!ShenandoahNMethod::gc_data(nm)->is_unregistered(), "Should not be here");
208 NMethodToOopClosure::do_nmethod(nm);
209 _bs->disarm(nm);
210 }
211
212
213 //
214 // ========= Update References
215 //
216
217 template <ShenandoahGenerationType GENERATION>
218 ShenandoahMarkUpdateRefsClosure<GENERATION>::ShenandoahMarkUpdateRefsClosure(ShenandoahObjToScanQueue* q, ShenandoahReferenceProcessor* rp) :
219 ShenandoahMarkRefsSuperClosure(q, rp) {
220 assert(_heap->is_stw_gc_in_progress(), "Can only be used for STW GC");
221 }
222
223 template<ShenandoahGenerationType GENERATION>
224 template<class T>
225 inline void ShenandoahMarkUpdateRefsClosure<GENERATION>::work(T* p) {
226 // Update the location
227 _heap->non_conc_update_with_forwarded(p);
228
229 // ...then do the usual thing
230 ShenandoahMarkRefsSuperClosure::work<T, GENERATION>(p);
231 }
232
233 template<class T>
234 inline void ShenandoahNonConcUpdateRefsClosure::work(T* p) {
235 _heap->non_conc_update_with_forwarded(p);
236 }
237
238 template<class T>
239 inline void ShenandoahConcUpdateRefsClosure::work(T* p) {
|
1 /*
2 * Copyright (c) 2019, 2020, Red Hat, Inc. All rights reserved.
3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
43 #include "runtime/javaThread.hpp"
44
45 //
46 // ========= Super
47 //
48
49 ShenandoahSuperClosure::ShenandoahSuperClosure() :
50 MetadataVisitingOopIterateClosure(), _heap(ShenandoahHeap::heap()) {}
51
52 ShenandoahSuperClosure::ShenandoahSuperClosure(ShenandoahReferenceProcessor* rp) :
53 MetadataVisitingOopIterateClosure(rp), _heap(ShenandoahHeap::heap()) {}
54
55 void ShenandoahSuperClosure::do_nmethod(nmethod* nm) {
56 nm->run_nmethod_entry_barrier();
57 }
58
59 //
60 // ========= Marking
61 //
62
63 ShenandoahMarkRefsSuperClosure::ShenandoahMarkRefsSuperClosure(ShenandoahObjToScanQueue* q,
64 ShenandoahReferenceProcessor* rp,
65 ShenandoahObjToScanQueue* old_q) :
66 ShenandoahSuperClosure(rp),
67 _queue(q),
68 _old_queue(old_q),
69 _mark_context(ShenandoahHeap::heap()->marking_context()),
70 _weak(false) {}
71
72 template<class T, ShenandoahGenerationType GENERATION>
73 inline void ShenandoahMarkRefsSuperClosure::work(T* p) {
74 ShenandoahMark::mark_through_ref<T, GENERATION>(p, _queue, _old_queue, _mark_context, _weak);
75 }
76
77 ShenandoahForwardedIsAliveClosure::ShenandoahForwardedIsAliveClosure() :
78 _mark_context(ShenandoahHeap::heap()->marking_context()) {}
79
80 bool ShenandoahForwardedIsAliveClosure::do_object_b(oop obj) {
81 if (CompressedOops::is_null(obj)) {
82 return false;
83 }
84 obj = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
85 shenandoah_assert_not_forwarded_if(nullptr, obj, ShenandoahHeap::heap()->is_concurrent_mark_in_progress());
86 return _mark_context->is_marked_or_old(obj);
87 }
88
89 ShenandoahIsAliveClosure::ShenandoahIsAliveClosure() :
90 _mark_context(ShenandoahHeap::heap()->marking_context()) {}
91
92 bool ShenandoahIsAliveClosure::do_object_b(oop obj) {
93 if (CompressedOops::is_null(obj)) {
94 return false;
95 }
96 shenandoah_assert_not_forwarded(nullptr, obj);
97 return _mark_context->is_marked_or_old(obj);
98 }
99
100 BoolObjectClosure* ShenandoahIsAliveSelector::is_alive_closure() {
101 return ShenandoahHeap::heap()->has_forwarded_objects() ?
102 reinterpret_cast<BoolObjectClosure*>(&_fwd_alive_cl) :
103 reinterpret_cast<BoolObjectClosure*>(&_alive_cl);
104 }
105
106 ShenandoahKeepAliveClosure::ShenandoahKeepAliveClosure() :
107 _bs(ShenandoahBarrierSet::barrier_set()) {}
108
109 template <typename T>
110 void ShenandoahKeepAliveClosure::do_oop_work(T* p) {
111 assert(ShenandoahHeap::heap()->is_concurrent_mark_in_progress(), "Only for concurrent marking phase");
112 assert(ShenandoahHeap::heap()->is_concurrent_old_mark_in_progress() || !ShenandoahHeap::heap()->has_forwarded_objects(), "Not expected");
113
114 T o = RawAccess<>::oop_load(p);
115 if (!CompressedOops::is_null(o)) {
116 oop obj = CompressedOops::decode_not_null(o);
117 _bs->enqueue(obj);
118 }
119 }
120
121
122 //
123 // ========= Evacuating + Roots
124 //
125
126 template <bool CONCURRENT, bool STABLE_THREAD>
127 void ShenandoahEvacuateUpdateRootClosureBase<CONCURRENT, STABLE_THREAD>::do_oop(oop* p) {
128 if (CONCURRENT) {
129 ShenandoahEvacOOMScope scope;
130 do_oop_work(p);
131 } else {
132 do_oop_work(p);
202 }
203
204 ShenandoahNMethodAndDisarmClosure::ShenandoahNMethodAndDisarmClosure(OopClosure* cl) :
205 NMethodToOopClosure(cl, true /* fix_relocations */),
206 _bs(BarrierSet::barrier_set()->barrier_set_nmethod()) {
207 }
208
209 void ShenandoahNMethodAndDisarmClosure::do_nmethod(nmethod* nm) {
210 assert(nm != nullptr, "Sanity");
211 assert(!ShenandoahNMethod::gc_data(nm)->is_unregistered(), "Should not be here");
212 NMethodToOopClosure::do_nmethod(nm);
213 _bs->disarm(nm);
214 }
215
216
217 //
218 // ========= Update References
219 //
220
221 template <ShenandoahGenerationType GENERATION>
222 ShenandoahMarkUpdateRefsClosure<GENERATION>::ShenandoahMarkUpdateRefsClosure(ShenandoahObjToScanQueue* q,
223 ShenandoahReferenceProcessor* rp,
224 ShenandoahObjToScanQueue* old_q) :
225 ShenandoahMarkRefsSuperClosure(q, rp, old_q) {
226 assert(_heap->is_stw_gc_in_progress(), "Can only be used for STW GC");
227 }
228
229 template<ShenandoahGenerationType GENERATION>
230 template<class T>
231 inline void ShenandoahMarkUpdateRefsClosure<GENERATION>::work(T* p) {
232 // Update the location
233 _heap->non_conc_update_with_forwarded(p);
234
235 // ...then do the usual thing
236 ShenandoahMarkRefsSuperClosure::work<T, GENERATION>(p);
237 }
238
239 template<class T>
240 inline void ShenandoahNonConcUpdateRefsClosure::work(T* p) {
241 _heap->non_conc_update_with_forwarded(p);
242 }
243
244 template<class T>
245 inline void ShenandoahConcUpdateRefsClosure::work(T* p) {
|