< prev index next >

src/hotspot/share/oops/typeArrayKlass.cpp

Print this page
rev 49800 : 8201593: Print array length in ArrayIndexOutOfBoundsException.


 121 }
 122 
 123 oop TypeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {
 124   // For typeArrays this is only called for the last dimension
 125   assert(rank == 1, "just checking");
 126   int length = *last_size;
 127   return allocate(length, THREAD);
 128 }
 129 
 130 
 131 void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
 132   assert(s->is_typeArray(), "must be type array");
 133 
 134   // Check destination
 135   if (!d->is_typeArray() || element_type() != TypeArrayKlass::cast(d->klass())->element_type()) {
 136     THROW(vmSymbols::java_lang_ArrayStoreException());
 137   }
 138 
 139   // Check is all offsets and lengths are non negative
 140   if (src_pos < 0 || dst_pos < 0 || length < 0) {
 141     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());











 142   }
 143   // Check if the ranges are valid
 144   if  ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
 145      || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
 146     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());








 147   }
 148   // Check zero copy
 149   if (length == 0)
 150     return;
 151 
 152   // This is an attempt to make the copy_array fast.
 153   int l2es = log2_element_size();
 154   int ihs = array_header_in_bytes() / wordSize;
 155   void* src = (char*) (s->base(element_type())) + ((size_t)src_pos << l2es);
 156   void* dst = (char*) (d->base(element_type())) + ((size_t)dst_pos << l2es);
 157   HeapAccess<ARRAYCOPY_ATOMIC>::arraycopy(s, d, src, dst, (size_t)length << l2es);
 158 }
 159 
 160 
 161 // create a klass of array holding typeArrays
 162 Klass* TypeArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
 163   int dim = dimension();
 164   assert(dim <= n, "check order of chain");
 165     if (dim == n)
 166       return this;




 121 }
 122 
 123 oop TypeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {
 124   // For typeArrays this is only called for the last dimension
 125   assert(rank == 1, "just checking");
 126   int length = *last_size;
 127   return allocate(length, THREAD);
 128 }
 129 
 130 
 131 void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
 132   assert(s->is_typeArray(), "must be type array");
 133 
 134   // Check destination
 135   if (!d->is_typeArray() || element_type() != TypeArrayKlass::cast(d->klass())->element_type()) {
 136     THROW(vmSymbols::java_lang_ArrayStoreException());
 137   }
 138 
 139   // Check is all offsets and lengths are non negative
 140   if (src_pos < 0 || dst_pos < 0 || length < 0) {
 141     // Pass specific exception reason.
 142     ResourceMark rm;
 143     stringStream ss;
 144     if (src_pos < 0) {
 145       ss.print("while trying to copy from index %i of a type array with length %i", src_pos, s->length());
 146     } else if (dst_pos < 0) {
 147       ss.print("while trying to copy to index %i of a type array with length %i", dst_pos, d->length());
 148     } else {
 149       ss.print("while trying to copy a negative range %i from a type array with length %i to a type array with length %i",
 150         length, s->length(), d->length());
 151     }
 152     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
 153   }
 154   // Check if the ranges are valid
 155   if  ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
 156      || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
 157     // Pass specific exception reason.
 158     ResourceMark rm;
 159     stringStream ss;
 160     if (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) {
 161       ss.print("while trying to copy from index %u of a type array with length %i", (unsigned int) length + (unsigned int) src_pos, s->length());
 162     } else {
 163       ss.print("while trying to copy to index %u of a type array with length %i", (unsigned int) length + (unsigned int) dst_pos, d->length());
 164     }
 165     THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());
 166   }
 167   // Check zero copy
 168   if (length == 0)
 169     return;
 170 
 171   // This is an attempt to make the copy_array fast.
 172   int l2es = log2_element_size();
 173   int ihs = array_header_in_bytes() / wordSize;
 174   void* src = (char*) (s->base(element_type())) + ((size_t)src_pos << l2es);
 175   void* dst = (char*) (d->base(element_type())) + ((size_t)dst_pos << l2es);
 176   HeapAccess<ARRAYCOPY_ATOMIC>::arraycopy(s, d, src, dst, (size_t)length << l2es);
 177 }
 178 
 179 
 180 // create a klass of array holding typeArrays
 181 Klass* TypeArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
 182   int dim = dimension();
 183   assert(dim <= n, "check order of chain");
 184     if (dim == n)
 185       return this;


< prev index next >