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