hotspot/src/share/vm/utilities/copy.cpp
author jcoomes
Thu, 01 Jul 2010 21:40:45 -0700
changeset 5918 73b96456819a
parent 5883 8dc4bdc132d5
child 7397 5b173b4ca846
permissions -rw-r--r--
6957084: simplify TaskQueue overflow handling Reviewed-by: ysr, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 2006, 2007, 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_copy.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Copy bytes; larger units are filled atomically if everything is aligned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
void Copy::conjoint_memory_atomic(void* from, void* to, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  address src = (address) from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  address dst = (address) to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  uintptr_t bits = (uintptr_t) src | (uintptr_t) dst | (uintptr_t) size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // (Note:  We could improve performance by ignoring the low bits of size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // and putting a short cleanup loop after each bulk copy loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // There are plenty of other ways to make this faster also,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // and it's a slippery slope.  For now, let's keep this code simple
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // since the simplicity helps clarify the atomicity semantics of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // this operation.  There are also CPU-specific assembly versions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // which may or may not want to include such optimizations.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  if (bits % sizeof(jlong) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    Copy::conjoint_jlongs_atomic((jlong*) src, (jlong*) dst, size / sizeof(jlong));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  } else if (bits % sizeof(jint) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    Copy::conjoint_jints_atomic((jint*) src, (jint*) dst, size / sizeof(jint));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  } else if (bits % sizeof(jshort) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    Copy::conjoint_jshorts_atomic((jshort*) src, (jshort*) dst, size / sizeof(jshort));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    // 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
    51
    Copy::conjoint_jbytes((void*) src, (void*) dst, size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  }
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
// Fill bytes; larger units are filled atomically if everything is aligned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
void Copy::fill_to_memory_atomic(void* to, size_t size, jubyte value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  address dst = (address) to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  uintptr_t bits = (uintptr_t) to | (uintptr_t) size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  if (bits % sizeof(jlong) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    jlong fill = (julong)( (jubyte)value ); // zero-extend
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    if (fill != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      fill += fill << 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      fill += fill << 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      fill += fill << 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    //Copy::fill_to_jlongs_atomic((jlong*) dst, size / sizeof(jlong));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    for (uintptr_t off = 0; off < size; off += sizeof(jlong)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      *(jlong*)(dst + off) = fill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  } else if (bits % sizeof(jint) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    jint fill = (juint)( (jubyte)value ); // zero-extend
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    if (fill != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      fill += fill << 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      fill += fill << 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    //Copy::fill_to_jints_atomic((jint*) dst, size / sizeof(jint));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    for (uintptr_t off = 0; off < size; off += sizeof(jint)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      *(jint*)(dst + off) = fill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  } else if (bits % sizeof(jshort) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    jshort fill = (jushort)( (jubyte)value ); // zero-extend
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    fill += fill << 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    //Copy::fill_to_jshorts_atomic((jshort*) dst, size / sizeof(jshort));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    for (uintptr_t off = 0; off < size; off += sizeof(jshort)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      *(jshort*)(dst + off) = fill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    // Not aligned, so no need to be atomic.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    Copy::fill_to_bytes(dst, size, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}