1 /*
2 * Copyright (c) 1997, 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_TYPEARRAYKLASS_HPP
26 #define SHARE_OOPS_TYPEARRAYKLASS_HPP
27
28 #include "oops/arrayKlass.hpp"
29
30 class ClassLoaderData;
31
32 // A TypeArrayKlass is the klass of a typeArray
33 // It contains the type and size of the elements
34
35 class TypeArrayKlass : public ArrayKlass {
36 friend class Deoptimization;
37 friend class oopFactory;
38 friend class VMStructs;
39
40 public:
41 static const KlassKind Kind = TypeArrayKlassKind;
42
43 private:
44 jint _max_length; // maximum number of elements allowed in an array
45
46 // Constructor
47 TypeArrayKlass(BasicType type, Symbol* name);
48 static TypeArrayKlass* allocate_klass(ClassLoaderData* loader_data, BasicType type, Symbol* name, TRAPS);
49
50 typeArrayOop allocate_common(int length, bool do_zero, TRAPS);
51 typeArrayOop allocate_instance(int length, TRAPS) { return allocate_common(length, true, THREAD); }
52 public:
53 TypeArrayKlass() {} // For dummy objects.
54
55 // instance variables
56 jint max_length() { return _max_length; }
57 void set_max_length(jint m) { _max_length = m; }
58
59 u2 compute_modifier_flags() const;
60
61 // testers
62 DEBUG_ONLY(bool is_typeArray_klass_slow() const { return true; })
63
64 // klass allocation
65 static TypeArrayKlass* create_klass(BasicType type, const char* name_str,
66 TRAPS);
67 static TypeArrayKlass* create_klass(BasicType type, TRAPS) {
68 return create_klass(type, external_name(type), THREAD);
69 }
70
71 size_t oop_size(oop obj, markWord mark) const;
72
73 // Allocation
74 oop multi_allocate(int rank, jint* sizes, TRAPS);
75
76 oop protection_domain() const { return nullptr; }
77
78 // Copying
79 void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
80
81 // Oop iterators. Since there are no oops in TypeArrayKlasses,
82 // these functions only return the size of the object.
83
84 private:
85 // The implementation used by all oop_oop_iterate functions in TypeArrayKlasses.
86 inline void oop_oop_iterate_impl(oop obj, OopIterateClosure* closure);
87
88 public:
89 // Wraps oop_oop_iterate_impl to conform to macros.
90 template <typename T, typename OopClosureType>
91 inline void oop_oop_iterate(oop obj, OopClosureType* closure);
92
93 // Wraps oop_oop_iterate_impl to conform to macros.
94 template <typename T, typename OopClosureType>
95 inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);
96
97 // Wraps oop_oop_iterate_impl to conform to macros.
98 template <typename T, typename OopClosureType>
99 inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure);
100
101 public:
102 static TypeArrayKlass* cast(Klass* k) {
103 return const_cast<TypeArrayKlass*>(cast(const_cast<const Klass*>(k)));
104 }
105
106 static const TypeArrayKlass* cast(const Klass* k) {
107 assert(k->is_typeArray_klass(), "cast to TypeArrayKlass");
108 return static_cast<const TypeArrayKlass*>(k);
109 }
110
111 // Naming
112 static const char* external_name(BasicType type);
113
114 // Sizing
115 static int header_size() { return sizeof(TypeArrayKlass)/wordSize; }
116 int size() const { return ArrayKlass::static_size(header_size()); }
117
118 // Initialization (virtual from Klass)
119 void initialize(TRAPS);
120
121 public:
122 // Printing
123 void oop_print_on(oop obj, outputStream* st);
124 void oop_print_elements_on(typeArrayOop ta, outputStream* st);
125 void print_on(outputStream* st) const;
126 void print_value_on(outputStream* st) const;
127
128 public:
129 const char* internal_name() const;
130
131 ModuleEntry* module() const;
132 PackageEntry* package() const;
133 };
134
135 #endif // SHARE_OOPS_TYPEARRAYKLASS_HPP