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