249 THROW(vmSymbols::java_lang_ArrayStoreException()); |
249 THROW(vmSymbols::java_lang_ArrayStoreException()); |
250 } |
250 } |
251 |
251 |
252 // Check is all offsets and lengths are non negative |
252 // Check is all offsets and lengths are non negative |
253 if (src_pos < 0 || dst_pos < 0 || length < 0) { |
253 if (src_pos < 0 || dst_pos < 0 || length < 0) { |
254 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); |
254 // Pass specific exception reason. |
|
255 ResourceMark rm; |
|
256 stringStream ss; |
|
257 if (src_pos < 0) { |
|
258 ss.print("arraycopy: source index %d out of bounds for object array[%d]", |
|
259 src_pos, s->length()); |
|
260 } else if (dst_pos < 0) { |
|
261 ss.print("arraycopy: destination index %d out of bounds for object array[%d]", |
|
262 dst_pos, d->length()); |
|
263 } else { |
|
264 ss.print("arraycopy: length %d is negative", length); |
|
265 } |
|
266 THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string()); |
255 } |
267 } |
256 // Check if the ranges are valid |
268 // Check if the ranges are valid |
257 if ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) |
269 if ((((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) || |
258 || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) { |
270 (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length())) { |
259 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); |
271 // Pass specific exception reason. |
|
272 ResourceMark rm; |
|
273 stringStream ss; |
|
274 if (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) { |
|
275 ss.print("arraycopy: last source index %u out of bounds for object array[%d]", |
|
276 (unsigned int) length + (unsigned int) src_pos, s->length()); |
|
277 } else { |
|
278 ss.print("arraycopy: last destination index %u out of bounds for object array[%d]", |
|
279 (unsigned int) length + (unsigned int) dst_pos, d->length()); |
|
280 } |
|
281 THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string()); |
260 } |
282 } |
261 |
283 |
262 // Special case. Boundary cases must be checked first |
284 // Special case. Boundary cases must be checked first |
263 // This allows the following call: copy_array(s, s.length(), d.length(), 0). |
285 // This allows the following call: copy_array(s, s.length(), d.length(), 0). |
264 // This is correct, since the position is supposed to be an 'in between point', i.e., s.length(), |
286 // This is correct, since the position is supposed to be an 'in between point', i.e., s.length(), |