hotspot/src/share/vm/utilities/copy.cpp
author xlu
Mon, 06 Apr 2009 15:47:39 -0700
changeset 2526 39a58a50be35
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6699669: Hotspot server leaves synchronized block with monitor in bad state Summary: Remove usage of _highest_lock field in Thread so that is_lock_owned won't depend on the correct update of that field. Reviewed-by: never, dice, acorn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2006-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    Copy::conjoint_bytes((void*) src, (void*) dst, size);
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
}