< prev index next >

src/hotspot/share/oops/instanceKlass.inline.hpp

Print this page

  1 /*
  2  * Copyright (c) 2015, 2025, Oracle and/or its affiliates. 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  *

 46 inline int InstanceKlass::java_fields_count() const { return FieldInfoStream::num_java_fields(fieldinfo_stream()); }
 47 inline int InstanceKlass::total_fields_count() const { return FieldInfoStream::num_total_fields(fieldinfo_stream()); }
 48 
 49 inline OopMapBlock* InstanceKlass::start_of_nonstatic_oop_maps() const {
 50   return (OopMapBlock*)(start_of_itable() + itable_length());
 51 }
 52 
 53 inline Klass** InstanceKlass::end_of_nonstatic_oop_maps() const {
 54   return (Klass**)(start_of_nonstatic_oop_maps() +
 55                    nonstatic_oop_map_count());
 56 }
 57 
 58 inline InstanceKlass* volatile* InstanceKlass::adr_implementor() const {
 59   if (is_interface()) {
 60     return (InstanceKlass* volatile*)end_of_nonstatic_oop_maps();
 61   } else {
 62     return nullptr;
 63   }
 64 }
 65 




















 66 inline ObjArrayKlass* InstanceKlass::array_klasses_acquire() const {
 67   return AtomicAccess::load_acquire(&_array_klasses);
 68 }
 69 
 70 inline void InstanceKlass::release_set_array_klasses(ObjArrayKlass* k) {
 71   AtomicAccess::release_store(&_array_klasses, k);
 72 }
 73 
 74 // The iteration over the oops in objects is a hot path in the GC code.
 75 // By force inlining the following functions, we get similar GC performance
 76 // as the previous macro based implementation.
 77 
 78 template <typename T, class OopClosureType>
 79 ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure) {
 80   T* p         = obj->field_addr<T>(map->offset());
 81   T* const end = p + map->count();
 82 
 83   for (; p < end; ++p) {
 84     Devirtualizer::do_oop(closure, p);
 85   }

161 
162 template <typename T, class OopClosureType>
163 ALWAYSINLINE void InstanceKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) {
164   assert(!Devirtualizer::do_metadata(closure),
165       "Code to handle metadata is not implemented");
166 
167   oop_oop_iterate_oop_maps_reverse<T>(obj, closure);
168 }
169 
170 template <typename T, class OopClosureType>
171 ALWAYSINLINE void InstanceKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) {
172   if (Devirtualizer::do_metadata(closure)) {
173     if (mr.contains(obj)) {
174       Devirtualizer::do_klass(closure, this);
175     }
176   }
177 
178   oop_oop_iterate_oop_maps_bounded<T>(obj, closure, mr);
179 }
180 













181 #endif // SHARE_OOPS_INSTANCEKLASS_INLINE_HPP

  1 /*
  2  * Copyright (c) 2015, 2026, Oracle and/or its affiliates. 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  *

 46 inline int InstanceKlass::java_fields_count() const { return FieldInfoStream::num_java_fields(fieldinfo_stream()); }
 47 inline int InstanceKlass::total_fields_count() const { return FieldInfoStream::num_total_fields(fieldinfo_stream()); }
 48 
 49 inline OopMapBlock* InstanceKlass::start_of_nonstatic_oop_maps() const {
 50   return (OopMapBlock*)(start_of_itable() + itable_length());
 51 }
 52 
 53 inline Klass** InstanceKlass::end_of_nonstatic_oop_maps() const {
 54   return (Klass**)(start_of_nonstatic_oop_maps() +
 55                    nonstatic_oop_map_count());
 56 }
 57 
 58 inline InstanceKlass* volatile* InstanceKlass::adr_implementor() const {
 59   if (is_interface()) {
 60     return (InstanceKlass* volatile*)end_of_nonstatic_oop_maps();
 61   } else {
 62     return nullptr;
 63   }
 64 }
 65 
 66 inline address InstanceKlass::end_of_instance_klass() const {
 67   return (address)end_of_nonstatic_oop_maps() +
 68       (is_interface() ? sizeof(InstanceKlass*) : 0);
 69 }
 70 
 71 inline InlineKlass* InstanceKlass::get_inline_type_field_klass(int idx) const {
 72   assert(has_inlined_fields(), "Sanity checking");
 73   assert(idx < java_fields_count(), "IOOB");
 74   InlineKlass* k = inline_layout_info(idx).klass();
 75   assert(k != nullptr, "Should always be set before being read");
 76   return k;
 77 }
 78 
 79 inline InlineKlass* InstanceKlass::get_inline_type_field_klass_or_null(int idx) const {
 80   assert(has_inlined_fields(), "Sanity checking");
 81   assert(idx < java_fields_count(), "IOOB");
 82   InlineKlass* k = inline_layout_info(idx).klass();
 83   return k;
 84 }
 85 
 86 inline ObjArrayKlass* InstanceKlass::array_klasses_acquire() const {
 87   return AtomicAccess::load_acquire(&_array_klasses);
 88 }
 89 
 90 inline void InstanceKlass::release_set_array_klasses(ObjArrayKlass* k) {
 91   AtomicAccess::release_store(&_array_klasses, k);
 92 }
 93 
 94 // The iteration over the oops in objects is a hot path in the GC code.
 95 // By force inlining the following functions, we get similar GC performance
 96 // as the previous macro based implementation.
 97 
 98 template <typename T, class OopClosureType>
 99 ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure) {
100   T* p         = obj->field_addr<T>(map->offset());
101   T* const end = p + map->count();
102 
103   for (; p < end; ++p) {
104     Devirtualizer::do_oop(closure, p);
105   }

181 
182 template <typename T, class OopClosureType>
183 ALWAYSINLINE void InstanceKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) {
184   assert(!Devirtualizer::do_metadata(closure),
185       "Code to handle metadata is not implemented");
186 
187   oop_oop_iterate_oop_maps_reverse<T>(obj, closure);
188 }
189 
190 template <typename T, class OopClosureType>
191 ALWAYSINLINE void InstanceKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) {
192   if (Devirtualizer::do_metadata(closure)) {
193     if (mr.contains(obj)) {
194       Devirtualizer::do_klass(closure, this);
195     }
196   }
197 
198   oop_oop_iterate_oop_maps_bounded<T>(obj, closure, mr);
199 }
200 
201 template<typename T, typename TConsumerType>
202 inline void InstanceKlass::print_array_on(outputStream* st, Array<T>* array, TConsumerType elem_printer) {
203    if (array == nullptr) { st->print_cr("nullptr"); return; }
204    array->print_value_on(st); st->cr();
205    if (Verbose || WizardMode) {
206      for (int i = 0; i < array->length(); i++) {
207        st->print("%d : ", i);
208        elem_printer(st, array->at(i));
209        st->cr();
210      }
211    }
212 }
213 
214 #endif // SHARE_OOPS_INSTANCEKLASS_INLINE_HPP
< prev index next >