1 /*
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 memmove(dst_addr, src_addr, length << l2es);
1412 return ac_ok;
1413 } else if (src->is_objArray() && dst->is_objArray()) {
1414 if (UseCompressedOops) {
1415 narrowOop *src_addr = objArrayOop(src)->obj_at_addr<narrowOop>(src_pos);
1416 narrowOop *dst_addr = objArrayOop(dst)->obj_at_addr<narrowOop>(dst_pos);
1417 return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1418 } else {
1419 oop *src_addr = objArrayOop(src)->obj_at_addr<oop>(src_pos);
1420 oop *dst_addr = objArrayOop(dst)->obj_at_addr<oop>(dst_pos);
1421 return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);
1422 }
1423 }
1424 return ac_failed;
1425 JRT_END
1426
1427
1428 JRT_LEAF(int, Runtime1::is_instance_of(oopDesc* mirror, oopDesc* obj))
1429 // had to return int instead of bool, otherwise there may be a mismatch
1430 // between the C calling convention and the Java one.
1431 // e.g., on x86, GCC may clear only %al when returning a bool false, but
|
1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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
|