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