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