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