1 /*
   2  * Copyright (c) 2015, 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_VALUEARRAYKLASS_HPP
  26 #define SHARE_VM_OOPS_VALUEARRAYKLASS_HPP
  27 
  28 #include "classfile/classLoaderData.hpp"
  29 #include "oops/arrayKlass.hpp"
  30 #include "oops/valueKlass.hpp"
  31 #include "utilities/macros.hpp"
  32 
  33 /**
  34  * Array of values, gives a layout of typeArrayOop, but needs oops iterators
  35  */
  36 class ValueArrayKlass : public ArrayKlass {
  37   friend class VMStructs;
  38  private:
  39   ValueKlass*    _element_klass;             // The klass of the elements of this array type
  40 
  41   // Constructor
  42   ValueArrayKlass(KlassHandle element_klass, Symbol* name);
  43   void set_element_klass(ValueKlass* k) { _element_klass = k; }
  44 
  45   static ValueArrayKlass* allocate_klass(KlassHandle element_klass, Symbol* name, TRAPS);
  46 protected:
  47   // Returns the ArrayKlass for n'th dimension.
  48   Klass* array_klass_impl(bool or_null, int n, TRAPS);
  49 
  50   // Returns the array class with this class as element type.
  51   Klass* array_klass_impl(bool or_null, TRAPS);
  52 
  53  public:
  54 
  55   ValueArrayKlass() {}
  56 
  57   // Casting from Klass*
  58   static ValueArrayKlass* cast(Klass* k) {
  59     assert(k->is_valueArray_klass(), "cast to ValueArrayKlass");
  60     return (ValueArrayKlass*) k;
  61   }
  62 
  63   // klass allocation
  64   static ValueArrayKlass* allocate_klass(KlassHandle element_klass, TRAPS);
  65 
  66   // Instance variables
  67   ValueKlass* element_klass() const     { return _element_klass; }
  68   ValueKlass** element_klass_addr()     { return &_element_klass; }
  69 
  70   int element_byte_size() const { return element_klass()->raw_value_byte_size(); }
  71 
  72   bool is_typeArray_klass_slow() const { return true; }
  73   bool is_valueArray_klass_slow() const { return true; }
  74 
  75   bool contains_oops() { return element_klass()->contains_oops(); }
  76   bool is_atomic() { return element_klass()->is_atomic(); }
  77 
  78   oop protection_domain() const;
  79 
  80   static jint array_layout_helper(ValueKlass* vklass); // layout helper for values
  81 
  82   // sizing
  83   static int header_size()  { return sizeof(ValueArrayKlass)/HeapWordSize; }
  84   int size() const          { return ArrayKlass::static_size(header_size()); }
  85 
  86   jint max_elements() const;
  87 
  88   int oop_size(oop obj) const;
  89 
  90   // Oop Allocation
  91   oop allocate(int length, bool do_zero, TRAPS);
  92   oop multi_allocate(int rank, jint* sizes, TRAPS);
  93 
  94   // Naming
  95   const char* internal_name() const { return external_name(); }
  96 
  97   // Copying
  98   void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);
  99 
 100   // Compiler/Interpreter offset
 101   static ByteSize element_klass_offset() { return in_ByteSize(offset_of(ValueArrayKlass, _element_klass)); }
 102 
 103   // GC specific object visitors
 104   //
 105   // Mark Sweep
 106   int oop_ms_adjust_pointers(oop obj);
 107 
 108 #if INCLUDE_ALL_GCS
 109   // Parallel Scavenge
 110   void oop_ps_push_contents(  oop obj, PSPromotionManager* pm);
 111   // Parallel Compact
 112   void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
 113   void oop_pc_update_pointers(oop obj, ParCompactionManager* cm);
 114 #endif
 115 
 116   CMH("Oop iterators. Don't have embedded oops yet, so CMH...")
 117 
 118  private:
 119   template <bool nv, typename OopClosureType>
 120   inline void oop_oop_iterate_impl(oop obj, OopClosureType* closure);
 121   template <bool nv, typename OopClosureType>
 122   inline void oop_oop_iterate(oop obj, OopClosureType* closure);
 123   template <bool nv, typename OopClosureType>
 124   inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);
 125 
 126   template <bool nv, typename T, class OopClosureType>
 127   inline void oop_oop_iterate_elements_specialized(valueArrayOop a, OopClosureType* closure);
 128 
 129  public:
 130   template <bool nv, class OopClosureType>
 131   inline void oop_oop_iterate_elements(valueArrayOop a, OopClosureType* closure);
 132 
 133   ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_OOP_ITERATE_DECL)
 134   ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_OOP_ITERATE_DECL)
 135   ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_OOP_ITERATE_DECL_RANGE)
 136   ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_OOP_ITERATE_DECL_RANGE)
 137 
 138 #if INCLUDE_ALL_GCS
 139   ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_OOP_ITERATE_DECL_NO_BACKWARDS)
 140   ALL_OOP_OOP_ITERATE_CLOSURES_2(OOP_OOP_ITERATE_DECL_NO_BACKWARDS)
 141 #endif // INCLUDE_ALL_GCS
 142 
 143 
 144   // Printing
 145   void print_on(outputStream* st) const;
 146 #ifndef PRODUCT
 147   void oop_print_on(oop obj, outputStream* st);
 148 #endif
 149 
 150 };
 151 
 152 #endif
 153