< prev index next >

src/hotspot/share/oops/objArrayKlass.cpp

Print this page
rev 49887 : 8201593: Print array length in ArrayIndexOutOfBoundsException.
Reviewed-by: dholmes, mdoerr


 234     } else {
 235       // slow case: need individual subtype checks
 236       // note: don't use obj_at_put below because it includes a redundant store check
 237       if (!HeapAccess<ARRAYCOPY_DISJOINT | ARRAYCOPY_CHECKCAST>::oop_arraycopy(s, d, src, dst, length)) {
 238         THROW(vmSymbols::java_lang_ArrayStoreException());
 239       }
 240     }
 241   }
 242 }
 243 
 244 void ObjArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d,
 245                                int dst_pos, int length, TRAPS) {
 246   assert(s->is_objArray(), "must be obj array");
 247 
 248   if (!d->is_objArray()) {
 249     THROW(vmSymbols::java_lang_ArrayStoreException());
 250   }
 251 
 252   // Check is all offsets and lengths are non negative
 253   if (src_pos < 0 || dst_pos < 0 || length < 0) {
 254     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());












 255   }
 256   // Check if the ranges are valid
 257   if  ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
 258      || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
 259     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());










 260   }
 261 
 262   // Special case. Boundary cases must be checked first
 263   // 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(),
 265   // points to the right of the last element.
 266   if (length==0) {
 267     return;
 268   }
 269   if (UseCompressedOops) {
 270     narrowOop* const src = objArrayOop(s)->obj_at_addr<narrowOop>(src_pos);
 271     narrowOop* const dst = objArrayOop(d)->obj_at_addr<narrowOop>(dst_pos);
 272     do_copy<narrowOop>(s, src, d, dst, length, CHECK);
 273   } else {
 274     oop* const src = objArrayOop(s)->obj_at_addr<oop>(src_pos);
 275     oop* const dst = objArrayOop(d)->obj_at_addr<oop>(dst_pos);
 276     do_copy<oop> (s, src, d, dst, length, CHECK);
 277   }
 278 }
 279 




 234     } else {
 235       // slow case: need individual subtype checks
 236       // note: don't use obj_at_put below because it includes a redundant store check
 237       if (!HeapAccess<ARRAYCOPY_DISJOINT | ARRAYCOPY_CHECKCAST>::oop_arraycopy(s, d, src, dst, length)) {
 238         THROW(vmSymbols::java_lang_ArrayStoreException());
 239       }
 240     }
 241   }
 242 }
 243 
 244 void ObjArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d,
 245                                int dst_pos, int length, TRAPS) {
 246   assert(s->is_objArray(), "must be obj array");
 247 
 248   if (!d->is_objArray()) {
 249     THROW(vmSymbols::java_lang_ArrayStoreException());
 250   }
 251 
 252   // Check is all offsets and lengths are non negative
 253   if (src_pos < 0 || dst_pos < 0 || length < 0) {
 254     // Pass specific exception reason.
 255     ResourceMark rm;
 256     stringStream ss;
 257     if (src_pos < 0) {
 258       ss.print("arraycopy source index %i out of bounds for object array[%i].",
 259                src_pos, s->length());
 260     } else if (dst_pos < 0) {
 261       ss.print("arraycopy destination index %i out of bounds for object array[%i].",
 262                dst_pos, d->length());
 263     } else {
 264       ss.print("arraycopy length %i is negative.", length);
 265     }
 266     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
 267   }
 268   // Check if the ranges are valid
 269   if ((((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) ||
 270       (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length())) {
 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[%i].",
 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[%i].",
 279                (unsigned int) length + (unsigned int) dst_pos, d->length());
 280     }
 281     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
 282   }
 283 
 284   // Special case. Boundary cases must be checked first
 285   // This allows the following call: copy_array(s, s.length(), d.length(), 0).
 286   // This is correct, since the position is supposed to be an 'in between point', i.e., s.length(),
 287   // points to the right of the last element.
 288   if (length==0) {
 289     return;
 290   }
 291   if (UseCompressedOops) {
 292     narrowOop* const src = objArrayOop(s)->obj_at_addr<narrowOop>(src_pos);
 293     narrowOop* const dst = objArrayOop(d)->obj_at_addr<narrowOop>(dst_pos);
 294     do_copy<narrowOop>(s, src, d, dst, length, CHECK);
 295   } else {
 296     oop* const src = objArrayOop(s)->obj_at_addr<oop>(src_pos);
 297     oop* const dst = objArrayOop(d)->obj_at_addr<oop>(dst_pos);
 298     do_copy<oop> (s, src, d, dst, length, CHECK);
 299   }
 300 }
 301 


< prev index next >