< prev index next >

src/share/vm/runtime/stubRoutines.cpp

Print this page
rev 7968 : 8074552:  SafeFetch32 and SafeFetchN do not work in error handling
Summary: handle SafeFetch faults in secondary signal handlers
Reviewed-by: dholmes
Contributed-by: Thomas Stuefe

*** 208,219 **** ((arraycopy_fn)func)(buffer + alignment, buffer2, 0); for (i = 0; i < sizeof(lbuffer); i++) { assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything"); } } - #endif void StubRoutines::initialize2() { if (_code2 == NULL) { ResourceMark rm; TraceTime timer("StubRoutines generation 2", TraceStartupTime); --- 208,247 ---- ((arraycopy_fn)func)(buffer + alignment, buffer2, 0); for (i = 0; i < sizeof(lbuffer); i++) { assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything"); } } + // simple test for SafeFetch32 + static void test_safefetch32() { + int dummy = 17; + int* const p_invalid = (int*) get_segfault_address(); + int* const p_valid = &dummy; + int result_invalid = SafeFetch32(p_invalid, 0xABC); + assert(result_invalid == 0xABC, "SafeFetch32 error"); + int result_valid = SafeFetch32(p_valid, 0xABC); + assert(result_valid == 17, "SafeFetch32 error"); + } + + // simple test for SafeFetchN + static void test_safefetchN() { + #ifdef _LP64 + const intptr_t v1 = UCONST64(0xABCD00000000ABCD); + const intptr_t v2 = UCONST64(0xDEFD00000000DEFD); + #else + const intptr_t v1 = 0xABCDABCD; + const intptr_t v2 = 0xDEFDDEFD; + #endif + intptr_t dummy = v1; + intptr_t* const p_invalid = (intptr_t*) get_segfault_address(); + intptr_t* const p_valid = &dummy; + intptr_t result_invalid = SafeFetchN(p_invalid, v2); + assert(result_invalid == v2, "SafeFetchN error"); + intptr_t result_valid = SafeFetchN(p_valid, v2); + assert(result_valid == v1, "SafeFetchN error"); + } + #endif void StubRoutines::initialize2() { if (_code2 == NULL) { ResourceMark rm; TraceTime timer("StubRoutines generation 2", TraceStartupTime);
*** 298,307 **** --- 326,346 ---- test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::disjoint_words_atomic), sizeof(HeapWord)); // Aligned to BytesPerLong test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong)); test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong)); + // test safefetch routines + // Not on Windows 32bit until 8074860 is fixed + #if ! (defined(_WIN32) && defined(_M_IX86)) + if (CanUseSafeFetch32()) { + test_safefetch32(); + } + if (CanUseSafeFetchN()) { + test_safefetchN(); + } + #endif + #endif } void stubRoutines_init1() { StubRoutines::initialize1(); }
< prev index next >