hotspot/src/share/vm/utilities/copy.cpp
author kbarrett
Tue, 13 Jan 2015 14:30:53 -0500
changeset 28477 157314902d78
parent 7397 5b173b4ca846
child 36086 f70e100d3195
permissions -rw-r--r--
8068396: Rename assert() to vmassert() Summary: Macro renaming, with temporary old name synonyms for compatibilty Reviewed-by: ehelin, dholmes, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5883
diff changeset
     2
 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5883
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5883
diff changeset
    26
#include "runtime/sharedRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5883
diff changeset
    27
#include "utilities/copy.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Copy bytes; larger units are filled atomically if everything is aligned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
void Copy::conjoint_memory_atomic(void* from, void* to, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  address src = (address) from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  address dst = (address) to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  uintptr_t bits = (uintptr_t) src | (uintptr_t) dst | (uintptr_t) size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // (Note:  We could improve performance by ignoring the low bits of size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // and putting a short cleanup loop after each bulk copy loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // There are plenty of other ways to make this faster also,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // and it's a slippery slope.  For now, let's keep this code simple
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // since the simplicity helps clarify the atomicity semantics of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // this operation.  There are also CPU-specific assembly versions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // which may or may not want to include such optimizations.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  if (bits % sizeof(jlong) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    Copy::conjoint_jlongs_atomic((jlong*) src, (jlong*) dst, size / sizeof(jlong));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  } else if (bits % sizeof(jint) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    Copy::conjoint_jints_atomic((jint*) src, (jint*) dst, size / sizeof(jint));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  } else if (bits % sizeof(jshort) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    Copy::conjoint_jshorts_atomic((jshort*) src, (jshort*) dst, size / sizeof(jshort));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    // Not aligned, so no need to be atomic.
5883
8dc4bdc132d5 6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents: 5547
diff changeset
    52
    Copy::conjoint_jbytes((void*) src, (void*) dst, size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// Fill bytes; larger units are filled atomically if everything is aligned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
void Copy::fill_to_memory_atomic(void* to, size_t size, jubyte value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  address dst = (address) to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  uintptr_t bits = (uintptr_t) to | (uintptr_t) size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  if (bits % sizeof(jlong) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    jlong fill = (julong)( (jubyte)value ); // zero-extend
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    if (fill != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      fill += fill << 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      fill += fill << 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      fill += fill << 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    //Copy::fill_to_jlongs_atomic((jlong*) dst, size / sizeof(jlong));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    for (uintptr_t off = 0; off < size; off += sizeof(jlong)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      *(jlong*)(dst + off) = fill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  } else if (bits % sizeof(jint) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    jint fill = (juint)( (jubyte)value ); // zero-extend
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    if (fill != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      fill += fill << 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      fill += fill << 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    //Copy::fill_to_jints_atomic((jint*) dst, size / sizeof(jint));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    for (uintptr_t off = 0; off < size; off += sizeof(jint)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      *(jint*)(dst + off) = fill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  } else if (bits % sizeof(jshort) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    jshort fill = (jushort)( (jubyte)value ); // zero-extend
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    fill += fill << 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    //Copy::fill_to_jshorts_atomic((jshort*) dst, size / sizeof(jshort));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    for (uintptr_t off = 0; off < size; off += sizeof(jshort)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      *(jshort*)(dst + off) = fill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    // Not aligned, so no need to be atomic.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    Copy::fill_to_bytes(dst, size, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}