1/*
2 * Copyright (c) 2019, Red Hat, Inc. 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 */
23
24#ifndef SHARE_GC_SHARED_BARRIERSET_INLINE_HPP
25#define SHARE_GC_SHARED_BARRIERSET_INLINE_HPP
26
27#include "gc/shared/barrierSet.hpp"
28#include "oops/accessDecorators.hpp"
29#include "oops/arrayOop.hpp"
30#include "oops/compressedOops.inline.hpp"
31#include "oops/objArrayOop.inline.hpp"
32#include "oops/oop.hpp"
33
34template <DecoratorSet decorators, typename BarrierSetT>
35template <typename T>
36inline bool BarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
37 arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
38 size_t length) {
39 T* src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
40 T* dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
41
42 if (!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
43 // Covariant, copy without checks
44 return Raw::oop_arraycopy(NULL, 0, src, NULL, 0, dst, length);
45 }
46
47 // Copy each element with checking casts
48 Klass* const dst_klass = objArrayOop(dst_obj)->element_klass();
49 for (const T* const end = src + length; src < end; src++, dst++) {
50 const T elem = *src;
51 if (!oopDesc::is_instanceof_or_null(CompressedOops::decode(elem), dst_klass)) {
52 return false;
53 }
54 *dst = elem;
55 }
56
57 return true;
58}
59
60#endif // SHARE_GC_SHARED_BARRIERSET_INLINE_HPP
61