0N/A/*
2273N/A * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_UTILITIES_COPY_HPP
1879N/A#define SHARE_VM_UTILITIES_COPY_HPP
1879N/A
1879N/A#include "runtime/stubRoutines.hpp"
1879N/A
0N/A// Assembly code for platforms that need it.
0N/Aextern "C" {
0N/A void _Copy_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
0N/A void _Copy_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
0N/A
0N/A void _Copy_conjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
0N/A void _Copy_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
0N/A
0N/A void _Copy_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
0N/A void _Copy_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
0N/A
0N/A void _Copy_conjoint_bytes(void* from, void* to, size_t count);
0N/A
0N/A void _Copy_conjoint_bytes_atomic (void* from, void* to, size_t count);
0N/A void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count);
0N/A void _Copy_conjoint_jints_atomic (jint* from, jint* to, size_t count);
0N/A void _Copy_conjoint_jlongs_atomic (jlong* from, jlong* to, size_t count);
0N/A void _Copy_conjoint_oops_atomic (oop* from, oop* to, size_t count);
0N/A
0N/A void _Copy_arrayof_conjoint_bytes (HeapWord* from, HeapWord* to, size_t count);
0N/A void _Copy_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count);
0N/A void _Copy_arrayof_conjoint_jints (HeapWord* from, HeapWord* to, size_t count);
0N/A void _Copy_arrayof_conjoint_jlongs (HeapWord* from, HeapWord* to, size_t count);
0N/A void _Copy_arrayof_conjoint_oops (HeapWord* from, HeapWord* to, size_t count);
0N/A}
0N/A
0N/Aclass Copy : AllStatic {
0N/A public:
0N/A // Block copy methods have four attributes. We don't define all possibilities.
1491N/A // alignment: aligned to BytesPerLong
0N/A // arrayof: arraycopy operation with both operands aligned on the same
0N/A // boundary as the first element of an array of the copy unit.
0N/A // This is currently a HeapWord boundary on all platforms, except
0N/A // for long and double arrays, which are aligned on an 8-byte
0N/A // boundary on all platforms.
0N/A // arraycopy operations are implicitly atomic on each array element.
0N/A // overlap: disjoint or conjoint.
0N/A // copy unit: bytes or words (i.e., HeapWords) or oops (i.e., pointers).
0N/A // atomicity: atomic or non-atomic on the copy unit.
0N/A //
0N/A // Names are constructed thusly:
0N/A //
0N/A // [ 'aligned_' | 'arrayof_' ]
0N/A // ('conjoint_' | 'disjoint_')
0N/A // ('words' | 'bytes' | 'jshorts' | 'jints' | 'jlongs' | 'oops')
0N/A // [ '_atomic' ]
0N/A //
0N/A // Except in the arrayof case, whatever the alignment is, we assume we can copy
1491N/A // whole alignment units. E.g., if BytesPerLong is 2x word alignment, an odd
0N/A // count may copy an extra word. In the arrayof case, we are allowed to copy
0N/A // only the number of copy units specified.
1523N/A //
1523N/A // All callees check count for 0.
1523N/A //
0N/A
0N/A // HeapWords
0N/A
0N/A // Word-aligned words, conjoint, not atomic on each word
0N/A static void conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A assert_params_ok(from, to, LogHeapWordSize);
0N/A pd_conjoint_words(from, to, count);
0N/A }
0N/A
0N/A // Word-aligned words, disjoint, not atomic on each word
0N/A static void disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A assert_params_ok(from, to, LogHeapWordSize);
0N/A assert_disjoint(from, to, count);
0N/A pd_disjoint_words(from, to, count);
0N/A }
0N/A
0N/A // Word-aligned words, disjoint, atomic on each word
0N/A static void disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
0N/A assert_params_ok(from, to, LogHeapWordSize);
0N/A assert_disjoint(from, to, count);
0N/A pd_disjoint_words_atomic(from, to, count);
0N/A }
0N/A
0N/A // Object-aligned words, conjoint, not atomic on each word
0N/A static void aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A assert_params_aligned(from, to);
0N/A pd_aligned_conjoint_words(from, to, count);
0N/A }
0N/A
0N/A // Object-aligned words, disjoint, not atomic on each word
0N/A static void aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A assert_params_aligned(from, to);
0N/A assert_disjoint(from, to, count);
0N/A pd_aligned_disjoint_words(from, to, count);
0N/A }
0N/A
0N/A // bytes, jshorts, jints, jlongs, oops
0N/A
0N/A // bytes, conjoint, not atomic on each byte (not that it matters)
1523N/A static void conjoint_jbytes(void* from, void* to, size_t count) {
0N/A pd_conjoint_bytes(from, to, count);
0N/A }
0N/A
0N/A // bytes, conjoint, atomic on each byte (not that it matters)
1523N/A static void conjoint_jbytes_atomic(void* from, void* to, size_t count) {
0N/A pd_conjoint_bytes(from, to, count);
0N/A }
0N/A
0N/A // jshorts, conjoint, atomic on each jshort
0N/A static void conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
0N/A assert_params_ok(from, to, LogBytesPerShort);
0N/A pd_conjoint_jshorts_atomic(from, to, count);
0N/A }
0N/A
0N/A // jints, conjoint, atomic on each jint
0N/A static void conjoint_jints_atomic(jint* from, jint* to, size_t count) {
0N/A assert_params_ok(from, to, LogBytesPerInt);
0N/A pd_conjoint_jints_atomic(from, to, count);
0N/A }
0N/A
0N/A // jlongs, conjoint, atomic on each jlong
0N/A static void conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
0N/A assert_params_ok(from, to, LogBytesPerLong);
0N/A pd_conjoint_jlongs_atomic(from, to, count);
0N/A }
0N/A
0N/A // oops, conjoint, atomic on each oop
0N/A static void conjoint_oops_atomic(oop* from, oop* to, size_t count) {
113N/A assert_params_ok(from, to, LogBytesPerHeapOop);
0N/A pd_conjoint_oops_atomic(from, to, count);
0N/A }
0N/A
113N/A // overloaded for UseCompressedOops
113N/A static void conjoint_oops_atomic(narrowOop* from, narrowOop* to, size_t count) {
113N/A assert(sizeof(narrowOop) == sizeof(jint), "this cast is wrong");
113N/A assert_params_ok(from, to, LogBytesPerInt);
113N/A pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
113N/A }
113N/A
0N/A // Copy a span of memory. If the span is an integral number of aligned
0N/A // longs, words, or ints, copy those units atomically.
0N/A // The largest atomic transfer unit is 8 bytes, or the largest power
0N/A // of two which divides all of from, to, and size, whichever is smaller.
0N/A static void conjoint_memory_atomic(void* from, void* to, size_t size);
0N/A
0N/A // bytes, conjoint array, atomic on each byte (not that it matters)
1523N/A static void arrayof_conjoint_jbytes(HeapWord* from, HeapWord* to, size_t count) {
0N/A pd_arrayof_conjoint_bytes(from, to, count);
0N/A }
0N/A
0N/A // jshorts, conjoint array, atomic on each jshort
0N/A static void arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
0N/A assert_params_ok(from, to, LogBytesPerShort);
0N/A pd_arrayof_conjoint_jshorts(from, to, count);
0N/A }
0N/A
0N/A // jints, conjoint array, atomic on each jint
0N/A static void arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
0N/A assert_params_ok(from, to, LogBytesPerInt);
0N/A pd_arrayof_conjoint_jints(from, to, count);
0N/A }
0N/A
0N/A // jlongs, conjoint array, atomic on each jlong
0N/A static void arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
0N/A assert_params_ok(from, to, LogBytesPerLong);
0N/A pd_arrayof_conjoint_jlongs(from, to, count);
0N/A }
0N/A
0N/A // oops, conjoint array, atomic on each oop
0N/A static void arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
113N/A assert_params_ok(from, to, LogBytesPerHeapOop);
0N/A pd_arrayof_conjoint_oops(from, to, count);
0N/A }
0N/A
0N/A // Known overlap methods
0N/A
0N/A // Copy word-aligned words from higher to lower addresses, not atomic on each word
0N/A inline static void conjoint_words_to_lower(HeapWord* from, HeapWord* to, size_t byte_count) {
0N/A // byte_count is in bytes to check its alignment
0N/A assert_params_ok(from, to, LogHeapWordSize);
0N/A assert_byte_count_ok(byte_count, HeapWordSize);
0N/A
0N/A size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
0N/A assert(to <= from || from + count <= to, "do not overwrite source data");
0N/A
0N/A while (count-- > 0) {
0N/A *to++ = *from++;
0N/A }
0N/A }
0N/A
0N/A // Copy word-aligned words from lower to higher addresses, not atomic on each word
0N/A inline static void conjoint_words_to_higher(HeapWord* from, HeapWord* to, size_t byte_count) {
0N/A // byte_count is in bytes to check its alignment
0N/A assert_params_ok(from, to, LogHeapWordSize);
0N/A assert_byte_count_ok(byte_count, HeapWordSize);
0N/A
0N/A size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
0N/A assert(from <= to || to + count <= from, "do not overwrite source data");
0N/A
0N/A from += count - 1;
0N/A to += count - 1;
0N/A while (count-- > 0) {
0N/A *to-- = *from--;
0N/A }
0N/A }
0N/A
0N/A // Fill methods
0N/A
0N/A // Fill word-aligned words, not atomic on each word
0N/A // set_words
0N/A static void fill_to_words(HeapWord* to, size_t count, juint value = 0) {
0N/A assert_params_ok(to, LogHeapWordSize);
0N/A pd_fill_to_words(to, count, value);
0N/A }
0N/A
0N/A static void fill_to_aligned_words(HeapWord* to, size_t count, juint value = 0) {
0N/A assert_params_aligned(to);
0N/A pd_fill_to_aligned_words(to, count, value);
0N/A }
0N/A
0N/A // Fill bytes
0N/A static void fill_to_bytes(void* to, size_t count, jubyte value = 0) {
0N/A pd_fill_to_bytes(to, count, value);
0N/A }
0N/A
0N/A // Fill a span of memory. If the span is an integral number of aligned
0N/A // longs, words, or ints, store to those units atomically.
0N/A // The largest atomic transfer unit is 8 bytes, or the largest power
0N/A // of two which divides both to and size, whichever is smaller.
0N/A static void fill_to_memory_atomic(void* to, size_t size, jubyte value = 0);
0N/A
0N/A // Zero-fill methods
0N/A
0N/A // Zero word-aligned words, not atomic on each word
0N/A static void zero_to_words(HeapWord* to, size_t count) {
0N/A assert_params_ok(to, LogHeapWordSize);
0N/A pd_zero_to_words(to, count);
0N/A }
0N/A
0N/A // Zero bytes
0N/A static void zero_to_bytes(void* to, size_t count) {
0N/A pd_zero_to_bytes(to, count);
0N/A }
0N/A
0N/A private:
0N/A static bool params_disjoint(HeapWord* from, HeapWord* to, size_t count) {
0N/A if (from < to) {
0N/A return pointer_delta(to, from) >= count;
0N/A }
0N/A return pointer_delta(from, to) >= count;
0N/A }
0N/A
0N/A // These methods raise a fatal if they detect a problem.
0N/A
0N/A static void assert_disjoint(HeapWord* from, HeapWord* to, size_t count) {
0N/A#ifdef ASSERT
0N/A if (!params_disjoint(from, to, count))
0N/A basic_fatal("source and dest overlap");
0N/A#endif
0N/A }
0N/A
0N/A static void assert_params_ok(void* from, void* to, intptr_t log_align) {
0N/A#ifdef ASSERT
0N/A if (mask_bits((uintptr_t)from, right_n_bits(log_align)) != 0)
0N/A basic_fatal("not aligned");
0N/A if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
0N/A basic_fatal("not aligned");
0N/A#endif
0N/A }
0N/A
0N/A static void assert_params_ok(HeapWord* to, intptr_t log_align) {
0N/A#ifdef ASSERT
0N/A if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
0N/A basic_fatal("not word aligned");
0N/A#endif
0N/A }
0N/A static void assert_params_aligned(HeapWord* from, HeapWord* to) {
0N/A#ifdef ASSERT
1491N/A if (mask_bits((uintptr_t)from, BytesPerLong-1) != 0)
1491N/A basic_fatal("not long aligned");
1491N/A if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0)
1491N/A basic_fatal("not long aligned");
0N/A#endif
0N/A }
0N/A
0N/A static void assert_params_aligned(HeapWord* to) {
0N/A#ifdef ASSERT
1491N/A if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0)
1491N/A basic_fatal("not long aligned");
0N/A#endif
0N/A }
0N/A
0N/A static void assert_byte_count_ok(size_t byte_count, size_t unit_size) {
0N/A#ifdef ASSERT
0N/A if ((size_t)round_to(byte_count, unit_size) != byte_count) {
0N/A basic_fatal("byte count must be aligned");
0N/A }
0N/A#endif
0N/A }
0N/A
0N/A // Platform dependent implementations of the above methods.
1879N/A#ifdef TARGET_ARCH_x86
1879N/A# include "copy_x86.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_sparc
1879N/A# include "copy_sparc.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_zero
1879N/A# include "copy_zero.hpp"
1879N/A#endif
2073N/A#ifdef TARGET_ARCH_arm
2073N/A# include "copy_arm.hpp"
2073N/A#endif
2073N/A#ifdef TARGET_ARCH_ppc
2073N/A# include "copy_ppc.hpp"
2073N/A#endif
1879N/A
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_UTILITIES_COPY_HPP