comparison src/share/vm/runtime/stubRoutines.cpp @ 1930:2d26b0046e0d

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 30 Nov 2010 14:53:30 +0100
parents 14197af1010e
children f95d63e2154a
comparison
equal deleted inserted replaced
1484:6b7001391c97 1930:2d26b0046e0d
1 /* 1 /*
2 * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
14 * 14 *
15 * You should have received a copy of the GNU General Public License version 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, 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. 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * CA 95054 USA or visit www.sun.com if you need additional information or 20 * or visit www.oracle.com if you need additional information or have any
21 * have any questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 #include "incls/_precompiled.incl" 25 #include "incls/_precompiled.incl"
26 #include "incls/_stubRoutines.cpp.incl" 26 #include "incls/_stubRoutines.cpp.incl"
95 95
96 address StubRoutines::_checkcast_arraycopy = NULL; 96 address StubRoutines::_checkcast_arraycopy = NULL;
97 address StubRoutines::_unsafe_arraycopy = NULL; 97 address StubRoutines::_unsafe_arraycopy = NULL;
98 address StubRoutines::_generic_arraycopy = NULL; 98 address StubRoutines::_generic_arraycopy = NULL;
99 99
100
101 address StubRoutines::_jbyte_fill;
102 address StubRoutines::_jshort_fill;
103 address StubRoutines::_jint_fill;
104 address StubRoutines::_arrayof_jbyte_fill;
105 address StubRoutines::_arrayof_jshort_fill;
106 address StubRoutines::_arrayof_jint_fill;
107
108
100 double (* StubRoutines::_intrinsic_log )(double) = NULL; 109 double (* StubRoutines::_intrinsic_log )(double) = NULL;
101 double (* StubRoutines::_intrinsic_log10 )(double) = NULL; 110 double (* StubRoutines::_intrinsic_log10 )(double) = NULL;
102 double (* StubRoutines::_intrinsic_exp )(double) = NULL; 111 double (* StubRoutines::_intrinsic_exp )(double) = NULL;
103 double (* StubRoutines::_intrinsic_pow )(double, double) = NULL; 112 double (* StubRoutines::_intrinsic_pow )(double, double) = NULL;
104 double (* StubRoutines::_intrinsic_sin )(double) = NULL; 113 double (* StubRoutines::_intrinsic_sin )(double) = NULL;
116 void StubRoutines::initialize1() { 125 void StubRoutines::initialize1() {
117 if (_code1 == NULL) { 126 if (_code1 == NULL) {
118 ResourceMark rm; 127 ResourceMark rm;
119 TraceTime timer("StubRoutines generation 1", TraceStartupTime); 128 TraceTime timer("StubRoutines generation 1", TraceStartupTime);
120 _code1 = BufferBlob::create("StubRoutines (1)", code_size1); 129 _code1 = BufferBlob::create("StubRoutines (1)", code_size1);
121 if( _code1 == NULL) vm_exit_out_of_memory1(code_size1, "CodeCache: no room for %s", "StubRoutines (1)"); 130 if (_code1 == NULL) {
122 CodeBuffer buffer(_code1->instructions_begin(), _code1->instructions_size()); 131 vm_exit_out_of_memory(code_size1, "CodeCache: no room for StubRoutines (1)");
132 }
133 CodeBuffer buffer(_code1);
123 StubGenerator_generate(&buffer, false); 134 StubGenerator_generate(&buffer, false);
124 } 135 }
125 } 136 }
126 137
127 138
130 141
131 // simple tests of generated arraycopy functions 142 // simple tests of generated arraycopy functions
132 static void test_arraycopy_func(address func, int alignment) { 143 static void test_arraycopy_func(address func, int alignment) {
133 int v = 0xcc; 144 int v = 0xcc;
134 int v2 = 0x11; 145 int v2 = 0x11;
135 jlong lbuffer[2]; 146 jlong lbuffer[8];
136 jlong lbuffer2[2]; 147 jlong lbuffer2[8];
137 address buffer = (address) lbuffer; 148 address fbuffer = (address) lbuffer;
138 address buffer2 = (address) lbuffer2; 149 address fbuffer2 = (address) lbuffer2;
139 unsigned int i; 150 unsigned int i;
140 for (i = 0; i < sizeof(lbuffer); i++) { 151 for (i = 0; i < sizeof(lbuffer); i++) {
141 buffer[i] = v; buffer2[i] = v2; 152 fbuffer[i] = v; fbuffer2[i] = v2;
142 } 153 }
154 // C++ does not guarantee jlong[] array alignment to 8 bytes.
155 // Use middle of array to check that memory before it is not modified.
156 address buffer = (address) round_to((intptr_t)&lbuffer[4], BytesPerLong);
157 address buffer2 = (address) round_to((intptr_t)&lbuffer2[4], BytesPerLong);
143 // do an aligned copy 158 // do an aligned copy
144 ((arraycopy_fn)func)(buffer, buffer2, 0); 159 ((arraycopy_fn)func)(buffer, buffer2, 0);
145 for (i = 0; i < sizeof(lbuffer); i++) { 160 for (i = 0; i < sizeof(lbuffer); i++) {
146 assert(buffer[i] == v && buffer2[i] == v2, "shouldn't have copied anything"); 161 assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
147 } 162 }
148 // adjust destination alignment 163 // adjust destination alignment
149 ((arraycopy_fn)func)(buffer, buffer2 + alignment, 0); 164 ((arraycopy_fn)func)(buffer, buffer2 + alignment, 0);
150 for (i = 0; i < sizeof(lbuffer); i++) { 165 for (i = 0; i < sizeof(lbuffer); i++) {
151 assert(buffer[i] == v && buffer2[i] == v2, "shouldn't have copied anything"); 166 assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
152 } 167 }
153 // adjust source alignment 168 // adjust source alignment
154 ((arraycopy_fn)func)(buffer + alignment, buffer2, 0); 169 ((arraycopy_fn)func)(buffer + alignment, buffer2, 0);
155 for (i = 0; i < sizeof(lbuffer); i++) { 170 for (i = 0; i < sizeof(lbuffer); i++) {
156 assert(buffer[i] == v && buffer2[i] == v2, "shouldn't have copied anything"); 171 assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
157 } 172 }
158 } 173 }
159 #endif 174 #endif
160 175
161 176
162 void StubRoutines::initialize2() { 177 void StubRoutines::initialize2() {
163 if (_code2 == NULL) { 178 if (_code2 == NULL) {
164 ResourceMark rm; 179 ResourceMark rm;
165 TraceTime timer("StubRoutines generation 2", TraceStartupTime); 180 TraceTime timer("StubRoutines generation 2", TraceStartupTime);
166 _code2 = BufferBlob::create("StubRoutines (2)", code_size2); 181 _code2 = BufferBlob::create("StubRoutines (2)", code_size2);
167 if( _code2 == NULL) vm_exit_out_of_memory1(code_size2, "CodeCache: no room for %s", "StubRoutines (2)"); 182 if (_code2 == NULL) {
168 CodeBuffer buffer(_code2->instructions_begin(), _code2->instructions_size()); 183 vm_exit_out_of_memory(code_size2, "CodeCache: no room for StubRoutines (2)");
184 }
185 CodeBuffer buffer(_code2);
169 StubGenerator_generate(&buffer, true); 186 StubGenerator_generate(&buffer, true);
170 } 187 }
171 188
172 #ifdef ASSERT 189 #ifdef ASSERT
173 190
175 test_arraycopy_func( type##_arraycopy(), sizeof(type)); \ 192 test_arraycopy_func( type##_arraycopy(), sizeof(type)); \
176 test_arraycopy_func( type##_disjoint_arraycopy(), sizeof(type)); \ 193 test_arraycopy_func( type##_disjoint_arraycopy(), sizeof(type)); \
177 test_arraycopy_func(arrayof_##type##_arraycopy(), sizeof(HeapWord)); \ 194 test_arraycopy_func(arrayof_##type##_arraycopy(), sizeof(HeapWord)); \
178 test_arraycopy_func(arrayof_##type##_disjoint_arraycopy(), sizeof(HeapWord)) 195 test_arraycopy_func(arrayof_##type##_disjoint_arraycopy(), sizeof(HeapWord))
179 196
180 // Make sure all the arraycopy stubs properly handle zeros 197 // Make sure all the arraycopy stubs properly handle zero count
181 TEST_ARRAYCOPY(jbyte); 198 TEST_ARRAYCOPY(jbyte);
182 TEST_ARRAYCOPY(jshort); 199 TEST_ARRAYCOPY(jshort);
183 TEST_ARRAYCOPY(jint); 200 TEST_ARRAYCOPY(jint);
184 TEST_ARRAYCOPY(jlong); 201 TEST_ARRAYCOPY(jlong);
185 202
186 #undef TEST_ARRAYCOPY 203 #undef TEST_ARRAYCOPY
204
205 #define TEST_FILL(type) \
206 if (_##type##_fill != NULL) { \
207 union { \
208 double d; \
209 type body[96]; \
210 } s; \
211 \
212 int v = 32; \
213 for (int offset = -2; offset <= 2; offset++) { \
214 for (int i = 0; i < 96; i++) { \
215 s.body[i] = 1; \
216 } \
217 type* start = s.body + 8 + offset; \
218 for (int aligned = 0; aligned < 2; aligned++) { \
219 if (aligned) { \
220 if (((intptr_t)start) % HeapWordSize == 0) { \
221 ((void (*)(type*, int, int))StubRoutines::_arrayof_##type##_fill)(start, v, 80); \
222 } else { \
223 continue; \
224 } \
225 } else { \
226 ((void (*)(type*, int, int))StubRoutines::_##type##_fill)(start, v, 80); \
227 } \
228 for (int i = 0; i < 96; i++) { \
229 if (i < (8 + offset) || i >= (88 + offset)) { \
230 assert(s.body[i] == 1, "what?"); \
231 } else { \
232 assert(s.body[i] == 32, "what?"); \
233 } \
234 } \
235 } \
236 } \
237 } \
238
239 TEST_FILL(jbyte);
240 TEST_FILL(jshort);
241 TEST_FILL(jint);
242
243 #undef TEST_FILL
244
245 #define TEST_COPYRTN(type) \
246 test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_##type##s_atomic), sizeof(type)); \
247 test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::arrayof_conjoint_##type##s), (int)MAX2(sizeof(HeapWord), sizeof(type)))
248
249 // Make sure all the copy runtime routines properly handle zero count
250 TEST_COPYRTN(jbyte);
251 TEST_COPYRTN(jshort);
252 TEST_COPYRTN(jint);
253 TEST_COPYRTN(jlong);
254
255 #undef TEST_COPYRTN
256
257 test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_words), sizeof(HeapWord));
258 test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words), sizeof(HeapWord));
259 test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words_atomic), sizeof(HeapWord));
260 // Aligned to BytesPerLong
261 test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong));
262 test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong));
187 263
188 #endif 264 #endif
189 } 265 }
190 266
191 267
213 289
214 JRT_LEAF(void, StubRoutines::jbyte_copy(jbyte* src, jbyte* dest, size_t count)) 290 JRT_LEAF(void, StubRoutines::jbyte_copy(jbyte* src, jbyte* dest, size_t count))
215 #ifndef PRODUCT 291 #ifndef PRODUCT
216 SharedRuntime::_jbyte_array_copy_ctr++; // Slow-path byte array copy 292 SharedRuntime::_jbyte_array_copy_ctr++; // Slow-path byte array copy
217 #endif // !PRODUCT 293 #endif // !PRODUCT
218 assert(count != 0, "count should be non-zero"); 294 Copy::conjoint_jbytes_atomic(src, dest, count);
219 Copy::conjoint_bytes_atomic(src, dest, count);
220 JRT_END 295 JRT_END
221 296
222 JRT_LEAF(void, StubRoutines::jshort_copy(jshort* src, jshort* dest, size_t count)) 297 JRT_LEAF(void, StubRoutines::jshort_copy(jshort* src, jshort* dest, size_t count))
223 #ifndef PRODUCT 298 #ifndef PRODUCT
224 SharedRuntime::_jshort_array_copy_ctr++; // Slow-path short/char array copy 299 SharedRuntime::_jshort_array_copy_ctr++; // Slow-path short/char array copy
225 #endif // !PRODUCT 300 #endif // !PRODUCT
226 assert(count != 0, "count should be non-zero");
227 Copy::conjoint_jshorts_atomic(src, dest, count); 301 Copy::conjoint_jshorts_atomic(src, dest, count);
228 JRT_END 302 JRT_END
229 303
230 JRT_LEAF(void, StubRoutines::jint_copy(jint* src, jint* dest, size_t count)) 304 JRT_LEAF(void, StubRoutines::jint_copy(jint* src, jint* dest, size_t count))
231 #ifndef PRODUCT 305 #ifndef PRODUCT
232 SharedRuntime::_jint_array_copy_ctr++; // Slow-path int/float array copy 306 SharedRuntime::_jint_array_copy_ctr++; // Slow-path int/float array copy
233 #endif // !PRODUCT 307 #endif // !PRODUCT
234 assert(count != 0, "count should be non-zero");
235 Copy::conjoint_jints_atomic(src, dest, count); 308 Copy::conjoint_jints_atomic(src, dest, count);
236 JRT_END 309 JRT_END
237 310
238 JRT_LEAF(void, StubRoutines::jlong_copy(jlong* src, jlong* dest, size_t count)) 311 JRT_LEAF(void, StubRoutines::jlong_copy(jlong* src, jlong* dest, size_t count))
239 #ifndef PRODUCT 312 #ifndef PRODUCT
240 SharedRuntime::_jlong_array_copy_ctr++; // Slow-path long/double array copy 313 SharedRuntime::_jlong_array_copy_ctr++; // Slow-path long/double array copy
241 #endif // !PRODUCT 314 #endif // !PRODUCT
242 assert(count != 0, "count should be non-zero");
243 Copy::conjoint_jlongs_atomic(src, dest, count); 315 Copy::conjoint_jlongs_atomic(src, dest, count);
244 JRT_END 316 JRT_END
245 317
246 JRT_LEAF(void, StubRoutines::oop_copy(oop* src, oop* dest, size_t count)) 318 JRT_LEAF(void, StubRoutines::oop_copy(oop* src, oop* dest, size_t count))
247 #ifndef PRODUCT 319 #ifndef PRODUCT
255 327
256 JRT_LEAF(void, StubRoutines::arrayof_jbyte_copy(HeapWord* src, HeapWord* dest, size_t count)) 328 JRT_LEAF(void, StubRoutines::arrayof_jbyte_copy(HeapWord* src, HeapWord* dest, size_t count))
257 #ifndef PRODUCT 329 #ifndef PRODUCT
258 SharedRuntime::_jbyte_array_copy_ctr++; // Slow-path byte array copy 330 SharedRuntime::_jbyte_array_copy_ctr++; // Slow-path byte array copy
259 #endif // !PRODUCT 331 #endif // !PRODUCT
260 assert(count != 0, "count should be non-zero"); 332 Copy::arrayof_conjoint_jbytes(src, dest, count);
261 Copy::arrayof_conjoint_bytes(src, dest, count);
262 JRT_END 333 JRT_END
263 334
264 JRT_LEAF(void, StubRoutines::arrayof_jshort_copy(HeapWord* src, HeapWord* dest, size_t count)) 335 JRT_LEAF(void, StubRoutines::arrayof_jshort_copy(HeapWord* src, HeapWord* dest, size_t count))
265 #ifndef PRODUCT 336 #ifndef PRODUCT
266 SharedRuntime::_jshort_array_copy_ctr++; // Slow-path short/char array copy 337 SharedRuntime::_jshort_array_copy_ctr++; // Slow-path short/char array copy
267 #endif // !PRODUCT 338 #endif // !PRODUCT
268 assert(count != 0, "count should be non-zero");
269 Copy::arrayof_conjoint_jshorts(src, dest, count); 339 Copy::arrayof_conjoint_jshorts(src, dest, count);
270 JRT_END 340 JRT_END
271 341
272 JRT_LEAF(void, StubRoutines::arrayof_jint_copy(HeapWord* src, HeapWord* dest, size_t count)) 342 JRT_LEAF(void, StubRoutines::arrayof_jint_copy(HeapWord* src, HeapWord* dest, size_t count))
273 #ifndef PRODUCT 343 #ifndef PRODUCT
274 SharedRuntime::_jint_array_copy_ctr++; // Slow-path int/float array copy 344 SharedRuntime::_jint_array_copy_ctr++; // Slow-path int/float array copy
275 #endif // !PRODUCT 345 #endif // !PRODUCT
276 assert(count != 0, "count should be non-zero");
277 Copy::arrayof_conjoint_jints(src, dest, count); 346 Copy::arrayof_conjoint_jints(src, dest, count);
278 JRT_END 347 JRT_END
279 348
280 JRT_LEAF(void, StubRoutines::arrayof_jlong_copy(HeapWord* src, HeapWord* dest, size_t count)) 349 JRT_LEAF(void, StubRoutines::arrayof_jlong_copy(HeapWord* src, HeapWord* dest, size_t count))
281 #ifndef PRODUCT 350 #ifndef PRODUCT
282 SharedRuntime::_jlong_array_copy_ctr++; // Slow-path int/float array copy 351 SharedRuntime::_jlong_array_copy_ctr++; // Slow-path int/float array copy
283 #endif // !PRODUCT 352 #endif // !PRODUCT
284 assert(count != 0, "count should be non-zero");
285 Copy::arrayof_conjoint_jlongs(src, dest, count); 353 Copy::arrayof_conjoint_jlongs(src, dest, count);
286 JRT_END 354 JRT_END
287 355
288 JRT_LEAF(void, StubRoutines::arrayof_oop_copy(HeapWord* src, HeapWord* dest, size_t count)) 356 JRT_LEAF(void, StubRoutines::arrayof_oop_copy(HeapWord* src, HeapWord* dest, size_t count))
289 #ifndef PRODUCT 357 #ifndef PRODUCT
292 assert(count != 0, "count should be non-zero"); 360 assert(count != 0, "count should be non-zero");
293 gen_arraycopy_barrier_pre((oop *) dest, count); 361 gen_arraycopy_barrier_pre((oop *) dest, count);
294 Copy::arrayof_conjoint_oops(src, dest, count); 362 Copy::arrayof_conjoint_oops(src, dest, count);
295 gen_arraycopy_barrier((oop *) dest, count); 363 gen_arraycopy_barrier((oop *) dest, count);
296 JRT_END 364 JRT_END
365
366
367 address StubRoutines::select_fill_function(BasicType t, bool aligned, const char* &name) {
368 #define RETURN_STUB(xxx_fill) { \
369 name = #xxx_fill; \
370 return StubRoutines::xxx_fill(); }
371
372 switch (t) {
373 case T_BYTE:
374 case T_BOOLEAN:
375 if (!aligned) RETURN_STUB(jbyte_fill);
376 RETURN_STUB(arrayof_jbyte_fill);
377 case T_CHAR:
378 case T_SHORT:
379 if (!aligned) RETURN_STUB(jshort_fill);
380 RETURN_STUB(arrayof_jshort_fill);
381 case T_INT:
382 case T_FLOAT:
383 if (!aligned) RETURN_STUB(jint_fill);
384 RETURN_STUB(arrayof_jint_fill);
385 case T_DOUBLE:
386 case T_LONG:
387 case T_ARRAY:
388 case T_OBJECT:
389 case T_NARROWOOP:
390 case T_ADDRESS:
391 // Currently unsupported
392 return NULL;
393
394 default:
395 ShouldNotReachHere();
396 return NULL;
397 }
398
399 #undef RETURN_STUB
400 }