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) 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 return *byte_at_addr(which);
94 }
95 inline void typeArrayOopDesc::byte_at_put(int which, jbyte contents) {
96 *byte_at_addr(which) = contents;
97 }
98
99 inline jboolean typeArrayOopDesc::bool_at(int which) const {
100 return *bool_at_addr(which);
101 }
102 inline void typeArrayOopDesc::bool_at_put(int which, jboolean contents) {
103 *bool_at_addr(which) = jboolean(contents & 1);
104 }
105
106 inline jchar typeArrayOopDesc::char_at(int which) const {
107 return *char_at_addr(which);
108 }
109 inline void typeArrayOopDesc::char_at_put(int which, jchar contents) {
110 *char_at_addr(which) = contents;
111 }
112
113 inline jint typeArrayOopDesc::int_at(int which) const {
114 return *int_at_addr(which);
115 }
116 inline void typeArrayOopDesc::int_at_put(int which, jint contents) {
117 *int_at_addr(which) = contents;
118 }
119
120 inline jshort typeArrayOopDesc::short_at(int which) const {
121 return *short_at_addr(which);
122 }
123 inline void typeArrayOopDesc::short_at_put(int which, jshort contents) {
124 *short_at_addr(which) = contents;
125 }
126
127 inline jushort typeArrayOopDesc::ushort_at(int which) const {
128 return *ushort_at_addr(which);
129 }
130
131 inline void typeArrayOopDesc::ushort_at_put(int which, jushort contents) {
132 *ushort_at_addr(which) = contents;
133 }
134
135 inline jlong typeArrayOopDesc::long_at(int which) const {
136 return *long_at_addr(which);
137 }
138 inline void typeArrayOopDesc::long_at_put(int which, jlong contents) {
139 *long_at_addr(which) = contents;
140 }
141
142 inline jfloat typeArrayOopDesc::float_at(int which) const {
143 return *float_at_addr(which);
144 }
145
146 inline void typeArrayOopDesc::float_at_put(int which, jfloat contents) {
147 *float_at_addr(which) = contents;
148 }
149
150 inline jdouble typeArrayOopDesc::double_at(int which) const {
151 return *double_at_addr(which);
152 }
153
154 inline void typeArrayOopDesc::double_at_put(int which, jdouble contents) {
155 *double_at_addr(which) = contents;
156 }
157
158 inline jbyte typeArrayOopDesc::byte_at_acquire(int which) const {
159 return Atomic::load_acquire(byte_at_addr(which));
160 }
161 inline void typeArrayOopDesc::release_byte_at_put(int which, jbyte contents) {
162 Atomic::release_store(byte_at_addr(which), contents);
163 }
164
165 // Java thinks Symbol arrays are just arrays of either long or int, since
166 // there doesn't seem to be T_ADDRESS, so this is a bit of unfortunate
167 // casting
168 #ifdef _LP64
169 inline Symbol* typeArrayOopDesc::symbol_at(int which) const {
170 return *reinterpret_cast<Symbol**>(long_at_addr(which));
171 }
172
173 inline void typeArrayOopDesc::symbol_at_put(int which, Symbol* contents) {
174 *reinterpret_cast<Symbol**>(long_at_addr(which)) = contents;
175 }
176 #else
177 inline Symbol* typeArrayOopDesc::symbol_at(int which) const {
178 return *reinterpret_cast<Symbol**>(int_at_addr(which));
179 }
180 inline void typeArrayOopDesc::symbol_at_put(int which, Symbol* contents) {
181 *reinterpret_cast<Symbol**>(int_at_addr(which)) = contents;
182 }
183 #endif // _LP64
184
185
186 #endif // SHARE_OOPS_TYPEARRAYOOP_INLINE_HPP