|
1 /* |
|
2 * Copyright (c) 1997, 2017, 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_VM_OOPS_OBJARRAYKLASS_HPP |
|
26 #define SHARE_VM_OOPS_OBJARRAYKLASS_HPP |
|
27 |
|
28 #include "classfile/classLoaderData.hpp" |
|
29 #include "oops/arrayKlass.hpp" |
|
30 #include "utilities/macros.hpp" |
|
31 |
|
32 // ObjArrayKlass is the klass for objArrays |
|
33 |
|
34 class ObjArrayKlass : public ArrayKlass { |
|
35 friend class VMStructs; |
|
36 friend class JVMCIVMStructs; |
|
37 private: |
|
38 // If you add a new field that points to any metaspace object, you |
|
39 // must add this field to ObjArrayKlass::metaspace_pointers_do(). |
|
40 Klass* _element_klass; // The klass of the elements of this array type |
|
41 Klass* _bottom_klass; // The one-dimensional type (InstanceKlass or TypeArrayKlass) |
|
42 |
|
43 // Constructor |
|
44 ObjArrayKlass(int n, Klass* element_klass, Symbol* name); |
|
45 static ObjArrayKlass* allocate(ClassLoaderData* loader_data, int n, Klass* k, Symbol* name, TRAPS); |
|
46 public: |
|
47 // For dummy objects |
|
48 ObjArrayKlass() {} |
|
49 |
|
50 // Instance variables |
|
51 Klass* element_klass() const { return _element_klass; } |
|
52 void set_element_klass(Klass* k) { _element_klass = k; } |
|
53 Klass** element_klass_addr() { return &_element_klass; } |
|
54 |
|
55 Klass* bottom_klass() const { return _bottom_klass; } |
|
56 void set_bottom_klass(Klass* k) { _bottom_klass = k; } |
|
57 Klass** bottom_klass_addr() { return &_bottom_klass; } |
|
58 |
|
59 ModuleEntry* module() const; |
|
60 PackageEntry* package() const; |
|
61 |
|
62 // Compiler/Interpreter offset |
|
63 static ByteSize element_klass_offset() { return in_ByteSize(offset_of(ObjArrayKlass, _element_klass)); } |
|
64 |
|
65 // Dispatched operation |
|
66 bool can_be_primary_super_slow() const; |
|
67 GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots); |
|
68 bool compute_is_subtype_of(Klass* k); |
|
69 DEBUG_ONLY(bool is_objArray_klass_slow() const { return true; }) |
|
70 int oop_size(oop obj) const; |
|
71 |
|
72 // Allocation |
|
73 static Klass* allocate_objArray_klass(ClassLoaderData* loader_data, |
|
74 int n, Klass* element_klass, TRAPS); |
|
75 |
|
76 objArrayOop allocate(int length, TRAPS); |
|
77 oop multi_allocate(int rank, jint* sizes, TRAPS); |
|
78 |
|
79 // Copying |
|
80 void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS); |
|
81 |
|
82 // Compute protection domain |
|
83 oop protection_domain() const { return bottom_klass()->protection_domain(); } |
|
84 |
|
85 virtual void metaspace_pointers_do(MetaspaceClosure* iter); |
|
86 |
|
87 private: |
|
88 // Either oop or narrowOop depending on UseCompressedOops. |
|
89 // must be called from within ObjArrayKlass.cpp |
|
90 template <class T> void do_copy(arrayOop s, T* src, arrayOop d, |
|
91 T* dst, int length, TRAPS); |
|
92 protected: |
|
93 // Returns the ObjArrayKlass for n'th dimension. |
|
94 virtual Klass* array_klass_impl(bool or_null, int n, TRAPS); |
|
95 |
|
96 // Returns the array class with this class as element type. |
|
97 virtual Klass* array_klass_impl(bool or_null, TRAPS); |
|
98 |
|
99 public: |
|
100 |
|
101 static ObjArrayKlass* cast(Klass* k) { |
|
102 return const_cast<ObjArrayKlass*>(cast(const_cast<const Klass*>(k))); |
|
103 } |
|
104 |
|
105 static const ObjArrayKlass* cast(const Klass* k) { |
|
106 assert(k->is_objArray_klass(), "cast to ObjArrayKlass"); |
|
107 return static_cast<const ObjArrayKlass*>(k); |
|
108 } |
|
109 |
|
110 // Sizing |
|
111 static int header_size() { return sizeof(ObjArrayKlass)/wordSize; } |
|
112 int size() const { return ArrayKlass::static_size(header_size()); } |
|
113 |
|
114 // Initialization (virtual from Klass) |
|
115 void initialize(TRAPS); |
|
116 |
|
117 // GC specific object visitors |
|
118 // |
|
119 #if INCLUDE_ALL_GCS |
|
120 // Parallel Scavenge |
|
121 void oop_ps_push_contents( oop obj, PSPromotionManager* pm); |
|
122 // Parallel Compact |
|
123 void oop_pc_follow_contents(oop obj, ParCompactionManager* cm); |
|
124 void oop_pc_update_pointers(oop obj, ParCompactionManager* cm); |
|
125 #endif |
|
126 |
|
127 // Oop fields (and metadata) iterators |
|
128 // [nv = true] Use non-virtual calls to do_oop_nv. |
|
129 // [nv = false] Use virtual calls to do_oop. |
|
130 // |
|
131 // The ObjArrayKlass iterators also visits the Object's klass. |
|
132 |
|
133 private: |
|
134 |
|
135 // Iterate over oop elements and metadata. |
|
136 template <bool nv, typename OopClosureType> |
|
137 inline void oop_oop_iterate(oop obj, OopClosureType* closure); |
|
138 |
|
139 // Iterate over oop elements within mr, and metadata. |
|
140 template <bool nv, typename OopClosureType> |
|
141 inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr); |
|
142 |
|
143 // Iterate over oop elements with indices within [start, end), and metadata. |
|
144 template <bool nv, class OopClosureType> |
|
145 inline void oop_oop_iterate_range(oop obj, OopClosureType* closure, int start, int end); |
|
146 |
|
147 // Iterate over oop elements within [start, end), and metadata. |
|
148 // Specialized for [T = oop] or [T = narrowOop]. |
|
149 template <bool nv, typename T, class OopClosureType> |
|
150 inline void oop_oop_iterate_range_specialized(objArrayOop a, OopClosureType* closure, int start, int end); |
|
151 |
|
152 public: |
|
153 // Iterate over all oop elements. |
|
154 template <bool nv, class OopClosureType> |
|
155 inline void oop_oop_iterate_elements(objArrayOop a, OopClosureType* closure); |
|
156 |
|
157 private: |
|
158 // Iterate over all oop elements. |
|
159 // Specialized for [T = oop] or [T = narrowOop]. |
|
160 template <bool nv, typename T, class OopClosureType> |
|
161 inline void oop_oop_iterate_elements_specialized(objArrayOop a, OopClosureType* closure); |
|
162 |
|
163 // Iterate over all oop elements with indices within mr. |
|
164 template <bool nv, class OopClosureType> |
|
165 inline void oop_oop_iterate_elements_bounded(objArrayOop a, OopClosureType* closure, MemRegion mr); |
|
166 |
|
167 // Iterate over oop elements within [low, high).. |
|
168 // Specialized for [T = oop] or [T = narrowOop]. |
|
169 template <bool nv, typename T, class OopClosureType> |
|
170 inline void oop_oop_iterate_elements_specialized_bounded(objArrayOop a, OopClosureType* closure, void* low, void* high); |
|
171 |
|
172 |
|
173 public: |
|
174 |
|
175 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_OOP_ITERATE_DECL) |
|
176 ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_OOP_ITERATE_DECL) |
|
177 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_OOP_ITERATE_DECL_RANGE) |
|
178 ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_OOP_ITERATE_DECL_RANGE) |
|
179 |
|
180 #if INCLUDE_ALL_GCS |
|
181 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_OOP_ITERATE_DECL_NO_BACKWARDS) |
|
182 ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_OOP_ITERATE_DECL_NO_BACKWARDS) |
|
183 #endif // INCLUDE_ALL_GCS |
|
184 |
|
185 // JVM support |
|
186 jint compute_modifier_flags(TRAPS) const; |
|
187 |
|
188 public: |
|
189 // Printing |
|
190 void print_on(outputStream* st) const; |
|
191 void print_value_on(outputStream* st) const; |
|
192 |
|
193 void oop_print_value_on(oop obj, outputStream* st); |
|
194 #ifndef PRODUCT |
|
195 void oop_print_on (oop obj, outputStream* st); |
|
196 #endif //PRODUCT |
|
197 |
|
198 const char* internal_name() const; |
|
199 |
|
200 // Verification |
|
201 void verify_on(outputStream* st); |
|
202 |
|
203 void oop_verify_on(oop obj, outputStream* st); |
|
204 }; |
|
205 |
|
206 #endif // SHARE_VM_OOPS_OBJARRAYKLASS_HPP |