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_INLINE_HPP
26 #define SHARE_VM_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 
object_size()33 int typeArrayOopDesc::object_size() {
34   TypeArrayKlass* tk = TypeArrayKlass::cast(klass());
35   return object_size(tk->layout_helper(), length());
36 }
37 
char_base() const38 inline jchar*    typeArrayOopDesc::char_base()   const { return (jchar*)   base(T_CHAR); }
bool_base() const39 inline jboolean* typeArrayOopDesc::bool_base()   const { return (jboolean*)base(T_BOOLEAN); }
byte_base() const40 inline jbyte*    typeArrayOopDesc::byte_base()   const { return (jbyte*)   base(T_BYTE); }
int_base() const41 inline jint*     typeArrayOopDesc::int_base()    const { return (jint*)    base(T_INT); }
long_base() const42 inline jlong*    typeArrayOopDesc::long_base()   const { return (jlong*)   base(T_LONG); }
short_base() const43 inline jshort*   typeArrayOopDesc::short_base()  const { return (jshort*)  base(T_SHORT); }
float_base() const44 inline jfloat*   typeArrayOopDesc::float_base()  const { return (jfloat*)  base(T_FLOAT); }
double_base() const45 inline jdouble*  typeArrayOopDesc::double_base() const { return (jdouble*) base(T_DOUBLE); }
46 
byte_at_addr(int which) const47 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 
bool_at_addr(int which) const52 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 
char_at_addr(int which) const57 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 
int_at_addr(int which) const62 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 
short_at_addr(int which) const67 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 
ushort_at_addr(int which) const72 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 
long_at_addr(int which) const77 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 
float_at_addr(int which) const82 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 
double_at_addr(int which) const87 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 
byte_at(int which) const92 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 }
byte_at_put(int which,jbyte contents)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 
bool_at(int which) const103 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 }
bool_at_put(int which,jboolean contents)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 
char_at(int which) const114 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 }
char_at_put(int which,jchar contents)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 
int_at(int which) const125 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 }
int_at_put(int which,jint contents)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 
short_at(int which) const136 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 }
short_at_put(int which,jshort contents)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 
ushort_at(int which) const147 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 }
ushort_at_put(int which,jushort contents)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 
long_at(int which) const158 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 }
long_at_put(int which,jlong contents)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 
float_at(int which) const169 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 }
float_at_put(int which,jfloat contents)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 
double_at(int which) const180 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 }
double_at_put(int which,jdouble contents)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 
byte_at_acquire(int which) const191 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 }
release_byte_at_put(int which,jbyte contents)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
symbol_at(int which) const206 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 }
symbol_at_put(int which,Symbol * contents)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
symbol_at(int which) const217 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 }
symbol_at_put(int which,Symbol * contents)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_VM_OOPS_TYPEARRAYOOP_INLINE_HPP
231