1 /* 2 * Copyright (c) 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_OOPS_REFARRAYKLASS_HPP 26 #define SHARE_OOPS_REFARRAYKLASS_HPP 27 28 #include "oops/arrayKlass.hpp" 29 #include "oops/objArrayKlass.hpp" 30 #include "utilities/macros.hpp" 31 32 class ClassLoaderData; 33 34 // RefArrayKlass is the klass for arrays of references 35 36 class RefArrayKlass : public ObjArrayKlass { 37 friend class Deoptimization; 38 friend class oopFactory; 39 friend class VMStructs; 40 friend class JVMCIVMStructs; 41 42 public: 43 static const KlassKind Kind = RefArrayKlassKind; 44 45 private: 46 // Constructor 47 RefArrayKlass(int n, Klass* element_klass, Symbol* name, ArrayKlass::ArrayProperties props); 48 static RefArrayKlass* allocate_klass(ClassLoaderData* loader_data, int n, Klass* k, Symbol* name, 49 ArrayKlass::ArrayProperties props, TRAPS); 50 51 public: 52 // For dummy objects 53 RefArrayKlass() {} 54 55 // Dispatched operation 56 DEBUG_ONLY(bool is_refArray_klass_slow() const { return true; }) 57 size_t oop_size(oop obj) const; // TODO FIXME make it virtual in objArrayKlass 58 59 // Allocation 60 static RefArrayKlass* allocate_refArray_klass(ClassLoaderData* loader_data, 61 int n, Klass* element_klass, 62 ArrayKlass::ArrayProperties props, TRAPS); 63 64 private: 65 objArrayOop allocate_instance(int length, ArrayProperties props, TRAPS); 66 67 public: 68 // Copying TODO FIXME make copying method in objArrayKlass virtual and default implementation invalid (ShouldNotReachHere()) 69 void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS); 70 71 virtual void metaspace_pointers_do(MetaspaceClosure* iter); 72 73 private: 74 // Either oop or narrowOop depending on UseCompressedOops. 75 // must be called from within ObjArrayKlass.cpp 76 void do_copy(arrayOop s, size_t src_offset, 77 arrayOop d, size_t dst_offset, 78 int length, TRAPS); 79 80 public: 81 static RefArrayKlass *cast(Klass* k) { 82 assert(k->is_refArray_klass(), "cast to RefArrayKlass"); 83 return const_cast<RefArrayKlass *>(cast(const_cast<const Klass *>(k))); 84 } 85 86 static const RefArrayKlass *cast(const Klass* k) { 87 assert(k->is_refArray_klass(), "cast to RefArrayKlass"); 88 return static_cast<const RefArrayKlass *>(k); 89 } 90 91 // Sizing 92 static int header_size() { return sizeof(RefArrayKlass) / wordSize; } 93 int size() const { return ArrayKlass::static_size(header_size()); } 94 95 // Initialization (virtual from Klass) 96 void initialize(TRAPS); 97 98 // Oop fields (and metadata) iterators 99 // 100 // The RefArrayKlass iterators also visits the Object's klass. 101 102 // Iterate over oop elements and metadata. 103 template <typename T, typename OopClosureType> 104 inline void oop_oop_iterate(oop obj, OopClosureType* closure); 105 106 // Iterate over oop elements and metadata. 107 template <typename T, typename OopClosureType> 108 inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure); 109 110 // Iterate over oop elements within mr, and metadata. 111 template <typename T, typename OopClosureType> 112 inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr); 113 114 // Iterate over oop elements within [start, end), and metadata. 115 template <typename T, class OopClosureType> 116 inline void oop_oop_iterate_range(refArrayOop a, OopClosureType* closure, int start, int end); 117 118 public: 119 // Iterate over all oop elements. 120 template <typename T, class OopClosureType> 121 inline void oop_oop_iterate_elements(refArrayOop a, OopClosureType* closure); 122 123 private: 124 // Iterate over all oop elements with indices within mr. 125 template <typename T, class OopClosureType> 126 inline void oop_oop_iterate_elements_bounded(refArrayOop a, OopClosureType* closure, void* low, void* high); 127 128 public: 129 // Printing 130 void print_on(outputStream* st) const; 131 void print_value_on(outputStream* st) const; 132 133 void oop_print_value_on(oop obj, outputStream* st); 134 #ifndef PRODUCT 135 void oop_print_on(oop obj, outputStream* st); 136 #endif // PRODUCT 137 138 // Verification 139 void verify_on(outputStream* st); 140 141 void oop_verify_on(oop obj, outputStream* st); 142 }; 143 144 #endif // SHARE_OOPS_REFARRAYKLASS_HPP