8244386: convert runtime/Safepoint/AssertSafepointCheckConsistency tests to gtest

Reviewed-by: stuefe, lfoltan, dcubed
This commit is contained in:
Coleen Phillimore 2020-08-26 07:55:05 -04:00
parent 0c20de1954
commit b978ebee46
9 changed files with 64 additions and 355 deletions

View File

@ -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 },

View File

@ -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.

View File

@ -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

View File

@ -1,61 +0,0 @@
/*
* Copyright (c) 2014, 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.
*/
/*
* @test
* @bug 8047290
* @summary Ensure that a Monitor::lock_without_safepoint_check fires an assert when it incorrectly acquires a lock which must always have safepoint checks.
* @requires vm.debug
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run driver AssertSafepointCheckConsistency1
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import sun.hotspot.WhiteBox;
public class AssertSafepointCheckConsistency1 {
public static void main(String args[]) throws Exception {
if (args.length > 0) {
WhiteBox.getWhiteBox().assertMatchingSafepointCalls(true, true);
return;
}
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xbootclasspath/a:.",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"-XX:-CreateCoredumpOnCrash",
"-Xmx128m",
"AssertSafepointCheckConsistency1",
"test");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("assert")
.shouldContain("always")
.shouldNotHaveExitValue(0);
}
}

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2014, 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.
*/
/*
* @test
* @bug 8047290
* @summary Ensure that a Monitor::lock fires an assert when it incorrectly acquires a lock which must never have safepoint checks.
* @requires vm.debug
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run driver AssertSafepointCheckConsistency2
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import sun.hotspot.WhiteBox;
public class AssertSafepointCheckConsistency2 {
public static void main(String args[]) throws Exception {
if (args.length > 0) {
WhiteBox.getWhiteBox().assertMatchingSafepointCalls(false, false);
return;
}
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xbootclasspath/a:.",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"-XX:-CreateCoredumpOnCrash",
"-Xmx128m",
"AssertSafepointCheckConsistency2",
"test");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("assert")
.shouldContain("never")
.shouldNotHaveExitValue(0);
}
}

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 2014, 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.
*/
/*
* @test
* @bug 8047290
* @summary Ensure that Monitor::lock_without_safepoint_check does not assert when it correctly acquires a lock which must never have safepoint checks.
* @requires vm.debug
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run driver AssertSafepointCheckConsistency3
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import sun.hotspot.WhiteBox;
public class AssertSafepointCheckConsistency3 {
public static void main(String args[]) throws Exception {
if (args.length > 0) {
WhiteBox.getWhiteBox().assertMatchingSafepointCalls(false, true);
return;
}
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xbootclasspath/a:.",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"-XX:-CreateCoredumpOnCrash",
"-Xmx32m",
"AssertSafepointCheckConsistency3",
"test");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldNotContain("assert")
.shouldNotContain("never")
.shouldNotContain("always")
.shouldHaveExitValue(0);
}
}

View File

@ -1,65 +0,0 @@
/*
* Copyright (c) 2014, 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.
*/
/*
* @test
* @bug 8047290
* @summary Ensure that Monitor::lock does not assert when it correctly acquires a lock which must always have safepoint checks.
* @requires vm.debug
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run driver AssertSafepointCheckConsistency4
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import sun.hotspot.WhiteBox;
public class AssertSafepointCheckConsistency4 {
public static void main(String args[]) throws Exception {
if (args.length > 0) {
WhiteBox.getWhiteBox().assertMatchingSafepointCalls(true, false);
return;
}
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xbootclasspath/a:.",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"-XX:-CreateCoredumpOnCrash",
"-Xmx32m",
"AssertSafepointCheckConsistency4",
"test");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldNotContain("assert")
.shouldNotContain("never")
.shouldNotContain("always")
.shouldHaveExitValue(0);
}
}

View File

@ -1,72 +0,0 @@
/*
* Copyright (c) 2018, 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.
*/
/*
* @test
* @bug 8184732
* @summary Ensure that special locks never safepoint check.
* @requires vm.debug
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* @run driver NoSafepointVerifier
*/
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import sun.hotspot.WhiteBox;
public class NoSafepointVerifier {
static void runTest(String test) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-Xbootclasspath/a:.",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"-XX:-CreateCoredumpOnCrash",
"NoSafepointVerifier",
test);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain(test)
.shouldNotHaveExitValue(0);
}
static String test1 = "Special locks or below should never safepoint";
static String test2 = "Possible safepoint reached by thread that does not allow it";
public static void main(String args[]) throws Exception {
if (args.length > 0) {
if (args[0].equals(test1)) {
WhiteBox.getWhiteBox().assertSpecialLock(/*vm_block*/true, /*safepoint_check_always*/true);
} else if (args[0].equals(test2)) {
WhiteBox.getWhiteBox().assertSpecialLock(/*vm_block*/true, /*safepoint_check_always*/false);
}
} else {
runTest(test1);
runTest(test2);
}
}
}

View File

@ -567,10 +567,6 @@ public class WhiteBox {
.orElse(null);
}
// Safepoint Checking
public native void assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue);
public native void assertSpecialLock(boolean allowVMBlock, boolean safepointCheck);
// Sharing & archiving
public native String getDefaultArchivePath();
public native boolean cdsMemoryMappingFailed();