1 /*
   2  * Copyright (c) 1997, 2013, 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  private:
  37   jint _max_length;            // maximum number of elements allowed in an array
  38 
  39   // Constructor
  40   TypeArrayKlass(BasicType type, Symbol* name);
  41   static TypeArrayKlass* allocate(ClassLoaderData* loader_data, BasicType type, Symbol* name, TRAPS);
  42  public:
  43   TypeArrayKlass() {} // For dummy objects.
  44 
  45   // instance variables
  46   jint max_length()                     { return _max_length; }
  47   void set_max_length(jint m)           { _max_length = m;    }
  48 
  49   // testers
  50   bool oop_is_typeArray_slow() const    { return true; }
  51 
  52   // klass allocation
  53   static TypeArrayKlass* create_klass(BasicType type, const char* name_str,
  54                                TRAPS);
  55   static inline Klass* create_klass(BasicType type, int scale, TRAPS) {
  56     TypeArrayKlass* tak = create_klass(type, external_name(type), CHECK_NULL);
  57     assert(scale == (1 << tak->log2_element_size()), "scale must check out");
  58     return tak;
  59   }
  60 
  61   int oop_size(oop obj) const;
  62 
  63   bool compute_is_subtype_of(Klass* k);
  64 
  65   // Allocation
  66   typeArrayOop allocate_common(int length, bool do_zero, TRAPS);
  67   typeArrayOop allocate(int length, TRAPS) { return allocate_common(length, true, THREAD); }
  68   oop multi_allocate(int rank, jint* sizes, TRAPS);
  69 
  70   oop protection_domain() const { return NULL; }
  71 
  72   // Copying
  73   void  copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
  74 
  75   // GC specific object visitors
  76   //
  77   // Mark Sweep
  78   int  oop_ms_adjust_pointers(oop obj);
  79 #if INCLUDE_ALL_GCS
  80   // Parallel Scavenge
  81   void oop_ps_push_contents(  oop obj, PSPromotionManager* pm);
  82   // Parallel Compact
  83   void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
  84   void oop_pc_update_pointers(oop obj);
  85 #endif
  86 
  87   // Oop iterators. Since there are no oops in TypeArrayKlasses,
  88   // these functions only return the size of the object.
  89 
  90  private:
  91   // The implementation used by all oop_oop_iterate functions in TypeArrayKlasses.
  92   inline int oop_oop_iterate_impl(oop obj, ExtendedOopClosure* closure);
  93 
  94   // Wraps oop_oop_iterate_impl to conform to macros.
  95   template <bool nv, typename OopClosureType>
  96   inline int oop_oop_iterate(oop obj, OopClosureType* closure);
  97 
  98   // Wraps oop_oop_iterate_impl to conform to macros.
  99   template <bool nv, typename OopClosureType>
 100   inline int oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);
 101 
 102  public:
 103 
 104   ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_OOP_ITERATE_DECL)
 105   ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_OOP_ITERATE_DECL)
 106   ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_OOP_ITERATE_DECL_RANGE)
 107   ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_OOP_ITERATE_DECL_RANGE)
 108 
 109 #if INCLUDE_ALL_GCS
 110   ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_OOP_ITERATE_DECL_NO_BACKWARDS)
 111   ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_OOP_ITERATE_DECL_NO_BACKWARDS)
 112 #endif // INCLUDE_ALL_GCS
 113 
 114 
 115  protected:
 116   // Find n'th dimensional array
 117   virtual Klass* array_klass_impl(bool or_null, int n, TRAPS);
 118 
 119   // Returns the array class with this class as element type
 120   virtual Klass* array_klass_impl(bool or_null, TRAPS);
 121 
 122  public:
 123   // Casting from Klass*
 124   static TypeArrayKlass* cast(Klass* k) {
 125     assert(k->oop_is_typeArray(), "cast to TypeArrayKlass");
 126     return (TypeArrayKlass*) k;
 127   }
 128 
 129   // Naming
 130   static const char* external_name(BasicType type);
 131 
 132   // Sizing
 133   static int header_size()  { return sizeof(TypeArrayKlass)/HeapWordSize; }
 134   int size() const          { return ArrayKlass::static_size(header_size()); }
 135 
 136   // Initialization (virtual from Klass)
 137   void initialize(TRAPS);
 138 
 139  public:
 140   // Printing
 141 #ifndef PRODUCT
 142   void oop_print_on(oop obj, outputStream* st);
 143 #endif
 144 
 145   void print_on(outputStream* st) const;
 146   void print_value_on(outputStream* st) const;
 147 
 148  public:
 149   const char* internal_name() const;
 150 };
 151 
 152 #endif // SHARE_VM_OOPS_TYPEARRAYKLASS_HPP