1 /*
 2  * Copyright (c) 2017, 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  *
23  */
24 #ifndef SHARE_VM_OOPS_INLINEKLASS_INLINE_HPP
25 #define SHARE_VM_OOPS_INLINEKLASS_INLINE_HPP
26 
27 #include "oops/inlineKlass.hpp"
28 
29 #include "memory/iterator.hpp"
30 #include "oops/flatArrayKlass.hpp"
31 #include "oops/instanceKlass.inline.hpp"
32 #include "oops/oop.inline.hpp"
33 #include "utilities/devirtualizer.inline.hpp"
34 #include "utilities/macros.hpp"
35 
36 inline InlineKlassFixedBlock* InlineKlass::inlineklass_static_block() const {
37 
38   InstanceKlass* volatile* adr_impl = adr_implementor();
39   if (adr_impl != nullptr) {
40     return (InlineKlassFixedBlock*)(adr_impl + 1);
41   }
42 
43   return (InlineKlassFixedBlock*)end_of_nonstatic_oop_maps();
44 }
45 
46 inline address InlineKlass::adr_return_regs() const {
47   InlineKlassFixedBlock* vkst = inlineklass_static_block();
48   return ((address)_adr_inlineklass_fixed_block) + in_bytes(byte_offset_of(InlineKlassFixedBlock, _return_regs));
49 }
50 
51 inline Array<VMRegPair>* InlineKlass::return_regs() const {
52   return *((Array<VMRegPair>**)adr_return_regs());
53 }
54 
55 inline address InlineKlass::payload_addr(oop o) const {
56   return ((address) (void*) o) + payload_offset();
57 }
58 
59 template <typename T, class OopClosureType>
60 void InlineKlass::oop_iterate_specialized(const address oop_addr, OopClosureType* closure) {
61   OopMapBlock* map = start_of_nonstatic_oop_maps();
62   OopMapBlock* const end_map = map + nonstatic_oop_map_count();
63 
64   for (; map < end_map; map++) {
65     T* p = (T*) (oop_addr + map->offset());
66     T* const end = p + map->count();
67     for (; p < end; ++p) {
68       Devirtualizer::do_oop(closure, p);
69     }
70   }
71 }
72 
73 template <typename T, class OopClosureType>
74 inline void InlineKlass::oop_iterate_specialized_bounded(const address oop_addr, OopClosureType* closure, void* lo, void* hi) {
75   OopMapBlock* map = start_of_nonstatic_oop_maps();
76   OopMapBlock* const end_map = map + nonstatic_oop_map_count();
77 
78   T* const l   = (T*) lo;
79   T* const h   = (T*) hi;
80 
81   for (; map < end_map; map++) {
82     T* p = (T*) (oop_addr + map->offset());
83     T* end = p + map->count();
84     if (p < l) {
85       p = l;
86     }
87     if (end > h) {
88       end = h;
89     }
90     for (; p < end; ++p) {
91       Devirtualizer::do_oop(closure, p);
92     }
93   }
94 }
95 
96 
97 #endif // SHARE_VM_OOPS_INLINEKLASS_INLINE_HPP