Skip to content

Commit

Permalink
8258469: Cleanup remaining safefetch test coding
Browse files Browse the repository at this point in the history
Reviewed-by: coleenp, dholmes
  • Loading branch information
tstuefe committed Dec 18, 2020
1 parent 1e03ca1 commit 853c047
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 62 deletions.
43 changes: 1 addition & 42 deletions src/hotspot/share/runtime/stubRoutines.cpp
Expand Up @@ -34,7 +34,6 @@
#include "runtime/stubRoutines.hpp"
#include "utilities/align.hpp"
#include "utilities/copy.hpp"
#include "utilities/vmError.hpp"
#ifdef COMPILER2
#include "opto/runtime.hpp"
#endif
Expand Down Expand Up @@ -268,40 +267,7 @@ static void test_arraycopy_func(address func, int alignment) {
assert(fbuffer[i] == v && fbuffer2[i] == v2, "shouldn't have copied anything");
}
}

// simple test for SafeFetch32
static void test_safefetch32() {
if (CanUseSafeFetch32()) {
int dummy = 17;
int* const p_invalid = (int*) VMError::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() {
if (CanUseSafeFetchN()) {
#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*) VMError::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
#endif // ASSERT

void StubRoutines::initialize2() {
if (_code2 == NULL) {
Expand Down Expand Up @@ -393,13 +359,6 @@ void StubRoutines::initialize2() {
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))
test_safefetch32();
test_safefetchN();
#endif

#endif
}

Expand Down
15 changes: 2 additions & 13 deletions src/hotspot/share/utilities/vmError.cpp
Expand Up @@ -84,17 +84,6 @@ const char* VMError::_filename;
int VMError::_lineno;
size_t VMError::_size;

// returns an address which is guaranteed to generate a SIGSEGV on read,
// for test purposes, which is not NULL and contains bits in every word
void* VMError::get_segfault_address() {
return (void*)
#ifdef _LP64
0xABC0000000000ABCULL;
#else
0x00000ABC;
#endif
}

// List of environment variables that should be reported in error log file.
static const char* env_list[] = {
// All platforms
Expand Down Expand Up @@ -504,7 +493,7 @@ void VMError::report(outputStream* st, bool _verbose) {
if (_verbose && TestSafeFetchInErrorHandler) {
st->print_cr("Will test SafeFetch...");
if (CanUseSafeFetch32()) {
int* const invalid_pointer = (int*) get_segfault_address();
int* const invalid_pointer = (int*)segfault_address;
const int x = 0x76543210;
int i1 = SafeFetch32(invalid_pointer, x);
int i2 = SafeFetch32(invalid_pointer, x);
Expand Down Expand Up @@ -1756,7 +1745,7 @@ static void crash_with_sigfpe() {
// crash with sigsegv at non-null address.
static void crash_with_segfault() {

char* const crash_addr = (char*) VMError::get_segfault_address();
char* const crash_addr = (char*)VMError::segfault_address;
*crash_addr = 'X';

} // end: crash_with_segfault
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/share/utilities/vmError.hpp
Expand Up @@ -181,8 +181,9 @@ class VMError : public AllStatic {

DEBUG_ONLY(static void controlled_crash(int how);)

// returns an address which is guaranteed to generate a SIGSEGV on read,
// for test purposes, which is not NULL and contains bits in every word
static void* get_segfault_address();
// Address which is guaranteed to generate a fault on read, for test purposes,
// which is not NULL and contains bits in every word.
static const intptr_t segfault_address = LP64_ONLY(0xABC0000000000ABCULL) NOT_LP64(0x00000ABC);

};
#endif // SHARE_UTILITIES_VMERROR_HPP
12 changes: 8 additions & 4 deletions test/hotspot/gtest/runtime/test_safefetch.cpp
Expand Up @@ -28,26 +28,30 @@
#include "runtime/vmOperations.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/vmError.hpp"
#include "unittest.hpp"

static const intptr_t pattern = LP64_ONLY(0xABCDABCDABCDABCDULL) NOT_LP64(0xABCDABCD);
static intptr_t* invalid_address = (intptr_t*)(intptr_t) NOT_AIX(os::min_page_size()) AIX_ONLY(-1);
static intptr_t* invalid_address = (intptr_t*)VMError::segfault_address;

TEST_VM(os, safefetch_can_use) {
// Once VM initialization is through,
// safefetch should work on every platform.
ASSERT_TRUE(CanUseSafeFetch32());
}

TEST_VM(os, safefetch_positive) {
intptr_t v = pattern;
intptr_t a = SafeFetchN(&v, 1);
ASSERT_EQ(v, a);
}

#ifndef _WIN32
// Needs JDK-8185734 to be solved
TEST_VM(os, safefetch_negative) {
intptr_t a = SafeFetchN(invalid_address, pattern);
ASSERT_EQ(pattern, a);
a = SafeFetchN(invalid_address, ~pattern);
ASSERT_EQ(~pattern, a);
}
#endif // _WIN32

class VM_TestSafeFetchAtSafePoint : public VM_GTestExecuteAtSafepoint {
public:
Expand Down

1 comment on commit 853c047

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.