Global lock levels.
Introduce the notion of the mutators/GC being a shared-exclusive (aka
reader-writer) lock. Introduce globally ordered locks, analysable by
annotalysis, statically at compile time. Add locking attributes to
methods.
More subtly, remove the heap_lock_ and split between various locks that
are held for smaller periods (where work doesn't get blocked). Remove
buggy Dalvik style thread transitions. Make GC use CMS in all cases when
concurrent is enabled. Fix bug where suspend counts rather than debug
suspend counts were sent to JDWP. Move the PathClassLoader to
WellKnownClasses. In debugger refactor calls to send request and
possibly suspend. Break apart different VmWait thread states. Move
identity hash code to a shared method.
Change-Id: Icdbfc3ce3fcccd14341860ac7305d8e97b51f5c6
diff --git a/src/mutex_test.cc b/src/mutex_test.cc
index 69507d1..8a40cd6 100644
--- a/src/mutex_test.cc
+++ b/src/mutex_test.cc
@@ -60,7 +60,7 @@
// GCC has trouble with our mutex tests, so we have to turn off thread safety analysis.
static void RecursiveLockUnlockTest() NO_THREAD_SAFETY_ANALYSIS {
- Mutex mu("test mutex");
+ Mutex mu("test mutex", kDefaultMutexLevel, true);
MutexTester::AssertDepth(mu, 0U);
mu.Lock();
MutexTester::AssertDepth(mu, 1U);
@@ -78,7 +78,7 @@
// GCC has trouble with our mutex tests, so we have to turn off thread safety analysis.
static void RecursiveTryLockUnlockTest() NO_THREAD_SAFETY_ANALYSIS {
- Mutex mu("test mutex");
+ Mutex mu("test mutex", kDefaultMutexLevel, true);
MutexTester::AssertDepth(mu, 0U);
ASSERT_TRUE(mu.TryLock());
MutexTester::AssertDepth(mu, 1U);
@@ -96,7 +96,9 @@
struct RecursiveLockWait {
- explicit RecursiveLockWait() : mu("test mutex"), cv("test condition variable") {}
+ explicit RecursiveLockWait()
+ : mu("test mutex", kDefaultMutexLevel, true), cv("test condition variable") {
+ }
static void* Callback(void* arg) {
RecursiveLockWait* state = reinterpret_cast<RecursiveLockWait*>(arg);
@@ -132,4 +134,38 @@
RecursiveLockWaitTest();
}
+TEST_F(MutexTest, SharedLockUnlock) {
+ ReaderWriterMutex mu("test rwmutex");
+ mu.AssertNotHeld();
+ mu.SharedLock();
+ mu.AssertSharedHeld();
+ mu.AssertNotExclusiveHeld();
+ mu.SharedUnlock();
+ mu.AssertNotHeld();
+}
+
+TEST_F(MutexTest, ExclusiveLockUnlock) {
+ ReaderWriterMutex mu("test rwmutex");
+ mu.AssertNotHeld();
+ mu.ExclusiveLock();
+ mu.AssertSharedHeld();
+ mu.AssertExclusiveHeld();
+ mu.ExclusiveUnlock();
+ mu.AssertNotHeld();
+}
+
+// GCC has trouble with our mutex tests, so we have to turn off thread safety analysis.
+static void SharedTryLockUnlockTest() NO_THREAD_SAFETY_ANALYSIS {
+ ReaderWriterMutex mu("test rwmutex");
+ mu.AssertNotHeld();
+ ASSERT_TRUE(mu.SharedTryLock());
+ mu.AssertSharedHeld();
+ mu.SharedUnlock();
+ mu.AssertNotHeld();
+}
+
+TEST_F(MutexTest, SharedTryLockUnlock) {
+ SharedTryLockUnlockTest();
+}
+
} // namespace art