1 /* 2 * Copyright (c) 2017, 2025, 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, LayoutKind lk); 45 46 LayoutKind _layout_kind; 47 48 public: 49 50 FlatArrayKlass() {} // used by CppVtableCloner<T>::initialize() 51 52 InlineKlass* element_klass() const { return InlineKlass::cast(_element_klass); } 53 void set_element_klass(Klass* k) { _element_klass = k; } 54 55 LayoutKind layout_kind() const { return _layout_kind; } 56 void set_layout_kind(LayoutKind lk) { _layout_kind = lk; } 57 static ByteSize layout_kind_offset() { return in_ByteSize(offset_of(FlatArrayKlass, _layout_kind)); } 58 59 // Casting from Klass* 60 static FlatArrayKlass* cast(Klass* k) { 61 assert(k->is_flatArray_klass(), "cast to FlatArrayKlass"); 62 return (FlatArrayKlass*) k; 63 } 64 65 // klass allocation 66 static FlatArrayKlass* allocate_klass(Klass* element_klass, LayoutKind lk, TRAPS); 67 68 void initialize(TRAPS); 69 70 ModuleEntry* module() const; 71 PackageEntry* package() const; 72 73 bool can_be_primary_super_slow() const; 74 GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots, 75 Array<InstanceKlass*>* transitive_interfaces); 76 77 int element_byte_size() const { return 1 << layout_helper_log2_element_size(_layout_helper); } 78 79 bool is_flatArray_klass_slow() const { return true; } 80 81 bool contains_oops() { 82 return element_klass()->contains_oops(); 83 } 84 85 // Override. 86 bool element_access_must_be_atomic() { 87 return element_klass()->must_be_atomic(); 88 } 89 90 oop protection_domain() const; 91 92 virtual void metaspace_pointers_do(MetaspaceClosure* iter); 93 94 static jint array_layout_helper(InlineKlass* vklass, LayoutKind lk); // layout helper for values 95 96 // sizing 97 static int header_size() { return sizeof(FlatArrayKlass)/HeapWordSize; } 98 int size() const { return ArrayKlass::static_size(header_size()); } 99 100 jint max_elements() const; 101 102 size_t oop_size(oop obj) const; 103 104 // Oop Allocation 105 flatArrayOop allocate(int length, LayoutKind lk, TRAPS); 106 oop multi_allocate(int rank, jint* sizes, TRAPS); 107 108 // Naming 109 const char* internal_name() const { return external_name(); } 110 111 // Copying 112 void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS); 113 114 // GC specific object visitors 115 // 116 // Mark Sweep 117 int oop_ms_adjust_pointers(oop obj); 118 119 120 template <typename T, typename OopClosureType> 121 inline void oop_oop_iterate(oop obj, OopClosureType* closure); 122 123 template <typename T, typename OopClosureType> 124 inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure); 125 126 template <typename T, typename OopClosureType> 127 inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr); 128 129 template <typename T, class OopClosureType> 130 inline void oop_oop_iterate_elements(flatArrayOop a, OopClosureType* closure); 131 132 private: 133 template <typename T, class OopClosureType> 134 inline void oop_oop_iterate_elements_specialized(flatArrayOop a, OopClosureType* closure); 135 136 template <typename T, class OopClosureType> 137 inline void oop_oop_iterate_elements_bounded(flatArrayOop a, OopClosureType* closure, MemRegion mr); 138 139 template <typename T, class OopClosureType> 140 inline void oop_oop_iterate_elements_specialized_bounded(flatArrayOop a, OopClosureType* closure, void* low, void* high); 141 142 public: 143 u2 compute_modifier_flags() const; 144 145 // Printing 146 void print_on(outputStream* st) const; 147 void print_value_on(outputStream* st) const; 148 149 void oop_print_value_on(oop obj, outputStream* st); 150 #ifndef PRODUCT 151 void oop_print_on(oop obj, outputStream* st); 152 #endif 153 154 // Verification 155 void verify_on(outputStream* st); 156 void oop_verify_on(oop obj, outputStream* st); 157 }; 158 159 #endif