Skip to content

Commit 853c047

Browse files
committed
8258469: Cleanup remaining safefetch test coding
Reviewed-by: coleenp, dholmes
1 parent 1e03ca1 commit 853c047

File tree

4 files changed

+15
-62
lines changed

4 files changed

+15
-62
lines changed

src/hotspot/share/runtime/stubRoutines.cpp

+1-42
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "runtime/stubRoutines.hpp"
3535
#include "utilities/align.hpp"
3636
#include "utilities/copy.hpp"
37-
#include "utilities/vmError.hpp"
3837
#ifdef COMPILER2
3938
#include "opto/runtime.hpp"
4039
#endif
@@ -268,40 +267,7 @@ static void test_arraycopy_func(address func, int alignment) {
268267
assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
269268
}
270269
}
271-
272-
// simple test for SafeFetch32
273-
static void test_safefetch32() {
274-
if (CanUseSafeFetch32()) {
275-
int dummy = 17;
276-
int* const p_invalid = (int*) VMError::get_segfault_address();
277-
int* const p_valid = &dummy;
278-
int result_invalid = SafeFetch32(p_invalid, 0xABC);
279-
assert(result_invalid == 0xABC, "SafeFetch32 error");
280-
int result_valid = SafeFetch32(p_valid, 0xABC);
281-
assert(result_valid == 17, "SafeFetch32 error");
282-
}
283-
}
284-
285-
// simple test for SafeFetchN
286-
static void test_safefetchN() {
287-
if (CanUseSafeFetchN()) {
288-
#ifdef _LP64
289-
const intptr_t v1 = UCONST64(0xABCD00000000ABCD);
290-
const intptr_t v2 = UCONST64(0xDEFD00000000DEFD);
291-
#else
292-
const intptr_t v1 = 0xABCDABCD;
293-
const intptr_t v2 = 0xDEFDDEFD;
294-
#endif
295-
intptr_t dummy = v1;
296-
intptr_t* const p_invalid = (intptr_t*) VMError::get_segfault_address();
297-
intptr_t* const p_valid = &dummy;
298-
intptr_t result_invalid = SafeFetchN(p_invalid, v2);
299-
assert(result_invalid == v2, "SafeFetchN error");
300-
intptr_t result_valid = SafeFetchN(p_valid, v2);
301-
assert(result_valid == v1, "SafeFetchN error");
302-
}
303-
}
304-
#endif
270+
#endif // ASSERT
305271

306272
void StubRoutines::initialize2() {
307273
if (_code2 == NULL) {
@@ -393,13 +359,6 @@ void StubRoutines::initialize2() {
393359
test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong));
394360
test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong));
395361

396-
// test safefetch routines
397-
// Not on Windows 32bit until 8074860 is fixed
398-
#if ! (defined(_WIN32) && defined(_M_IX86))
399-
test_safefetch32();
400-
test_safefetchN();
401-
#endif
402-
403362
#endif
404363
}
405364

src/hotspot/share/utilities/vmError.cpp

+2-13
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,6 @@ const char* VMError::_filename;
8484
int VMError::_lineno;
8585
size_t VMError::_size;
8686

87-
// returns an address which is guaranteed to generate a SIGSEGV on read,
88-
// for test purposes, which is not NULL and contains bits in every word
89-
void* VMError::get_segfault_address() {
90-
return (void*)
91-
#ifdef _LP64
92-
0xABC0000000000ABCULL;
93-
#else
94-
0x00000ABC;
95-
#endif
96-
}
97-
9887
// List of environment variables that should be reported in error log file.
9988
static const char* env_list[] = {
10089
// All platforms
@@ -504,7 +493,7 @@ void VMError::report(outputStream* st, bool _verbose) {
504493
if (_verbose && TestSafeFetchInErrorHandler) {
505494
st->print_cr("Will test SafeFetch...");
506495
if (CanUseSafeFetch32()) {
507-
int* const invalid_pointer = (int*) get_segfault_address();
496+
int* const invalid_pointer = (int*)segfault_address;
508497
const int x = 0x76543210;
509498
int i1 = SafeFetch32(invalid_pointer, x);
510499
int i2 = SafeFetch32(invalid_pointer, x);
@@ -1756,7 +1745,7 @@ static void crash_with_sigfpe() {
17561745
// crash with sigsegv at non-null address.
17571746
static void crash_with_segfault() {
17581747

1759-
char* const crash_addr = (char*) VMError::get_segfault_address();
1748+
char* const crash_addr = (char*)VMError::segfault_address;
17601749
*crash_addr = 'X';
17611750

17621751
} // end: crash_with_segfault

src/hotspot/share/utilities/vmError.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ class VMError : public AllStatic {
181181

182182
DEBUG_ONLY(static void controlled_crash(int how);)
183183

184-
// returns an address which is guaranteed to generate a SIGSEGV on read,
185-
// for test purposes, which is not NULL and contains bits in every word
186-
static void* get_segfault_address();
184+
// Address which is guaranteed to generate a fault on read, for test purposes,
185+
// which is not NULL and contains bits in every word.
186+
static const intptr_t segfault_address = LP64_ONLY(0xABC0000000000ABCULL) NOT_LP64(0x00000ABC);
187+
187188
};
188189
#endif // SHARE_UTILITIES_VMERROR_HPP

test/hotspot/gtest/runtime/test_safefetch.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,30 @@
2828
#include "runtime/vmOperations.hpp"
2929
#include "runtime/vmThread.hpp"
3030
#include "utilities/globalDefinitions.hpp"
31+
#include "utilities/vmError.hpp"
3132
#include "unittest.hpp"
3233

3334
static const intptr_t pattern = LP64_ONLY(0xABCDABCDABCDABCDULL) NOT_LP64(0xABCDABCD);
34-
static intptr_t* invalid_address = (intptr_t*)(intptr_t) NOT_AIX(os::min_page_size()) AIX_ONLY(-1);
35+
static intptr_t* invalid_address = (intptr_t*)VMError::segfault_address;
36+
37+
TEST_VM(os, safefetch_can_use) {
38+
// Once VM initialization is through,
39+
// safefetch should work on every platform.
40+
ASSERT_TRUE(CanUseSafeFetch32());
41+
}
3542

3643
TEST_VM(os, safefetch_positive) {
3744
intptr_t v = pattern;
3845
intptr_t a = SafeFetchN(&v, 1);
3946
ASSERT_EQ(v, a);
4047
}
4148

42-
#ifndef _WIN32
43-
// Needs JDK-8185734 to be solved
4449
TEST_VM(os, safefetch_negative) {
4550
intptr_t a = SafeFetchN(invalid_address, pattern);
4651
ASSERT_EQ(pattern, a);
4752
a = SafeFetchN(invalid_address, ~pattern);
4853
ASSERT_EQ(~pattern, a);
4954
}
50-
#endif // _WIN32
5155

5256
class VM_TestSafeFetchAtSafePoint : public VM_GTestExecuteAtSafepoint {
5357
public:

0 commit comments

Comments
 (0)