1 /* 2 * Copyright (c) 2017, 2020, 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_FLATARRAYKLASS_HPP 26 #define SHARE_VM_OOPS_FLATARRAYKLASS_HPP 27 28 #include "classfile/classLoaderData.hpp" 29 #include "oops/arrayKlass.hpp" 30 #include "oops/inlineKlass.hpp" 31 #include "utilities/macros.hpp" 32 33 /** 34 * Array of inline types, gives a layout of typeArrayOop, but needs oops iterators 35 */ 36 class FlatArrayKlass : public ArrayKlass { 37 friend class VMStructs; 38 39 public: 40 static const KlassKind Kind = FlatArrayKlassKind; 41 42 private: 43 // Constructor 44 FlatArrayKlass(Klass* element_klass, Symbol* name); 45 46 public: 47 48 FlatArrayKlass() {} 49 50 // Returns the ObjArrayKlass for n'th dimension. 51 virtual Klass* array_klass(int n, TRAPS); 52 virtual Klass* array_klass_or_null(int n); 53 54 // Returns the array class with this class as element type. 55 virtual Klass* array_klass(TRAPS); 56 virtual Klass* array_klass_or_null(); 57 58 virtual InlineKlass* element_klass() const; 59 virtual void set_element_klass(Klass* k); 60 61 // Casting from Klass* 62 static FlatArrayKlass* cast(Klass* k) { 63 assert(k->is_flatArray_klass(), "cast to FlatArrayKlass"); 64 return (FlatArrayKlass*) k; 65 } 66 67 // klass allocation 68 static FlatArrayKlass* allocate_klass(Klass* element_klass, TRAPS); 69 70 void initialize(TRAPS); 71 72 ModuleEntry* module() const; 73 PackageEntry* package() const; 74 75 bool can_be_primary_super_slow() const; 76 GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots, 77 Array<InstanceKlass*>* transitive_interfaces); 78 79 int element_byte_size() const { return 1 << layout_helper_log2_element_size(_layout_helper); } 80 81 bool is_flatArray_klass_slow() const { return true; } 82 83 bool contains_oops() { 84 return element_klass()->contains_oops(); 85 } 86 87 // Override. 88 bool element_access_is_atomic() { 89 return element_klass()->is_atomic(); 90 } 91 92 oop protection_domain() const; 93 94 virtual void metaspace_pointers_do(MetaspaceClosure* iter); 95 96 static jint array_layout_helper(InlineKlass* vklass); // layout helper for values 97 98 // sizing 99 static int header_size() { return sizeof(FlatArrayKlass)/HeapWordSize; } 100 int size() const { return ArrayKlass::static_size(header_size()); } 101 102 jint max_elements() const; 103 104 size_t oop_size(oop obj) const; 105 106 // Oop Allocation 107 flatArrayOop allocate(int length, TRAPS); 108 oop multi_allocate(int rank, jint* sizes, TRAPS); 109 110 // Naming 111 const char* internal_name() const { return external_name(); } 112 113 // Copying 114 void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS); 115 116 // GC specific object visitors 117 // 118 // Mark Sweep 119 int oop_ms_adjust_pointers(oop obj); 120 121 122 template <typename T, typename OopClosureType> 123 inline void oop_oop_iterate(oop obj, OopClosureType* closure); 124 125 template <typename T, typename OopClosureType> 126 inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure); 127 128 template <typename T, typename OopClosureType> 129 inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr); 130 131 template <typename T, class OopClosureType> 132 inline void oop_oop_iterate_elements(flatArrayOop a, OopClosureType* closure); 133 134 private: 135 template <typename T, class OopClosureType> 136 inline void oop_oop_iterate_elements_specialized(flatArrayOop a, OopClosureType* closure); 137 138 template <typename T, class OopClosureType> 139 inline void oop_oop_iterate_elements_bounded(flatArrayOop a, OopClosureType* closure, MemRegion mr); 140 141 template <typename T, class OopClosureType> 142 inline void oop_oop_iterate_elements_specialized_bounded(flatArrayOop a, OopClosureType* closure, void* low, void* high); 143 144 public: 145 jint compute_modifier_flags() const; 146 147 // Printing 148 void print_on(outputStream* st) const; 149 void print_value_on(outputStream* st) const; 150 151 void oop_print_value_on(oop obj, outputStream* st); 152 #ifndef PRODUCT 153 void oop_print_on(oop obj, outputStream* st); 154 #endif 155 156 // Verification 157 void verify_on(outputStream* st); 158 void oop_verify_on(oop obj, outputStream* st); 159 }; 160 161 #endif