< prev index next >

src/hotspot/share/c1/c1_Runtime1.cpp

Print this page
rev 49182 : 8198445: Access API for primitive/native arraycopy
rev 49183 : [mq]: 8198445-1.patch


1385   return ac_failed;
1386 }
1387 
1388 // fast and direct copy of arrays; returning -1, means that an exception may be thrown
1389 // and we did not copy anything
1390 JRT_LEAF(int, Runtime1::arraycopy(oopDesc* src, int src_pos, oopDesc* dst, int dst_pos, int length))
1391 #ifndef PRODUCT
1392   _generic_arraycopy_cnt++;        // Slow-path oop array copy
1393 #endif
1394 
1395   if (src == NULL || dst == NULL || src_pos < 0 || dst_pos < 0 || length < 0) return ac_failed;
1396   if (!dst->is_array() || !src->is_array()) return ac_failed;
1397   if ((unsigned int) arrayOop(src)->length() < (unsigned int)src_pos + (unsigned int)length) return ac_failed;
1398   if ((unsigned int) arrayOop(dst)->length() < (unsigned int)dst_pos + (unsigned int)length) return ac_failed;
1399 
1400   if (length == 0) return ac_ok;
1401   if (src->is_typeArray()) {
1402     Klass* klass_oop = src->klass();
1403     if (klass_oop != dst->klass()) return ac_failed;
1404     TypeArrayKlass* klass = TypeArrayKlass::cast(klass_oop);
1405     const int l2es = klass->log2_element_size();
1406     const int ihs = klass->array_header_in_bytes() / wordSize;
1407     char* src_addr = (char*) ((oopDesc**)src + ihs) + (src_pos << l2es);
1408     char* dst_addr = (char*) ((oopDesc**)dst + ihs) + (dst_pos << l2es);
1409     // Potential problem: memmove is not guaranteed to be word atomic
1410     // Revisit in Merlin
1411     return HeapAccess<>::arraycopy(arrayOop(src), arrayOop(dst), src_addr, dst_addr, length << l2es) ? ac_ok : ac_failed;
1412   } else if (src->is_objArray() && dst->is_objArray()) {
1413     if (UseCompressedOops) {
1414       narrowOop *src_addr  = objArrayOop(src)->obj_at_addr<narrowOop>(src_pos);
1415       narrowOop *dst_addr  = objArrayOop(dst)->obj_at_addr<narrowOop>(dst_pos);
1416       return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1417     } else {
1418       oop *src_addr  = objArrayOop(src)->obj_at_addr<oop>(src_pos);
1419       oop *dst_addr  = objArrayOop(dst)->obj_at_addr<oop>(dst_pos);
1420       return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1421     }
1422   }
1423   return ac_failed;
1424 JRT_END
1425 
1426 
1427 JRT_LEAF(int, Runtime1::is_instance_of(oopDesc* mirror, oopDesc* obj))
1428   // had to return int instead of bool, otherwise there may be a mismatch
1429   // between the C calling convention and the Java one.
1430   // e.g., on x86, GCC may clear only %al when returning a bool false, but
1431   // JVM takes the whole %eax as the return value, which may misinterpret




1385   return ac_failed;
1386 }
1387 
1388 // fast and direct copy of arrays; returning -1, means that an exception may be thrown
1389 // and we did not copy anything
1390 JRT_LEAF(int, Runtime1::arraycopy(oopDesc* src, int src_pos, oopDesc* dst, int dst_pos, int length))
1391 #ifndef PRODUCT
1392   _generic_arraycopy_cnt++;        // Slow-path oop array copy
1393 #endif
1394 
1395   if (src == NULL || dst == NULL || src_pos < 0 || dst_pos < 0 || length < 0) return ac_failed;
1396   if (!dst->is_array() || !src->is_array()) return ac_failed;
1397   if ((unsigned int) arrayOop(src)->length() < (unsigned int)src_pos + (unsigned int)length) return ac_failed;
1398   if ((unsigned int) arrayOop(dst)->length() < (unsigned int)dst_pos + (unsigned int)length) return ac_failed;
1399 
1400   if (length == 0) return ac_ok;
1401   if (src->is_typeArray()) {
1402     Klass* klass_oop = src->klass();
1403     if (klass_oop != dst->klass()) return ac_failed;
1404     TypeArrayKlass* klass = TypeArrayKlass::cast(klass_oop);
1405     klass->copy_array(arrayOop(src), src_pos, arrayOop(dst), dst_pos, length, Thread::current());
1406     return ac_ok;





1407   } else if (src->is_objArray() && dst->is_objArray()) {
1408     if (UseCompressedOops) {
1409       narrowOop *src_addr  = objArrayOop(src)->obj_at_addr<narrowOop>(src_pos);
1410       narrowOop *dst_addr  = objArrayOop(dst)->obj_at_addr<narrowOop>(dst_pos);
1411       return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1412     } else {
1413       oop *src_addr  = objArrayOop(src)->obj_at_addr<oop>(src_pos);
1414       oop *dst_addr  = objArrayOop(dst)->obj_at_addr<oop>(dst_pos);
1415       return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1416     }
1417   }
1418   return ac_failed;
1419 JRT_END
1420 
1421 
1422 JRT_LEAF(int, Runtime1::is_instance_of(oopDesc* mirror, oopDesc* obj))
1423   // had to return int instead of bool, otherwise there may be a mismatch
1424   // between the C calling convention and the Java one.
1425   // e.g., on x86, GCC may clear only %al when returning a bool false, but
1426   // JVM takes the whole %eax as the return value, which may misinterpret


< prev index next >