src/hotspot/share/utilities/copy.hpp
author mr
Tue, 29 Oct 2019 13:52:04 -0700
changeset 58850 f4290bf1cc21
parent 53244 9807daeb47c4
permissions -rw-r--r--
8233137: runtime/ErrorHandling/VeryEarlyAssertTest.java fails after 8232080 Reviewed-by: stuefe, iignatyev, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49011
diff changeset
     2
 * Copyright (c) 2003, 2019, 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: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
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: 670
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49011
diff changeset
    25
#ifndef SHARE_UTILITIES_COPY_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49011
diff changeset
    26
#define SHARE_UTILITIES_COPY_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5883
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5883
diff changeset
    28
#include "runtime/stubRoutines.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    29
#include "utilities/align.hpp"
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
    30
#include "utilities/debug.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 36086
diff changeset
    31
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5883
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Assembly code for platforms that need it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
extern "C" {
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    35
  void _Copy_conjoint_words(const HeapWord* from, HeapWord* to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    36
  void _Copy_disjoint_words(const HeapWord* from, HeapWord* to, size_t count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    38
  void _Copy_conjoint_words_atomic(const HeapWord* from, HeapWord* to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    39
  void _Copy_disjoint_words_atomic(const HeapWord* from, HeapWord* to, size_t count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    41
  void _Copy_aligned_conjoint_words(const HeapWord* from, HeapWord* to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    42
  void _Copy_aligned_disjoint_words(const HeapWord* from, HeapWord* to, size_t count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    44
  void _Copy_conjoint_bytes(const void* from, void* to, size_t count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    46
  void _Copy_conjoint_bytes_atomic  (const void*   from, void*   to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    47
  void _Copy_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    48
  void _Copy_conjoint_jints_atomic  (const jint*   from, jint*   to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    49
  void _Copy_conjoint_jlongs_atomic (const jlong*  from, jlong*  to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    50
  void _Copy_conjoint_oops_atomic   (const oop*    from, oop*    to, size_t count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    52
  void _Copy_arrayof_conjoint_bytes  (const HeapWord* from, HeapWord* to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    53
  void _Copy_arrayof_conjoint_jshorts(const HeapWord* from, HeapWord* to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    54
  void _Copy_arrayof_conjoint_jints  (const HeapWord* from, HeapWord* to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    55
  void _Copy_arrayof_conjoint_jlongs (const HeapWord* from, HeapWord* to, size_t count);
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    56
  void _Copy_arrayof_conjoint_oops   (const HeapWord* from, HeapWord* to, size_t count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
class Copy : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Block copy methods have four attributes.  We don't define all possibilities.
5694
1e0532a6abff 6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents: 670
diff changeset
    62
  //   alignment: aligned to BytesPerLong
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  //   arrayof:   arraycopy operation with both operands aligned on the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  //              boundary as the first element of an array of the copy unit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  //              This is currently a HeapWord boundary on all platforms, except
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  //              for long and double arrays, which are aligned on an 8-byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  //              boundary on all platforms.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  //              arraycopy operations are implicitly atomic on each array element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  //   overlap:   disjoint or conjoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  //   copy unit: bytes or words (i.e., HeapWords) or oops (i.e., pointers).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  //   atomicity: atomic or non-atomic on the copy unit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Names are constructed thusly:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  //     [ 'aligned_' | 'arrayof_' ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  //     ('conjoint_' | 'disjoint_')
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  //     ('words' | 'bytes' | 'jshorts' | 'jints' | 'jlongs' | 'oops')
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  //     [ '_atomic' ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Except in the arrayof case, whatever the alignment is, we assume we can copy
5694
1e0532a6abff 6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents: 670
diff changeset
    81
  // whole alignment units.  E.g., if BytesPerLong is 2x word alignment, an odd
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // count may copy an extra word.  In the arrayof case, we are allowed to copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // only the number of copy units specified.
5883
8dc4bdc132d5 6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents: 5702
diff changeset
    84
  //
8dc4bdc132d5 6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents: 5702
diff changeset
    85
  // All callees check count for 0.
8dc4bdc132d5 6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents: 5702
diff changeset
    86
  //
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // HeapWords
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Word-aligned words,    conjoint, not atomic on each word
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    91
  static void conjoint_words(const HeapWord* from, HeapWord* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
    92
    assert_params_ok(from, to, HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    pd_conjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Word-aligned words,    disjoint, not atomic on each word
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
    97
  static void disjoint_words(const HeapWord* from, HeapWord* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
    98
    assert_params_ok(from, to, HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    assert_disjoint(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    pd_disjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // Word-aligned words,    disjoint, atomic on each word
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   104
  static void disjoint_words_atomic(const HeapWord* from, HeapWord* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   105
    assert_params_ok(from, to, HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    assert_disjoint(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    pd_disjoint_words_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // Object-aligned words,  conjoint, not atomic on each word
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   111
  static void aligned_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    assert_params_aligned(from, to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    pd_aligned_conjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Object-aligned words,  disjoint, not atomic on each word
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   117
  static void aligned_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    assert_params_aligned(from, to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    assert_disjoint(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    pd_aligned_disjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // bytes, jshorts, jints, jlongs, oops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // bytes,                 conjoint, not atomic on each byte (not that it matters)
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   126
  static void conjoint_jbytes(const void* from, void* to, size_t count) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    pd_conjoint_bytes(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // bytes,                 conjoint, atomic on each byte (not that it matters)
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   131
  static void conjoint_jbytes_atomic(const void* from, void* to, size_t count) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    pd_conjoint_bytes(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
  // jshorts,               conjoint, atomic on each jshort
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   136
  static void conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   137
    assert_params_ok(from, to, BytesPerShort);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    pd_conjoint_jshorts_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // jints,                 conjoint, atomic on each jint
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   142
  static void conjoint_jints_atomic(const jint* from, jint* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   143
    assert_params_ok(from, to, BytesPerInt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    pd_conjoint_jints_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // jlongs,                conjoint, atomic on each jlong
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   148
  static void conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   149
    assert_params_ok(from, to, BytesPerLong);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    pd_conjoint_jlongs_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // oops,                  conjoint, atomic on each oop
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   154
  static void conjoint_oops_atomic(const oop* from, oop* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   155
    assert_params_ok(from, to, BytesPerHeapOop);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    pd_conjoint_oops_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   159
  // overloaded for UseCompressedOops
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   160
  static void conjoint_oops_atomic(const narrowOop* from, narrowOop* to, size_t count) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   161
    assert(sizeof(narrowOop) == sizeof(jint), "this cast is wrong");
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   162
    assert_params_ok(from, to, BytesPerInt);
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   163
    pd_conjoint_jints_atomic((const jint*)from, (jint*)to, count);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   164
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   165
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // Copy a span of memory.  If the span is an integral number of aligned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // longs, words, or ints, copy those units atomically.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // The largest atomic transfer unit is 8 bytes, or the largest power
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // of two which divides all of from, to, and size, whichever is smaller.
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   170
  static void conjoint_memory_atomic(const void* from, void* to, size_t size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // bytes,                 conjoint array, atomic on each byte (not that it matters)
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   173
  static void arrayof_conjoint_jbytes(const HeapWord* from, HeapWord* to, size_t count) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    pd_arrayof_conjoint_bytes(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // jshorts,               conjoint array, atomic on each jshort
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   178
  static void arrayof_conjoint_jshorts(const HeapWord* from, HeapWord* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   179
    assert_params_ok(from, to, BytesPerShort);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    pd_arrayof_conjoint_jshorts(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // jints,                 conjoint array, atomic on each jint
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   184
  static void arrayof_conjoint_jints(const HeapWord* from, HeapWord* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   185
    assert_params_ok(from, to, BytesPerInt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    pd_arrayof_conjoint_jints(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
  // jlongs,                conjoint array, atomic on each jlong
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   190
  static void arrayof_conjoint_jlongs(const HeapWord* from, HeapWord* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   191
    assert_params_ok(from, to, BytesPerLong);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    pd_arrayof_conjoint_jlongs(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // oops,                  conjoint array, atomic on each oop
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   196
  static void arrayof_conjoint_oops(const HeapWord* from, HeapWord* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   197
    assert_params_ok(from, to, BytesPerHeapOop);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    pd_arrayof_conjoint_oops(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // Known overlap methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // Copy word-aligned words from higher to lower addresses, not atomic on each word
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   204
  inline static void conjoint_words_to_lower(const HeapWord* from, HeapWord* to, size_t byte_count) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    // byte_count is in bytes to check its alignment
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   206
    assert_params_ok(from, to, HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    assert_byte_count_ok(byte_count, HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46504
diff changeset
   209
    size_t count = align_up(byte_count, HeapWordSize) >> LogHeapWordSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    assert(to <= from || from + count <= to, "do not overwrite source data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      *to++ = *from++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Copy word-aligned words from lower to higher addresses, not atomic on each word
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   218
  inline static void conjoint_words_to_higher(const HeapWord* from, HeapWord* to, size_t byte_count) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    // byte_count is in bytes to check its alignment
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   220
    assert_params_ok(from, to, HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    assert_byte_count_ok(byte_count, HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46504
diff changeset
   223
    size_t count = align_up(byte_count, HeapWordSize) >> LogHeapWordSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    assert(from <= to || to + count <= from, "do not overwrite source data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    from += count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    to   += count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      *to-- = *from--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
36086
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 29180
diff changeset
   233
  /**
46504
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   234
   * Copy elements
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   235
   *
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   236
   * @param src address of source
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   237
   * @param dst address of destination
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   238
   * @param byte_count number of bytes to copy
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   239
   * @param elem_size size of the elements to copy-swap
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   240
   */
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   241
  static void conjoint_copy(const void* src, void* dst, size_t byte_count, size_t elem_size);
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   242
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   243
  /**
36086
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 29180
diff changeset
   244
   * Copy and *unconditionally* byte swap elements
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 29180
diff changeset
   245
   *
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 29180
diff changeset
   246
   * @param src address of source
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 29180
diff changeset
   247
   * @param dst address of destination
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 29180
diff changeset
   248
   * @param byte_count number of bytes to copy
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 29180
diff changeset
   249
   * @param elem_size size of the elements to copy-swap
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 29180
diff changeset
   250
   */
46504
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   251
  static void conjoint_swap(const void* src, void* dst, size_t byte_count, size_t elem_size);
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   252
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   253
  /**
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   254
   * Copy and byte swap elements from the specified endian to the native (cpu) endian if needed (if they differ)
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   255
   *
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   256
   * @param src address of source
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   257
   * @param dst address of destination
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   258
   * @param byte_count number of bytes to copy
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   259
   * @param elem_size size of the elements to copy-swap
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   260
   */
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   261
  template <Endian::Order endian>
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   262
  static void conjoint_swap_if_needed(const void* src, void* dst, size_t byte_count, size_t elem_size) {
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   263
    if (Endian::NATIVE != endian) {
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   264
      conjoint_swap(src, dst, byte_count, elem_size);
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   265
    } else {
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   266
      conjoint_copy(src, dst, byte_count, elem_size);
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   267
    }
38048d4d20e7 8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents: 40010
diff changeset
   268
  }
36086
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 29180
diff changeset
   269
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  // Fill methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  // Fill word-aligned words, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  // set_words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  static void fill_to_words(HeapWord* to, size_t count, juint value = 0) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   275
    assert_params_ok(to, HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    pd_fill_to_words(to, count, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  static void fill_to_aligned_words(HeapWord* to, size_t count, juint value = 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    assert_params_aligned(to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    pd_fill_to_aligned_words(to, count, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // Fill bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  static void fill_to_bytes(void* to, size_t count, jubyte value = 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    pd_fill_to_bytes(to, count, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  // Fill a span of memory.  If the span is an integral number of aligned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  // longs, words, or ints, store to those units atomically.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  // The largest atomic transfer unit is 8 bytes, or the largest power
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  // of two which divides both to and size, whichever is smaller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  static void fill_to_memory_atomic(void* to, size_t size, jubyte value = 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // Zero-fill methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // Zero word-aligned words, not atomic on each word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  static void zero_to_words(HeapWord* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   299
    assert_params_ok(to, HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    pd_zero_to_words(to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  // Zero bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  static void zero_to_bytes(void* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    pd_zero_to_bytes(to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
 private:
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   309
  static bool params_disjoint(const HeapWord* from, HeapWord* to, size_t count) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    if (from < to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      return pointer_delta(to, from) >= count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    return pointer_delta(from, to) >= count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // These methods raise a fatal if they detect a problem.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   318
  static void assert_disjoint(const HeapWord* from, HeapWord* to, size_t count) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   319
    assert(params_disjoint(from, to, count), "source and dest overlap");
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   320
  }
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   321
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   322
  static void assert_params_ok(const void* from, void* to, intptr_t alignment) {
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   323
    assert(is_aligned(from, alignment), "must be aligned: " INTPTR_FORMAT, p2i(from));
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   324
    assert(is_aligned(to, alignment),   "must be aligned: " INTPTR_FORMAT, p2i(to));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   327
  static void assert_params_ok(HeapWord* to, intptr_t alignment) {
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   328
    assert(is_aligned(to, alignment), "must be aligned: " INTPTR_FORMAT, p2i(to));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
48951
950c35ea6237 8165929: Constify arguments of Copy methods
coleenp
parents: 47216
diff changeset
   331
  static void assert_params_aligned(const HeapWord* from, HeapWord* to) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   332
    assert(is_aligned(from, BytesPerLong), "must be aligned: " INTPTR_FORMAT, p2i(from));
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   333
    assert(is_aligned(to, BytesPerLong),   "must be aligned: " INTPTR_FORMAT, p2i(to));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  static void assert_params_aligned(HeapWord* to) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   337
    assert(is_aligned(to, BytesPerLong), "must be aligned: " INTPTR_FORMAT, p2i(to));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  static void assert_byte_count_ok(size_t byte_count, size_t unit_size) {
49011
a0e246b7403a 8182847: Copy class should use assert macros
coleenp
parents: 48951
diff changeset
   341
    assert(is_aligned(byte_count, unit_size), "byte count must be aligned");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // Platform dependent implementations of the above methods.
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 36086
diff changeset
   345
#include CPU_HEADER(copy)
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5883
diff changeset
   346
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5883
diff changeset
   348
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49011
diff changeset
   349
#endif // SHARE_UTILITIES_COPY_HPP