8250844: Make sure {type,obj}ArrayOopDesc accessors check the bounds

Reviewed-by: rrich, coleenp
This commit is contained in:
Aleksey Shipilev 2020-08-02 16:58:14 +02:00
parent aab365f746
commit ddb726d4a0
2 changed files with 28 additions and 2 deletions

View file

@ -35,21 +35,23 @@ inline HeapWord* objArrayOopDesc::base() const { return (HeapWord*) arrayOopDesc
inline HeapWord* objArrayOopDesc::base_raw() const { return (HeapWord*) arrayOopDesc::base_raw(T_OBJECT); }
template <class T> T* objArrayOopDesc::obj_at_addr(int index) const {
assert(is_within_bounds(index), "index out of bounds");
assert(is_within_bounds(index), "index %d out of bounds %d", index, length());
return &((T*)base())[index];
}
template <class T> T* objArrayOopDesc::obj_at_addr_raw(int index) const {
assert(is_within_bounds(index), "index out of bounds");
assert(is_within_bounds(index), "index %d out of bounds %d", index, length());
return &((T*)base_raw())[index];
}
inline oop objArrayOopDesc::obj_at(int index) const {
assert(is_within_bounds(index), "index %d out of bounds %d", index, length());
ptrdiff_t offset = UseCompressedOops ? obj_at_offset<narrowOop>(index) : obj_at_offset<oop>(index);
return HeapAccess<IS_ARRAY>::oop_load_at(as_oop(), offset);
}
inline void objArrayOopDesc::obj_at_put(int index, oop value) {
assert(is_within_bounds(index), "index %d out of bounds %d", index, length());
ptrdiff_t offset = UseCompressedOops ? obj_at_offset<narrowOop>(index) : obj_at_offset<oop>(index);
HeapAccess<IS_ARRAY>::oop_store_at(as_oop(), offset, value);
}