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
25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_INLINE_HPP
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_INLINE_HPP
27
28 #include "gc/shenandoah/shenandoahNMethod.hpp"
29
30 #include "gc/shared/barrierSet.hpp"
31 #include "gc/shared/barrierSetNMethod.hpp"
32 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
33
34 nmethod* ShenandoahNMethod::nm() const {
35 return _nm;
36 }
37
38 ShenandoahNMethodLock* ShenandoahNMethod::lock() {
39 return &_lock;
40 }
41
42 ShenandoahNMethodLock* ShenandoahNMethod::ic_lock() {
43 return &_ic_lock;
44 }
45
46 bool ShenandoahNMethod::is_unregistered() const {
47 return _unregistered;
48 }
49
50 void ShenandoahNMethod::oops_do(OopClosure* oops, bool fix_relocations) {
51 for (int c = 0; c < _oops_count; c ++) {
52 oops->do_oop(_oops[c]);
53 }
54
55 oop* const begin = _nm->oops_begin();
56 oop* const end = _nm->oops_end();
57 for (oop* p = begin; p < end; p++) {
58 if (*p != Universe::non_oop_word()) {
59 oops->do_oop(p);
60 }
61 }
62
63 if (fix_relocations && _has_non_immed_oops) {
64 _nm->fix_oop_relocations();
65 }
66 }
67
68 void ShenandoahNMethod::heal_nmethod_metadata(ShenandoahNMethod* nmethod_data) {
69 ShenandoahEvacuateUpdateMetadataClosure cl;
70 nmethod_data->oops_do(&cl, true /*fix relocation*/);
71 }
72
73 void ShenandoahNMethod::disarm_nmethod(nmethod* nm) {
74 BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod();
75 if (bs->is_armed(nm)) {
76 bs->disarm(nm);
77 }
78 }
79
80 ShenandoahNMethod* ShenandoahNMethod::gc_data(nmethod* nm) {
81 return nm->gc_data<ShenandoahNMethod>();
82 }
83
84 void ShenandoahNMethod::attach_gc_data(nmethod* nm, ShenandoahNMethod* gc_data) {
85 nm->set_gc_data<ShenandoahNMethod>(gc_data);
86 }
87
88 ShenandoahNMethodLock* ShenandoahNMethod::lock_for_nmethod(nmethod* nm) {
89 return gc_data(nm)->lock();
90 }
91
92 ShenandoahNMethodLock* ShenandoahNMethod::ic_lock_for_nmethod(nmethod* nm) {
93 return gc_data(nm)->ic_lock();
94 }
95
96 bool ShenandoahNMethodTable::iteration_in_progress() const {
97 return _itr_cnt > 0;
98 }
99
100 int ShenandoahNMethodList::size() const {
101 return _size;
102 }
103
104 ShenandoahNMethod* ShenandoahNMethodList::at(int index) const {
105 assert(index < size(), "Index out of bound");
106 return _list[index];
107 }
108
109 void ShenandoahNMethodList::set(int index, ShenandoahNMethod* snm) {
110 assert(index < size(), "Index out of bound");
111 _list[index] = snm;
112 }
113
114 ShenandoahNMethod** ShenandoahNMethodList::list() const {
115 return _list;
116 }
117
118 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_INLINE_HPP