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_TYPEARRAYOOP_HPP 26 #define SHARE_VM_OOPS_TYPEARRAYOOP_HPP 27 28 #include "oops/arrayOop.hpp" 29 #include "oops/typeArrayKlass.hpp" 30 #include "runtime/orderAccess.inline.hpp" 31 32 // A typeArrayOop is an array containing basic types (non oop elements). 33 // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs} 34 #include <limits.h> 35 36 class typeArrayOopDesc : public arrayOopDesc { 37 private: 38 template <class T> 39 static ptrdiff_t element_offset(BasicType bt, int index) { 40 return arrayOopDesc::base_offset_in_bytes(bt) + sizeof(T) * index; 41 } 42 43 protected: 44 jchar* char_base() const; 45 jboolean* bool_base() const; 46 jbyte* byte_base() const; 47 jint* int_base() const; 48 jlong* long_base() const; 49 jshort* short_base() const; 50 jfloat* float_base() const; 51 jdouble* double_base() const; 52 53 friend class TypeArrayKlass; 54 55 public: 56 jbyte* byte_at_addr(int which) const; 57 jboolean* bool_at_addr(int which) const; 58 jchar* char_at_addr(int which) const; 59 jint* int_at_addr(int which) const; 60 jshort* short_at_addr(int which) const; 61 jushort* ushort_at_addr(int which) const; 62 jlong* long_at_addr(int which) const; 63 jfloat* float_at_addr(int which) const; 64 jdouble* double_at_addr(int which) const; 65 66 jbyte byte_at(int which) const; 67 void byte_at_put(int which, jbyte contents); 68 69 jboolean bool_at(int which) const; 70 void bool_at_put(int which, jboolean contents); 71 72 jchar char_at(int which) const; 73 void char_at_put(int which, jchar contents); 74 75 jint int_at(int which) const; 76 void int_at_put(int which, jint contents); 77 78 jshort short_at(int which) const; 79 void short_at_put(int which, jshort contents); 80 81 jushort ushort_at(int which) const; 82 void ushort_at_put(int which, jushort contents); 83 84 jlong long_at(int which) const; 85 void long_at_put(int which, jlong contents); 86 87 jfloat float_at(int which) const; 88 void float_at_put(int which, jfloat contents); 89 90 jdouble double_at(int which) const; 91 void double_at_put(int which, jdouble contents); 92 93 jbyte byte_at_acquire(int which) const; 94 void release_byte_at_put(int which, jbyte contents); 95 96 Symbol* symbol_at(int which) const; 97 void symbol_at_put(int which, Symbol* contents); 98 99 // Sizing 100 101 // Returns the number of words necessary to hold an array of "len" 102 // elements each of the given "byte_size". 103 private: 104 static int object_size(int lh, int length) { 105 int instance_header_size = Klass::layout_helper_header_size(lh); 106 int element_shift = Klass::layout_helper_log2_element_size(lh); 107 DEBUG_ONLY(BasicType etype = Klass::layout_helper_element_type(lh)); 108 assert(length <= arrayOopDesc::max_array_length(etype), "no overflow"); 109 110 julong size_in_bytes = (juint)length; 111 size_in_bytes <<= element_shift; 112 size_in_bytes += instance_header_size; 113 julong size_in_words = ((size_in_bytes + (HeapWordSize-1)) >> LogHeapWordSize); 114 assert(size_in_words <= (julong)max_jint, "no overflow"); 115 116 return align_object_size((intptr_t)size_in_words); 117 } 118 119 public: 120 inline int object_size(); 121 }; 122 123 #endif // SHARE_VM_OOPS_TYPEARRAYOOP_HPP