| 1 | /* |
| 2 | * Copyright (c) 1997, 2019, 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/access.inline.hpp" |
| 29 | #include "oops/oop.inline.hpp" |
| 30 | #include "oops/arrayOop.inline.hpp" |
| 31 | #include "oops/typeArrayOop.hpp" |
| 32 | |
| 33 | int typeArrayOopDesc::object_size() { |
| 34 | TypeArrayKlass* tk = TypeArrayKlass::cast(klass()); |
| 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 | ptrdiff_t offset = element_offset<jbyte>(which); |
| 94 | return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 95 | } |
| 96 | inline void typeArrayOopDesc::byte_at_put(int which, jbyte contents) { |
| 97 | ptrdiff_t offset = element_offset<jbyte>(which); |
| 98 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); |
| 99 | } |
| 100 | |
| 101 | inline jboolean typeArrayOopDesc::bool_at(int which) const { |
| 102 | ptrdiff_t offset = element_offset<jboolean>(which); |
| 103 | return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 104 | } |
| 105 | inline void typeArrayOopDesc::bool_at_put(int which, jboolean contents) { |
| 106 | ptrdiff_t offset = element_offset<jboolean>(which); |
| 107 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, jboolean(contents & 1)); |
| 108 | } |
| 109 | |
| 110 | inline jchar typeArrayOopDesc::char_at(int which) const { |
| 111 | ptrdiff_t offset = element_offset<jchar>(which); |
| 112 | return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 113 | } |
| 114 | inline void typeArrayOopDesc::char_at_put(int which, jchar contents) { |
| 115 | ptrdiff_t offset = element_offset<jchar>(which); |
| 116 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); |
| 117 | } |
| 118 | |
| 119 | inline jint typeArrayOopDesc::int_at(int which) const { |
| 120 | ptrdiff_t offset = element_offset<jint>(which); |
| 121 | return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 122 | } |
| 123 | inline void typeArrayOopDesc::int_at_put(int which, jint contents) { |
| 124 | ptrdiff_t offset = element_offset<jint>(which); |
| 125 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); |
| 126 | } |
| 127 | |
| 128 | inline jshort typeArrayOopDesc::short_at(int which) const { |
| 129 | ptrdiff_t offset = element_offset<jshort>(which); |
| 130 | return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 131 | } |
| 132 | inline void typeArrayOopDesc::short_at_put(int which, jshort contents) { |
| 133 | ptrdiff_t offset = element_offset<jshort>(which); |
| 134 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); |
| 135 | } |
| 136 | |
| 137 | inline jushort typeArrayOopDesc::ushort_at(int which) const { |
| 138 | ptrdiff_t offset = element_offset<jushort>(which); |
| 139 | return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 140 | } |
| 141 | inline void typeArrayOopDesc::ushort_at_put(int which, jushort contents) { |
| 142 | ptrdiff_t offset = element_offset<jushort>(which); |
| 143 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); |
| 144 | } |
| 145 | |
| 146 | inline jlong typeArrayOopDesc::long_at(int which) const { |
| 147 | ptrdiff_t offset = element_offset<jlong>(which); |
| 148 | return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 149 | } |
| 150 | inline void typeArrayOopDesc::long_at_put(int which, jlong contents) { |
| 151 | ptrdiff_t offset = element_offset<jlong>(which); |
| 152 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); |
| 153 | } |
| 154 | |
| 155 | inline jfloat typeArrayOopDesc::float_at(int which) const { |
| 156 | ptrdiff_t offset = element_offset<jfloat>(which); |
| 157 | return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 158 | } |
| 159 | inline void typeArrayOopDesc::float_at_put(int which, jfloat contents) { |
| 160 | ptrdiff_t offset = element_offset<jfloat>(which); |
| 161 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); |
| 162 | } |
| 163 | |
| 164 | inline jdouble typeArrayOopDesc::double_at(int which) const { |
| 165 | ptrdiff_t offset = element_offset<jdouble>(which); |
| 166 | return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 167 | } |
| 168 | inline void typeArrayOopDesc::double_at_put(int which, jdouble contents) { |
| 169 | ptrdiff_t offset = element_offset<jdouble>(which); |
| 170 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents); |
| 171 | } |
| 172 | |
| 173 | inline jbyte typeArrayOopDesc::byte_at_acquire(int which) const { |
| 174 | ptrdiff_t offset = element_offset<jbyte>(which); |
| 175 | return HeapAccess<MO_ACQUIRE | IS_ARRAY>::load_at(as_oop(), offset); |
| 176 | } |
| 177 | inline void typeArrayOopDesc::release_byte_at_put(int which, jbyte contents) { |
| 178 | ptrdiff_t offset = element_offset<jbyte>(which); |
| 179 | HeapAccess<MO_RELEASE | IS_ARRAY>::store_at(as_oop(), offset, contents); |
| 180 | } |
| 181 | |
| 182 | // Java thinks Symbol arrays are just arrays of either long or int, since |
| 183 | // there doesn't seem to be T_ADDRESS, so this is a bit of unfortunate |
| 184 | // casting |
| 185 | #ifdef _LP64 |
| 186 | inline Symbol* typeArrayOopDesc::symbol_at(int which) const { |
| 187 | ptrdiff_t offset = element_offset<jlong>(which); |
| 188 | return (Symbol*)(jlong) HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 189 | } |
| 190 | inline void typeArrayOopDesc::symbol_at_put(int which, Symbol* contents) { |
| 191 | ptrdiff_t offset = element_offset<jlong>(which); |
| 192 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, (jlong)contents); |
| 193 | } |
| 194 | #else |
| 195 | inline Symbol* typeArrayOopDesc::symbol_at(int which) const { |
| 196 | ptrdiff_t offset = element_offset<jint>(which); |
| 197 | return (Symbol*)(jint) HeapAccess<IS_ARRAY>::load_at(as_oop(), offset); |
| 198 | } |
| 199 | inline void typeArrayOopDesc::symbol_at_put(int which, Symbol* contents) { |
| 200 | ptrdiff_t offset = element_offset<jint>(which); |
| 201 | HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, (jint)contents); |
| 202 | } |
| 203 | #endif // _LP64 |
| 204 | |
| 205 | |
| 206 | #endif // SHARE_OOPS_TYPEARRAYOOP_INLINE_HPP |
| 207 | |