summaryrefslogtreecommitdiff
path: root/runtime/monitor_test.cc
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2015-08-28 11:16:54 -0700
committer Mathieu Chartier <mathieuc@google.com> 2015-08-28 13:31:51 -0700
commited15000a5099f5e230c8ded5ac75692bae272650 (patch)
treebe78bce04c0c9611abc221fd71d9251d05e35d2b /runtime/monitor_test.cc
parent12b7025d0393a2ce15410df6019844e59b77314d (diff)
Fix some HandleScope bugs and add corresponding checks
Some places were creating or destroying handle scopes without holding the mutator lock. This can cause GC crashes if thread roots are being marked or hprof dumps to also fail. Also added checks to catch some of these errors. Bug: 23468617 Change-Id: I1a2d615923484cfc25014967656775c445aa3f1f
Diffstat (limited to 'runtime/monitor_test.cc')
-rw-r--r--runtime/monitor_test.cc42
1 files changed, 17 insertions, 25 deletions
diff --git a/runtime/monitor_test.cc b/runtime/monitor_test.cc
index e1173bb026..69112b18ec 100644
--- a/runtime/monitor_test.cc
+++ b/runtime/monitor_test.cc
@@ -290,15 +290,13 @@ class WatchdogTask : public Task {
static void CommonWaitSetup(MonitorTest* test, ClassLinker* class_linker, uint64_t create_sleep,
int64_t c_millis, bool c_expected, bool interrupt, uint64_t use_sleep,
int64_t u_millis, bool u_expected, const char* pool_name) {
+ Thread* const self = Thread::Current();
+ ScopedObjectAccess soa(self);
// First create the object we lock. String is easiest.
- StackHandleScope<3> hs(Thread::Current());
- {
- ScopedObjectAccess soa(Thread::Current());
- test->object_ = hs.NewHandle(mirror::String::AllocFromModifiedUtf8(Thread::Current(),
- "hello, world!"));
- test->watchdog_object_ = hs.NewHandle(mirror::String::AllocFromModifiedUtf8(Thread::Current(),
- "hello, world!"));
- }
+ StackHandleScope<3> hs(soa.Self());
+ test->object_ = hs.NewHandle(mirror::String::AllocFromModifiedUtf8(self, "hello, world!"));
+ test->watchdog_object_ = hs.NewHandle(mirror::String::AllocFromModifiedUtf8(self,
+ "hello, world!"));
// Create the barrier used to synchronize.
test->barrier_ = std::unique_ptr<Barrier>(new Barrier(2));
@@ -308,23 +306,17 @@ static void CommonWaitSetup(MonitorTest* test, ClassLinker* class_linker, uint64
// Fill the heap.
std::unique_ptr<StackHandleScope<kMaxHandles>> hsp;
std::vector<MutableHandle<mirror::Object>> handles;
- {
- Thread* self = Thread::Current();
- ScopedObjectAccess soa(self);
- // Our job: Fill the heap, then try Wait.
- FillHeap(self, class_linker, &hsp, &handles);
+ // Our job: Fill the heap, then try Wait.
+ FillHeap(soa.Self(), class_linker, &hsp, &handles);
- // Now release everything.
- auto it = handles.begin();
- auto end = handles.end();
-
- for ( ; it != end; ++it) {
- it->Assign(nullptr);
- }
- } // Need to drop the mutator lock to allow barriers.
+ // Now release everything.
+ for (MutableHandle<mirror::Object>& h : handles) {
+ h.Assign(nullptr);
+ }
- Thread* self = Thread::Current();
+ // Need to drop the mutator lock to allow barriers.
+ soa.Self()->TransitionFromRunnableToSuspended(kNative);
ThreadPool thread_pool(pool_name, 3);
thread_pool.AddTask(self, new CreateTask(test, create_sleep, c_millis, c_expected));
if (interrupt) {
@@ -336,19 +328,19 @@ static void CommonWaitSetup(MonitorTest* test, ClassLinker* class_linker, uint64
thread_pool.StartWorkers(self);
// Wait on completion barrier.
- test->complete_barrier_->Wait(Thread::Current());
+ test->complete_barrier_->Wait(self);
test->completed_ = true;
// Wake the watchdog.
{
- ScopedObjectAccess soa(Thread::Current());
-
+ ScopedObjectAccess soa2(self);
test->watchdog_object_.Get()->MonitorEnter(self); // Lock the object.
test->watchdog_object_.Get()->NotifyAll(self); // Wake up waiting parties.
test->watchdog_object_.Get()->MonitorExit(self); // Release the lock.
}
thread_pool.StopWorkers(self);
+ soa.Self()->TransitionFromSuspendedToRunnable();
}