hotspot/src/share/vm/utilities/copy.hpp
changeset 5883 8dc4bdc132d5
parent 5702 201c5cde25bb
child 7397 5b173b4ca846
equal deleted inserted replaced
5882:6b2aecc4f7d8 5883:8dc4bdc132d5
    71   //
    71   //
    72   // Except in the arrayof case, whatever the alignment is, we assume we can copy
    72   // Except in the arrayof case, whatever the alignment is, we assume we can copy
    73   // whole alignment units.  E.g., if BytesPerLong is 2x word alignment, an odd
    73   // whole alignment units.  E.g., if BytesPerLong is 2x word alignment, an odd
    74   // count may copy an extra word.  In the arrayof case, we are allowed to copy
    74   // count may copy an extra word.  In the arrayof case, we are allowed to copy
    75   // only the number of copy units specified.
    75   // only the number of copy units specified.
       
    76   //
       
    77   // All callees check count for 0.
       
    78   //
    76 
    79 
    77   // HeapWords
    80   // HeapWords
    78 
    81 
    79   // Word-aligned words,    conjoint, not atomic on each word
    82   // Word-aligned words,    conjoint, not atomic on each word
    80   static void conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    83   static void conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    97   }
   100   }
    98 
   101 
    99   // Object-aligned words,  conjoint, not atomic on each word
   102   // Object-aligned words,  conjoint, not atomic on each word
   100   static void aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
   103   static void aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
   101     assert_params_aligned(from, to);
   104     assert_params_aligned(from, to);
   102     assert_non_zero(count);
       
   103     pd_aligned_conjoint_words(from, to, count);
   105     pd_aligned_conjoint_words(from, to, count);
   104   }
   106   }
   105 
   107 
   106   // Object-aligned words,  disjoint, not atomic on each word
   108   // Object-aligned words,  disjoint, not atomic on each word
   107   static void aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
   109   static void aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
   108     assert_params_aligned(from, to);
   110     assert_params_aligned(from, to);
   109     assert_disjoint(from, to, count);
   111     assert_disjoint(from, to, count);
   110     assert_non_zero(count);
       
   111     pd_aligned_disjoint_words(from, to, count);
   112     pd_aligned_disjoint_words(from, to, count);
   112   }
   113   }
   113 
   114 
   114   // bytes, jshorts, jints, jlongs, oops
   115   // bytes, jshorts, jints, jlongs, oops
   115 
   116 
   116   // bytes,                 conjoint, not atomic on each byte (not that it matters)
   117   // bytes,                 conjoint, not atomic on each byte (not that it matters)
   117   static void conjoint_bytes(void* from, void* to, size_t count) {
   118   static void conjoint_jbytes(void* from, void* to, size_t count) {
   118     assert_non_zero(count);
       
   119     pd_conjoint_bytes(from, to, count);
   119     pd_conjoint_bytes(from, to, count);
   120   }
   120   }
   121 
   121 
   122   // bytes,                 conjoint, atomic on each byte (not that it matters)
   122   // bytes,                 conjoint, atomic on each byte (not that it matters)
   123   static void conjoint_bytes_atomic(void* from, void* to, size_t count) {
   123   static void conjoint_jbytes_atomic(void* from, void* to, size_t count) {
   124     assert_non_zero(count);
       
   125     pd_conjoint_bytes(from, to, count);
   124     pd_conjoint_bytes(from, to, count);
   126   }
   125   }
   127 
   126 
   128   // jshorts,               conjoint, atomic on each jshort
   127   // jshorts,               conjoint, atomic on each jshort
   129   static void conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
   128   static void conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
   130     assert_params_ok(from, to, LogBytesPerShort);
   129     assert_params_ok(from, to, LogBytesPerShort);
   131     assert_non_zero(count);
       
   132     pd_conjoint_jshorts_atomic(from, to, count);
   130     pd_conjoint_jshorts_atomic(from, to, count);
   133   }
   131   }
   134 
   132 
   135   // jints,                 conjoint, atomic on each jint
   133   // jints,                 conjoint, atomic on each jint
   136   static void conjoint_jints_atomic(jint* from, jint* to, size_t count) {
   134   static void conjoint_jints_atomic(jint* from, jint* to, size_t count) {
   137     assert_params_ok(from, to, LogBytesPerInt);
   135     assert_params_ok(from, to, LogBytesPerInt);
   138     assert_non_zero(count);
       
   139     pd_conjoint_jints_atomic(from, to, count);
   136     pd_conjoint_jints_atomic(from, to, count);
   140   }
   137   }
   141 
   138 
   142   // jlongs,                conjoint, atomic on each jlong
   139   // jlongs,                conjoint, atomic on each jlong
   143   static void conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
   140   static void conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
   144     assert_params_ok(from, to, LogBytesPerLong);
   141     assert_params_ok(from, to, LogBytesPerLong);
   145     assert_non_zero(count);
       
   146     pd_conjoint_jlongs_atomic(from, to, count);
   142     pd_conjoint_jlongs_atomic(from, to, count);
   147   }
   143   }
   148 
   144 
   149   // oops,                  conjoint, atomic on each oop
   145   // oops,                  conjoint, atomic on each oop
   150   static void conjoint_oops_atomic(oop* from, oop* to, size_t count) {
   146   static void conjoint_oops_atomic(oop* from, oop* to, size_t count) {
   151     assert_params_ok(from, to, LogBytesPerHeapOop);
   147     assert_params_ok(from, to, LogBytesPerHeapOop);
   152     assert_non_zero(count);
       
   153     pd_conjoint_oops_atomic(from, to, count);
   148     pd_conjoint_oops_atomic(from, to, count);
   154   }
   149   }
   155 
   150 
   156   // overloaded for UseCompressedOops
   151   // overloaded for UseCompressedOops
   157   static void conjoint_oops_atomic(narrowOop* from, narrowOop* to, size_t count) {
   152   static void conjoint_oops_atomic(narrowOop* from, narrowOop* to, size_t count) {
   158     assert(sizeof(narrowOop) == sizeof(jint), "this cast is wrong");
   153     assert(sizeof(narrowOop) == sizeof(jint), "this cast is wrong");
   159     assert_params_ok(from, to, LogBytesPerInt);
   154     assert_params_ok(from, to, LogBytesPerInt);
   160     assert_non_zero(count);
       
   161     pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
   155     pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
   162   }
   156   }
   163 
   157 
   164   // Copy a span of memory.  If the span is an integral number of aligned
   158   // Copy a span of memory.  If the span is an integral number of aligned
   165   // longs, words, or ints, copy those units atomically.
   159   // longs, words, or ints, copy those units atomically.
   166   // The largest atomic transfer unit is 8 bytes, or the largest power
   160   // The largest atomic transfer unit is 8 bytes, or the largest power
   167   // of two which divides all of from, to, and size, whichever is smaller.
   161   // of two which divides all of from, to, and size, whichever is smaller.
   168   static void conjoint_memory_atomic(void* from, void* to, size_t size);
   162   static void conjoint_memory_atomic(void* from, void* to, size_t size);
   169 
   163 
   170   // bytes,                 conjoint array, atomic on each byte (not that it matters)
   164   // bytes,                 conjoint array, atomic on each byte (not that it matters)
   171   static void arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
   165   static void arrayof_conjoint_jbytes(HeapWord* from, HeapWord* to, size_t count) {
   172     assert_non_zero(count);
       
   173     pd_arrayof_conjoint_bytes(from, to, count);
   166     pd_arrayof_conjoint_bytes(from, to, count);
   174   }
   167   }
   175 
   168 
   176   // jshorts,               conjoint array, atomic on each jshort
   169   // jshorts,               conjoint array, atomic on each jshort
   177   static void arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
   170   static void arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
   178     assert_params_ok(from, to, LogBytesPerShort);
   171     assert_params_ok(from, to, LogBytesPerShort);
   179     assert_non_zero(count);
       
   180     pd_arrayof_conjoint_jshorts(from, to, count);
   172     pd_arrayof_conjoint_jshorts(from, to, count);
   181   }
   173   }
   182 
   174 
   183   // jints,                 conjoint array, atomic on each jint
   175   // jints,                 conjoint array, atomic on each jint
   184   static void arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
   176   static void arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
   185     assert_params_ok(from, to, LogBytesPerInt);
   177     assert_params_ok(from, to, LogBytesPerInt);
   186     assert_non_zero(count);
       
   187     pd_arrayof_conjoint_jints(from, to, count);
   178     pd_arrayof_conjoint_jints(from, to, count);
   188   }
   179   }
   189 
   180 
   190   // jlongs,                conjoint array, atomic on each jlong
   181   // jlongs,                conjoint array, atomic on each jlong
   191   static void arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
   182   static void arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
   192     assert_params_ok(from, to, LogBytesPerLong);
   183     assert_params_ok(from, to, LogBytesPerLong);
   193     assert_non_zero(count);
       
   194     pd_arrayof_conjoint_jlongs(from, to, count);
   184     pd_arrayof_conjoint_jlongs(from, to, count);
   195   }
   185   }
   196 
   186 
   197   // oops,                  conjoint array, atomic on each oop
   187   // oops,                  conjoint array, atomic on each oop
   198   static void arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
   188   static void arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
   199     assert_params_ok(from, to, LogBytesPerHeapOop);
   189     assert_params_ok(from, to, LogBytesPerHeapOop);
   200     assert_non_zero(count);
       
   201     pd_arrayof_conjoint_oops(from, to, count);
   190     pd_arrayof_conjoint_oops(from, to, count);
   202   }
   191   }
   203 
   192 
   204   // Known overlap methods
   193   // Known overlap methods
   205 
   194 
   317     if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0)
   306     if (mask_bits((uintptr_t)to, BytesPerLong-1) != 0)
   318       basic_fatal("not long aligned");
   307       basic_fatal("not long aligned");
   319 #endif
   308 #endif
   320   }
   309   }
   321 
   310 
   322   static void assert_non_zero(size_t count) {
       
   323 #ifdef ASSERT
       
   324     if (count == 0) {
       
   325       basic_fatal("count must be non-zero");
       
   326     }
       
   327 #endif
       
   328   }
       
   329 
       
   330   static void assert_byte_count_ok(size_t byte_count, size_t unit_size) {
   311   static void assert_byte_count_ok(size_t byte_count, size_t unit_size) {
   331 #ifdef ASSERT
   312 #ifdef ASSERT
   332     if ((size_t)round_to(byte_count, unit_size) != byte_count) {
   313     if ((size_t)round_to(byte_count, unit_size) != byte_count) {
   333       basic_fatal("byte count must be aligned");
   314       basic_fatal("byte count must be aligned");
   334     }
   315     }