hotspot/src/share/vm/utilities/copy.hpp
author kvn
Thu, 06 Mar 2008 10:30:17 -0800
changeset 211 e2b60448c234
parent 1 489c9b5090e2
child 360 21d113ecbf6a
permissions -rw-r--r--
6667610: (Escape Analysis) retry compilation without EA if it fails Summary: During split unique types EA could exceed nodes limit and fail the method compilation. Reviewed-by: rasbold
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 2003-2006 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
// Assembly code for platforms that need it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
extern "C" {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
  void _Copy_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
  void _Copy_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  void _Copy_conjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  void _Copy_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  void _Copy_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  void _Copy_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  void _Copy_conjoint_bytes(void* from, void* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  void _Copy_conjoint_bytes_atomic  (void*   from, void*   to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  void _Copy_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  void _Copy_conjoint_jints_atomic  (jint*   from, jint*   to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  void _Copy_conjoint_jlongs_atomic (jlong*  from, jlong*  to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  void _Copy_conjoint_oops_atomic   (oop*    from, oop*    to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  void _Copy_arrayof_conjoint_bytes  (HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  void _Copy_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  void _Copy_arrayof_conjoint_jints  (HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  void _Copy_arrayof_conjoint_jlongs (HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  void _Copy_arrayof_conjoint_oops   (HeapWord* from, HeapWord* to, size_t count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
class Copy : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Block copy methods have four attributes.  We don't define all possibilities.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  //   alignment: aligned according to minimum Java object alignment (MinObjAlignment)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  //   arrayof:   arraycopy operation with both operands aligned on the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  //              boundary as the first element of an array of the copy unit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  //              This is currently a HeapWord boundary on all platforms, except
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  //              for long and double arrays, which are aligned on an 8-byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  //              boundary on all platforms.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  //              arraycopy operations are implicitly atomic on each array element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  //   overlap:   disjoint or conjoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  //   copy unit: bytes or words (i.e., HeapWords) or oops (i.e., pointers).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  //   atomicity: atomic or non-atomic on the copy unit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Names are constructed thusly:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  //     [ 'aligned_' | 'arrayof_' ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  //     ('conjoint_' | 'disjoint_')
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  //     ('words' | 'bytes' | 'jshorts' | 'jints' | 'jlongs' | 'oops')
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  //     [ '_atomic' ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Except in the arrayof case, whatever the alignment is, we assume we can copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // whole alignment units.  E.g., if MinObjAlignment is 2x word alignment, an odd
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // count may copy an extra word.  In the arrayof case, we are allowed to copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // only the number of copy units specified.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // HeapWords
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Word-aligned words,    conjoint, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  static void conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    assert_params_ok(from, to, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    pd_conjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Word-aligned words,    disjoint, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  static void disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    assert_params_ok(from, to, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    assert_disjoint(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    pd_disjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Word-aligned words,    disjoint, atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  static void disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    assert_params_ok(from, to, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    assert_disjoint(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    pd_disjoint_words_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Object-aligned words,  conjoint, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  static void aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    assert_params_aligned(from, to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    pd_aligned_conjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Object-aligned words,  disjoint, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  static void aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    assert_params_aligned(from, to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    assert_disjoint(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    pd_aligned_disjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // bytes, jshorts, jints, jlongs, oops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // bytes,                 conjoint, not atomic on each byte (not that it matters)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  static void conjoint_bytes(void* from, void* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    pd_conjoint_bytes(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // bytes,                 conjoint, atomic on each byte (not that it matters)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  static void conjoint_bytes_atomic(void* from, void* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    pd_conjoint_bytes(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // jshorts,               conjoint, atomic on each jshort
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  static void conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    assert_params_ok(from, to, LogBytesPerShort);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    pd_conjoint_jshorts_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // jints,                 conjoint, atomic on each jint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  static void conjoint_jints_atomic(jint* from, jint* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    assert_params_ok(from, to, LogBytesPerInt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    pd_conjoint_jints_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // jlongs,                conjoint, atomic on each jlong
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  static void conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    assert_params_ok(from, to, LogBytesPerLong);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    pd_conjoint_jlongs_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // oops,                  conjoint, atomic on each oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  static void conjoint_oops_atomic(oop* from, oop* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    assert_params_ok(from, to, LogBytesPerOop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    pd_conjoint_oops_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // Copy a span of memory.  If the span is an integral number of aligned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // longs, words, or ints, copy those units atomically.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // The largest atomic transfer unit is 8 bytes, or the largest power
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // of two which divides all of from, to, and size, whichever is smaller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  static void conjoint_memory_atomic(void* from, void* to, size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // bytes,                 conjoint array, atomic on each byte (not that it matters)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  static void arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    pd_arrayof_conjoint_bytes(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // jshorts,               conjoint array, atomic on each jshort
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  static void arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    assert_params_ok(from, to, LogBytesPerShort);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    pd_arrayof_conjoint_jshorts(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // jints,                 conjoint array, atomic on each jint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  static void arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    assert_params_ok(from, to, LogBytesPerInt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    pd_arrayof_conjoint_jints(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // jlongs,                conjoint array, atomic on each jlong
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  static void arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    assert_params_ok(from, to, LogBytesPerLong);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    pd_arrayof_conjoint_jlongs(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // oops,                  conjoint array, atomic on each oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  static void arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    assert_params_ok(from, to, LogBytesPerOop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    assert_non_zero(count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    pd_arrayof_conjoint_oops(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // Known overlap methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // Copy word-aligned words from higher to lower addresses, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  inline static void conjoint_words_to_lower(HeapWord* from, HeapWord* to, size_t byte_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    // byte_count is in bytes to check its alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    assert_params_ok(from, to, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    assert_byte_count_ok(byte_count, HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    assert(to <= from || from + count <= to, "do not overwrite source data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      *to++ = *from++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // Copy word-aligned words from lower to higher addresses, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  inline static void conjoint_words_to_higher(HeapWord* from, HeapWord* to, size_t byte_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    // byte_count is in bytes to check its alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    assert_params_ok(from, to, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    assert_byte_count_ok(byte_count, HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    size_t count = (size_t)round_to(byte_count, HeapWordSize) >> LogHeapWordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    assert(from <= to || to + count <= from, "do not overwrite source data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    from += count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    to   += count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      *to-- = *from--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // Fill methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // Fill word-aligned words, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // set_words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  static void fill_to_words(HeapWord* to, size_t count, juint value = 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    assert_params_ok(to, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    pd_fill_to_words(to, count, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  static void fill_to_aligned_words(HeapWord* to, size_t count, juint value = 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    assert_params_aligned(to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    pd_fill_to_aligned_words(to, count, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // Fill bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  static void fill_to_bytes(void* to, size_t count, jubyte value = 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    pd_fill_to_bytes(to, count, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // Fill a span of memory.  If the span is an integral number of aligned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // longs, words, or ints, store to those units atomically.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  // The largest atomic transfer unit is 8 bytes, or the largest power
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  // of two which divides both to and size, whichever is smaller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  static void fill_to_memory_atomic(void* to, size_t size, jubyte value = 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // Zero-fill methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  // Zero word-aligned words, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  static void zero_to_words(HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    assert_params_ok(to, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    pd_zero_to_words(to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // Zero bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  static void zero_to_bytes(void* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    pd_zero_to_bytes(to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  static bool params_disjoint(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    if (from < to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      return pointer_delta(to, from) >= count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    return pointer_delta(from, to) >= count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  // These methods raise a fatal if they detect a problem.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  static void assert_disjoint(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    if (!params_disjoint(from, to, count))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      basic_fatal("source and dest overlap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  static void assert_params_ok(void* from, void* to, intptr_t log_align) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    if (mask_bits((uintptr_t)from, right_n_bits(log_align)) != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      basic_fatal("not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      basic_fatal("not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  static void assert_params_ok(HeapWord* to, intptr_t log_align) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    if (mask_bits((uintptr_t)to, right_n_bits(log_align)) != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
      basic_fatal("not word aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  static void assert_params_aligned(HeapWord* from, HeapWord* to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    if (mask_bits((uintptr_t)from, MinObjAlignmentInBytes-1) != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      basic_fatal("not object aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    if (mask_bits((uintptr_t)to, MinObjAlignmentInBytes-1) != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      basic_fatal("not object aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  static void assert_params_aligned(HeapWord* to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    if (mask_bits((uintptr_t)to, MinObjAlignmentInBytes-1) != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      basic_fatal("not object aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  static void assert_non_zero(size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    if (count == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      basic_fatal("count must be non-zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  static void assert_byte_count_ok(size_t byte_count, size_t unit_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    if ((size_t)round_to(byte_count, unit_size) != byte_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      basic_fatal("byte count must be aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  // Platform dependent implementations of the above methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  #include "incls/_copy_pd.hpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
};