1 /*
2  * Copyright (c) 1997, 2021, 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 VMStructs;
37 
38  public:
39   static const KlassID ID = TypeArrayKlassID;
40 
41  private:
42   jint _max_length;            // maximum number of elements allowed in an array
43 
44   // Constructor
45   TypeArrayKlass(BasicType type, Symbol* name);
46   static TypeArrayKlass* allocate(ClassLoaderData* loader_data, BasicType type, Symbol* name, TRAPS);
47  public:
TypeArrayKlass()48   TypeArrayKlass() {} // For dummy objects.
49 
50   // instance variables
max_length()51   jint max_length()                     { return _max_length; }
set_max_length(jint m)52   void set_max_length(jint m)           { _max_length = m;    }
53 
54   // testers
55   DEBUG_ONLY(bool is_typeArray_klass_slow() const  { return true; })
56 
57   // klass allocation
58   static TypeArrayKlass* create_klass(BasicType type, const char* name_str,
59                                TRAPS);
create_klass(BasicType type,TRAPS)60   static TypeArrayKlass* create_klass(BasicType type, TRAPS) {
61     return create_klass(type, external_name(type), THREAD);
62   }
63 
64   int oop_size(oop obj) const;
65 
66   // Allocation
67   typeArrayOop allocate_common(int length, bool do_zero, TRAPS);
allocate(int length,TRAPS)68   typeArrayOop allocate(int length, TRAPS) { return allocate_common(length, true, THREAD); }
69   oop multi_allocate(int rank, jint* sizes, TRAPS);
70 
protection_domain() const71   oop protection_domain() const { return NULL; }
72 
73   // Copying
74   void  copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
75 
76   // Oop iterators. Since there are no oops in TypeArrayKlasses,
77   // these functions only return the size of the object.
78 
79  private:
80   // The implementation used by all oop_oop_iterate functions in TypeArrayKlasses.
81   inline void oop_oop_iterate_impl(oop obj, OopIterateClosure* closure);
82 
83  public:
84   // Wraps oop_oop_iterate_impl to conform to macros.
85   template <typename T, typename OopClosureType>
86   inline void oop_oop_iterate(oop obj, OopClosureType* closure);
87 
88   // Wraps oop_oop_iterate_impl to conform to macros.
89   template <typename T, typename OopClosureType>
90   inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);
91 
92   // Wraps oop_oop_iterate_impl to conform to macros.
93   template <typename T, typename OopClosureType>
94   inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure);
95 
96  public:
97   // Find n'th dimensional array
98   virtual Klass* array_klass(int n, TRAPS);
99   virtual Klass* array_klass_or_null(int n);
100 
101   // Returns the array class with this class as element type
102   virtual Klass* array_klass(TRAPS);
103   virtual Klass* array_klass_or_null();
104 
cast(Klass * k)105   static TypeArrayKlass* cast(Klass* k) {
106     return const_cast<TypeArrayKlass*>(cast(const_cast<const Klass*>(k)));
107   }
108 
cast(const Klass * k)109   static const TypeArrayKlass* cast(const Klass* k) {
110     assert(k->is_typeArray_klass(), "cast to TypeArrayKlass");
111     return static_cast<const TypeArrayKlass*>(k);
112   }
113 
114   // Naming
115   static const char* external_name(BasicType type);
116 
117   // Sizing
header_size()118   static int header_size()  { return sizeof(TypeArrayKlass)/wordSize; }
size() const119   int size() const          { return ArrayKlass::static_size(header_size()); }
120 
121   // Initialization (virtual from Klass)
122   void initialize(TRAPS);
123 
124  public:
125   // Printing
126 #ifndef PRODUCT
127   void oop_print_on(oop obj, outputStream* st);
128 #endif
129 
130   void print_on(outputStream* st) const;
131   void print_value_on(outputStream* st) const;
132 
133  public:
134   const char* internal_name() const;
135 
136   ModuleEntry* module() const;
137   PackageEntry* package() const;
138 };
139 
140 #endif // SHARE_OOPS_TYPEARRAYKLASS_HPP
141