< prev index next >

src/share/vm/runtime/stubRoutines.cpp

Print this page
@  rev 7996 : 8075533: Zero JVM segfaults for -version after JDK-8074552
|


 194   // Use middle of array to check that memory before it is not modified.
 195   address buffer  = (address) round_to((intptr_t)&lbuffer[4], BytesPerLong);
 196   address buffer2 = (address) round_to((intptr_t)&lbuffer2[4], BytesPerLong);
 197   // do an aligned copy
 198   ((arraycopy_fn)func)(buffer, buffer2, 0);
 199   for (i = 0; i < sizeof(lbuffer); i++) {
 200     assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
 201   }
 202   // adjust destination alignment
 203   ((arraycopy_fn)func)(buffer, buffer2 + alignment, 0);
 204   for (i = 0; i < sizeof(lbuffer); i++) {
 205     assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
 206   }
 207   // adjust source alignment
 208   ((arraycopy_fn)func)(buffer + alignment, buffer2, 0);
 209   for (i = 0; i < sizeof(lbuffer); i++) {
 210     assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
 211   }
 212 }
 213 

 214 // simple test for SafeFetch32
 215 static void test_safefetch32() {
 216   int dummy = 17;
 217   int* const p_invalid = (int*) get_segfault_address();
 218   int* const p_valid = &dummy;
 219   int result_invalid = SafeFetch32(p_invalid, 0xABC);
 220   assert(result_invalid == 0xABC, "SafeFetch32 error");
 221   int result_valid = SafeFetch32(p_valid, 0xABC);
 222   assert(result_valid == 17, "SafeFetch32 error");
 223 }
 224 
 225 // simple test for SafeFetchN
 226 static void test_safefetchN() {
 227 #ifdef _LP64
 228   const intptr_t v1 = UCONST64(0xABCD00000000ABCD);
 229   const intptr_t v2 = UCONST64(0xDEFD00000000DEFD);
 230 #else
 231   const intptr_t v1 = 0xABCDABCD;
 232   const intptr_t v2 = 0xDEFDDEFD;
 233 #endif
 234   intptr_t dummy = v1;
 235   intptr_t* const p_invalid = (intptr_t*) get_segfault_address();
 236   intptr_t* const p_valid = &dummy;
 237   intptr_t result_invalid = SafeFetchN(p_invalid, v2);
 238   assert(result_invalid == v2, "SafeFetchN error");
 239   intptr_t result_valid = SafeFetchN(p_valid, v2);
 240   assert(result_valid == v1, "SafeFetchN error");
 241 }
 242 #endif

 243 
 244 void StubRoutines::initialize2() {
 245   if (_code2 == NULL) {
 246     ResourceMark rm;
 247     TraceTime timer("StubRoutines generation 2", TraceStartupTime);
 248     _code2 = BufferBlob::create("StubRoutines (2)", code_size2);
 249     if (_code2 == NULL) {
 250       vm_exit_out_of_memory(code_size2, OOM_MALLOC_ERROR, "CodeCache: no room for StubRoutines (2)");
 251     }
 252     CodeBuffer buffer(_code2);
 253     StubGenerator_generate(&buffer, true);
 254   }
 255 
 256 #ifdef ASSERT
 257 
 258 #define TEST_ARRAYCOPY(type)                                                    \
 259   test_arraycopy_func(          type##_arraycopy(),          sizeof(type));     \
 260   test_arraycopy_func(          type##_disjoint_arraycopy(), sizeof(type));     \
 261   test_arraycopy_func(arrayof_##type##_arraycopy(),          sizeof(HeapWord)); \
 262   test_arraycopy_func(arrayof_##type##_disjoint_arraycopy(), sizeof(HeapWord))


 313   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_##type##s_atomic),  sizeof(type)); \
 314   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::arrayof_conjoint_##type##s), (int)MAX2(sizeof(HeapWord), sizeof(type)))
 315 
 316   // Make sure all the copy runtime routines properly handle zero count
 317   TEST_COPYRTN(jbyte);
 318   TEST_COPYRTN(jshort);
 319   TEST_COPYRTN(jint);
 320   TEST_COPYRTN(jlong);
 321 
 322 #undef TEST_COPYRTN
 323 
 324   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_words), sizeof(HeapWord));
 325   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words), sizeof(HeapWord));
 326   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words_atomic), sizeof(HeapWord));
 327   // Aligned to BytesPerLong
 328   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong));
 329   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong));
 330 
 331   // test safefetch routines
 332   // Not on Windows 32bit until 8074860 is fixed
 333 #if ! (defined(_WIN32) && defined(_M_IX86))
 334   test_safefetch32();
 335   test_safefetchN();
 336 #endif
 337 
 338 #endif
 339 }
 340 
 341 
 342 void stubRoutines_init1() { StubRoutines::initialize1(); }
 343 void stubRoutines_init2() { StubRoutines::initialize2(); }
 344 
 345 //
 346 // Default versions of arraycopy functions
 347 //
 348 
 349 static void gen_arraycopy_barrier_pre(oop* dest, size_t count, bool dest_uninitialized) {
 350     assert(count != 0, "count should be non-zero");
 351     assert(count <= (size_t)max_intx, "count too large");
 352     BarrierSet* bs = Universe::heap()->barrier_set();
 353     assert(bs->has_write_ref_array_pre_opt(), "Must have pre-barrier opt");




 194   // Use middle of array to check that memory before it is not modified.
 195   address buffer  = (address) round_to((intptr_t)&lbuffer[4], BytesPerLong);
 196   address buffer2 = (address) round_to((intptr_t)&lbuffer2[4], BytesPerLong);
 197   // do an aligned copy
 198   ((arraycopy_fn)func)(buffer, buffer2, 0);
 199   for (i = 0; i < sizeof(lbuffer); i++) {
 200     assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
 201   }
 202   // adjust destination alignment
 203   ((arraycopy_fn)func)(buffer, buffer2 + alignment, 0);
 204   for (i = 0; i < sizeof(lbuffer); i++) {
 205     assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
 206   }
 207   // adjust source alignment
 208   ((arraycopy_fn)func)(buffer + alignment, buffer2, 0);
 209   for (i = 0; i < sizeof(lbuffer); i++) {
 210     assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
 211   }
 212 }
 213 
 214 #ifndef ZERO
 215 // simple test for SafeFetch32
 216 static void test_safefetch32() {
 217   int dummy = 17;
 218   int* const p_invalid = (int*) get_segfault_address();
 219   int* const p_valid = &dummy;
 220   int result_invalid = SafeFetch32(p_invalid, 0xABC);
 221   assert(result_invalid == 0xABC, "SafeFetch32 error");
 222   int result_valid = SafeFetch32(p_valid, 0xABC);
 223   assert(result_valid == 17, "SafeFetch32 error");
 224 }
 225 
 226 // simple test for SafeFetchN
 227 static void test_safefetchN() {
 228 #ifdef _LP64
 229   const intptr_t v1 = UCONST64(0xABCD00000000ABCD);
 230   const intptr_t v2 = UCONST64(0xDEFD00000000DEFD);
 231 #else
 232   const intptr_t v1 = 0xABCDABCD;
 233   const intptr_t v2 = 0xDEFDDEFD;
 234 #endif
 235   intptr_t dummy = v1;
 236   intptr_t* const p_invalid = (intptr_t*) get_segfault_address();
 237   intptr_t* const p_valid = &dummy;
 238   intptr_t result_invalid = SafeFetchN(p_invalid, v2);
 239   assert(result_invalid == v2, "SafeFetchN error");
 240   intptr_t result_valid = SafeFetchN(p_valid, v2);
 241   assert(result_valid == v1, "SafeFetchN error");
 242 }
 243 #endif
 244 #endif // ZERO
 245 
 246 void StubRoutines::initialize2() {
 247   if (_code2 == NULL) {
 248     ResourceMark rm;
 249     TraceTime timer("StubRoutines generation 2", TraceStartupTime);
 250     _code2 = BufferBlob::create("StubRoutines (2)", code_size2);
 251     if (_code2 == NULL) {
 252       vm_exit_out_of_memory(code_size2, OOM_MALLOC_ERROR, "CodeCache: no room for StubRoutines (2)");
 253     }
 254     CodeBuffer buffer(_code2);
 255     StubGenerator_generate(&buffer, true);
 256   }
 257 
 258 #ifdef ASSERT
 259 
 260 #define TEST_ARRAYCOPY(type)                                                    \
 261   test_arraycopy_func(          type##_arraycopy(),          sizeof(type));     \
 262   test_arraycopy_func(          type##_disjoint_arraycopy(), sizeof(type));     \
 263   test_arraycopy_func(arrayof_##type##_arraycopy(),          sizeof(HeapWord)); \
 264   test_arraycopy_func(arrayof_##type##_disjoint_arraycopy(), sizeof(HeapWord))


 315   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_##type##s_atomic),  sizeof(type)); \
 316   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::arrayof_conjoint_##type##s), (int)MAX2(sizeof(HeapWord), sizeof(type)))
 317 
 318   // Make sure all the copy runtime routines properly handle zero count
 319   TEST_COPYRTN(jbyte);
 320   TEST_COPYRTN(jshort);
 321   TEST_COPYRTN(jint);
 322   TEST_COPYRTN(jlong);
 323 
 324 #undef TEST_COPYRTN
 325 
 326   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_words), sizeof(HeapWord));
 327   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words), sizeof(HeapWord));
 328   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words_atomic), sizeof(HeapWord));
 329   // Aligned to BytesPerLong
 330   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong));
 331   test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong));
 332 
 333   // test safefetch routines
 334   // Not on Windows 32bit until 8074860 is fixed
 335 #if ! (defined(_WIN32) && defined(_M_IX86) ) && ! defined(ZERO)
 336   test_safefetch32();
 337   test_safefetchN();
 338 #endif
 339 
 340 #endif
 341 }
 342 
 343 
 344 void stubRoutines_init1() { StubRoutines::initialize1(); }
 345 void stubRoutines_init2() { StubRoutines::initialize2(); }
 346 
 347 //
 348 // Default versions of arraycopy functions
 349 //
 350 
 351 static void gen_arraycopy_barrier_pre(oop* dest, size_t count, bool dest_uninitialized) {
 352     assert(count != 0, "count should be non-zero");
 353     assert(count <= (size_t)max_intx, "count too large");
 354     BarrierSet* bs = Universe::heap()->barrier_set();
 355     assert(bs->has_write_ref_array_pre_opt(), "Must have pre-barrier opt");


< prev index next >