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