Skip to content

Commit b772e67

Browse files
committedJul 20, 2023
8312395: Improve assertions in growableArray
Reviewed-by: dholmes, stuefe
1 parent 9fa944e commit b772e67

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
 

‎src/hotspot/share/utilities/growableArray.hpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,17 @@ class GrowableArrayView : public GrowableArrayBase {
142142
}
143143

144144
E& at(int i) {
145-
assert(0 <= i && i < _len, "illegal index");
145+
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
146146
return _data[i];
147147
}
148148

149149
E const& at(int i) const {
150-
assert(0 <= i && i < _len, "illegal index");
150+
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
151151
return _data[i];
152152
}
153153

154154
E* adr_at(int i) const {
155-
assert(0 <= i && i < _len, "illegal index");
155+
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
156156
return &_data[i];
157157
}
158158

@@ -184,7 +184,7 @@ class GrowableArrayView : public GrowableArrayBase {
184184
}
185185

186186
void at_put(int i, const E& elem) {
187-
assert(0 <= i && i < _len, "illegal index");
187+
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
188188
_data[i] = elem;
189189
}
190190

@@ -245,7 +245,7 @@ class GrowableArrayView : public GrowableArrayBase {
245245
}
246246

247247
void remove_at(int index) {
248-
assert(0 <= index && index < _len, "illegal index");
248+
assert(0 <= index && index < _len, "illegal index %d for length %d", index, _len);
249249
for (int j = index + 1; j < _len; j++) {
250250
_data[j-1] = _data[j];
251251
}
@@ -259,8 +259,8 @@ class GrowableArrayView : public GrowableArrayBase {
259259

260260
// Remove all elements in the range [start - end). The order is preserved.
261261
void remove_range(int start, int end) {
262-
assert(0 <= start, "illegal index");
263-
assert(start < end && end <= _len, "erase called with invalid range");
262+
assert(0 <= start, "illegal start index %d", start);
263+
assert(start < end && end <= _len, "erase called with invalid range (%d, %d) for length %d", start, end, _len);
264264

265265
for (int i = start, j = end; j < length(); i++, j++) {
266266
at_put(i, at(j));
@@ -270,7 +270,7 @@ class GrowableArrayView : public GrowableArrayBase {
270270

271271
// The order is changed.
272272
void delete_at(int index) {
273-
assert(0 <= index && index < _len, "illegal index");
273+
assert(0 <= index && index < _len, "illegal index %d for length %d", index, _len);
274274
if (index < --_len) {
275275
// Replace removed element with last one.
276276
_data[index] = _data[_len];
@@ -403,7 +403,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
403403
void push(const E& elem) { append(elem); }
404404

405405
E at_grow(int i, const E& fill = E()) {
406-
assert(0 <= i, "negative index");
406+
assert(0 <= i, "negative index %d", i);
407407
if (i >= this->_len) {
408408
if (i >= this->_capacity) grow(i);
409409
for (int j = this->_len; j <= i; j++)
@@ -414,7 +414,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
414414
}
415415

416416
void at_put_grow(int i, const E& elem, const E& fill = E()) {
417-
assert(0 <= i, "negative index");
417+
assert(0 <= i, "negative index %d", i);
418418
if (i >= this->_len) {
419419
if (i >= this->_capacity) grow(i);
420420
for (int j = this->_len; j < i; j++)
@@ -426,7 +426,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
426426

427427
// inserts the given element before the element at index i
428428
void insert_before(const int idx, const E& elem) {
429-
assert(0 <= idx && idx <= this->_len, "illegal index");
429+
assert(0 <= idx && idx <= this->_len, "illegal index %d for length %d", idx, this->_len);
430430
if (this->_len == this->_capacity) grow(this->_len);
431431
for (int j = this->_len - 1; j >= idx; j--) {
432432
this->_data[j + 1] = this->_data[j];
@@ -436,7 +436,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
436436
}
437437

438438
void insert_before(const int idx, const GrowableArrayView<E>* array) {
439-
assert(0 <= idx && idx <= this->_len, "illegal index");
439+
assert(0 <= idx && idx <= this->_len, "illegal index %d for length %d", idx, this->_len);
440440
int array_len = array->length();
441441
int new_len = this->_len + array_len;
442442
if (new_len >= this->_capacity) grow(new_len);

0 commit comments

Comments
 (0)