201 ArrayKlass* ak = ArrayKlass::cast(ld_klass);
202 oop sub_array = ak->multi_allocate(rank-1, &sizes[1], CHECK_NULL);
203 h_array->obj_at_put(index, sub_array);
204 }
205 } else {
206 // Since this array dimension has zero length, nothing will be
207 // allocated, however the lower dimension values must be checked
208 // for illegal values.
209 for (int i = 0; i < rank - 1; ++i) {
210 sizes += 1;
211 if (*sizes < 0) {
212 THROW_MSG_0(vmSymbols::java_lang_NegativeArraySizeException(), err_msg("%d", *sizes));
213 }
214 }
215 }
216 }
217 return h_array();
218 }
219
220 // Either oop or narrowOop depending on UseCompressedOops.
221 template <class T> void ObjArrayKlass::do_copy(arrayOop s, T* src,
222 arrayOop d, T* dst, int length, TRAPS) {
223 if (oopDesc::equals(s, d)) {
224 // since source and destination are equal we do not need conversion checks.
225 assert(length > 0, "sanity check");
226 HeapAccess<>::oop_arraycopy(s, d, src, dst, length);
227 } else {
228 // We have to make sure all elements conform to the destination array
229 Klass* bound = ObjArrayKlass::cast(d->klass())->element_klass();
230 Klass* stype = ObjArrayKlass::cast(s->klass())->element_klass();
231 if (stype == bound || stype->is_subtype_of(bound)) {
232 // elements are guaranteed to be subtypes, so no check necessary
233 HeapAccess<ARRAYCOPY_DISJOINT>::oop_arraycopy(s, d, src, dst, length);
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) {
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());
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
302
303 Klass* ObjArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
304
305 assert(dimension() <= n, "check order of chain");
306 int dim = dimension();
307 if (dim == n) return this;
308
309 // lock-free read needs acquire semantics
310 if (higher_dimension_acquire() == NULL) {
311 if (or_null) return NULL;
312
313 ResourceMark rm;
314 JavaThread *jt = (JavaThread *)THREAD;
315 {
316 MutexLocker mc(Compile_lock, THREAD); // for vtables
317 // Ensure atomic creation of higher dimensions
318 MutexLocker mu(MultiArray_lock, THREAD);
|
201 ArrayKlass* ak = ArrayKlass::cast(ld_klass);
202 oop sub_array = ak->multi_allocate(rank-1, &sizes[1], CHECK_NULL);
203 h_array->obj_at_put(index, sub_array);
204 }
205 } else {
206 // Since this array dimension has zero length, nothing will be
207 // allocated, however the lower dimension values must be checked
208 // for illegal values.
209 for (int i = 0; i < rank - 1; ++i) {
210 sizes += 1;
211 if (*sizes < 0) {
212 THROW_MSG_0(vmSymbols::java_lang_NegativeArraySizeException(), err_msg("%d", *sizes));
213 }
214 }
215 }
216 }
217 return h_array();
218 }
219
220 // Either oop or narrowOop depending on UseCompressedOops.
221 template <class T> void ObjArrayKlass::do_copy(arrayOop s, size_t src_offset,
222 arrayOop d, size_t dst_offset, int length, TRAPS) {
223 if (oopDesc::equals(s, d)) {
224 // since source and destination are equal we do not need conversion checks.
225 assert(length > 0, "sanity check");
226 ArrayAccess<>::template oop_arraycopy<T>(s, src_offset, d, dst_offset, length);
227 } else {
228 // We have to make sure all elements conform to the destination array
229 Klass* bound = ObjArrayKlass::cast(d->klass())->element_klass();
230 Klass* stype = ObjArrayKlass::cast(s->klass())->element_klass();
231 if (stype == bound || stype->is_subtype_of(bound)) {
232 // elements are guaranteed to be subtypes, so no check necessary
233 ArrayAccess<ARRAYCOPY_DISJOINT>::template oop_arraycopy<T>(s, src_offset, d, dst_offset, length);
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 (!ArrayAccess<ARRAYCOPY_DISJOINT | ARRAYCOPY_CHECKCAST>::template oop_arraycopy<T>(s, src_offset, d, dst_offset, 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) {
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());
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 size_t src_offset = (size_t) objArrayOopDesc::obj_at_offset<narrowOop>(src_pos);
293 size_t dst_offset = (size_t) objArrayOopDesc::obj_at_offset<narrowOop>(dst_pos);
294 assert(arrayOopDesc::obj_offset_to_raw<narrowOop>(s, src_offset, NULL) == objArrayOop(s)->obj_at_addr<narrowOop>(src_pos), "sanity");
295 assert(arrayOopDesc::obj_offset_to_raw<narrowOop>(d, dst_offset, NULL) == objArrayOop(d)->obj_at_addr<narrowOop>(dst_pos), "sanity");
296 do_copy<narrowOop>(s, src_offset, d, dst_offset, length, CHECK);
297 } else {
298 size_t src_offset = (size_t) objArrayOopDesc::obj_at_offset<oop>(src_pos);
299 size_t dst_offset = (size_t) objArrayOopDesc::obj_at_offset<oop>(dst_pos);
300 assert(arrayOopDesc::obj_offset_to_raw<oop>(s, src_offset, NULL) == objArrayOop(s)->obj_at_addr<oop>(src_pos), "sanity");
301 assert(arrayOopDesc::obj_offset_to_raw<oop>(d, dst_offset, NULL) == objArrayOop(d)->obj_at_addr<oop>(dst_pos), "sanity");
302 do_copy<oop> (s, src_offset, d, dst_offset, length, CHECK);
303 }
304 }
305
306
307 Klass* ObjArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
308
309 assert(dimension() <= n, "check order of chain");
310 int dim = dimension();
311 if (dim == n) return this;
312
313 // lock-free read needs acquire semantics
314 if (higher_dimension_acquire() == NULL) {
315 if (or_null) return NULL;
316
317 ResourceMark rm;
318 JavaThread *jt = (JavaThread *)THREAD;
319 {
320 MutexLocker mc(Compile_lock, THREAD); // for vtables
321 // Ensure atomic creation of higher dimensions
322 MutexLocker mu(MultiArray_lock, THREAD);
|