Skip to content

Commit e80200f

Browse files
committed
8312395: Improve assertions in growableArray
Reviewed-by: clanger Backport-of: b772e67e2929afd9f9d6a4b08713e41f891667c0
1 parent 05c6ae4 commit e80200f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/hotspot/share/utilities/growableArray.hpp

+10-10
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
}
@@ -262,7 +262,7 @@ class GrowableArrayView : public GrowableArrayBase {
262262

263263
// The order is changed.
264264
void delete_at(int index) {
265-
assert(0 <= index && index < _len, "illegal index");
265+
assert(0 <= index && index < _len, "illegal index %d for length %d", index, _len);
266266
if (index < --_len) {
267267
// Replace removed element with last one.
268268
_data[index] = _data[_len];
@@ -390,7 +390,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
390390
void push(const E& elem) { append(elem); }
391391

392392
E at_grow(int i, const E& fill = E()) {
393-
assert(0 <= i, "negative index");
393+
assert(0 <= i, "negative index %d", i);
394394
if (i >= this->_len) {
395395
if (i >= this->_max) grow(i);
396396
for (int j = this->_len; j <= i; j++)
@@ -401,7 +401,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
401401
}
402402

403403
void at_put_grow(int i, const E& elem, const E& fill = E()) {
404-
assert(0 <= i, "negative index");
404+
assert(0 <= i, "negative index %d", i);
405405
if (i >= this->_len) {
406406
if (i >= this->_max) grow(i);
407407
for (int j = this->_len; j < i; j++)
@@ -413,7 +413,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
413413

414414
// inserts the given element before the element at index i
415415
void insert_before(const int idx, const E& elem) {
416-
assert(0 <= idx && idx <= this->_len, "illegal index");
416+
assert(0 <= idx && idx <= this->_len, "illegal index %d for length %d", idx, this->_len);
417417
if (this->_len == this->_max) grow(this->_len);
418418
for (int j = this->_len - 1; j >= idx; j--) {
419419
this->_data[j + 1] = this->_data[j];
@@ -423,7 +423,7 @@ class GrowableArrayWithAllocator : public GrowableArrayView<E> {
423423
}
424424

425425
void insert_before(const int idx, const GrowableArrayView<E>* array) {
426-
assert(0 <= idx && idx <= this->_len, "illegal index");
426+
assert(0 <= idx && idx <= this->_len, "illegal index %d for length %d", idx, this->_len);
427427
int array_len = array->length();
428428
int new_len = this->_len + array_len;
429429
if (new_len >= this->_max) grow(new_len);

0 commit comments

Comments
 (0)