src/share/vm/utilities/copy.hpp

Wed, 02 Feb 2011 11:35:26 -0500

author
bobv
date
Wed, 02 Feb 2011 11:35:26 -0500
changeset 2508
b92c45f2bc75
parent 2314
f95d63e2154a
child 2708
1d1603768966
permissions
-rw-r--r--

7016023: Enable building ARM and PPC from src/closed repository
Reviewed-by: dholmes, bdelsart

     1 /*
     2  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_UTILITIES_COPY_HPP
    26 #define SHARE_VM_UTILITIES_COPY_HPP
    28 #include "runtime/stubRoutines.hpp"
    30 // Assembly code for platforms that need it.
    31 extern "C" {
    32   void _Copy_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
    33   void _Copy_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
    35   void _Copy_conjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
    36   void _Copy_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
    38   void _Copy_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
    39   void _Copy_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
    41   void _Copy_conjoint_bytes(void* from, void* to, size_t count);
    43   void _Copy_conjoint_bytes_atomic  (void*   from, void*   to, size_t count);
    44   void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count);
    45   void _Copy_conjoint_jints_atomic  (jint*   from, jint*   to, size_t count);
    46   void _Copy_conjoint_jlongs_atomic (jlong*  from, jlong*  to, size_t count);
    47   void _Copy_conjoint_oops_atomic   (oop*    from, oop*    to, size_t count);
    49   void _Copy_arrayof_conjoint_bytes  (HeapWord* from, HeapWord* to, size_t count);
    50   void _Copy_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count);
    51   void _Copy_arrayof_conjoint_jints  (HeapWord* from, HeapWord* to, size_t count);
    52   void _Copy_arrayof_conjoint_jlongs (HeapWord* from, HeapWord* to, size_t count);
    53   void _Copy_arrayof_conjoint_oops   (HeapWord* from, HeapWord* to, size_t count);
    54 }
    56 class Copy : AllStatic {
    57  public:
    58   // Block copy methods have four attributes.  We don't define all possibilities.
    59   //   alignment: aligned to BytesPerLong
    60   //   arrayof:   arraycopy operation with both operands aligned on the same
    61   //              boundary as the first element of an array of the copy unit.
    62   //              This is currently a HeapWord boundary on all platforms, except
    63   //              for long and double arrays, which are aligned on an 8-byte
    64   //              boundary on all platforms.
    65   //              arraycopy operations are implicitly atomic on each array element.
    66   //   overlap:   disjoint or conjoint.
    67   //   copy unit: bytes or words (i.e., HeapWords) or oops (i.e., pointers).
    68   //   atomicity: atomic or non-atomic on the copy unit.
    69   //
    70   // Names are constructed thusly:
    71   //
    72   //     [ 'aligned_' | 'arrayof_' ]
    73   //     ('conjoint_' | 'disjoint_')
    74   //     ('words' | 'bytes' | 'jshorts' | 'jints' | 'jlongs' | 'oops')
    75   //     [ '_atomic' ]
    76   //
    77   // Except in the arrayof case, whatever the alignment is, we assume we can copy
    78   // whole alignment units.  E.g., if BytesPerLong is 2x word alignment, an odd
    79   // count may copy an extra word.  In the arrayof case, we are allowed to copy
    80   // only the number of copy units specified.
    81   //
    82   // All callees check count for 0.
    83   //
    85   // HeapWords
    87   // Word-aligned words,    conjoint, not atomic on each word
    88   static void conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    89     assert_params_ok(from, to, LogHeapWordSize);
    90     pd_conjoint_words(from, to, count);
    91   }
    93   // Word-aligned words,    disjoint, not atomic on each word
    94   static void disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    95     assert_params_ok(from, to, LogHeapWordSize);
    96     assert_disjoint(from, to, count);
    97     pd_disjoint_words(from, to, count);
    98   }
   100   // Word-aligned words,    disjoint, atomic on each word
   101   static void disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
   102     assert_params_ok(from, to, LogHeapWordSize);
   103     assert_disjoint(from, to, count);
   104     pd_disjoint_words_atomic(from, to, count);
   105   }
   107   // Object-aligned words,  conjoint, not atomic on each word
   108   static void aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
   109     assert_params_aligned(from, to);
   110     pd_aligned_conjoint_words(from, to, count);
   111   }
   113   // Object-aligned words,  disjoint, not atomic on each word
   114   static void aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
   115     assert_params_aligned(from, to);
   116     assert_disjoint(from, to, count);
   117     pd_aligned_disjoint_words(from, to, count);
   118   }
   120   // bytes, jshorts, jints, jlongs, oops
   122   // bytes,                 conjoint, not atomic on each byte (not that it matters)
   123   static void conjoint_jbytes(void* from, void* to, size_t count) {
   124     pd_conjoint_bytes(from, to, count);
   125   }
   127   // bytes,                 conjoint, atomic on each byte (not that it matters)
   128   static void conjoint_jbytes_atomic(void* from, void* to, size_t count) {
   129     pd_conjoint_bytes(from, to, count);
   130   }
   132   // jshorts,               conjoint, atomic on each jshort
   133   static void conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
   134     assert_params_ok(from, to, LogBytesPerShort);
   135     pd_conjoint_jshorts_atomic(from, to, count);
   136   }
   138   // jints,                 conjoint, atomic on each jint
   139   static void conjoint_jints_atomic(jint* from, jint* to, size_t count) {
   140     assert_params_ok(from, to, LogBytesPerInt);
   141     pd_conjoint_jints_atomic(from, to, count);
   142   }
   144   // jlongs,                conjoint, atomic on each jlong
   145   static void conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
   146     assert_params_ok(from, to, LogBytesPerLong);
   147     pd_conjoint_jlongs_atomic(from, to, count);
   148   }
   150   // oops,                  conjoint, atomic on each oop
   151   static void conjoint_oops_atomic(oop* from, oop* to, size_t count) {
   152     assert_params_ok(from, to, LogBytesPerHeapOop);
   153     pd_conjoint_oops_atomic(from, to, count);
   154   }
   156   // overloaded for UseCompressedOops
   157   static void conjoint_oops_atomic(narrowOop* from, narrowOop* to, size_t count) {
   158     assert(sizeof(narrowOop) == sizeof(jint), "this cast is wrong");
   159     assert_params_ok(from, to, LogBytesPerInt);
   160     pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
   161   }
   163   // Copy a span of memory.  If the span is an integral number of aligned
   164   // longs, words, or ints, copy those units atomically.
   165   // The largest atomic transfer unit is 8 bytes, or the largest power
   166   // of two which divides all of from, to, and size, whichever is smaller.
   167   static void conjoint_memory_atomic(void* from, void* to, size_t size);
   169   // bytes,                 conjoint array, atomic on each byte (not that it matters)
   170   static void arrayof_conjoint_jbytes(HeapWord* from, HeapWord* to, size_t count) {
   171     pd_arrayof_conjoint_bytes(from, to, count);
   172   }
   174   // jshorts,               conjoint array, atomic on each jshort
   175   static void arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
   176     assert_params_ok(from, to, LogBytesPerShort);
   177     pd_arrayof_conjoint_jshorts(from, to, count);
   178   }
   180   // jints,                 conjoint array, atomic on each jint
   181   static void arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
   182     assert_params_ok(from, to, LogBytesPerInt);
   183     pd_arrayof_conjoint_jints(from, to, count);
   184   }
   186   // jlongs,                conjoint array, atomic on each jlong
   187   static void arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
   188     assert_params_ok(from, to, LogBytesPerLong);
   189     pd_arrayof_conjoint_jlongs(from, to, count);
   190   }
   192   // oops,                  conjoint array, atomic on each oop
   193   static void arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
   194     assert_params_ok(from, to, LogBytesPerHeapOop);
   195     pd_arrayof_conjoint_oops(from, to, count);
   196   }
   198   // Known overlap methods
   200   // Copy word-aligned words from higher to lower addresses, not atomic on each word
   201   inline static void conjoint_words_to_lower(HeapWord* from, HeapWord* to, size_t byte_count) {
   202     // byte_count is in bytes to check its alignment
   203     assert_params_ok(from, to, LogHeapWordSize);
   204     assert_byte_count_ok(byte_count, HeapWordSize);
   206     size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
   207     assert(to <= from || from + count <= to, "do not overwrite source data");
   209     while (count-- > 0) {
   210       *to++ = *from++;
   211     }
   212   }
   214   // Copy word-aligned words from lower to higher addresses, not atomic on each word
   215   inline static void conjoint_words_to_higher(HeapWord* from, HeapWord* to, size_t byte_count) {
   216     // byte_count is in bytes to check its alignment
   217     assert_params_ok(from, to, LogHeapWordSize);
   218     assert_byte_count_ok(byte_count, HeapWordSize);
   220     size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
   221     assert(from <= to || to + count <= from, "do not overwrite source data");
   223     from += count - 1;
   224     to   += count - 1;
   225     while (count-- > 0) {
   226       *to-- = *from--;
   227     }
   228   }
   230   // Fill methods
   232   // Fill word-aligned words, not atomic on each word
   233   // set_words
   234   static void fill_to_words(HeapWord* to, size_t count, juint value = 0) {
   235     assert_params_ok(to, LogHeapWordSize);
   236     pd_fill_to_words(to, count, value);
   237   }
   239   static void fill_to_aligned_words(HeapWord* to, size_t count, juint value = 0) {
   240     assert_params_aligned(to);
   241     pd_fill_to_aligned_words(to, count, value);
   242   }
   244   // Fill bytes
   245   static void fill_to_bytes(void* to, size_t count, jubyte value = 0) {
   246     pd_fill_to_bytes(to, count, value);
   247   }
   249   // Fill a span of memory.  If the span is an integral number of aligned
   250   // longs, words, or ints, store to those units atomically.
   251   // The largest atomic transfer unit is 8 bytes, or the largest power
   252   // of two which divides both to and size, whichever is smaller.
   253   static void fill_to_memory_atomic(void* to, size_t size, jubyte value = 0);
   255   // Zero-fill methods
   257   // Zero word-aligned words, not atomic on each word
   258   static void zero_to_words(HeapWord* to, size_t count) {
   259     assert_params_ok(to, LogHeapWordSize);
   260     pd_zero_to_words(to, count);
   261   }
   263   // Zero bytes
   264   static void zero_to_bytes(void* to, size_t count) {
   265     pd_zero_to_bytes(to, count);
   266   }
   268  private:
   269   static bool params_disjoint(HeapWord* from, HeapWord* to, size_t count) {
   270     if (from < to) {
   271       return pointer_delta(to, from) >= count;
   272     }
   273     return pointer_delta(from, to) >= count;
   274   }
   276   // These methods raise a fatal if they detect a problem.
   278   static void assert_disjoint(HeapWord* from, HeapWord* to, size_t count) {
   279 #ifdef ASSERT
   280     if (!params_disjoint(from, to, count))
   281       basic_fatal("source and dest overlap");
   282 #endif
   283   }
   285   static void assert_params_ok(void* from, void* to, intptr_t log_align) {
   286 #ifdef ASSERT
   287     if (mask_bits((uintptr_t)from, right_n_bits(log_align)) != 0)
   288       basic_fatal("not aligned");
   289     if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
   290       basic_fatal("not aligned");
   291 #endif
   292   }
   294   static void assert_params_ok(HeapWord* to, intptr_t log_align) {
   295 #ifdef ASSERT
   296     if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
   297       basic_fatal("not word aligned");
   298 #endif
   299   }
   300   static void assert_params_aligned(HeapWord* from, HeapWord* to) {
   301 #ifdef ASSERT
   302     if (mask_bits((uintptr_t)from, BytesPerLong-1) != 0)
   303       basic_fatal("not long aligned");
   304     if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0)
   305       basic_fatal("not long aligned");
   306 #endif
   307   }
   309   static void assert_params_aligned(HeapWord* to) {
   310 #ifdef ASSERT
   311     if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0)
   312       basic_fatal("not long aligned");
   313 #endif
   314   }
   316   static void assert_byte_count_ok(size_t byte_count, size_t unit_size) {
   317 #ifdef ASSERT
   318     if ((size_t)round_to(byte_count, unit_size) != byte_count) {
   319       basic_fatal("byte count must be aligned");
   320     }
   321 #endif
   322   }
   324   // Platform dependent implementations of the above methods.
   325 #ifdef TARGET_ARCH_x86
   326 # include "copy_x86.hpp"
   327 #endif
   328 #ifdef TARGET_ARCH_sparc
   329 # include "copy_sparc.hpp"
   330 #endif
   331 #ifdef TARGET_ARCH_zero
   332 # include "copy_zero.hpp"
   333 #endif
   334 #ifdef TARGET_ARCH_arm
   335 # include "copy_arm.hpp"
   336 #endif
   337 #ifdef TARGET_ARCH_ppc
   338 # include "copy_ppc.hpp"
   339 #endif
   341 };
   343 #endif // SHARE_VM_UTILITIES_COPY_HPP

mercurial