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   ShenandoahNMethod* data = gc_data(nm);
 75   assert(data != nullptr, "Sanity");
 76   ShenandoahNMethodLock* lock = data->lock();
 77   assert(lock != nullptr, "Must be");
 78   ShenandoahNMethodLocker locker(lock);
 79 
 80   disarm_nmethod_unlocked(nm);
 81 }
 82 
 83 void ShenandoahNMethod::disarm_nmethod_unlocked(nmethod* nm) {
 84   ShenandoahNMethod* data = gc_data(nm);
 85   assert(data != nullptr, "Sanity");
 86   assert(data->lock()->owned_by_self(), "Must hold the lock");
 87 
 88   BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod();
 89   if (bs->is_armed(nm)) {
 90     data->update_barriers();
 91     bs->disarm(nm);
 92   }
 93 }
 94 
 95 ShenandoahNMethod* ShenandoahNMethod::gc_data(nmethod* nm) {
 96   return nm->gc_data<ShenandoahNMethod>();
 97 }
 98 
 99 void ShenandoahNMethod::attach_gc_data(nmethod* nm, ShenandoahNMethod* gc_data) {
100   nm->set_gc_data<ShenandoahNMethod>(gc_data);
101 }
102 
103 ShenandoahNMethodLock* ShenandoahNMethod::lock_for_nmethod(nmethod* nm) {
104   return gc_data(nm)->lock();
105 }
106 
107 ShenandoahNMethodLock* ShenandoahNMethod::ic_lock_for_nmethod(nmethod* nm) {
108   return gc_data(nm)->ic_lock();
109 }
110 
111 bool ShenandoahNMethodTable::iteration_in_progress() const {
112   return _itr_cnt > 0;
113 }
114 
115 int ShenandoahNMethodList::size() const {
116   return _size;
117 }
118 
119 ShenandoahNMethod* ShenandoahNMethodList::at(int index) const {
120   assert(index < size(), "Index out of bound");
121   return _list[index];
122 }
123 
124 void ShenandoahNMethodList::set(int index, ShenandoahNMethod* snm) {
125   assert(index < size(), "Index out of bound");
126   _list[index] = snm;
127 }
128 
129 ShenandoahNMethod** ShenandoahNMethodList::list() const {
130   return _list;
131 }
132 
133 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_INLINE_HPP