src/share/vm/utilities/copy.hpp

Thu, 10 Jun 2010 13:04:20 -0700

author
kvn
date
Thu, 10 Jun 2010 13:04:20 -0700
changeset 1958
d93949c5bdcc
parent 1934
e9ff18c4ace7
child 2314
f95d63e2154a
permissions
-rw-r--r--

6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
Summary: Modify assembler code to check for 0 count for all copy routines.
Reviewed-by: never, ysr, jcoomes

duke@435 1 /*
trims@1907 2 * Copyright (c) 2003, 2008, 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
duke@435 25 // Assembly code for platforms that need it.
duke@435 26 extern "C" {
duke@435 27 void _Copy_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
duke@435 28 void _Copy_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
duke@435 29
duke@435 30 void _Copy_conjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
duke@435 31 void _Copy_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
duke@435 32
duke@435 33 void _Copy_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
duke@435 34 void _Copy_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
duke@435 35
duke@435 36 void _Copy_conjoint_bytes(void* from, void* to, size_t count);
duke@435 37
duke@435 38 void _Copy_conjoint_bytes_atomic (void* from, void* to, size_t count);
duke@435 39 void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count);
duke@435 40 void _Copy_conjoint_jints_atomic (jint* from, jint* to, size_t count);
duke@435 41 void _Copy_conjoint_jlongs_atomic (jlong* from, jlong* to, size_t count);
duke@435 42 void _Copy_conjoint_oops_atomic (oop* from, oop* to, size_t count);
duke@435 43
duke@435 44 void _Copy_arrayof_conjoint_bytes (HeapWord* from, HeapWord* to, size_t count);
duke@435 45 void _Copy_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count);
duke@435 46 void _Copy_arrayof_conjoint_jints (HeapWord* from, HeapWord* to, size_t count);
duke@435 47 void _Copy_arrayof_conjoint_jlongs (HeapWord* from, HeapWord* to, size_t count);
duke@435 48 void _Copy_arrayof_conjoint_oops (HeapWord* from, HeapWord* to, size_t count);
duke@435 49 }
duke@435 50
duke@435 51 class Copy : AllStatic {
duke@435 52 public:
duke@435 53 // Block copy methods have four attributes. We don't define all possibilities.
kvn@1926 54 // alignment: aligned to BytesPerLong
duke@435 55 // arrayof: arraycopy operation with both operands aligned on the same
duke@435 56 // boundary as the first element of an array of the copy unit.
duke@435 57 // This is currently a HeapWord boundary on all platforms, except
duke@435 58 // for long and double arrays, which are aligned on an 8-byte
duke@435 59 // boundary on all platforms.
duke@435 60 // arraycopy operations are implicitly atomic on each array element.
duke@435 61 // overlap: disjoint or conjoint.
duke@435 62 // copy unit: bytes or words (i.e., HeapWords) or oops (i.e., pointers).
duke@435 63 // atomicity: atomic or non-atomic on the copy unit.
duke@435 64 //
duke@435 65 // Names are constructed thusly:
duke@435 66 //
duke@435 67 // [ 'aligned_' | 'arrayof_' ]
duke@435 68 // ('conjoint_' | 'disjoint_')
duke@435 69 // ('words' | 'bytes' | 'jshorts' | 'jints' | 'jlongs' | 'oops')
duke@435 70 // [ '_atomic' ]
duke@435 71 //
duke@435 72 // Except in the arrayof case, whatever the alignment is, we assume we can copy
kvn@1926 73 // whole alignment units. E.g., if BytesPerLong is 2x word alignment, an odd
duke@435 74 // count may copy an extra word. In the arrayof case, we are allowed to copy
duke@435 75 // only the number of copy units specified.
kvn@1958 76 //
kvn@1958 77 // All callees check count for 0.
kvn@1958 78 //
duke@435 79
duke@435 80 // HeapWords
duke@435 81
duke@435 82 // Word-aligned words, conjoint, not atomic on each word
duke@435 83 static void conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
duke@435 84 assert_params_ok(from, to, LogHeapWordSize);
duke@435 85 pd_conjoint_words(from, to, count);
duke@435 86 }
duke@435 87
duke@435 88 // Word-aligned words, disjoint, not atomic on each word
duke@435 89 static void disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
duke@435 90 assert_params_ok(from, to, LogHeapWordSize);
duke@435 91 assert_disjoint(from, to, count);
duke@435 92 pd_disjoint_words(from, to, count);
duke@435 93 }
duke@435 94
duke@435 95 // Word-aligned words, disjoint, atomic on each word
duke@435 96 static void disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
duke@435 97 assert_params_ok(from, to, LogHeapWordSize);
duke@435 98 assert_disjoint(from, to, count);
duke@435 99 pd_disjoint_words_atomic(from, to, count);
duke@435 100 }
duke@435 101
duke@435 102 // Object-aligned words, conjoint, not atomic on each word
duke@435 103 static void aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
duke@435 104 assert_params_aligned(from, to);
duke@435 105 pd_aligned_conjoint_words(from, to, count);
duke@435 106 }
duke@435 107
duke@435 108 // Object-aligned words, disjoint, not atomic on each word
duke@435 109 static void aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
duke@435 110 assert_params_aligned(from, to);
duke@435 111 assert_disjoint(from, to, count);
duke@435 112 pd_aligned_disjoint_words(from, to, count);
duke@435 113 }
duke@435 114
duke@435 115 // bytes, jshorts, jints, jlongs, oops
duke@435 116
duke@435 117 // bytes, conjoint, not atomic on each byte (not that it matters)
kvn@1958 118 static void conjoint_jbytes(void* from, void* to, size_t count) {
duke@435 119 pd_conjoint_bytes(from, to, count);
duke@435 120 }
duke@435 121
duke@435 122 // bytes, conjoint, atomic on each byte (not that it matters)
kvn@1958 123 static void conjoint_jbytes_atomic(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 // jshorts, conjoint, atomic on each jshort
duke@435 128 static void conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
duke@435 129 assert_params_ok(from, to, LogBytesPerShort);
duke@435 130 pd_conjoint_jshorts_atomic(from, to, count);
duke@435 131 }
duke@435 132
duke@435 133 // jints, conjoint, atomic on each jint
duke@435 134 static void conjoint_jints_atomic(jint* from, jint* to, size_t count) {
duke@435 135 assert_params_ok(from, to, LogBytesPerInt);
duke@435 136 pd_conjoint_jints_atomic(from, to, count);
duke@435 137 }
duke@435 138
duke@435 139 // jlongs, conjoint, atomic on each jlong
duke@435 140 static void conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
duke@435 141 assert_params_ok(from, to, LogBytesPerLong);
duke@435 142 pd_conjoint_jlongs_atomic(from, to, count);
duke@435 143 }
duke@435 144
duke@435 145 // oops, conjoint, atomic on each oop
duke@435 146 static void conjoint_oops_atomic(oop* from, oop* to, size_t count) {
coleenp@548 147 assert_params_ok(from, to, LogBytesPerHeapOop);
duke@435 148 pd_conjoint_oops_atomic(from, to, count);
duke@435 149 }
duke@435 150
coleenp@548 151 // overloaded for UseCompressedOops
coleenp@548 152 static void conjoint_oops_atomic(narrowOop* from, narrowOop* to, size_t count) {
coleenp@548 153 assert(sizeof(narrowOop) == sizeof(jint), "this cast is wrong");
coleenp@548 154 assert_params_ok(from, to, LogBytesPerInt);
coleenp@548 155 pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
coleenp@548 156 }
coleenp@548 157
duke@435 158 // Copy a span of memory. If the span is an integral number of aligned
duke@435 159 // longs, words, or ints, copy those units atomically.
duke@435 160 // The largest atomic transfer unit is 8 bytes, or the largest power
duke@435 161 // of two which divides all of from, to, and size, whichever is smaller.
duke@435 162 static void conjoint_memory_atomic(void* from, void* to, size_t size);
duke@435 163
duke@435 164 // bytes, conjoint array, atomic on each byte (not that it matters)
kvn@1958 165 static void arrayof_conjoint_jbytes(HeapWord* from, HeapWord* to, size_t count) {
duke@435 166 pd_arrayof_conjoint_bytes(from, to, count);
duke@435 167 }
duke@435 168
duke@435 169 // jshorts, conjoint array, atomic on each jshort
duke@435 170 static void arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
duke@435 171 assert_params_ok(from, to, LogBytesPerShort);
duke@435 172 pd_arrayof_conjoint_jshorts(from, to, count);
duke@435 173 }
duke@435 174
duke@435 175 // jints, conjoint array, atomic on each jint
duke@435 176 static void arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
duke@435 177 assert_params_ok(from, to, LogBytesPerInt);
duke@435 178 pd_arrayof_conjoint_jints(from, to, count);
duke@435 179 }
duke@435 180
duke@435 181 // jlongs, conjoint array, atomic on each jlong
duke@435 182 static void arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
duke@435 183 assert_params_ok(from, to, LogBytesPerLong);
duke@435 184 pd_arrayof_conjoint_jlongs(from, to, count);
duke@435 185 }
duke@435 186
duke@435 187 // oops, conjoint array, atomic on each oop
duke@435 188 static void arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
coleenp@548 189 assert_params_ok(from, to, LogBytesPerHeapOop);
duke@435 190 pd_arrayof_conjoint_oops(from, to, count);
duke@435 191 }
duke@435 192
duke@435 193 // Known overlap methods
duke@435 194
duke@435 195 // Copy word-aligned words from higher to lower addresses, not atomic on each word
duke@435 196 inline static void conjoint_words_to_lower(HeapWord* from, HeapWord* to, size_t byte_count) {
duke@435 197 // byte_count is in bytes to check its alignment
duke@435 198 assert_params_ok(from, to, LogHeapWordSize);
duke@435 199 assert_byte_count_ok(byte_count, HeapWordSize);
duke@435 200
duke@435 201 size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
duke@435 202 assert(to <= from || from + count <= to, "do not overwrite source data");
duke@435 203
duke@435 204 while (count-- > 0) {
duke@435 205 *to++ = *from++;
duke@435 206 }
duke@435 207 }
duke@435 208
duke@435 209 // Copy word-aligned words from lower to higher addresses, not atomic on each word
duke@435 210 inline static void conjoint_words_to_higher(HeapWord* from, HeapWord* to, size_t byte_count) {
duke@435 211 // byte_count is in bytes to check its alignment
duke@435 212 assert_params_ok(from, to, LogHeapWordSize);
duke@435 213 assert_byte_count_ok(byte_count, HeapWordSize);
duke@435 214
duke@435 215 size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
duke@435 216 assert(from <= to || to + count <= from, "do not overwrite source data");
duke@435 217
duke@435 218 from += count - 1;
duke@435 219 to += count - 1;
duke@435 220 while (count-- > 0) {
duke@435 221 *to-- = *from--;
duke@435 222 }
duke@435 223 }
duke@435 224
duke@435 225 // Fill methods
duke@435 226
duke@435 227 // Fill word-aligned words, not atomic on each word
duke@435 228 // set_words
duke@435 229 static void fill_to_words(HeapWord* to, size_t count, juint value = 0) {
duke@435 230 assert_params_ok(to, LogHeapWordSize);
duke@435 231 pd_fill_to_words(to, count, value);
duke@435 232 }
duke@435 233
duke@435 234 static void fill_to_aligned_words(HeapWord* to, size_t count, juint value = 0) {
duke@435 235 assert_params_aligned(to);
duke@435 236 pd_fill_to_aligned_words(to, count, value);
duke@435 237 }
duke@435 238
duke@435 239 // Fill bytes
duke@435 240 static void fill_to_bytes(void* to, size_t count, jubyte value = 0) {
duke@435 241 pd_fill_to_bytes(to, count, value);
duke@435 242 }
duke@435 243
duke@435 244 // Fill a span of memory. If the span is an integral number of aligned
duke@435 245 // longs, words, or ints, store to those units atomically.
duke@435 246 // The largest atomic transfer unit is 8 bytes, or the largest power
duke@435 247 // of two which divides both to and size, whichever is smaller.
duke@435 248 static void fill_to_memory_atomic(void* to, size_t size, jubyte value = 0);
duke@435 249
duke@435 250 // Zero-fill methods
duke@435 251
duke@435 252 // Zero word-aligned words, not atomic on each word
duke@435 253 static void zero_to_words(HeapWord* to, size_t count) {
duke@435 254 assert_params_ok(to, LogHeapWordSize);
duke@435 255 pd_zero_to_words(to, count);
duke@435 256 }
duke@435 257
duke@435 258 // Zero bytes
duke@435 259 static void zero_to_bytes(void* to, size_t count) {
duke@435 260 pd_zero_to_bytes(to, count);
duke@435 261 }
duke@435 262
duke@435 263 private:
duke@435 264 static bool params_disjoint(HeapWord* from, HeapWord* to, size_t count) {
duke@435 265 if (from < to) {
duke@435 266 return pointer_delta(to, from) >= count;
duke@435 267 }
duke@435 268 return pointer_delta(from, to) >= count;
duke@435 269 }
duke@435 270
duke@435 271 // These methods raise a fatal if they detect a problem.
duke@435 272
duke@435 273 static void assert_disjoint(HeapWord* from, HeapWord* to, size_t count) {
duke@435 274 #ifdef ASSERT
duke@435 275 if (!params_disjoint(from, to, count))
duke@435 276 basic_fatal("source and dest overlap");
duke@435 277 #endif
duke@435 278 }
duke@435 279
duke@435 280 static void assert_params_ok(void* from, void* to, intptr_t log_align) {
duke@435 281 #ifdef ASSERT
duke@435 282 if (mask_bits((uintptr_t)from, right_n_bits(log_align)) != 0)
duke@435 283 basic_fatal("not aligned");
duke@435 284 if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
duke@435 285 basic_fatal("not aligned");
duke@435 286 #endif
duke@435 287 }
duke@435 288
duke@435 289 static void assert_params_ok(HeapWord* to, intptr_t log_align) {
duke@435 290 #ifdef ASSERT
duke@435 291 if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
duke@435 292 basic_fatal("not word aligned");
duke@435 293 #endif
duke@435 294 }
duke@435 295 static void assert_params_aligned(HeapWord* from, HeapWord* to) {
duke@435 296 #ifdef ASSERT
kvn@1926 297 if (mask_bits((uintptr_t)from, BytesPerLong-1) != 0)
kvn@1926 298 basic_fatal("not long aligned");
kvn@1926 299 if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0)
kvn@1926 300 basic_fatal("not long aligned");
duke@435 301 #endif
duke@435 302 }
duke@435 303
duke@435 304 static void assert_params_aligned(HeapWord* to) {
duke@435 305 #ifdef ASSERT
kvn@1926 306 if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0)
kvn@1926 307 basic_fatal("not long aligned");
duke@435 308 #endif
duke@435 309 }
duke@435 310
duke@435 311 static void assert_byte_count_ok(size_t byte_count, size_t unit_size) {
duke@435 312 #ifdef ASSERT
duke@435 313 if ((size_t)round_to(byte_count, unit_size) != byte_count) {
duke@435 314 basic_fatal("byte count must be aligned");
duke@435 315 }
duke@435 316 #endif
duke@435 317 }
duke@435 318
duke@435 319 // Platform dependent implementations of the above methods.
duke@435 320 #include "incls/_copy_pd.hpp.incl"
duke@435 321 };

mercurial