Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 995c35c

Browse files
committedAug 2, 2020
8250844: Make sure {type,obj}ArrayOopDesc accessors check the bounds
Reviewed-by: rrich, coleenp
1 parent f951fa8 commit 995c35c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
 

‎src/hotspot/share/oops/objArrayOop.inline.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,23 @@ inline HeapWord* objArrayOopDesc::base() const { return (HeapWord*) arrayOopDesc
3535
inline HeapWord* objArrayOopDesc::base_raw() const { return (HeapWord*) arrayOopDesc::base_raw(T_OBJECT); }
3636

3737
template <class T> T* objArrayOopDesc::obj_at_addr(int index) const {
38-
assert(is_within_bounds(index), "index out of bounds");
38+
assert(is_within_bounds(index), "index %d out of bounds %d", index, length());
3939
return &((T*)base())[index];
4040
}
4141

4242
template <class T> T* objArrayOopDesc::obj_at_addr_raw(int index) const {
43-
assert(is_within_bounds(index), "index out of bounds");
43+
assert(is_within_bounds(index), "index %d out of bounds %d", index, length());
4444
return &((T*)base_raw())[index];
4545
}
4646

4747
inline oop objArrayOopDesc::obj_at(int index) const {
48+
assert(is_within_bounds(index), "index %d out of bounds %d", index, length());
4849
ptrdiff_t offset = UseCompressedOops ? obj_at_offset<narrowOop>(index) : obj_at_offset<oop>(index);
4950
return HeapAccess<IS_ARRAY>::oop_load_at(as_oop(), offset);
5051
}
5152

5253
inline void objArrayOopDesc::obj_at_put(int index, oop value) {
54+
assert(is_within_bounds(index), "index %d out of bounds %d", index, length());
5355
ptrdiff_t offset = UseCompressedOops ? obj_at_offset<narrowOop>(index) : obj_at_offset<oop>(index);
5456
HeapAccess<IS_ARRAY>::oop_store_at(as_oop(), offset, value);
5557
}

‎src/hotspot/share/oops/typeArrayOop.inline.hpp

+24
Original file line numberDiff line numberDiff line change
@@ -90,91 +90,111 @@ inline jdouble* typeArrayOopDesc::double_at_addr(int which) const {
9090
}
9191

9292
inline jbyte typeArrayOopDesc::byte_at(int which) const {
93+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
9394
ptrdiff_t offset = element_offset<jbyte>(which);
9495
return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
9596
}
9697
inline void typeArrayOopDesc::byte_at_put(int which, jbyte contents) {
98+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
9799
ptrdiff_t offset = element_offset<jbyte>(which);
98100
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents);
99101
}
100102

101103
inline jboolean typeArrayOopDesc::bool_at(int which) const {
104+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
102105
ptrdiff_t offset = element_offset<jboolean>(which);
103106
return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
104107
}
105108
inline void typeArrayOopDesc::bool_at_put(int which, jboolean contents) {
109+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
106110
ptrdiff_t offset = element_offset<jboolean>(which);
107111
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, jboolean(contents & 1));
108112
}
109113

110114
inline jchar typeArrayOopDesc::char_at(int which) const {
115+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
111116
ptrdiff_t offset = element_offset<jchar>(which);
112117
return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
113118
}
114119
inline void typeArrayOopDesc::char_at_put(int which, jchar contents) {
120+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
115121
ptrdiff_t offset = element_offset<jchar>(which);
116122
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents);
117123
}
118124

119125
inline jint typeArrayOopDesc::int_at(int which) const {
126+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
120127
ptrdiff_t offset = element_offset<jint>(which);
121128
return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
122129
}
123130
inline void typeArrayOopDesc::int_at_put(int which, jint contents) {
131+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
124132
ptrdiff_t offset = element_offset<jint>(which);
125133
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents);
126134
}
127135

128136
inline jshort typeArrayOopDesc::short_at(int which) const {
137+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
129138
ptrdiff_t offset = element_offset<jshort>(which);
130139
return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
131140
}
132141
inline void typeArrayOopDesc::short_at_put(int which, jshort contents) {
142+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
133143
ptrdiff_t offset = element_offset<jshort>(which);
134144
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents);
135145
}
136146

137147
inline jushort typeArrayOopDesc::ushort_at(int which) const {
148+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
138149
ptrdiff_t offset = element_offset<jushort>(which);
139150
return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
140151
}
141152
inline void typeArrayOopDesc::ushort_at_put(int which, jushort contents) {
153+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
142154
ptrdiff_t offset = element_offset<jushort>(which);
143155
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents);
144156
}
145157

146158
inline jlong typeArrayOopDesc::long_at(int which) const {
159+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
147160
ptrdiff_t offset = element_offset<jlong>(which);
148161
return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
149162
}
150163
inline void typeArrayOopDesc::long_at_put(int which, jlong contents) {
164+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
151165
ptrdiff_t offset = element_offset<jlong>(which);
152166
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents);
153167
}
154168

155169
inline jfloat typeArrayOopDesc::float_at(int which) const {
170+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
156171
ptrdiff_t offset = element_offset<jfloat>(which);
157172
return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
158173
}
159174
inline void typeArrayOopDesc::float_at_put(int which, jfloat contents) {
175+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
160176
ptrdiff_t offset = element_offset<jfloat>(which);
161177
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents);
162178
}
163179

164180
inline jdouble typeArrayOopDesc::double_at(int which) const {
181+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
165182
ptrdiff_t offset = element_offset<jdouble>(which);
166183
return HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
167184
}
168185
inline void typeArrayOopDesc::double_at_put(int which, jdouble contents) {
186+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
169187
ptrdiff_t offset = element_offset<jdouble>(which);
170188
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, contents);
171189
}
172190

173191
inline jbyte typeArrayOopDesc::byte_at_acquire(int which) const {
192+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
174193
ptrdiff_t offset = element_offset<jbyte>(which);
175194
return HeapAccess<MO_ACQUIRE | IS_ARRAY>::load_at(as_oop(), offset);
176195
}
177196
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());
178198
ptrdiff_t offset = element_offset<jbyte>(which);
179199
HeapAccess<MO_RELEASE | IS_ARRAY>::store_at(as_oop(), offset, contents);
180200
}
@@ -184,19 +204,23 @@ inline void typeArrayOopDesc::release_byte_at_put(int which, jbyte contents) {
184204
// casting
185205
#ifdef _LP64
186206
inline Symbol* typeArrayOopDesc::symbol_at(int which) const {
207+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
187208
ptrdiff_t offset = element_offset<jlong>(which);
188209
return (Symbol*)(jlong) HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
189210
}
190211
inline void typeArrayOopDesc::symbol_at_put(int which, Symbol* contents) {
212+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
191213
ptrdiff_t offset = element_offset<jlong>(which);
192214
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, (jlong)contents);
193215
}
194216
#else
195217
inline Symbol* typeArrayOopDesc::symbol_at(int which) const {
218+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
196219
ptrdiff_t offset = element_offset<jint>(which);
197220
return (Symbol*)(jint) HeapAccess<IS_ARRAY>::load_at(as_oop(), offset);
198221
}
199222
inline void typeArrayOopDesc::symbol_at_put(int which, Symbol* contents) {
223+
assert(is_within_bounds(which), "index %d out of bounds %d", which, length());
200224
ptrdiff_t offset = element_offset<jint>(which);
201225
HeapAccess<IS_ARRAY>::store_at(as_oop(), offset, (jint)contents);
202226
}

0 commit comments

Comments
 (0)
This repository has been archived.