1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/utilities/copy.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,92 @@ 1.4 +/* 1.5 + * Copyright 2006-2007 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 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_copy.cpp.incl" 1.30 + 1.31 + 1.32 +// Copy bytes; larger units are filled atomically if everything is aligned. 1.33 +void Copy::conjoint_memory_atomic(void* from, void* to, size_t size) { 1.34 + address src = (address) from; 1.35 + address dst = (address) to; 1.36 + uintptr_t bits = (uintptr_t) src | (uintptr_t) dst | (uintptr_t) size; 1.37 + 1.38 + // (Note: We could improve performance by ignoring the low bits of size, 1.39 + // and putting a short cleanup loop after each bulk copy loop. 1.40 + // There are plenty of other ways to make this faster also, 1.41 + // and it's a slippery slope. For now, let's keep this code simple 1.42 + // since the simplicity helps clarify the atomicity semantics of 1.43 + // this operation. There are also CPU-specific assembly versions 1.44 + // which may or may not want to include such optimizations.) 1.45 + 1.46 + if (bits % sizeof(jlong) == 0) { 1.47 + Copy::conjoint_jlongs_atomic((jlong*) src, (jlong*) dst, size / sizeof(jlong)); 1.48 + } else if (bits % sizeof(jint) == 0) { 1.49 + Copy::conjoint_jints_atomic((jint*) src, (jint*) dst, size / sizeof(jint)); 1.50 + } else if (bits % sizeof(jshort) == 0) { 1.51 + Copy::conjoint_jshorts_atomic((jshort*) src, (jshort*) dst, size / sizeof(jshort)); 1.52 + } else { 1.53 + // Not aligned, so no need to be atomic. 1.54 + Copy::conjoint_bytes((void*) src, (void*) dst, size); 1.55 + } 1.56 +} 1.57 + 1.58 + 1.59 +// Fill bytes; larger units are filled atomically if everything is aligned. 1.60 +void Copy::fill_to_memory_atomic(void* to, size_t size, jubyte value) { 1.61 + address dst = (address) to; 1.62 + uintptr_t bits = (uintptr_t) to | (uintptr_t) size; 1.63 + if (bits % sizeof(jlong) == 0) { 1.64 + jlong fill = (julong)( (jubyte)value ); // zero-extend 1.65 + if (fill != 0) { 1.66 + fill += fill << 8; 1.67 + fill += fill << 16; 1.68 + fill += fill << 32; 1.69 + } 1.70 + //Copy::fill_to_jlongs_atomic((jlong*) dst, size / sizeof(jlong)); 1.71 + for (uintptr_t off = 0; off < size; off += sizeof(jlong)) { 1.72 + *(jlong*)(dst + off) = fill; 1.73 + } 1.74 + } else if (bits % sizeof(jint) == 0) { 1.75 + jint fill = (juint)( (jubyte)value ); // zero-extend 1.76 + if (fill != 0) { 1.77 + fill += fill << 8; 1.78 + fill += fill << 16; 1.79 + } 1.80 + //Copy::fill_to_jints_atomic((jint*) dst, size / sizeof(jint)); 1.81 + for (uintptr_t off = 0; off < size; off += sizeof(jint)) { 1.82 + *(jint*)(dst + off) = fill; 1.83 + } 1.84 + } else if (bits % sizeof(jshort) == 0) { 1.85 + jshort fill = (jushort)( (jubyte)value ); // zero-extend 1.86 + fill += fill << 8; 1.87 + //Copy::fill_to_jshorts_atomic((jshort*) dst, size / sizeof(jshort)); 1.88 + for (uintptr_t off = 0; off < size; off += sizeof(jshort)) { 1.89 + *(jshort*)(dst + off) = fill; 1.90 + } 1.91 + } else { 1.92 + // Not aligned, so no need to be atomic. 1.93 + Copy::fill_to_bytes(dst, size, value); 1.94 + } 1.95 +}