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, ICacheInvalidationContext* icic) {
 51   assert(!fix_relocations || icic != nullptr, "Need ICIC if fixing relocations");
 52 
 53   for (int c = 0; c < _oops_count; c ++) {
 54     oops->do_oop(_oops[c]);
 55   }
 56 
 57   oop* const begin = _nm->oops_begin();
 58   oop* const end = _nm->oops_end();
 59   for (oop* p = begin; p < end; p++) {
 60     if (*p != Universe::non_oop_word()) {
 61       oops->do_oop(p);
 62     }
 63   }
 64 
 65   if (fix_relocations && _has_non_immed_oops) {
 66     _nm->fix_oop_relocations(icic);
 67   }
 68 }
 69 
 70 void ShenandoahNMethod::heal_nmethod_metadata(ShenandoahNMethod* nmethod_data, ICacheInvalidationContext* icic) {
 71   ShenandoahEvacuateUpdateMetadataClosure cl;
 72   nmethod_data->oops_do(&cl, /* fix_relocations = */ true, icic);
 73 }
 74 
 75 void ShenandoahNMethod::disarm_nmethod(nmethod* nm) {
 76   BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod();
 77   if (bs->is_armed(nm)) {
 78     bs->disarm(nm);
 79   }
 80 }
 81 
 82 ShenandoahNMethod* ShenandoahNMethod::gc_data(nmethod* nm) {
 83   return nm->gc_data<ShenandoahNMethod>();
 84 }
 85 
 86 void ShenandoahNMethod::attach_gc_data(nmethod* nm, ShenandoahNMethod* gc_data) {
 87   nm->set_gc_data<ShenandoahNMethod>(gc_data);
 88 }
 89 
 90 ShenandoahNMethodLock* ShenandoahNMethod::lock_for_nmethod(nmethod* nm) {
 91   return gc_data(nm)->lock();
 92 }
 93 
 94 ShenandoahNMethodLock* ShenandoahNMethod::ic_lock_for_nmethod(nmethod* nm) {
 95   return gc_data(nm)->ic_lock();
 96 }
 97 
 98 bool ShenandoahNMethodTable::iteration_in_progress() const {
 99   return _itr_cnt > 0;
100 }
101 
102 int ShenandoahNMethodList::size() const {
103   return _size;
104 }
105 
106 ShenandoahNMethod* ShenandoahNMethodList::at(int index) const {
107   assert(index < size(), "Index out of bound");
108   return _list[index];
109 }
110 
111 void ShenandoahNMethodList::set(int index, ShenandoahNMethod* snm) {
112   assert(index < size(), "Index out of bound");
113   _list[index] = snm;
114 }
115 
116 ShenandoahNMethod** ShenandoahNMethodList::list() const {
117   return _list;
118 }
119 
120 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_INLINE_HPP