duke@435: /* trims@2708: * Copyright (c) 2003, 2011, 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: stefank@2314: #ifndef SHARE_VM_UTILITIES_COPY_HPP stefank@2314: #define SHARE_VM_UTILITIES_COPY_HPP stefank@2314: stefank@2314: #include "runtime/stubRoutines.hpp" stefank@2314: duke@435: // Assembly code for platforms that need it. duke@435: extern "C" { duke@435: void _Copy_conjoint_words(HeapWord* from, HeapWord* to, size_t count); duke@435: void _Copy_disjoint_words(HeapWord* from, HeapWord* to, size_t count); duke@435: duke@435: void _Copy_conjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count); duke@435: void _Copy_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count); duke@435: duke@435: void _Copy_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count); duke@435: void _Copy_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count); duke@435: duke@435: void _Copy_conjoint_bytes(void* from, void* to, size_t count); duke@435: duke@435: void _Copy_conjoint_bytes_atomic (void* from, void* to, size_t count); duke@435: void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count); duke@435: void _Copy_conjoint_jints_atomic (jint* from, jint* to, size_t count); duke@435: void _Copy_conjoint_jlongs_atomic (jlong* from, jlong* to, size_t count); duke@435: void _Copy_conjoint_oops_atomic (oop* from, oop* to, size_t count); duke@435: duke@435: void _Copy_arrayof_conjoint_bytes (HeapWord* from, HeapWord* to, size_t count); duke@435: void _Copy_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count); duke@435: void _Copy_arrayof_conjoint_jints (HeapWord* from, HeapWord* to, size_t count); duke@435: void _Copy_arrayof_conjoint_jlongs (HeapWord* from, HeapWord* to, size_t count); duke@435: void _Copy_arrayof_conjoint_oops (HeapWord* from, HeapWord* to, size_t count); duke@435: } duke@435: duke@435: class Copy : AllStatic { duke@435: public: duke@435: // Block copy methods have four attributes. We don't define all possibilities. kvn@1926: // alignment: aligned to BytesPerLong duke@435: // arrayof: arraycopy operation with both operands aligned on the same duke@435: // boundary as the first element of an array of the copy unit. duke@435: // This is currently a HeapWord boundary on all platforms, except duke@435: // for long and double arrays, which are aligned on an 8-byte duke@435: // boundary on all platforms. duke@435: // arraycopy operations are implicitly atomic on each array element. duke@435: // overlap: disjoint or conjoint. duke@435: // copy unit: bytes or words (i.e., HeapWords) or oops (i.e., pointers). duke@435: // atomicity: atomic or non-atomic on the copy unit. duke@435: // duke@435: // Names are constructed thusly: duke@435: // duke@435: // [ 'aligned_' | 'arrayof_' ] duke@435: // ('conjoint_' | 'disjoint_') duke@435: // ('words' | 'bytes' | 'jshorts' | 'jints' | 'jlongs' | 'oops') duke@435: // [ '_atomic' ] duke@435: // duke@435: // Except in the arrayof case, whatever the alignment is, we assume we can copy kvn@1926: // whole alignment units. E.g., if BytesPerLong is 2x word alignment, an odd duke@435: // count may copy an extra word. In the arrayof case, we are allowed to copy duke@435: // only the number of copy units specified. kvn@1958: // kvn@1958: // All callees check count for 0. kvn@1958: // duke@435: duke@435: // HeapWords duke@435: duke@435: // Word-aligned words, conjoint, not atomic on each word duke@435: static void conjoint_words(HeapWord* from, HeapWord* to, size_t count) { duke@435: assert_params_ok(from, to, LogHeapWordSize); duke@435: pd_conjoint_words(from, to, count); duke@435: } duke@435: duke@435: // Word-aligned words, disjoint, not atomic on each word duke@435: static void disjoint_words(HeapWord* from, HeapWord* to, size_t count) { duke@435: assert_params_ok(from, to, LogHeapWordSize); duke@435: assert_disjoint(from, to, count); duke@435: pd_disjoint_words(from, to, count); duke@435: } duke@435: duke@435: // Word-aligned words, disjoint, atomic on each word duke@435: static void disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) { duke@435: assert_params_ok(from, to, LogHeapWordSize); duke@435: assert_disjoint(from, to, count); duke@435: pd_disjoint_words_atomic(from, to, count); duke@435: } duke@435: duke@435: // Object-aligned words, conjoint, not atomic on each word duke@435: static void aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) { duke@435: assert_params_aligned(from, to); duke@435: pd_aligned_conjoint_words(from, to, count); duke@435: } duke@435: duke@435: // Object-aligned words, disjoint, not atomic on each word duke@435: static void aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) { duke@435: assert_params_aligned(from, to); duke@435: assert_disjoint(from, to, count); duke@435: pd_aligned_disjoint_words(from, to, count); duke@435: } duke@435: duke@435: // bytes, jshorts, jints, jlongs, oops duke@435: duke@435: // bytes, conjoint, not atomic on each byte (not that it matters) kvn@1958: static void conjoint_jbytes(void* from, void* to, size_t count) { duke@435: pd_conjoint_bytes(from, to, count); duke@435: } duke@435: duke@435: // bytes, conjoint, atomic on each byte (not that it matters) kvn@1958: static void conjoint_jbytes_atomic(void* from, void* to, size_t count) { duke@435: pd_conjoint_bytes(from, to, count); duke@435: } duke@435: duke@435: // jshorts, conjoint, atomic on each jshort duke@435: static void conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { duke@435: assert_params_ok(from, to, LogBytesPerShort); duke@435: pd_conjoint_jshorts_atomic(from, to, count); duke@435: } duke@435: duke@435: // jints, conjoint, atomic on each jint duke@435: static void conjoint_jints_atomic(jint* from, jint* to, size_t count) { duke@435: assert_params_ok(from, to, LogBytesPerInt); duke@435: pd_conjoint_jints_atomic(from, to, count); duke@435: } duke@435: duke@435: // jlongs, conjoint, atomic on each jlong duke@435: static void conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) { duke@435: assert_params_ok(from, to, LogBytesPerLong); duke@435: pd_conjoint_jlongs_atomic(from, to, count); duke@435: } duke@435: duke@435: // oops, conjoint, atomic on each oop duke@435: static void conjoint_oops_atomic(oop* from, oop* to, size_t count) { coleenp@548: assert_params_ok(from, to, LogBytesPerHeapOop); duke@435: pd_conjoint_oops_atomic(from, to, count); duke@435: } duke@435: coleenp@548: // overloaded for UseCompressedOops coleenp@548: static void conjoint_oops_atomic(narrowOop* from, narrowOop* to, size_t count) { coleenp@548: assert(sizeof(narrowOop) == sizeof(jint), "this cast is wrong"); coleenp@548: assert_params_ok(from, to, LogBytesPerInt); coleenp@548: pd_conjoint_jints_atomic((jint*)from, (jint*)to, count); coleenp@548: } coleenp@548: duke@435: // Copy a span of memory. If the span is an integral number of aligned duke@435: // longs, words, or ints, copy those units atomically. duke@435: // The largest atomic transfer unit is 8 bytes, or the largest power duke@435: // of two which divides all of from, to, and size, whichever is smaller. duke@435: static void conjoint_memory_atomic(void* from, void* to, size_t size); duke@435: duke@435: // bytes, conjoint array, atomic on each byte (not that it matters) kvn@1958: static void arrayof_conjoint_jbytes(HeapWord* from, HeapWord* to, size_t count) { duke@435: pd_arrayof_conjoint_bytes(from, to, count); duke@435: } duke@435: duke@435: // jshorts, conjoint array, atomic on each jshort duke@435: static void arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) { duke@435: assert_params_ok(from, to, LogBytesPerShort); duke@435: pd_arrayof_conjoint_jshorts(from, to, count); duke@435: } duke@435: duke@435: // jints, conjoint array, atomic on each jint duke@435: static void arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) { duke@435: assert_params_ok(from, to, LogBytesPerInt); duke@435: pd_arrayof_conjoint_jints(from, to, count); duke@435: } duke@435: duke@435: // jlongs, conjoint array, atomic on each jlong duke@435: static void arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) { duke@435: assert_params_ok(from, to, LogBytesPerLong); duke@435: pd_arrayof_conjoint_jlongs(from, to, count); duke@435: } duke@435: duke@435: // oops, conjoint array, atomic on each oop duke@435: static void arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) { coleenp@548: assert_params_ok(from, to, LogBytesPerHeapOop); duke@435: pd_arrayof_conjoint_oops(from, to, count); duke@435: } duke@435: duke@435: // Known overlap methods duke@435: duke@435: // Copy word-aligned words from higher to lower addresses, not atomic on each word duke@435: inline static void conjoint_words_to_lower(HeapWord* from, HeapWord* to, size_t byte_count) { duke@435: // byte_count is in bytes to check its alignment duke@435: assert_params_ok(from, to, LogHeapWordSize); duke@435: assert_byte_count_ok(byte_count, HeapWordSize); duke@435: duke@435: size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize; duke@435: assert(to <= from || from + count <= to, "do not overwrite source data"); duke@435: duke@435: while (count-- > 0) { duke@435: *to++ = *from++; duke@435: } duke@435: } duke@435: duke@435: // Copy word-aligned words from lower to higher addresses, not atomic on each word duke@435: inline static void conjoint_words_to_higher(HeapWord* from, HeapWord* to, size_t byte_count) { duke@435: // byte_count is in bytes to check its alignment duke@435: assert_params_ok(from, to, LogHeapWordSize); duke@435: assert_byte_count_ok(byte_count, HeapWordSize); duke@435: duke@435: size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize; duke@435: assert(from <= to || to + count <= from, "do not overwrite source data"); duke@435: duke@435: from += count - 1; duke@435: to += count - 1; duke@435: while (count-- > 0) { duke@435: *to-- = *from--; duke@435: } duke@435: } duke@435: duke@435: // Fill methods duke@435: duke@435: // Fill word-aligned words, not atomic on each word duke@435: // set_words duke@435: static void fill_to_words(HeapWord* to, size_t count, juint value = 0) { duke@435: assert_params_ok(to, LogHeapWordSize); duke@435: pd_fill_to_words(to, count, value); duke@435: } duke@435: duke@435: static void fill_to_aligned_words(HeapWord* to, size_t count, juint value = 0) { duke@435: assert_params_aligned(to); duke@435: pd_fill_to_aligned_words(to, count, value); duke@435: } duke@435: duke@435: // Fill bytes duke@435: static void fill_to_bytes(void* to, size_t count, jubyte value = 0) { duke@435: pd_fill_to_bytes(to, count, value); duke@435: } duke@435: duke@435: // Fill a span of memory. If the span is an integral number of aligned duke@435: // longs, words, or ints, store to those units atomically. duke@435: // The largest atomic transfer unit is 8 bytes, or the largest power duke@435: // of two which divides both to and size, whichever is smaller. duke@435: static void fill_to_memory_atomic(void* to, size_t size, jubyte value = 0); duke@435: duke@435: // Zero-fill methods duke@435: duke@435: // Zero word-aligned words, not atomic on each word duke@435: static void zero_to_words(HeapWord* to, size_t count) { duke@435: assert_params_ok(to, LogHeapWordSize); duke@435: pd_zero_to_words(to, count); duke@435: } duke@435: duke@435: // Zero bytes duke@435: static void zero_to_bytes(void* to, size_t count) { duke@435: pd_zero_to_bytes(to, count); duke@435: } duke@435: duke@435: private: duke@435: static bool params_disjoint(HeapWord* from, HeapWord* to, size_t count) { duke@435: if (from < to) { duke@435: return pointer_delta(to, from) >= count; duke@435: } duke@435: return pointer_delta(from, to) >= count; duke@435: } duke@435: duke@435: // These methods raise a fatal if they detect a problem. duke@435: duke@435: static void assert_disjoint(HeapWord* from, HeapWord* to, size_t count) { duke@435: #ifdef ASSERT duke@435: if (!params_disjoint(from, to, count)) duke@435: basic_fatal("source and dest overlap"); duke@435: #endif duke@435: } duke@435: duke@435: static void assert_params_ok(void* from, void* to, intptr_t log_align) { duke@435: #ifdef ASSERT duke@435: if (mask_bits((uintptr_t)from, right_n_bits(log_align)) != 0) duke@435: basic_fatal("not aligned"); duke@435: if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0) duke@435: basic_fatal("not aligned"); duke@435: #endif duke@435: } duke@435: duke@435: static void assert_params_ok(HeapWord* to, intptr_t log_align) { duke@435: #ifdef ASSERT duke@435: if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0) duke@435: basic_fatal("not word aligned"); duke@435: #endif duke@435: } duke@435: static void assert_params_aligned(HeapWord* from, HeapWord* to) { duke@435: #ifdef ASSERT kvn@1926: if (mask_bits((uintptr_t)from, BytesPerLong-1) != 0) kvn@1926: basic_fatal("not long aligned"); kvn@1926: if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0) kvn@1926: basic_fatal("not long aligned"); duke@435: #endif duke@435: } duke@435: duke@435: static void assert_params_aligned(HeapWord* to) { duke@435: #ifdef ASSERT kvn@1926: if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0) kvn@1926: basic_fatal("not long aligned"); duke@435: #endif duke@435: } duke@435: duke@435: static void assert_byte_count_ok(size_t byte_count, size_t unit_size) { duke@435: #ifdef ASSERT duke@435: if ((size_t)round_to(byte_count, unit_size) != byte_count) { duke@435: basic_fatal("byte count must be aligned"); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: // Platform dependent implementations of the above methods. stefank@2314: #ifdef TARGET_ARCH_x86 stefank@2314: # include "copy_x86.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_sparc stefank@2314: # include "copy_sparc.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_zero stefank@2314: # include "copy_zero.hpp" stefank@2314: #endif bobv@2508: #ifdef TARGET_ARCH_arm bobv@2508: # include "copy_arm.hpp" bobv@2508: #endif bobv@2508: #ifdef TARGET_ARCH_ppc bobv@2508: # include "copy_ppc.hpp" bobv@2508: #endif stefank@2314: duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_UTILITIES_COPY_HPP