src/hotspot/share/c1/c1_Runtime1.cpp
changeset 49470 a273b521a559
parent 49449 ef5d5d343e2a
child 49480 d7df2dd501ce
equal deleted inserted replaced
49469:1708db7f94c6 49470:a273b521a559
  1356   // for now we just print out the block id
  1356   // for now we just print out the block id
  1357   tty->print("%d ", block_id);
  1357   tty->print("%d ", block_id);
  1358 JRT_END
  1358 JRT_END
  1359 
  1359 
  1360 
  1360 
  1361 // Array copy return codes.
       
  1362 enum {
       
  1363   ac_failed = -1, // arraycopy failed
       
  1364   ac_ok = 0       // arraycopy succeeded
       
  1365 };
       
  1366 
       
  1367 
       
  1368 // Below length is the # elements copied.
       
  1369 template <class T> int obj_arraycopy_work(oopDesc* src, T* src_addr,
       
  1370                                           oopDesc* dst, T* dst_addr,
       
  1371                                           int length) {
       
  1372   if (src == dst) {
       
  1373     // same object, no check
       
  1374     HeapAccess<>::oop_arraycopy(arrayOop(src), arrayOop(dst), src_addr, dst_addr, length);
       
  1375     return ac_ok;
       
  1376   } else {
       
  1377     Klass* bound = ObjArrayKlass::cast(dst->klass())->element_klass();
       
  1378     Klass* stype = ObjArrayKlass::cast(src->klass())->element_klass();
       
  1379     if (stype == bound || stype->is_subtype_of(bound)) {
       
  1380       // Elements are guaranteed to be subtypes, so no check necessary
       
  1381       HeapAccess<ARRAYCOPY_DISJOINT>::oop_arraycopy(arrayOop(src), arrayOop(dst), src_addr, dst_addr, length);
       
  1382       return ac_ok;
       
  1383     }
       
  1384   }
       
  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))
  1361 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
  1362   // had to return int instead of bool, otherwise there may be a mismatch
  1424   // between the C calling convention and the Java one.
  1363   // 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
  1364   // 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
  1365   // JVM takes the whole %eax as the return value, which may misinterpret