src/cpu/sparc/vm/copy_sparc.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/sparc/vm/copy_sparc.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,223 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef CPU_SPARC_VM_COPY_SPARC_HPP
    1.29 +#define CPU_SPARC_VM_COPY_SPARC_HPP
    1.30 +
    1.31 +// Inline functions for memory copy and fill.
    1.32 +
    1.33 +static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    1.34 +  (void)memmove(to, from, count * HeapWordSize);
    1.35 +}
    1.36 +
    1.37 +static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    1.38 +  switch (count) {
    1.39 +  case 8:  to[7] = from[7];
    1.40 +  case 7:  to[6] = from[6];
    1.41 +  case 6:  to[5] = from[5];
    1.42 +  case 5:  to[4] = from[4];
    1.43 +  case 4:  to[3] = from[3];
    1.44 +  case 3:  to[2] = from[2];
    1.45 +  case 2:  to[1] = from[1];
    1.46 +  case 1:  to[0] = from[0];
    1.47 +  case 0:  break;
    1.48 +  default: (void)memcpy(to, from, count * HeapWordSize);
    1.49 +           break;
    1.50 +  }
    1.51 +}
    1.52 +
    1.53 +static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
    1.54 +  switch (count) {
    1.55 +  case 8:  to[7] = from[7];
    1.56 +  case 7:  to[6] = from[6];
    1.57 +  case 6:  to[5] = from[5];
    1.58 +  case 5:  to[4] = from[4];
    1.59 +  case 4:  to[3] = from[3];
    1.60 +  case 3:  to[2] = from[2];
    1.61 +  case 2:  to[1] = from[1];
    1.62 +  case 1:  to[0] = from[0];
    1.63 +  case 0:  break;
    1.64 +  default: while (count-- > 0) {
    1.65 +             *to++ = *from++;
    1.66 +           }
    1.67 +           break;
    1.68 +  }
    1.69 +}
    1.70 +
    1.71 +static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    1.72 +  (void)memmove(to, from, count * HeapWordSize);
    1.73 +}
    1.74 +
    1.75 +static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
    1.76 +  pd_disjoint_words(from, to, count);
    1.77 +}
    1.78 +
    1.79 +static void pd_conjoint_bytes(void* from, void* to, size_t count) {
    1.80 +  (void)memmove(to, from, count);
    1.81 +}
    1.82 +
    1.83 +static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
    1.84 +  (void)memmove(to, from, count);
    1.85 +}
    1.86 +
    1.87 +static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
    1.88 +  if (from > to) {
    1.89 +    while (count-- > 0) {
    1.90 +      // Copy forwards
    1.91 +      *to++ = *from++;
    1.92 +    }
    1.93 +  } else {
    1.94 +    from += count - 1;
    1.95 +    to   += count - 1;
    1.96 +    while (count-- > 0) {
    1.97 +      // Copy backwards
    1.98 +      *to-- = *from--;
    1.99 +    }
   1.100 +  }
   1.101 +}
   1.102 +
   1.103 +static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
   1.104 +  if (from > to) {
   1.105 +    while (count-- > 0) {
   1.106 +      // Copy forwards
   1.107 +      *to++ = *from++;
   1.108 +    }
   1.109 +  } else {
   1.110 +    from += count - 1;
   1.111 +    to   += count - 1;
   1.112 +    while (count-- > 0) {
   1.113 +      // Copy backwards
   1.114 +      *to-- = *from--;
   1.115 +    }
   1.116 +  }
   1.117 +}
   1.118 +
   1.119 +static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
   1.120 +#ifdef _LP64
   1.121 +  assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
   1.122 +  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
   1.123 +#else
   1.124 +  // Guarantee use of ldd/std via some asm code, because compiler won't.
   1.125 +  // See solaris_sparc.il.
   1.126 +  _Copy_conjoint_jlongs_atomic(from, to, count);
   1.127 +#endif
   1.128 +}
   1.129 +
   1.130 +static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
   1.131 +  // Do better than this: inline memmove body  NEEDS CLEANUP
   1.132 +  if (from > to) {
   1.133 +    while (count-- > 0) {
   1.134 +      // Copy forwards
   1.135 +      *to++ = *from++;
   1.136 +    }
   1.137 +  } else {
   1.138 +    from += count - 1;
   1.139 +    to   += count - 1;
   1.140 +    while (count-- > 0) {
   1.141 +      // Copy backwards
   1.142 +      *to-- = *from--;
   1.143 +    }
   1.144 +  }
   1.145 +}
   1.146 +
   1.147 +static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
   1.148 +  pd_conjoint_bytes_atomic(from, to, count);
   1.149 +}
   1.150 +
   1.151 +static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
   1.152 +  pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count);
   1.153 +}
   1.154 +
   1.155 +static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
   1.156 +  pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
   1.157 +}
   1.158 +
   1.159 +static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
   1.160 +  pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
   1.161 +}
   1.162 +
   1.163 +static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
   1.164 +  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
   1.165 +}
   1.166 +
   1.167 +static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
   1.168 +#ifdef _LP64
   1.169 +  guarantee(mask_bits((uintptr_t)tohw, right_n_bits(LogBytesPerLong)) == 0,
   1.170 +         "unaligned fill words");
   1.171 +  julong* to = (julong*)tohw;
   1.172 +  julong  v  = ((julong)value << 32) | value;
   1.173 +  while (count-- > 0) {
   1.174 +    *to++ = v;
   1.175 +  }
   1.176 +#else // _LP64
   1.177 +  juint* to = (juint*)tohw;
   1.178 +  while (count-- > 0) {
   1.179 +    *to++ = value;
   1.180 +  }
   1.181 +#endif // _LP64
   1.182 +}
   1.183 +
   1.184 +typedef void (*_zero_Fn)(HeapWord* to, size_t count);
   1.185 +
   1.186 +static void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) {
   1.187 +  assert(MinObjAlignmentInBytes >= BytesPerLong, "need alternate implementation");
   1.188 +
   1.189 +  if (value == 0 && UseBlockZeroing &&
   1.190 +      (count > (size_t)(BlockZeroingLowLimit >> LogHeapWordSize))) {
   1.191 +   // Call it only when block zeroing is used
   1.192 +   ((_zero_Fn)StubRoutines::zero_aligned_words())(tohw, count);
   1.193 +  } else {
   1.194 +   julong* to = (julong*)tohw;
   1.195 +   julong  v  = ((julong)value << 32) | value;
   1.196 +   // If count is odd, odd will be equal to 1 on 32-bit platform
   1.197 +   // and be equal to 0 on 64-bit platform.
   1.198 +   size_t odd = count % (BytesPerLong / HeapWordSize) ;
   1.199 +
   1.200 +   size_t aligned_count = align_object_offset(count - odd) / HeapWordsPerLong;
   1.201 +   julong* end = ((julong*)tohw) + aligned_count - 1;
   1.202 +   while (to <= end) {
   1.203 +     DEBUG_ONLY(count -= BytesPerLong / HeapWordSize ;)
   1.204 +     *to++ = v;
   1.205 +   }
   1.206 +   assert(count == odd, "bad bounds on loop filling to aligned words");
   1.207 +   if (odd) {
   1.208 +     *((juint*)to) = value;
   1.209 +
   1.210 +   }
   1.211 +  }
   1.212 +}
   1.213 +
   1.214 +static void pd_fill_to_bytes(void* to, size_t count, jubyte value) {
   1.215 +  (void)memset(to, value, count);
   1.216 +}
   1.217 +
   1.218 +static void pd_zero_to_words(HeapWord* tohw, size_t count) {
   1.219 +  pd_fill_to_words(tohw, count, 0);
   1.220 +}
   1.221 +
   1.222 +static void pd_zero_to_bytes(void* to, size_t count) {
   1.223 +  (void)memset(to, 0, count);
   1.224 +}
   1.225 +
   1.226 +#endif // CPU_SPARC_VM_COPY_SPARC_HPP

mercurial