1 /* 2 * Copyright (c) 1997, 2020, 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_OOPS_TYPEARRAYOOP_INLINE_HPP 26 #define SHARE_OOPS_TYPEARRAYOOP_INLINE_HPP 27 28 #include "oops/typeArrayOop.hpp" 29 30 #include "oops/access.inline.hpp" 31 #include "oops/oop.inline.hpp" 32 #include "oops/arrayOop.hpp" 33 34 int typeArrayOopDesc::object_size(const TypeArrayKlass* tk) const { 35 return object_size(tk->layout_helper(), length()); 36 } 37 38 inline jchar* typeArrayOopDesc::char_base() const { return (jchar*) base(T_CHAR); } 39 inline jboolean* typeArrayOopDesc::bool_base() const { return (jboolean*)base(T_BOOLEAN); } 40 inline jbyte* typeArrayOopDesc::byte_base() const { return (jbyte*) base(T_BYTE); } 41 inline jint* typeArrayOopDesc::int_base() const { return (jint*) base(T_INT); } 42 inline jlong* typeArrayOopDesc::long_base() const { return (jlong*) base(T_LONG); } 43 inline jshort* typeArrayOopDesc::short_base() const { return (jshort*) base(T_SHORT); } 44 inline jfloat* typeArrayOopDesc::float_base() const { return (jfloat*) base(T_FLOAT); } 45 inline jdouble* typeArrayOopDesc::double_base() const { return (jdouble*) base(T_DOUBLE); } 46 47 inline jbyte* typeArrayOopDesc::byte_at_addr(int which) const { 48 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 49 return &byte_base()[which]; 50 } 51 52 inline jboolean* typeArrayOopDesc::bool_at_addr(int which) const { 53 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 54 return &bool_base()[which]; 55 } 56 57 inline jchar* typeArrayOopDesc::char_at_addr(int which) const { 58 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 59 return &char_base()[which]; 60 } 61 62 inline jint* typeArrayOopDesc::int_at_addr(int which) const { 63 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 64 return &int_base()[which]; 65 } 66 67 inline jshort* typeArrayOopDesc::short_at_addr(int which) const { 68 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 69 return &short_base()[which]; 70 } 71 72 inline jushort* typeArrayOopDesc::ushort_at_addr(int which) const { // for field descriptor arrays 73 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 74 return (jushort*) &short_base()[which]; 75 } 76 77 inline jlong* typeArrayOopDesc::long_at_addr(int which) const { 78 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 79 return &long_base()[which]; 80 } 81 82 inline jfloat* typeArrayOopDesc::float_at_addr(int which) const { 83 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 84 return &float_base()[which]; 85 } 86 87 inline jdouble* typeArrayOopDesc::double_at_addr(int which) const { 88 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 89 return &double_base()[which]; 90 } 91 92 inline jbyte typeArrayOopDesc::byte_at(int which) const { 93 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 94 ptrdiff_t offset = element_offset<jbyte>(which); 95 return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 96 } 97 inline void typeArrayOopDesc::byte_at_put(int which, jbyte contents) { 98 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 99 ptrdiff_t offset = element_offset<jbyte>(which); 100 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); 101 } 102 103 inline jboolean typeArrayOopDesc::bool_at(int which) const { 104 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 105 ptrdiff_t offset = element_offset<jboolean>(which); 106 return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 107 } 108 inline void typeArrayOopDesc::bool_at_put(int which, jboolean contents) { 109 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 110 ptrdiff_t offset = element_offset<jboolean>(which); 111 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, jboolean(contents & 1)); 112 } 113 114 inline jchar typeArrayOopDesc::char_at(int which) const { 115 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 116 ptrdiff_t offset = element_offset<jchar>(which); 117 return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 118 } 119 inline void typeArrayOopDesc::char_at_put(int which, jchar contents) { 120 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 121 ptrdiff_t offset = element_offset<jchar>(which); 122 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); 123 } 124 125 inline jint typeArrayOopDesc::int_at(int which) const { 126 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 127 ptrdiff_t offset = element_offset<jint>(which); 128 return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 129 } 130 inline void typeArrayOopDesc::int_at_put(int which, jint contents) { 131 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 132 ptrdiff_t offset = element_offset<jint>(which); 133 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); 134 } 135 136 inline jshort typeArrayOopDesc::short_at(int which) const { 137 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 138 ptrdiff_t offset = element_offset<jshort>(which); 139 return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 140 } 141 inline void typeArrayOopDesc::short_at_put(int which, jshort contents) { 142 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 143 ptrdiff_t offset = element_offset<jshort>(which); 144 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); 145 } 146 147 inline jushort typeArrayOopDesc::ushort_at(int which) const { 148 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 149 ptrdiff_t offset = element_offset<jushort>(which); 150 return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 151 } 152 inline void typeArrayOopDesc::ushort_at_put(int which, jushort contents) { 153 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 154 ptrdiff_t offset = element_offset<jushort>(which); 155 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); 156 } 157 158 inline jlong typeArrayOopDesc::long_at(int which) const { 159 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 160 ptrdiff_t offset = element_offset<jlong>(which); 161 return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 162 } 163 inline void typeArrayOopDesc::long_at_put(int which, jlong contents) { 164 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 165 ptrdiff_t offset = element_offset<jlong>(which); 166 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); 167 } 168 169 inline jfloat typeArrayOopDesc::float_at(int which) const { 170 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 171 ptrdiff_t offset = element_offset<jfloat>(which); 172 return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 173 } 174 inline void typeArrayOopDesc::float_at_put(int which, jfloat contents) { 175 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 176 ptrdiff_t offset = element_offset<jfloat>(which); 177 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); 178 } 179 180 inline jdouble typeArrayOopDesc::double_at(int which) const { 181 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 182 ptrdiff_t offset = element_offset<jdouble>(which); 183 return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 184 } 185 inline void typeArrayOopDesc::double_at_put(int which, jdouble contents) { 186 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 187 ptrdiff_t offset = element_offset<jdouble>(which); 188 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); 189 } 190 191 inline jbyte typeArrayOopDesc::byte_at_acquire(int which) const { 192 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 193 ptrdiff_t offset = element_offset<jbyte>(which); 194 return HeapAccess<MO_ACQUIRE | IS_ARRAY>::load_at(as_oop(), offset); 195 } 196 inline void typeArrayOopDesc::release_byte_at_put(int which, jbyte contents) { 197 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 198 ptrdiff_t offset = element_offset<jbyte>(which); 199 HeapAccess<MO_RELEASE | IS_ARRAY>::store_at(as_oop(), offset, contents); 200 } 201 202 // Java thinks Symbol arrays are just arrays of either long or int, since 203 // there doesn't seem to be T_ADDRESS, so this is a bit of unfortunate 204 // casting 205 #ifdef _LP64 206 inline Symbol* typeArrayOopDesc::symbol_at(int which) const { 207 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 208 ptrdiff_t offset = element_offset<jlong>(which); 209 return (Symbol*)(jlong) HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 210 } 211 inline void typeArrayOopDesc::symbol_at_put(int which, Symbol* contents) { 212 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 213 ptrdiff_t offset = element_offset<jlong>(which); 214 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, (jlong)contents); 215 } 216 #else 217 inline Symbol* typeArrayOopDesc::symbol_at(int which) const { 218 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 219 ptrdiff_t offset = element_offset<jint>(which); 220 return (Symbol*)(jint) HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); 221 } 222 inline void typeArrayOopDesc::symbol_at_put(int which, Symbol* contents) { 223 assert(is_within_bounds(which), "index %d out of bounds %d", which, length()); 224 ptrdiff_t offset = element_offset<jint>(which); 225 HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, (jint)contents); 226 } 227 #endif // _LP64 228 229 230 #endif // SHARE_OOPS_TYPEARRAYOOP_INLINE_HPP