copy_sparc.hpp revision 1472:c18cbe5936b8
1218885Sdim/* 2218885Sdim * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. 3218885Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4218885Sdim * 5218885Sdim * This code is free software; you can redistribute it and/or modify it 6218885Sdim * under the terms of the GNU General Public License version 2 only, as 7218885Sdim * published by the Free Software Foundation. 8218885Sdim * 9218885Sdim * This code is distributed in the hope that it will be useful, but WITHOUT 10218885Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11218885Sdim * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12218885Sdim * version 2 for more details (a copy is included in the LICENSE file that 13218885Sdim * accompanied this code). 14218885Sdim * 15218885Sdim * You should have received a copy of the GNU General Public License version 16234353Sdim * 2 along with this work; if not, write to the Free Software Foundation, 17218885Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18218885Sdim * 19218885Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20218885Sdim * or visit www.oracle.com if you need additional information or have any 21218885Sdim * questions. 22218885Sdim * 23218885Sdim */ 24218885Sdim 25263508Sdim// Inline functions for memory copy and fill. 26263508Sdim 27263508Sdimstatic void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { 28263508Sdim (void)memmove(to, from, count * HeapWordSize); 29263508Sdim} 30263508Sdim 31263508Sdimstatic void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { 32249423Sdim switch (count) { 33263508Sdim case 8: to[7] = from[7]; 34263508Sdim case 7: to[6] = from[6]; 35263508Sdim case 6: to[5] = from[5]; 36263508Sdim case 5: to[4] = from[4]; 37263508Sdim case 4: to[3] = from[3]; 38263508Sdim case 3: to[2] = from[2]; 39249423Sdim case 2: to[1] = from[1]; 40263508Sdim case 1: to[0] = from[0]; 41263508Sdim case 0: break; 42263508Sdim default: (void)memcpy(to, from, count * HeapWordSize); 43263508Sdim break; 44249423Sdim } 45218885Sdim} 46218885Sdim 47263508Sdimstatic void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) { 48263508Sdim switch (count) { 49263508Sdim case 8: to[7] = from[7]; 50263508Sdim case 7: to[6] = from[6]; 51263508Sdim case 6: to[5] = from[5]; 52263508Sdim case 5: to[4] = from[4]; 53263508Sdim case 4: to[3] = from[3]; 54263508Sdim case 3: to[2] = from[2]; 55263508Sdim case 2: to[1] = from[1]; 56263508Sdim case 1: to[0] = from[0]; 57263508Sdim case 0: break; 58263508Sdim default: while (count-- > 0) { 59218885Sdim *to++ = *from++; 60218885Sdim } 61218885Sdim break; 62218885Sdim } 63218885Sdim} 64218885Sdim 65218885Sdimstatic void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { 66218885Sdim (void)memmove(to, from, count * HeapWordSize); 67218885Sdim} 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