duke@435: /* trims@1907: * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: duke@435: // Inline functions for memory copy and fill. duke@435: duke@435: static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { duke@435: (void)memmove(to, from, count * HeapWordSize); duke@435: } duke@435: duke@435: static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { duke@435: switch (count) { duke@435: case 8: to[7] = from[7]; duke@435: case 7: to[6] = from[6]; duke@435: case 6: to[5] = from[5]; duke@435: case 5: to[4] = from[4]; duke@435: case 4: to[3] = from[3]; duke@435: case 3: to[2] = from[2]; duke@435: case 2: to[1] = from[1]; duke@435: case 1: to[0] = from[0]; duke@435: case 0: break; duke@435: default: (void)memcpy(to, from, count * HeapWordSize); duke@435: break; duke@435: } duke@435: } duke@435: duke@435: static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) { duke@435: switch (count) { duke@435: case 8: to[7] = from[7]; duke@435: case 7: to[6] = from[6]; duke@435: case 6: to[5] = from[5]; duke@435: case 5: to[4] = from[4]; duke@435: case 4: to[3] = from[3]; duke@435: case 3: to[2] = from[2]; duke@435: case 2: to[1] = from[1]; duke@435: case 1: to[0] = from[0]; duke@435: case 0: break; duke@435: default: while (count-- > 0) { duke@435: *to++ = *from++; duke@435: } duke@435: break; duke@435: } duke@435: } duke@435: duke@435: static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { duke@435: (void)memmove(to, from, count * HeapWordSize); duke@435: } duke@435: duke@435: static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { duke@435: pd_disjoint_words(from, to, count); duke@435: } duke@435: duke@435: static void pd_conjoint_bytes(void* from, void* to, size_t count) { duke@435: (void)memmove(to, from, count); duke@435: } duke@435: duke@435: static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) { duke@435: (void)memmove(to, from, count); duke@435: } duke@435: duke@435: static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { duke@435: // FIXME duke@435: (void)memmove(to, from, count << LogBytesPerShort); duke@435: } duke@435: duke@435: static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) { duke@435: // FIXME duke@435: (void)memmove(to, from, count << LogBytesPerInt); duke@435: } duke@435: duke@435: static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) { duke@435: #ifdef _LP64 duke@435: assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size"); duke@435: pd_conjoint_oops_atomic((oop*)from, (oop*)to, count); duke@435: #else duke@435: // Guarantee use of ldd/std via some asm code, because compiler won't. duke@435: // See solaris_sparc.il. duke@435: _Copy_conjoint_jlongs_atomic(from, to, count); duke@435: #endif duke@435: } duke@435: duke@435: static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) { duke@435: // Do better than this: inline memmove body NEEDS CLEANUP duke@435: if (from > to) { duke@435: while (count-- > 0) { duke@435: // Copy forwards duke@435: *to++ = *from++; duke@435: } duke@435: } else { duke@435: from += count - 1; duke@435: to += count - 1; duke@435: while (count-- > 0) { duke@435: // Copy backwards duke@435: *to-- = *from--; duke@435: } duke@435: } duke@435: } duke@435: duke@435: static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) { duke@435: pd_conjoint_bytes_atomic(from, to, count); duke@435: } duke@435: duke@435: static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) { duke@435: pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count); duke@435: } duke@435: duke@435: static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) { duke@435: pd_conjoint_jints_atomic((jint*)from, (jint*)to, count); duke@435: } duke@435: duke@435: static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) { duke@435: pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count); duke@435: } duke@435: duke@435: static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) { duke@435: pd_conjoint_oops_atomic((oop*)from, (oop*)to, count); duke@435: } duke@435: duke@435: static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) { coleenp@548: #ifdef _LP64 coleenp@548: guarantee(mask_bits((uintptr_t)tohw, right_n_bits(LogBytesPerLong)) == 0, coleenp@548: "unaligned fill words"); coleenp@548: julong* to = (julong*)tohw; coleenp@548: julong v = ((julong)value << 32) | value; coleenp@548: while (count-- > 0) { coleenp@548: *to++ = v; coleenp@548: } coleenp@548: #else // _LP64 coleenp@548: juint* to = (juint*)tohw; coleenp@548: while (count-- > 0) { coleenp@548: *to++ = value; coleenp@548: } coleenp@548: #endif // _LP64 duke@435: } duke@435: duke@435: static void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) { kvn@1926: assert(MinObjAlignmentInBytes >= BytesPerLong, "need alternate implementation"); duke@435: duke@435: julong* to = (julong*)tohw; duke@435: julong v = ((julong)value << 32) | value; duke@435: // If count is odd, odd will be equal to 1 on 32-bit platform duke@435: // and be equal to 0 on 64-bit platform. duke@435: size_t odd = count % (BytesPerLong / HeapWordSize) ; duke@435: kvn@1926: size_t aligned_count = align_object_offset(count - odd) / HeapWordsPerLong; duke@435: julong* end = ((julong*)tohw) + aligned_count - 1; duke@435: while (to <= end) { duke@435: DEBUG_ONLY(count -= BytesPerLong / HeapWordSize ;) duke@435: *to++ = v; duke@435: } duke@435: assert(count == odd, "bad bounds on loop filling to aligned words"); duke@435: if (odd) { duke@435: *((juint*)to) = value; duke@435: duke@435: } duke@435: } duke@435: duke@435: static void pd_fill_to_bytes(void* to, size_t count, jubyte value) { duke@435: (void)memset(to, value, count); duke@435: } duke@435: duke@435: static void pd_zero_to_words(HeapWord* tohw, size_t count) { duke@435: pd_fill_to_words(tohw, count, 0); duke@435: } duke@435: duke@435: static void pd_zero_to_bytes(void* to, size_t count) { duke@435: (void)memset(to, 0, count); duke@435: }