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