1 /*
2 * Copyright (c) 2010, 2022, 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
25 #ifndef SHARE_OOPS_OBJARRAYKLASS_INLINE_HPP
26 #define SHARE_OOPS_OBJARRAYKLASS_INLINE_HPP
27
28 #include "oops/objArrayKlass.hpp"
29
30 #include "memory/memRegion.hpp"
31 #include "oops/arrayKlass.hpp"
32 #include "oops/arrayOop.hpp"
33 #include "oops/klass.hpp"
34 #include "oops/objArrayOop.inline.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "utilities/devirtualizer.inline.hpp"
37 #include "utilities/macros.hpp"
38
39 template <typename T, class OopClosureType>
40 void ObjArrayKlass::oop_oop_iterate_elements(objArrayOop a, OopClosureType* closure) {
41 T* p = (T*)a->base();
42 T* const end = p + a->length();
43
44 for (;p < end; p++) {
45 Devirtualizer::do_oop(closure, p);
46 }
47 }
48
49 template <typename T, class OopClosureType>
50 void ObjArrayKlass::oop_oop_iterate_elements_bounded(
51 objArrayOop a, OopClosureType* closure, void* low, void* high) {
52
53 T* const l = (T*)low;
54 T* const h = (T*)high;
55
56 T* p = (T*)a->base();
57 T* end = p + a->length();
58
59 if (p < l) {
60 p = l;
61 }
62 if (end > h) {
63 end = h;
64 }
65
66 for (;p < end; ++p) {
67 Devirtualizer::do_oop(closure, p);
68 }
69 }
70
71 template <typename T, typename OopClosureType>
72 void ObjArrayKlass::oop_oop_iterate(oop obj, OopClosureType* closure) {
73 // In this assert, we cannot safely access the Klass* with compact headers.
74 assert (UseCompactObjectHeaders || obj->is_array(), "obj must be array");
75 objArrayOop a = objArrayOop(obj);
76
77 if (Devirtualizer::do_metadata(closure)) {
78 Devirtualizer::do_klass(closure, obj->klass());
79 }
80
81 oop_oop_iterate_elements<T>(a, closure);
82 }
83
84 template <typename T, typename OopClosureType>
85 void ObjArrayKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) {
86 // No reverse implementation ATM.
87 oop_oop_iterate<T>(obj, closure);
88 }
89
90 template <typename T, typename OopClosureType>
91 void ObjArrayKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) {
92 assert(obj->is_array(), "obj must be array");
93 objArrayOop a = objArrayOop(obj);
94
95 if (Devirtualizer::do_metadata(closure)) {
96 Devirtualizer::do_klass(closure, a->klass());
97 }
98
99 oop_oop_iterate_elements_bounded<T>(a, closure, mr.start(), mr.end());
100 }
101
102 // Like oop_oop_iterate but only iterates over a specified range and only used
103 // for objArrayOops.
104 template <typename T, class OopClosureType>
105 void ObjArrayKlass::oop_oop_iterate_range(objArrayOop a, OopClosureType* closure, int start, int end) {
106 T* low = (T*)a->base() + start;
107 T* high = (T*)a->base() + end;
108
109 oop_oop_iterate_elements_bounded<T>(a, closure, low, high);
110 }
111
112 // Placed here to resolve include cycle between objArrayKlass.inline.hpp and objArrayOop.inline.hpp
113 template <typename OopClosureType>
114 void objArrayOopDesc::oop_iterate_range(OopClosureType* blk, int start, int end) {
115 if (UseCompressedOops) {
116 ((ObjArrayKlass*)klass())->oop_oop_iterate_range<narrowOop>(this, blk, start, end);
117 } else {
118 ((ObjArrayKlass*)klass())->oop_oop_iterate_range<oop>(this, blk, start, end);
119 }
120 }
121
122 #endif // SHARE_OOPS_OBJARRAYKLASS_INLINE_HPP