Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8244386: convert runtime/Safepoint/AssertSafepointCheckConsistency te…
…sts to gtest

Reviewed-by: stuefe, lfoltan, dcubed
  • Loading branch information
coleenp committed Aug 26, 2020
1 parent 080b9ea commit 6fbbd9b11b6a0cdcf9e38a7395d57e69f214c47d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 355 deletions.
@@ -1767,31 +1767,6 @@ WB_ENTRY(jlong, WB_MetaspaceReserveAlignment(JNIEnv* env, jobject wb))
return (jlong)Metaspace::reserve_alignment();
WB_END

WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
Mutex::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
Mutex::_safepoint_check_always :
Mutex::_safepoint_check_never;
Mutex::SafepointCheckFlag sfpt_check_attempted = attemptedNoSafepointValue ?
Mutex::_no_safepoint_check_flag :
Mutex::_safepoint_check_flag;
MutexLocker ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required),
sfpt_check_attempted);
WB_END

WB_ENTRY(void, WB_AssertSpecialLock(JNIEnv* env, jobject o, jboolean allowVMBlock, jboolean safepointCheck))
// Create a special lock violating condition in value
Mutex::SafepointCheckRequired sfpt_check_required = safepointCheck ?
Mutex::_safepoint_check_always :
Mutex::_safepoint_check_never;
Mutex::SafepointCheckFlag safepoint_check = safepointCheck ?
Monitor::_safepoint_check_flag :
Monitor::_no_safepoint_check_flag;

MutexLocker ml(new Mutex(Mutex::special, "SpecialTest_lock", allowVMBlock, sfpt_check_required), safepoint_check);
// If the lock above succeeds, try to safepoint to test the NSV implied with this special lock.
ThreadBlockInVM tbivm(thread);
WB_END

WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
oop obj_oop = JNIHandles::resolve(obj);
return (jboolean) obj_oop->mark().has_monitor();
@@ -2468,8 +2443,6 @@ static JNINativeMethod methods[] = {
(void*)&WB_AddModuleExportsToAllUnnamed },
{CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
(void*)&WB_AddModuleExportsToAll },
{CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls },
{CC"assertSpecialLock", CC"(ZZ)V", (void*)&WB_AssertSpecialLock },
{CC"deflateIdleMonitors", CC"()Z", (void*)&WB_DeflateIdleMonitors },
{CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
{CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
@@ -989,7 +989,7 @@ void Thread::check_possible_safepoint() {

if (_no_safepoint_count > 0) {
print_owned_locks();
fatal("Possible safepoint reached by thread that does not allow it");
assert(false, "Possible safepoint reached by thread that does not allow it");
}
#ifdef CHECK_UNHANDLED_OOPS
// Clear unhandled oops in JavaThreads so we get a crash right away.
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

#include "precompiled.hpp"
#include "runtime/interfaceSupport.inline.hpp"
#include "runtime/mutex.hpp"
#include "runtime/mutexLocker.hpp"
#include "unittest.hpp"

#ifdef ASSERT

// Test mismatched safepoint check flag on lock declaration vs. lock acquisition.
TEST_VM_ASSERT_MSG(SafepointLockAssertTest, always_check,
"This lock should always have a safepoint check for Java threads") {
MutexLocker ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, Mutex::_safepoint_check_always),
Mutex::_no_safepoint_check_flag);
}

TEST_VM_ASSERT_MSG(SafepointLockAssertTest, never_check,
"This lock should never have a safepoint check for Java thread") {
MutexLocker ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, Mutex::_safepoint_check_never),
Mutex::_safepoint_check_flag);
}

TEST_VM_ASSERT_MSG(SafepointLockAssertTest, special_locks,
"Special locks or below should never safepoint") {
MutexLocker ml(new Mutex(Mutex::special, "SpecialTest_lock", /*vm_block*/true, Mutex::_safepoint_check_always),
Mutex::_safepoint_check_flag);
}

TEST_VM_ASSERT_MSG(SafepointLockAssertTest, possible_safepoint_lock,
"Possible safepoint reached by thread that does not allow it") {
JavaThread* thread = JavaThread::current();
ThreadInVMfromNative in_native(thread);
MutexLocker ml(new Mutex(Mutex::special, "SpecialTest_lock", /*vm_block*/true, Mutex::_safepoint_check_never),
Mutex::_no_safepoint_check_flag);
thread->print_thread_state_on(tty);
// If the lock above succeeds, try to safepoint to test the NSV implied with this special lock.
ThreadBlockInVM tbivm(thread);
thread->print_thread_state_on(tty);
}

#endif // ASSERT

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 6fbbd9b

Please sign in to comment.