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