src/share/vm/utilities/copy.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "runtime/sharedRuntime.hpp"
aoqi@0 27 #include "utilities/copy.hpp"
aoqi@0 28
aoqi@0 29
aoqi@0 30 // Copy bytes; larger units are filled atomically if everything is aligned.
aoqi@0 31 void Copy::conjoint_memory_atomic(void* from, void* to, size_t size) {
aoqi@0 32 address src = (address) from;
aoqi@0 33 address dst = (address) to;
aoqi@0 34 uintptr_t bits = (uintptr_t) src | (uintptr_t) dst | (uintptr_t) size;
aoqi@0 35
aoqi@0 36 // (Note: We could improve performance by ignoring the low bits of size,
aoqi@0 37 // and putting a short cleanup loop after each bulk copy loop.
aoqi@0 38 // There are plenty of other ways to make this faster also,
aoqi@0 39 // and it's a slippery slope. For now, let's keep this code simple
aoqi@0 40 // since the simplicity helps clarify the atomicity semantics of
aoqi@0 41 // this operation. There are also CPU-specific assembly versions
aoqi@0 42 // which may or may not want to include such optimizations.)
aoqi@0 43
aoqi@0 44 if (bits % sizeof(jlong) == 0) {
aoqi@0 45 Copy::conjoint_jlongs_atomic((jlong*) src, (jlong*) dst, size / sizeof(jlong));
aoqi@0 46 } else if (bits % sizeof(jint) == 0) {
aoqi@0 47 Copy::conjoint_jints_atomic((jint*) src, (jint*) dst, size / sizeof(jint));
aoqi@0 48 } else if (bits % sizeof(jshort) == 0) {
aoqi@0 49 Copy::conjoint_jshorts_atomic((jshort*) src, (jshort*) dst, size / sizeof(jshort));
aoqi@0 50 } else {
aoqi@0 51 // Not aligned, so no need to be atomic.
aoqi@0 52 Copy::conjoint_jbytes((void*) src, (void*) dst, size);
aoqi@0 53 }
aoqi@0 54 }
aoqi@0 55
aoqi@0 56
aoqi@0 57 // Fill bytes; larger units are filled atomically if everything is aligned.
aoqi@0 58 void Copy::fill_to_memory_atomic(void* to, size_t size, jubyte value) {
aoqi@0 59 address dst = (address) to;
aoqi@0 60 uintptr_t bits = (uintptr_t) to | (uintptr_t) size;
aoqi@0 61 if (bits % sizeof(jlong) == 0) {
aoqi@0 62 jlong fill = (julong)( (jubyte)value ); // zero-extend
aoqi@0 63 if (fill != 0) {
aoqi@0 64 fill += fill << 8;
aoqi@0 65 fill += fill << 16;
aoqi@0 66 fill += fill << 32;
aoqi@0 67 }
aoqi@0 68 //Copy::fill_to_jlongs_atomic((jlong*) dst, size / sizeof(jlong));
aoqi@0 69 for (uintptr_t off = 0; off < size; off += sizeof(jlong)) {
aoqi@0 70 *(jlong*)(dst + off) = fill;
aoqi@0 71 }
aoqi@0 72 } else if (bits % sizeof(jint) == 0) {
aoqi@0 73 jint fill = (juint)( (jubyte)value ); // zero-extend
aoqi@0 74 if (fill != 0) {
aoqi@0 75 fill += fill << 8;
aoqi@0 76 fill += fill << 16;
aoqi@0 77 }
aoqi@0 78 //Copy::fill_to_jints_atomic((jint*) dst, size / sizeof(jint));
aoqi@0 79 for (uintptr_t off = 0; off < size; off += sizeof(jint)) {
aoqi@0 80 *(jint*)(dst + off) = fill;
aoqi@0 81 }
aoqi@0 82 } else if (bits % sizeof(jshort) == 0) {
aoqi@0 83 jshort fill = (jushort)( (jubyte)value ); // zero-extend
aoqi@0 84 fill += fill << 8;
aoqi@0 85 //Copy::fill_to_jshorts_atomic((jshort*) dst, size / sizeof(jshort));
aoqi@0 86 for (uintptr_t off = 0; off < size; off += sizeof(jshort)) {
aoqi@0 87 *(jshort*)(dst + off) = fill;
aoqi@0 88 }
aoqi@0 89 } else {
aoqi@0 90 // Not aligned, so no need to be atomic.
aoqi@0 91 Copy::fill_to_bytes(dst, size, value);
aoqi@0 92 }
aoqi@0 93 }

mercurial