1 /*
  2  * Copyright (c) 2017, 2020, 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  *
 23  */
 24 #ifndef SHARE_VM_OOPS_INLINEKLASS_INLINE_HPP
 25 #define SHARE_VM_OOPS_INLINEKLASS_INLINE_HPP
 26 
 27 #include "memory/iterator.hpp"
 28 #include "oops/flatArrayKlass.hpp"
 29 #include "oops/inlineKlass.hpp"
 30 #include "oops/instanceKlass.inline.hpp"
 31 #include "oops/oop.inline.hpp"
 32 #include "utilities/devirtualizer.inline.hpp"
 33 #include "utilities/macros.hpp"
 34 
 35 inline InlineKlassFixedBlock* InlineKlass::inlineklass_static_block() const {
 36   address adr_jf = adr_inline_type_field_klasses();
 37   if (adr_jf != nullptr) {
 38     return (InlineKlassFixedBlock*)(adr_jf + this->java_fields_count() * sizeof(Klass*));
 39   }
 40 
 41   InstanceKlass* volatile* adr_impl = adr_implementor();
 42   if (adr_impl != nullptr) {
 43     return (InlineKlassFixedBlock*)(adr_impl + 1);
 44   }
 45 
 46   return (InlineKlassFixedBlock*)end_of_nonstatic_oop_maps();
 47 }
 48 
 49 inline address InlineKlass::adr_return_regs() const {
 50   InlineKlassFixedBlock* vkst = inlineklass_static_block();
 51   return ((address)_adr_inlineklass_fixed_block) + in_bytes(byte_offset_of(InlineKlassFixedBlock, _return_regs));
 52 }
 53 
 54 inline Array<VMRegPair>* InlineKlass::return_regs() const {
 55   return *((Array<VMRegPair>**)adr_return_regs());
 56 }
 57 
 58 
 59 inline InlineKlass* InlineKlass::cast(Klass* k) {
 60   assert(k->is_inline_klass(), "cast to InlineKlass");
 61   return (InlineKlass*) k;
 62 }
 63 
 64 inline address InlineKlass::data_for_oop(oop o) const {
 65   return ((address) (void*) o) + first_field_offset();
 66 }
 67 
 68 inline void InlineKlass::inline_copy_payload_to_new_oop(void* src, oop dst) {
 69   HeapAccess<IS_DEST_UNINITIALIZED>::value_copy(src, data_for_oop(dst), this);
 70 }
 71 
 72 inline void InlineKlass::inline_copy_oop_to_new_oop(oop src, oop dst) {
 73   HeapAccess<IS_DEST_UNINITIALIZED>::value_copy(data_for_oop(src), data_for_oop(dst), this);
 74 }
 75 
 76 inline void InlineKlass::inline_copy_oop_to_new_payload(oop src, void* dst) {
 77   HeapAccess<IS_DEST_UNINITIALIZED>::value_copy(data_for_oop(src), dst, this);
 78 }
 79 
 80 inline void InlineKlass::inline_copy_oop_to_payload(oop src, void* dst) {
 81   HeapAccess<>::value_copy(data_for_oop(src), dst, this);
 82 }
 83 
 84 
 85 template <typename T, class OopClosureType>
 86 void InlineKlass::oop_iterate_specialized(const address oop_addr, OopClosureType* closure) {
 87   OopMapBlock* map = start_of_nonstatic_oop_maps();
 88   OopMapBlock* const end_map = map + nonstatic_oop_map_count();
 89 
 90   for (; map < end_map; map++) {
 91     T* p = (T*) (oop_addr + map->offset());
 92     T* const end = p + map->count();
 93     for (; p < end; ++p) {
 94       Devirtualizer::do_oop(closure, p);
 95     }
 96   }
 97 }
 98 
 99 template <typename T, class OopClosureType>
100 inline void InlineKlass::oop_iterate_specialized_bounded(const address oop_addr, OopClosureType* closure, void* lo, void* hi) {
101   OopMapBlock* map = start_of_nonstatic_oop_maps();
102   OopMapBlock* const end_map = map + nonstatic_oop_map_count();
103 
104   T* const l   = (T*) lo;
105   T* const h   = (T*) hi;
106 
107   for (; map < end_map; map++) {
108     T* p = (T*) (oop_addr + map->offset());
109     T* end = p + map->count();
110     if (p < l) {
111       p = l;
112     }
113     if (end > h) {
114       end = h;
115     }
116     for (; p < end; ++p) {
117       Devirtualizer::do_oop(closure, p);
118     }
119   }
120 }
121 
122 
123 #endif // SHARE_VM_OOPS_INLINEKLASS_INLINE_HPP