1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/sparc/vm/copy_sparc.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,192 @@ 1.4 +/* 1.5 + * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// Inline functions for memory copy and fill. 1.29 + 1.30 +static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { 1.31 + (void)memmove(to, from, count * HeapWordSize); 1.32 +} 1.33 + 1.34 +static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { 1.35 + switch (count) { 1.36 + case 8: to[7] = from[7]; 1.37 + case 7: to[6] = from[6]; 1.38 + case 6: to[5] = from[5]; 1.39 + case 5: to[4] = from[4]; 1.40 + case 4: to[3] = from[3]; 1.41 + case 3: to[2] = from[2]; 1.42 + case 2: to[1] = from[1]; 1.43 + case 1: to[0] = from[0]; 1.44 + case 0: break; 1.45 + default: (void)memcpy(to, from, count * HeapWordSize); 1.46 + break; 1.47 + } 1.48 +} 1.49 + 1.50 +static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) { 1.51 + switch (count) { 1.52 + case 8: to[7] = from[7]; 1.53 + case 7: to[6] = from[6]; 1.54 + case 6: to[5] = from[5]; 1.55 + case 5: to[4] = from[4]; 1.56 + case 4: to[3] = from[3]; 1.57 + case 3: to[2] = from[2]; 1.58 + case 2: to[1] = from[1]; 1.59 + case 1: to[0] = from[0]; 1.60 + case 0: break; 1.61 + default: while (count-- > 0) { 1.62 + *to++ = *from++; 1.63 + } 1.64 + break; 1.65 + } 1.66 +} 1.67 + 1.68 +static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { 1.69 + (void)memmove(to, from, count * HeapWordSize); 1.70 +} 1.71 + 1.72 +static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { 1.73 + pd_disjoint_words(from, to, count); 1.74 +} 1.75 + 1.76 +static void pd_conjoint_bytes(void* from, void* to, size_t count) { 1.77 + (void)memmove(to, from, count); 1.78 +} 1.79 + 1.80 +static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) { 1.81 + (void)memmove(to, from, count); 1.82 +} 1.83 + 1.84 +static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { 1.85 + // FIXME 1.86 + (void)memmove(to, from, count << LogBytesPerShort); 1.87 +} 1.88 + 1.89 +static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) { 1.90 + // FIXME 1.91 + (void)memmove(to, from, count << LogBytesPerInt); 1.92 +} 1.93 + 1.94 +static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) { 1.95 +#ifdef _LP64 1.96 + assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size"); 1.97 + pd_conjoint_oops_atomic((oop*)from, (oop*)to, count); 1.98 +#else 1.99 + // Guarantee use of ldd/std via some asm code, because compiler won't. 1.100 + // See solaris_sparc.il. 1.101 + _Copy_conjoint_jlongs_atomic(from, to, count); 1.102 +#endif 1.103 +} 1.104 + 1.105 +static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) { 1.106 + // Do better than this: inline memmove body NEEDS CLEANUP 1.107 + if (from > to) { 1.108 + while (count-- > 0) { 1.109 + // Copy forwards 1.110 + *to++ = *from++; 1.111 + } 1.112 + } else { 1.113 + from += count - 1; 1.114 + to += count - 1; 1.115 + while (count-- > 0) { 1.116 + // Copy backwards 1.117 + *to-- = *from--; 1.118 + } 1.119 + } 1.120 +} 1.121 + 1.122 +static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) { 1.123 + pd_conjoint_bytes_atomic(from, to, count); 1.124 +} 1.125 + 1.126 +static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) { 1.127 + pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count); 1.128 +} 1.129 + 1.130 +static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) { 1.131 + pd_conjoint_jints_atomic((jint*)from, (jint*)to, count); 1.132 +} 1.133 + 1.134 +static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) { 1.135 + pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count); 1.136 +} 1.137 + 1.138 +static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) { 1.139 + pd_conjoint_oops_atomic((oop*)from, (oop*)to, count); 1.140 +} 1.141 + 1.142 +static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) { 1.143 +#if 0 1.144 + if (HeapWordsPerLong == 1 || 1.145 + (HeapWordsPerLong == 2 && 1.146 + mask_bits((uintptr_t)tohw, right_n_bits(LogBytesPerLong)) == 0 && 1.147 + ((count & 1) ? false : count >>= 1))) { 1.148 + julong* to = (julong*)tohw; 1.149 + julong v = ((julong)value << 32) | value; 1.150 + while (count-- > 0) { 1.151 + *to++ = v; 1.152 + } 1.153 + } else { 1.154 +#endif 1.155 + juint* to = (juint*)tohw; 1.156 + count *= HeapWordSize / BytesPerInt; 1.157 + while (count-- > 0) { 1.158 + *to++ = value; 1.159 + } 1.160 + // } 1.161 +} 1.162 + 1.163 +static void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) { 1.164 + assert(MinObjAlignmentInBytes == BytesPerLong, "need alternate implementation"); 1.165 + 1.166 + julong* to = (julong*)tohw; 1.167 + julong v = ((julong)value << 32) | value; 1.168 + // If count is odd, odd will be equal to 1 on 32-bit platform 1.169 + // and be equal to 0 on 64-bit platform. 1.170 + size_t odd = count % (BytesPerLong / HeapWordSize) ; 1.171 + 1.172 + size_t aligned_count = align_object_size(count - odd) / HeapWordsPerLong; 1.173 + julong* end = ((julong*)tohw) + aligned_count - 1; 1.174 + while (to <= end) { 1.175 + DEBUG_ONLY(count -= BytesPerLong / HeapWordSize ;) 1.176 + *to++ = v; 1.177 + } 1.178 + assert(count == odd, "bad bounds on loop filling to aligned words"); 1.179 + if (odd) { 1.180 + *((juint*)to) = value; 1.181 + 1.182 + } 1.183 +} 1.184 + 1.185 +static void pd_fill_to_bytes(void* to, size_t count, jubyte value) { 1.186 + (void)memset(to, value, count); 1.187 +} 1.188 + 1.189 +static void pd_zero_to_words(HeapWord* tohw, size_t count) { 1.190 + pd_fill_to_words(tohw, count, 0); 1.191 +} 1.192 + 1.193 +static void pd_zero_to_bytes(void* to, size_t count) { 1.194 + (void)memset(to, 0, count); 1.195 +}