1 /* 2 * Copyright (c) 2003, 2010, 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 * 23 */ 24 25 #ifndef OS_CPU_WINDOWS_X86_VM_COPY_WINDOWS_X86_INLINE_HPP 26 #define OS_CPU_WINDOWS_X86_VM_COPY_WINDOWS_X86_INLINE_HPP 27 28 static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { 29 (void)memmove(to, from, count * HeapWordSize); 30 } 31 32 static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { 33 #ifdef AMD64 34 switch (count) { 35 case 8: to[7] = from[7]; 36 case 7: to[6] = from[6]; 37 case 6: to[5] = from[5]; 38 case 5: to[4] = from[4]; 39 case 4: to[3] = from[3]; 40 case 3: to[2] = from[2]; 41 case 2: to[1] = from[1]; 42 case 1: to[0] = from[0]; 43 case 0: break; 44 default: 45 (void)memcpy(to, from, count * HeapWordSize); 46 break; 47 } 48 #else 49 (void)memcpy(to, from, count * HeapWordSize); 50 #endif // AMD64 51 } 52 53 static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) { 54 switch (count) { 55 case 8: to[7] = from[7]; 56 case 7: to[6] = from[6]; 57 case 6: to[5] = from[5]; 58 case 5: to[4] = from[4]; 59 case 4: to[3] = from[3]; 60 case 3: to[2] = from[2]; 61 case 2: to[1] = from[1]; 62 case 1: to[0] = from[0]; 63 case 0: break; 64 default: while (count-- > 0) { 65 *to++ = *from++; 66 } 67 break; 68 } 69 } 70 71 static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { 72 (void)memmove(to, from, count * HeapWordSize); 73 } 74 75 static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { 76 pd_disjoint_words(from, to, count); 77 } 78 79 static void pd_conjoint_bytes(void* from, void* to, size_t count) { 80 (void)memmove(to, from, count); 81 } 82 83 static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) { 84 pd_conjoint_bytes(from, to, count); 85 } 86 87 static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { 88 // FIXME 89 (void)memmove(to, from, count << LogBytesPerShort); 90 } 91 92 static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) { 93 // FIXME 94 (void)memmove(to, from, count << LogBytesPerInt); 95 } 96 97 static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) { 98 #ifdef AMD64 99 assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size"); 100 pd_conjoint_oops_atomic((oop*)from, (oop*)to, count); 101 #else 102 // Guarantee use of fild/fistp or xmm regs via some asm code, because compilers won't. 103 __asm { 104 mov eax, from; 105 mov edx, to; 106 mov ecx, count; 107 cmp eax, edx; 108 jbe downtest; 109 jmp uptest; 110 up: 111 fild qword ptr [eax]; 112 fistp qword ptr [edx]; 113 add eax, 8; 114 add edx, 8; 115 uptest: 116 sub ecx, 1; 117 jge up; 118 jmp done; 119 down: 120 fild qword ptr [eax][ecx*8]; 121 fistp qword ptr [edx][ecx*8]; 122 downtest: 123 sub ecx, 1; 124 jge down; 125 done:; 126 } 127 #endif // AMD64 128 } 129 130 static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) { 131 // Do better than this: inline memmove body NEEDS CLEANUP 132 if (from > to) { 133 while (count-- > 0) { 134 // Copy forwards 135 *to++ = *from++; 136 } 137 } else { 138 from += count - 1; 139 to += count - 1; 140 while (count-- > 0) { 141 // Copy backwards 142 *to-- = *from--; 143 } 144 } 145 } 146 147 static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) { 148 #ifdef AMD64 149 pd_conjoint_bytes_atomic(from, to, count); 150 #else 151 pd_conjoint_bytes(from, to, count); 152 #endif // AMD64 153 } 154 155 static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) { 156 pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count); 157 } 158 159 static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) { 160 pd_conjoint_jints_atomic((jint*)from, (jint*)to, count); 161 } 162 163 static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) { 164 pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count); 165 } 166 167 static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) { 168 pd_conjoint_oops_atomic((oop*)from, (oop*)to, count); 169 } 170 171 #endif // OS_CPU_WINDOWS_X86_VM_COPY_WINDOWS_X86_INLINE_HPP