1 /* 2 * Copyright (c) 2017, 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 39 public: 40 static const KlassID ID = ValueArrayKlassID; 41 42 private: 43 // Constructor 44 ValueArrayKlass(Klass* element_klass, Symbol* name); 45 46 static ValueArrayKlass* allocate_klass(Klass* element_klass, TRAPS); 47 protected: 48 // Returns the ArrayKlass for n'th dimension. 49 Klass* array_klass_impl(ArrayStorageProperties storage_props, bool or_null, int n, TRAPS); 50 51 // Returns the array class with this class as element type. 52 Klass* array_klass_impl(ArrayStorageProperties storage_props, bool or_null, TRAPS); 53 54 public: 55 56 ValueArrayKlass() {} 57 58 // Properties of an LWorld (LW2) flattened array 59 ArrayStorageProperties storage_properties() { return ArrayStorageProperties::flattened_and_null_free; } 60 61 virtual ValueKlass* element_klass() const; 62 virtual void set_element_klass(Klass* k); 63 64 // Casting from Klass* 65 static ValueArrayKlass* cast(Klass* k) { 66 assert(k->is_valueArray_klass(), "cast to ValueArrayKlass"); 67 return (ValueArrayKlass*) k; 68 } 69 70 // klass allocation 71 static ValueArrayKlass* allocate_klass(ArrayStorageProperties storage_props, Klass* element_klass, TRAPS); 72 73 void initialize(TRAPS); 74 75 ModuleEntry* module() const; 76 PackageEntry* package() const; 77 78 bool can_be_primary_super_slow() const; 79 GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots, 80 Array<InstanceKlass*>* transitive_interfaces); 81 82 int element_byte_size() const { return 1 << layout_helper_log2_element_size(_layout_helper); } 83 84 bool is_valueArray_klass_slow() const { return true; } 85 86 bool contains_oops() { 87 return element_klass()->contains_oops(); 88 } 89 90 // Override. 91 bool element_access_is_atomic() { 92 return element_klass()->is_atomic(); 93 } 94 95 oop protection_domain() const; 96 97 static jint array_layout_helper(ValueKlass* vklass); // layout helper for values 98 99 // sizing 100 static int header_size() { return sizeof(ValueArrayKlass)/HeapWordSize; } 101 int size() const { return ArrayKlass::static_size(header_size()); } 102 103 jint max_elements() const; 104 105 int oop_size(oop obj) const; 106 107 // Oop Allocation 108 valueArrayOop allocate(int length, TRAPS); 109 oop multi_allocate(int rank, jint* sizes, TRAPS); 110 111 // Naming 112 const char* internal_name() const { return external_name(); } 113 114 // Copying 115 void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS); 116 117 // GC specific object visitors 118 // 119 // Mark Sweep 120 int oop_ms_adjust_pointers(oop obj); 121 122 123 template <typename T, typename OopClosureType> 124 inline void oop_oop_iterate(oop obj, OopClosureType* closure); 125 126 template <typename T, typename OopClosureType> 127 inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure); 128 129 template <typename T, typename OopClosureType> 130 inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr); 131 132 template <typename T, class OopClosureType> 133 inline void oop_oop_iterate_elements(valueArrayOop a, OopClosureType* closure); 134 135 private: 136 template <typename T, class OopClosureType> 137 inline void oop_oop_iterate_elements_specialized(valueArrayOop a, OopClosureType* closure); 138 139 template <typename T, class OopClosureType> 140 inline void oop_oop_iterate_elements_bounded(valueArrayOop a, OopClosureType* closure, MemRegion mr); 141 142 template <typename T, class OopClosureType> 143 inline void oop_oop_iterate_elements_specialized_bounded(valueArrayOop a, OopClosureType* closure, void* low, void* high); 144 145 public: 146 // Printing 147 void print_on(outputStream* st) const; 148 void print_value_on(outputStream* st) const; 149 150 void oop_print_value_on(oop obj, outputStream* st); 151 #ifndef PRODUCT 152 void oop_print_on(oop obj, outputStream* st); 153 #endif 154 155 // Verification 156 void verify_on(outputStream* st); 157 void oop_verify_on(oop obj, outputStream* st); 158 }; 159 160 #endif 161