copy_sparc.hpp revision 1472:c18cbe5936b8
1/* 2 * Copyright (c) 2003, 2008, 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// Inline functions for memory copy and fill. 26 27static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { 28 (void)memmove(to, from, count * HeapWordSize); 29} 30 31static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { 32 switch (count) { 33 case 8: to[7] = from[7]; 34 case 7: to[6] = from[6]; 35 case 6: to[5] = from[5]; 36 case 5: to[4] = from[4]; 37 case 4: to[3] = from[3]; 38 case 3: to[2] = from[2]; 39 case 2: to[1] = from[1]; 40 case 1: to[0] = from[0]; 41 case 0: break; 42 default: (void)memcpy(to, from, count * HeapWordSize); 43 break; 44 } 45} 46 47static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) { 48 switch (count) { 49 case 8: to[7] = from[7]; 50 case 7: to[6] = from[6]; 51 case 6: to[5] = from[5]; 52 case 5: to[4] = from[4]; 53 case 4: to[3] = from[3]; 54 case 3: to[2] = from[2]; 55 case 2: to[1] = from[1]; 56 case 1: to[0] = from[0]; 57 case 0: break; 58 default: while (count-- > 0) { 59 *to++ = *from++; 60 } 61 break; 62 } 63} 64 65static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { 66 (void)memmove(to, from, count * HeapWordSize); 67} 68 69static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { 70 pd_disjoint_words(from, to, count); 71} 72 73static void pd_conjoint_bytes(void* from, void* to, size_t count) { 74 (void)memmove(to, from, count); 75} 76 77static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) { 78 (void)memmove(to, from, count); 79} 80 81static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { 82 // FIXME 83 (void)memmove(to, from, count << LogBytesPerShort); 84} 85 86static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) { 87 // FIXME 88 (void)memmove(to, from, count << LogBytesPerInt); 89} 90 91static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) { 92#ifdef _LP64 93 assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size"); 94 pd_conjoint_oops_atomic((oop*)from, (oop*)to, count); 95#else 96 // Guarantee use of ldd/std via some asm code, because compiler won't. 97 // See solaris_sparc.il. 98 _Copy_conjoint_jlongs_atomic(from, to, count); 99#endif 100} 101 102static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) { 103 // Do better than this: inline memmove body NEEDS CLEANUP 104 if (from > to) { 105 while (count-- > 0) { 106 // Copy forwards 107 *to++ = *from++; 108 } 109 } else { 110 from += count - 1; 111 to += count - 1; 112 while (count-- > 0) { 113 // Copy backwards 114 *to-- = *from--; 115 } 116 } 117} 118 119static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) { 120 pd_conjoint_bytes_atomic(from, to, count); 121} 122 123static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) { 124 pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count); 125} 126 127static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) { 128 pd_conjoint_jints_atomic((jint*)from, (jint*)to, count); 129} 130 131static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) { 132 pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count); 133} 134 135static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) { 136 pd_conjoint_oops_atomic((oop*)from, (oop*)to, count); 137} 138 139static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) { 140#ifdef _LP64 141 guarantee(mask_bits((uintptr_t)tohw, right_n_bits(LogBytesPerLong)) == 0, 142 "unaligned fill words"); 143 julong* to = (julong*)tohw; 144 julong v = ((julong)value << 32) | value; 145 while (count-- > 0) { 146 *to++ = v; 147 } 148#else // _LP64 149 juint* to = (juint*)tohw; 150 while (count-- > 0) { 151 *to++ = value; 152 } 153#endif // _LP64 154} 155 156static void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) { 157 assert(MinObjAlignmentInBytes == BytesPerLong, "need alternate implementation"); 158 159 julong* to = (julong*)tohw; 160 julong v = ((julong)value << 32) | value; 161 // If count is odd, odd will be equal to 1 on 32-bit platform 162 // and be equal to 0 on 64-bit platform. 163 size_t odd = count % (BytesPerLong / HeapWordSize) ; 164 165 size_t aligned_count = align_object_size(count - odd) / HeapWordsPerLong; 166 julong* end = ((julong*)tohw) + aligned_count - 1; 167 while (to <= end) { 168 DEBUG_ONLY(count -= BytesPerLong / HeapWordSize ;) 169 *to++ = v; 170 } 171 assert(count == odd, "bad bounds on loop filling to aligned words"); 172 if (odd) { 173 *((juint*)to) = value; 174 175 } 176} 177 178static void pd_fill_to_bytes(void* to, size_t count, jubyte value) { 179 (void)memset(to, value, count); 180} 181 182static void pd_zero_to_words(HeapWord* tohw, size_t count) { 183 pd_fill_to_words(tohw, count, 0); 184} 185 186static void pd_zero_to_bytes(void* to, size_t count) { 187 (void)memset(to, 0, count); 188} 189