copy_sparc.hpp revision 2657:baf763f388e6
1/*
2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#ifndef CPU_SPARC_VM_COPY_SPARC_HPP
26#define CPU_SPARC_VM_COPY_SPARC_HPP
27
28// Inline functions for memory copy and fill.
29
30static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
31  (void)memmove(to, from, count * HeapWordSize);
32}
33
34static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
35  switch (count) {
36  case 8:  to[7] = from[7];
37  case 7:  to[6] = from[6];
38  case 6:  to[5] = from[5];
39  case 5:  to[4] = from[4];
40  case 4:  to[3] = from[3];
41  case 3:  to[2] = from[2];
42  case 2:  to[1] = from[1];
43  case 1:  to[0] = from[0];
44  case 0:  break;
45  default: (void)memcpy(to, from, count * HeapWordSize);
46           break;
47  }
48}
49
50static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
51  switch (count) {
52  case 8:  to[7] = from[7];
53  case 7:  to[6] = from[6];
54  case 6:  to[5] = from[5];
55  case 5:  to[4] = from[4];
56  case 4:  to[3] = from[3];
57  case 3:  to[2] = from[2];
58  case 2:  to[1] = from[1];
59  case 1:  to[0] = from[0];
60  case 0:  break;
61  default: while (count-- > 0) {
62             *to++ = *from++;
63           }
64           break;
65  }
66}
67
68static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
69  (void)memmove(to, from, count * HeapWordSize);
70}
71
72static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
73  pd_disjoint_words(from, to, count);
74}
75
76static void pd_conjoint_bytes(void* from, void* to, size_t count) {
77  (void)memmove(to, from, count);
78}
79
80static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
81  (void)memmove(to, from, count);
82}
83
84static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
85  // FIXME
86  (void)memmove(to, from, count << LogBytesPerShort);
87}
88
89static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
90  // FIXME
91  (void)memmove(to, from, count << LogBytesPerInt);
92}
93
94static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
95#ifdef _LP64
96  assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
97  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
98#else
99  // Guarantee use of ldd/std via some asm code, because compiler won't.
100  // See solaris_sparc.il.
101  _Copy_conjoint_jlongs_atomic(from, to, count);
102#endif
103}
104
105static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
106  // Do better than this: inline memmove body  NEEDS CLEANUP
107  if (from > to) {
108    while (count-- > 0) {
109      // Copy forwards
110      *to++ = *from++;
111    }
112  } else {
113    from += count - 1;
114    to   += count - 1;
115    while (count-- > 0) {
116      // Copy backwards
117      *to-- = *from--;
118    }
119  }
120}
121
122static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
123  pd_conjoint_bytes_atomic(from, to, count);
124}
125
126static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
127  pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count);
128}
129
130static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
131  pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
132}
133
134static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
135  pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
136}
137
138static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
139  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
140}
141
142static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
143#ifdef _LP64
144  guarantee(mask_bits((uintptr_t)tohw, right_n_bits(LogBytesPerLong)) == 0,
145         "unaligned fill words");
146  julong* to = (julong*)tohw;
147  julong  v  = ((julong)value << 32) | value;
148  while (count-- > 0) {
149    *to++ = v;
150  }
151#else // _LP64
152  juint* to = (juint*)tohw;
153  while (count-- > 0) {
154    *to++ = value;
155  }
156#endif // _LP64
157}
158
159typedef void (*_zero_Fn)(HeapWord* to, size_t count);
160
161static void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) {
162  assert(MinObjAlignmentInBytes >= BytesPerLong, "need alternate implementation");
163
164  if (value == 0 && UseBlockZeroing &&
165      (count > (BlockZeroingLowLimit >> LogHeapWordSize))) {
166   // Call it only when block zeroing is used
167   ((_zero_Fn)StubRoutines::zero_aligned_words())(tohw, count);
168  } else {
169   julong* to = (julong*)tohw;
170   julong  v  = ((julong)value << 32) | value;
171   // If count is odd, odd will be equal to 1 on 32-bit platform
172   // and be equal to 0 on 64-bit platform.
173   size_t odd = count % (BytesPerLong / HeapWordSize) ;
174
175   size_t aligned_count = align_object_offset(count - odd) / HeapWordsPerLong;
176   julong* end = ((julong*)tohw) + aligned_count - 1;
177   while (to <= end) {
178     DEBUG_ONLY(count -= BytesPerLong / HeapWordSize ;)
179     *to++ = v;
180   }
181   assert(count == odd, "bad bounds on loop filling to aligned words");
182   if (odd) {
183     *((juint*)to) = value;
184
185   }
186  }
187}
188
189static void pd_fill_to_bytes(void* to, size_t count, jubyte value) {
190  (void)memset(to, value, count);
191}
192
193static void pd_zero_to_words(HeapWord* tohw, size_t count) {
194  pd_fill_to_words(tohw, count, 0);
195}
196
197static void pd_zero_to_bytes(void* to, size_t count) {
198  (void)memset(to, 0, count);
199}
200
201#endif // CPU_SPARC_VM_COPY_SPARC_HPP
202