0
|
1 /*
|
|
2 * Copyright 2003-2006 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 // Inline functions for memory copy and fill.
|
|
26
|
|
27 static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
|
|
28 (void)memmove(to, from, count * HeapWordSize);
|
|
29 }
|
|
30
|
|
31 static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
|
|
32 switch (count) {
|
|
33 case 8: to[7] = from[7];
|
|
34 case 7: to[6] = from[6];
|
|
35 case 6: to[5] = from[5];
|
|
36 case 5: to[4] = from[4];
|
|
37 case 4: to[3] = from[3];
|
|
38 case 3: to[2] = from[2];
|
|
39 case 2: to[1] = from[1];
|
|
40 case 1: to[0] = from[0];
|
|
41 case 0: break;
|
|
42 default: (void)memcpy(to, from, count * HeapWordSize);
|
|
43 break;
|
|
44 }
|
|
45 }
|
|
46
|
|
47 static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
|
|
48 switch (count) {
|
|
49 case 8: to[7] = from[7];
|
|
50 case 7: to[6] = from[6];
|
|
51 case 6: to[5] = from[5];
|
|
52 case 5: to[4] = from[4];
|
|
53 case 4: to[3] = from[3];
|
|
54 case 3: to[2] = from[2];
|
|
55 case 2: to[1] = from[1];
|
|
56 case 1: to[0] = from[0];
|
|
57 case 0: break;
|
|
58 default: while (count-- > 0) {
|
|
59 *to++ = *from++;
|
|
60 }
|
|
61 break;
|
|
62 }
|
|
63 }
|
|
64
|
|
65 static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
|
|
66 (void)memmove(to, from, count * HeapWordSize);
|
|
67 }
|
|
68
|
|
69 static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
|
|
70 pd_disjoint_words(from, to, count);
|
|
71 }
|
|
72
|
|
73 static void pd_conjoint_bytes(void* from, void* to, size_t count) {
|
|
74 (void)memmove(to, from, count);
|
|
75 }
|
|
76
|
|
77 static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
|
|
78 (void)memmove(to, from, count);
|
|
79 }
|
|
80
|
|
81 static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
|
|
82 // FIXME
|
|
83 (void)memmove(to, from, count << LogBytesPerShort);
|
|
84 }
|
|
85
|
|
86 static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
|
|
87 // FIXME
|
|
88 (void)memmove(to, from, count << LogBytesPerInt);
|
|
89 }
|
|
90
|
|
91 static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
|
|
92 #ifdef _LP64
|
|
93 assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
|
|
94 pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
|
|
95 #else
|
|
96 // Guarantee use of ldd/std via some asm code, because compiler won't.
|
|
97 // See solaris_sparc.il.
|
|
98 _Copy_conjoint_jlongs_atomic(from, to, count);
|
|
99 #endif
|
|
100 }
|
|
101
|
|
102 static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
|
|
103 // Do better than this: inline memmove body NEEDS CLEANUP
|
|
104 if (from > to) {
|
|
105 while (count-- > 0) {
|
|
106 // Copy forwards
|
|
107 *to++ = *from++;
|
|
108 }
|
|
109 } else {
|
|
110 from += count - 1;
|
|
111 to += count - 1;
|
|
112 while (count-- > 0) {
|
|
113 // Copy backwards
|
|
114 *to-- = *from--;
|
|
115 }
|
|
116 }
|
|
117 }
|
|
118
|
|
119 static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
|
|
120 pd_conjoint_bytes_atomic(from, to, count);
|
|
121 }
|
|
122
|
|
123 static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
|
|
124 pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count);
|
|
125 }
|
|
126
|
|
127 static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
|
|
128 pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
|
|
129 }
|
|
130
|
|
131 static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
|
|
132 pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
|
|
133 }
|
|
134
|
|
135 static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
|
|
136 pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
|
|
137 }
|
|
138
|
|
139 static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
|
|
140 #if 0
|
|
141 if (HeapWordsPerLong == 1 ||
|
|
142 (HeapWordsPerLong == 2 &&
|
|
143 mask_bits((uintptr_t)tohw, right_n_bits(LogBytesPerLong)) == 0 &&
|
|
144 ((count & 1) ? false : count >>= 1))) {
|
|
145 julong* to = (julong*)tohw;
|
|
146 julong v = ((julong)value << 32) | value;
|
|
147 while (count-- > 0) {
|
|
148 *to++ = v;
|
|
149 }
|
|
150 } else {
|
|
151 #endif
|
|
152 juint* to = (juint*)tohw;
|
|
153 count *= HeapWordSize / BytesPerInt;
|
|
154 while (count-- > 0) {
|
|
155 *to++ = value;
|
|
156 }
|
|
157 // }
|
|
158 }
|
|
159
|
|
160 static void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) {
|
|
161 assert(MinObjAlignmentInBytes == BytesPerLong, "need alternate implementation");
|
|
162
|
|
163 julong* to = (julong*)tohw;
|
|
164 julong v = ((julong)value << 32) | value;
|
|
165 // If count is odd, odd will be equal to 1 on 32-bit platform
|
|
166 // and be equal to 0 on 64-bit platform.
|
|
167 size_t odd = count % (BytesPerLong / HeapWordSize) ;
|
|
168
|
|
169 size_t aligned_count = align_object_size(count - odd) / HeapWordsPerLong;
|
|
170 julong* end = ((julong*)tohw) + aligned_count - 1;
|
|
171 while (to <= end) {
|
|
172 DEBUG_ONLY(count -= BytesPerLong / HeapWordSize ;)
|
|
173 *to++ = v;
|
|
174 }
|
|
175 assert(count == odd, "bad bounds on loop filling to aligned words");
|
|
176 if (odd) {
|
|
177 *((juint*)to) = value;
|
|
178
|
|
179 }
|
|
180 }
|
|
181
|
|
182 static void pd_fill_to_bytes(void* to, size_t count, jubyte value) {
|
|
183 (void)memset(to, value, count);
|
|
184 }
|
|
185
|
|
186 static void pd_zero_to_words(HeapWord* tohw, size_t count) {
|
|
187 pd_fill_to_words(tohw, count, 0);
|
|
188 }
|
|
189
|
|
190 static void pd_zero_to_bytes(void* to, size_t count) {
|
|
191 (void)memset(to, 0, count);
|
|
192 }
|