Path: blob/master/test/hotspot/gtest/runtime/test_safepoint_locks.cpp
41144 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "runtime/interfaceSupport.inline.hpp"25#include "runtime/mutex.hpp"26#include "runtime/mutexLocker.hpp"27#include "unittest.hpp"2829#ifdef ASSERT3031// Test mismatched safepoint check flag on lock declaration vs. lock acquisition.32TEST_VM_ASSERT_MSG(SafepointLockAssertTest, always_check,33".*This lock should always have a safepoint check for Java threads: SFPT_Test_lock") {34MutexLocker ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, Mutex::_safepoint_check_always),35Mutex::_no_safepoint_check_flag);36}3738TEST_VM_ASSERT_MSG(SafepointLockAssertTest, never_check,39".*This lock should never have a safepoint check for Java threads: SFPT_Test_lock") {40MutexLocker ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, Mutex::_safepoint_check_never),41Mutex::_safepoint_check_flag);42}4344TEST_VM_ASSERT_MSG(SafepointLockAssertTest, special_locks,45".*Special locks or below should never safepoint") {46MutexLocker ml(new Mutex(Mutex::special, "SpecialTest_lock", /*vm_block*/true, Mutex::_safepoint_check_always),47Mutex::_safepoint_check_flag);48}4950TEST_VM_ASSERT_MSG(SafepointLockAssertTest, possible_safepoint_lock,51".* Possible safepoint reached by thread that does not allow it") {52JavaThread* thread = JavaThread::current();53ThreadInVMfromNative in_native(thread);54MutexLocker ml(new Mutex(Mutex::special, "SpecialTest_lock", /*vm_block*/true, Mutex::_safepoint_check_never),55Mutex::_no_safepoint_check_flag);56thread->print_thread_state_on(tty);57// If the lock above succeeds, try to safepoint to test the NSV implied with this special lock.58ThreadBlockInVM tbivm(thread);59thread->print_thread_state_on(tty);60}6162#endif // ASSERT636465