src/share/vm/utilities/copy.hpp

changeset 435
a61af66fc99e
child 548
ba764ed4b6f2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/utilities/copy.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,332 @@
     1.4 +/*
     1.5 + * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// Assembly code for platforms that need it.
    1.29 +extern "C" {
    1.30 +  void _Copy_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
    1.31 +  void _Copy_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
    1.32 +
    1.33 +  void _Copy_conjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
    1.34 +  void _Copy_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
    1.35 +
    1.36 +  void _Copy_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
    1.37 +  void _Copy_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
    1.38 +
    1.39 +  void _Copy_conjoint_bytes(void* from, void* to, size_t count);
    1.40 +
    1.41 +  void _Copy_conjoint_bytes_atomic  (void*   from, void*   to, size_t count);
    1.42 +  void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count);
    1.43 +  void _Copy_conjoint_jints_atomic  (jint*   from, jint*   to, size_t count);
    1.44 +  void _Copy_conjoint_jlongs_atomic (jlong*  from, jlong*  to, size_t count);
    1.45 +  void _Copy_conjoint_oops_atomic   (oop*    from, oop*    to, size_t count);
    1.46 +
    1.47 +  void _Copy_arrayof_conjoint_bytes  (HeapWord* from, HeapWord* to, size_t count);
    1.48 +  void _Copy_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count);
    1.49 +  void _Copy_arrayof_conjoint_jints  (HeapWord* from, HeapWord* to, size_t count);
    1.50 +  void _Copy_arrayof_conjoint_jlongs (HeapWord* from, HeapWord* to, size_t count);
    1.51 +  void _Copy_arrayof_conjoint_oops   (HeapWord* from, HeapWord* to, size_t count);
    1.52 +}
    1.53 +
    1.54 +class Copy : AllStatic {
    1.55 + public:
    1.56 +  // Block copy methods have four attributes.  We don't define all possibilities.
    1.57 +  //   alignment: aligned according to minimum Java object alignment (MinObjAlignment)
    1.58 +  //   arrayof:   arraycopy operation with both operands aligned on the same
    1.59 +  //              boundary as the first element of an array of the copy unit.
    1.60 +  //              This is currently a HeapWord boundary on all platforms, except
    1.61 +  //              for long and double arrays, which are aligned on an 8-byte
    1.62 +  //              boundary on all platforms.
    1.63 +  //              arraycopy operations are implicitly atomic on each array element.
    1.64 +  //   overlap:   disjoint or conjoint.
    1.65 +  //   copy unit: bytes or words (i.e., HeapWords) or oops (i.e., pointers).
    1.66 +  //   atomicity: atomic or non-atomic on the copy unit.
    1.67 +  //
    1.68 +  // Names are constructed thusly:
    1.69 +  //
    1.70 +  //     [ 'aligned_' | 'arrayof_' ]
    1.71 +  //     ('conjoint_' | 'disjoint_')
    1.72 +  //     ('words' | 'bytes' | 'jshorts' | 'jints' | 'jlongs' | 'oops')
    1.73 +  //     [ '_atomic' ]
    1.74 +  //
    1.75 +  // Except in the arrayof case, whatever the alignment is, we assume we can copy
    1.76 +  // whole alignment units.  E.g., if MinObjAlignment is 2x word alignment, an odd
    1.77 +  // count may copy an extra word.  In the arrayof case, we are allowed to copy
    1.78 +  // only the number of copy units specified.
    1.79 +
    1.80 +  // HeapWords
    1.81 +
    1.82 +  // Word-aligned words,    conjoint, not atomic on each word
    1.83 +  static void conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    1.84 +    assert_params_ok(from, to, LogHeapWordSize);
    1.85 +    pd_conjoint_words(from, to, count);
    1.86 +  }
    1.87 +
    1.88 +  // Word-aligned words,    disjoint, not atomic on each word
    1.89 +  static void disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    1.90 +    assert_params_ok(from, to, LogHeapWordSize);
    1.91 +    assert_disjoint(from, to, count);
    1.92 +    pd_disjoint_words(from, to, count);
    1.93 +  }
    1.94 +
    1.95 +  // Word-aligned words,    disjoint, atomic on each word
    1.96 +  static void disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
    1.97 +    assert_params_ok(from, to, LogHeapWordSize);
    1.98 +    assert_disjoint(from, to, count);
    1.99 +    pd_disjoint_words_atomic(from, to, count);
   1.100 +  }
   1.101 +
   1.102 +  // Object-aligned words,  conjoint, not atomic on each word
   1.103 +  static void aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
   1.104 +    assert_params_aligned(from, to);
   1.105 +    assert_non_zero(count);
   1.106 +    pd_aligned_conjoint_words(from, to, count);
   1.107 +  }
   1.108 +
   1.109 +  // Object-aligned words,  disjoint, not atomic on each word
   1.110 +  static void aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
   1.111 +    assert_params_aligned(from, to);
   1.112 +    assert_disjoint(from, to, count);
   1.113 +    assert_non_zero(count);
   1.114 +    pd_aligned_disjoint_words(from, to, count);
   1.115 +  }
   1.116 +
   1.117 +  // bytes, jshorts, jints, jlongs, oops
   1.118 +
   1.119 +  // bytes,                 conjoint, not atomic on each byte (not that it matters)
   1.120 +  static void conjoint_bytes(void* from, void* to, size_t count) {
   1.121 +    assert_non_zero(count);
   1.122 +    pd_conjoint_bytes(from, to, count);
   1.123 +  }
   1.124 +
   1.125 +  // bytes,                 conjoint, atomic on each byte (not that it matters)
   1.126 +  static void conjoint_bytes_atomic(void* from, void* to, size_t count) {
   1.127 +    assert_non_zero(count);
   1.128 +    pd_conjoint_bytes(from, to, count);
   1.129 +  }
   1.130 +
   1.131 +  // jshorts,               conjoint, atomic on each jshort
   1.132 +  static void conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
   1.133 +    assert_params_ok(from, to, LogBytesPerShort);
   1.134 +    assert_non_zero(count);
   1.135 +    pd_conjoint_jshorts_atomic(from, to, count);
   1.136 +  }
   1.137 +
   1.138 +  // jints,                 conjoint, atomic on each jint
   1.139 +  static void conjoint_jints_atomic(jint* from, jint* to, size_t count) {
   1.140 +    assert_params_ok(from, to, LogBytesPerInt);
   1.141 +    assert_non_zero(count);
   1.142 +    pd_conjoint_jints_atomic(from, to, count);
   1.143 +  }
   1.144 +
   1.145 +  // jlongs,                conjoint, atomic on each jlong
   1.146 +  static void conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
   1.147 +    assert_params_ok(from, to, LogBytesPerLong);
   1.148 +    assert_non_zero(count);
   1.149 +    pd_conjoint_jlongs_atomic(from, to, count);
   1.150 +  }
   1.151 +
   1.152 +  // oops,                  conjoint, atomic on each oop
   1.153 +  static void conjoint_oops_atomic(oop* from, oop* to, size_t count) {
   1.154 +    assert_params_ok(from, to, LogBytesPerOop);
   1.155 +    assert_non_zero(count);
   1.156 +    pd_conjoint_oops_atomic(from, to, count);
   1.157 +  }
   1.158 +
   1.159 +  // Copy a span of memory.  If the span is an integral number of aligned
   1.160 +  // longs, words, or ints, copy those units atomically.
   1.161 +  // The largest atomic transfer unit is 8 bytes, or the largest power
   1.162 +  // of two which divides all of from, to, and size, whichever is smaller.
   1.163 +  static void conjoint_memory_atomic(void* from, void* to, size_t size);
   1.164 +
   1.165 +  // bytes,                 conjoint array, atomic on each byte (not that it matters)
   1.166 +  static void arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
   1.167 +    assert_non_zero(count);
   1.168 +    pd_arrayof_conjoint_bytes(from, to, count);
   1.169 +  }
   1.170 +
   1.171 +  // jshorts,               conjoint array, atomic on each jshort
   1.172 +  static void arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
   1.173 +    assert_params_ok(from, to, LogBytesPerShort);
   1.174 +    assert_non_zero(count);
   1.175 +    pd_arrayof_conjoint_jshorts(from, to, count);
   1.176 +  }
   1.177 +
   1.178 +  // jints,                 conjoint array, atomic on each jint
   1.179 +  static void arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
   1.180 +    assert_params_ok(from, to, LogBytesPerInt);
   1.181 +    assert_non_zero(count);
   1.182 +    pd_arrayof_conjoint_jints(from, to, count);
   1.183 +  }
   1.184 +
   1.185 +  // jlongs,                conjoint array, atomic on each jlong
   1.186 +  static void arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
   1.187 +    assert_params_ok(from, to, LogBytesPerLong);
   1.188 +    assert_non_zero(count);
   1.189 +    pd_arrayof_conjoint_jlongs(from, to, count);
   1.190 +  }
   1.191 +
   1.192 +  // oops,                  conjoint array, atomic on each oop
   1.193 +  static void arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
   1.194 +    assert_params_ok(from, to, LogBytesPerOop);
   1.195 +    assert_non_zero(count);
   1.196 +    pd_arrayof_conjoint_oops(from, to, count);
   1.197 +  }
   1.198 +
   1.199 +  // Known overlap methods
   1.200 +
   1.201 +  // Copy word-aligned words from higher to lower addresses, not atomic on each word
   1.202 +  inline static void conjoint_words_to_lower(HeapWord* from, HeapWord* to, size_t byte_count) {
   1.203 +    // byte_count is in bytes to check its alignment
   1.204 +    assert_params_ok(from, to, LogHeapWordSize);
   1.205 +    assert_byte_count_ok(byte_count, HeapWordSize);
   1.206 +
   1.207 +    size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
   1.208 +    assert(to <= from || from + count <= to, "do not overwrite source data");
   1.209 +
   1.210 +    while (count-- > 0) {
   1.211 +      *to++ = *from++;
   1.212 +    }
   1.213 +  }
   1.214 +
   1.215 +  // Copy word-aligned words from lower to higher addresses, not atomic on each word
   1.216 +  inline static void conjoint_words_to_higher(HeapWord* from, HeapWord* to, size_t byte_count) {
   1.217 +    // byte_count is in bytes to check its alignment
   1.218 +    assert_params_ok(from, to, LogHeapWordSize);
   1.219 +    assert_byte_count_ok(byte_count, HeapWordSize);
   1.220 +
   1.221 +    size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
   1.222 +    assert(from <= to || to + count <= from, "do not overwrite source data");
   1.223 +
   1.224 +    from += count - 1;
   1.225 +    to   += count - 1;
   1.226 +    while (count-- > 0) {
   1.227 +      *to-- = *from--;
   1.228 +    }
   1.229 +  }
   1.230 +
   1.231 +  // Fill methods
   1.232 +
   1.233 +  // Fill word-aligned words, not atomic on each word
   1.234 +  // set_words
   1.235 +  static void fill_to_words(HeapWord* to, size_t count, juint value = 0) {
   1.236 +    assert_params_ok(to, LogHeapWordSize);
   1.237 +    pd_fill_to_words(to, count, value);
   1.238 +  }
   1.239 +
   1.240 +  static void fill_to_aligned_words(HeapWord* to, size_t count, juint value = 0) {
   1.241 +    assert_params_aligned(to);
   1.242 +    pd_fill_to_aligned_words(to, count, value);
   1.243 +  }
   1.244 +
   1.245 +  // Fill bytes
   1.246 +  static void fill_to_bytes(void* to, size_t count, jubyte value = 0) {
   1.247 +    pd_fill_to_bytes(to, count, value);
   1.248 +  }
   1.249 +
   1.250 +  // Fill a span of memory.  If the span is an integral number of aligned
   1.251 +  // longs, words, or ints, store to those units atomically.
   1.252 +  // The largest atomic transfer unit is 8 bytes, or the largest power
   1.253 +  // of two which divides both to and size, whichever is smaller.
   1.254 +  static void fill_to_memory_atomic(void* to, size_t size, jubyte value = 0);
   1.255 +
   1.256 +  // Zero-fill methods
   1.257 +
   1.258 +  // Zero word-aligned words, not atomic on each word
   1.259 +  static void zero_to_words(HeapWord* to, size_t count) {
   1.260 +    assert_params_ok(to, LogHeapWordSize);
   1.261 +    pd_zero_to_words(to, count);
   1.262 +  }
   1.263 +
   1.264 +  // Zero bytes
   1.265 +  static void zero_to_bytes(void* to, size_t count) {
   1.266 +    pd_zero_to_bytes(to, count);
   1.267 +  }
   1.268 +
   1.269 + private:
   1.270 +  static bool params_disjoint(HeapWord* from, HeapWord* to, size_t count) {
   1.271 +    if (from < to) {
   1.272 +      return pointer_delta(to, from) >= count;
   1.273 +    }
   1.274 +    return pointer_delta(from, to) >= count;
   1.275 +  }
   1.276 +
   1.277 +  // These methods raise a fatal if they detect a problem.
   1.278 +
   1.279 +  static void assert_disjoint(HeapWord* from, HeapWord* to, size_t count) {
   1.280 +#ifdef ASSERT
   1.281 +    if (!params_disjoint(from, to, count))
   1.282 +      basic_fatal("source and dest overlap");
   1.283 +#endif
   1.284 +  }
   1.285 +
   1.286 +  static void assert_params_ok(void* from, void* to, intptr_t log_align) {
   1.287 +#ifdef ASSERT
   1.288 +    if (mask_bits((uintptr_t)from, right_n_bits(log_align)) != 0)
   1.289 +      basic_fatal("not aligned");
   1.290 +    if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
   1.291 +      basic_fatal("not aligned");
   1.292 +#endif
   1.293 +  }
   1.294 +
   1.295 +  static void assert_params_ok(HeapWord* to, intptr_t log_align) {
   1.296 +#ifdef ASSERT
   1.297 +    if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
   1.298 +      basic_fatal("not word aligned");
   1.299 +#endif
   1.300 +  }
   1.301 +  static void assert_params_aligned(HeapWord* from, HeapWord* to) {
   1.302 +#ifdef ASSERT
   1.303 +    if (mask_bits((uintptr_t)from, MinObjAlignmentInBytes-1) != 0)
   1.304 +      basic_fatal("not object aligned");
   1.305 +    if (mask_bits((uintptr_t)to, MinObjAlignmentInBytes-1) != 0)
   1.306 +      basic_fatal("not object aligned");
   1.307 +#endif
   1.308 +  }
   1.309 +
   1.310 +  static void assert_params_aligned(HeapWord* to) {
   1.311 +#ifdef ASSERT
   1.312 +    if (mask_bits((uintptr_t)to, MinObjAlignmentInBytes-1) != 0)
   1.313 +      basic_fatal("not object aligned");
   1.314 +#endif
   1.315 +  }
   1.316 +
   1.317 +  static void assert_non_zero(size_t count) {
   1.318 +#ifdef ASSERT
   1.319 +    if (count == 0) {
   1.320 +      basic_fatal("count must be non-zero");
   1.321 +    }
   1.322 +#endif
   1.323 +  }
   1.324 +
   1.325 +  static void assert_byte_count_ok(size_t byte_count, size_t unit_size) {
   1.326 +#ifdef ASSERT
   1.327 +    if ((size_t)round_to(byte_count, unit_size) != byte_count) {
   1.328 +      basic_fatal("byte count must be aligned");
   1.329 +    }
   1.330 +#endif
   1.331 +  }
   1.332 +
   1.333 +  // Platform dependent implementations of the above methods.
   1.334 +  #include "incls/_copy_pd.hpp.incl"
   1.335 +};

mercurial