src/share/vm/utilities/copy.hpp

Tue, 12 Feb 2013 12:19:28 -0500

author
zgu
date
Tue, 12 Feb 2013 12:19:28 -0500
changeset 4573
5ee2b330eacd
parent 2708
1d1603768966
child 6876
710a3c8b516e
child 9562
dee6a1ce4a0c
permissions
-rw-r--r--

8007950: Undo hs_file permission change
Summary: Reverse hs_err file permission back to 0666, as early push was premature
Reviewed-by: dsamersoff, dcubed, acorn

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

mercurial