1 /*
  2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2020, 2021, Huawei Technologies Co., Ltd. All rights reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #ifndef OS_CPU_LINUX_RISCV_VM_COPY_LINUX_RISCV_HPP
 27 #define OS_CPU_LINUX_RISCV_VM_COPY_LINUX_RISCV_HPP
 28 
 29 static void pd_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) {
 30   (void)memmove(to, from, count * HeapWordSize);
 31 }
 32 
 33 static inline void pd_disjoint_words_helper(const HeapWord* from, HeapWord* to, size_t count, bool is_atomic) {
 34   switch (count) {
 35     case 8:  to[7] = from[7];   // fall through
 36     case 7:  to[6] = from[6];   // fall through
 37     case 6:  to[5] = from[5];   // fall through
 38     case 5:  to[4] = from[4];   // fall through
 39     case 4:  to[3] = from[3];   // fall through
 40     case 3:  to[2] = from[2];   // fall through
 41     case 2:  to[1] = from[1];   // fall through
 42     case 1:  to[0] = from[0];   // fall through
 43     case 0:  break;
 44     default:
 45       if(is_atomic) {
 46         while (count-- > 0) { *to++ = *from++; }
 47       } else {
 48         memcpy(to, from, count * HeapWordSize);
 49       }
 50   }
 51 }
 52 
 53 static void pd_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) {
 54   pd_disjoint_words_helper(from, to, count, false);
 55 }
 56 
 57 static void pd_disjoint_words_atomic(const HeapWord* from, HeapWord* to, size_t count) {
 58   pd_disjoint_words_helper(from, to, count, true);
 59 }
 60 
 61 static void pd_aligned_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) {
 62   pd_conjoint_words(from, to, count);
 63 }
 64 
 65 static void pd_aligned_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) {
 66   pd_disjoint_words(from, to, count);
 67 }
 68 
 69 static void pd_conjoint_bytes(const void* from, void* to, size_t count) {
 70   (void)memmove(to, from, count);
 71 }
 72 
 73 static void pd_conjoint_bytes_atomic(const void* from, void* to, size_t count) {
 74   pd_conjoint_bytes(from, to, count);
 75 }
 76 
 77 static void pd_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) {
 78   _Copy_conjoint_jshorts_atomic(from, to, count);
 79 }
 80 
 81 static void pd_conjoint_jints_atomic(const jint* from, jint* to, size_t count) {
 82   _Copy_conjoint_jints_atomic(from, to, count);
 83 }
 84 
 85 static void pd_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) {
 86   _Copy_conjoint_jlongs_atomic(from, to, count);
 87 }
 88 
 89 static void pd_conjoint_oops_atomic(const oop* from, oop* to, size_t count) {
 90   assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size.");
 91   _Copy_conjoint_jlongs_atomic((const jlong*)from, (jlong*)to, count);
 92 }
 93 
 94 static void pd_arrayof_conjoint_bytes(const HeapWord* from, HeapWord* to, size_t count) {
 95   _Copy_arrayof_conjoint_bytes(from, to, count);
 96 }
 97 
 98 static void pd_arrayof_conjoint_jshorts(const HeapWord* from, HeapWord* to, size_t count) {
 99   _Copy_arrayof_conjoint_jshorts(from, to, count);
100 }
101 
102 static void pd_arrayof_conjoint_jints(const HeapWord* from, HeapWord* to, size_t count) {
103   _Copy_arrayof_conjoint_jints(from, to, count);
104 }
105 
106 static void pd_arrayof_conjoint_jlongs(const HeapWord* from, HeapWord* to, size_t count) {
107   _Copy_arrayof_conjoint_jlongs(from, to, count);
108 }
109 
110 static void pd_arrayof_conjoint_oops(const HeapWord* from, HeapWord* to, size_t count) {
111   assert(!UseCompressedOops, "foo!");
112   assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
113   _Copy_arrayof_conjoint_jlongs(from, to, count);
114 }
115 
116 #endif // OS_CPU_LINUX_RISCV_VM_COPY_LINUX_RISCV_HPP