|
1 /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 * |
|
4 * This code is free software; you can redistribute it and/or modify it |
|
5 * under the terms of the GNU General Public License version 2 only, as |
|
6 * published by the Free Software Foundation. |
|
7 * |
|
8 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
11 * version 2 for more details (a copy is included in the LICENSE file that |
|
12 * accompanied this code). |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License version |
|
15 * 2 along with this work; if not, write to the Free Software Foundation, |
|
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17 * |
|
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
19 * or visit www.oracle.com if you need additional information or have any |
|
20 * questions. |
|
21 * |
|
22 */ |
|
23 |
|
24 #ifndef SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP |
|
25 #define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP |
|
26 |
|
27 #include "classfile/javaClasses.hpp" |
|
28 #include "oops/instanceKlass.inline.hpp" |
|
29 #include "oops/instanceMirrorKlass.hpp" |
|
30 #include "oops/oop.inline.hpp" |
|
31 #include "utilities/debug.hpp" |
|
32 #include "utilities/globalDefinitions.hpp" |
|
33 #include "utilities/macros.hpp" |
|
34 |
|
35 template <bool nv, typename T, class OopClosureType> |
|
36 void InstanceMirrorKlass::oop_oop_iterate_statics_specialized(oop obj, OopClosureType* closure) { |
|
37 T* p = (T*)start_of_static_fields(obj); |
|
38 T* const end = p + java_lang_Class::static_oop_field_count(obj); |
|
39 |
|
40 for (; p < end; ++p) { |
|
41 Devirtualizer<nv>::do_oop(closure, p); |
|
42 } |
|
43 } |
|
44 |
|
45 template <bool nv, class OopClosureType> |
|
46 void InstanceMirrorKlass::oop_oop_iterate_statics(oop obj, OopClosureType* closure) { |
|
47 if (UseCompressedOops) { |
|
48 oop_oop_iterate_statics_specialized<nv, narrowOop>(obj, closure); |
|
49 } else { |
|
50 oop_oop_iterate_statics_specialized<nv, oop>(obj, closure); |
|
51 } |
|
52 } |
|
53 |
|
54 template <bool nv, class OopClosureType> |
|
55 int InstanceMirrorKlass::oop_oop_iterate(oop obj, OopClosureType* closure) { |
|
56 InstanceKlass::oop_oop_iterate<nv>(obj, closure); |
|
57 |
|
58 if (Devirtualizer<nv>::do_metadata(closure)) { |
|
59 Klass* klass = java_lang_Class::as_Klass(obj); |
|
60 // We'll get NULL for primitive mirrors. |
|
61 if (klass != NULL) { |
|
62 Devirtualizer<nv>::do_klass(closure, klass); |
|
63 } |
|
64 } |
|
65 |
|
66 oop_oop_iterate_statics<nv>(obj, closure); |
|
67 |
|
68 return oop_size(obj); |
|
69 } |
|
70 |
|
71 #if INCLUDE_ALL_GCS |
|
72 template <bool nv, class OopClosureType> |
|
73 int InstanceMirrorKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) { |
|
74 InstanceKlass::oop_oop_iterate_reverse<nv>(obj, closure); |
|
75 |
|
76 InstanceMirrorKlass::oop_oop_iterate_statics<nv>(obj, closure); |
|
77 |
|
78 return oop_size(obj); |
|
79 } |
|
80 #endif |
|
81 |
|
82 template <bool nv, typename T, class OopClosureType> |
|
83 void InstanceMirrorKlass::oop_oop_iterate_statics_specialized_bounded(oop obj, |
|
84 OopClosureType* closure, |
|
85 MemRegion mr) { |
|
86 T* p = (T*)start_of_static_fields(obj); |
|
87 T* end = p + java_lang_Class::static_oop_field_count(obj); |
|
88 |
|
89 T* const l = (T*)mr.start(); |
|
90 T* const h = (T*)mr.end(); |
|
91 assert(mask_bits((intptr_t)l, sizeof(T)-1) == 0 && |
|
92 mask_bits((intptr_t)h, sizeof(T)-1) == 0, |
|
93 "bounded region must be properly aligned"); |
|
94 |
|
95 if (p < l) { |
|
96 p = l; |
|
97 } |
|
98 if (end > h) { |
|
99 end = h; |
|
100 } |
|
101 |
|
102 for (;p < end; ++p) { |
|
103 Devirtualizer<nv>::do_oop(closure, p); |
|
104 } |
|
105 } |
|
106 |
|
107 template <bool nv, class OopClosureType> |
|
108 void InstanceMirrorKlass::oop_oop_iterate_statics_bounded(oop obj, OopClosureType* closure, MemRegion mr) { |
|
109 if (UseCompressedOops) { |
|
110 oop_oop_iterate_statics_specialized_bounded<nv, narrowOop>(obj, closure, mr); |
|
111 } else { |
|
112 oop_oop_iterate_statics_specialized_bounded<nv, oop>(obj, closure, mr); |
|
113 } |
|
114 } |
|
115 |
|
116 template <bool nv, class OopClosureType> |
|
117 int InstanceMirrorKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) { |
|
118 InstanceKlass::oop_oop_iterate_bounded<nv>(obj, closure, mr); |
|
119 |
|
120 if (Devirtualizer<nv>::do_metadata(closure)) { |
|
121 if (mr.contains(obj)) { |
|
122 Klass* klass = java_lang_Class::as_Klass(obj); |
|
123 // We'll get NULL for primitive mirrors. |
|
124 if (klass != NULL) { |
|
125 Devirtualizer<nv>::do_klass(closure, klass); |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 oop_oop_iterate_statics_bounded<nv>(obj, closure, mr); |
|
131 |
|
132 return oop_size(obj); |
|
133 } |
|
134 |
|
135 |
|
136 #define InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ |
|
137 \ |
|
138 int InstanceMirrorKlass::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ |
|
139 return oop_oop_iterate<nvs_to_bool(nv_suffix)>(obj, closure); \ |
|
140 } |
|
141 |
|
142 #if INCLUDE_ALL_GCS |
|
143 #define InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \ |
|
144 \ |
|
145 int InstanceMirrorKlass::oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) { \ |
|
146 return oop_oop_iterate_reverse<nvs_to_bool(nv_suffix)>(obj, closure); \ |
|
147 } |
|
148 #else |
|
149 #define InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) |
|
150 #endif |
|
151 |
|
152 |
|
153 #define InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \ |
|
154 \ |
|
155 int InstanceMirrorKlass::oop_oop_iterate##nv_suffix##_m(oop obj, OopClosureType* closure, MemRegion mr) { \ |
|
156 return oop_oop_iterate_bounded<nvs_to_bool(nv_suffix)>(obj, closure, mr); \ |
|
157 } |
|
158 |
|
159 #define ALL_INSTANCE_MIRROR_KLASS_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ |
|
160 InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN( OopClosureType, nv_suffix) \ |
|
161 InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN_m( OopClosureType, nv_suffix) \ |
|
162 InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) |
|
163 |
|
164 #endif // SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP |