diff options
| author | 2014-12-15 23:46:59 +0000 | |
|---|---|---|
| committer | 2014-12-15 23:47:00 +0000 | |
| commit | 5dd24d89714aeca69a3a06561d5a3687d54cf43b (patch) | |
| tree | d71e3533daa3bc6bd99207b7cdbb375d6b999a6f /runtime/gc/heap.cc | |
| parent | f7f687bbb14aa7493bbe44d62a9de6fc17dbe542 (diff) | |
| parent | 079101a17575114622f6e1d5be5c9ba643630e9a (diff) | |
Merge "Move GC daemon locking logic into heap"
Diffstat (limited to 'runtime/gc/heap.cc')
| -rw-r--r-- | runtime/gc/heap.cc | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 10fe64e1e0..d420500592 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -142,6 +142,7 @@ Heap::Heap(size_t initial_size, size_t growth_limit, size_t min_free, size_t max zygote_creation_lock_("zygote creation lock", kZygoteCreationLock), zygote_space_(nullptr), large_object_threshold_(large_object_threshold), + gc_request_pending_(false), collector_type_running_(kCollectorTypeNone), last_gc_type_(collector::kGcTypeNone), next_gc_type_(collector::kGcTypePartial), @@ -409,6 +410,8 @@ Heap::Heap(size_t initial_size, size_t growth_limit, size_t min_free, size_t max gc_complete_lock_ = new Mutex("GC complete lock"); gc_complete_cond_.reset(new ConditionVariable("GC complete condition variable", *gc_complete_lock_)); + gc_request_lock_ = new Mutex("GC request lock"); + gc_request_cond_.reset(new ConditionVariable("GC request condition variable", *gc_request_lock_)); heap_trim_request_lock_ = new Mutex("Heap trim request lock"); last_gc_size_ = GetBytesAllocated(); if (ignore_max_footprint_) { @@ -3038,12 +3041,7 @@ void Heap::RequestConcurrentGC(Thread* self) { self->IsHandlingStackOverflow()) { return; } - JNIEnv* env = self->GetJniEnv(); - DCHECK(WellKnownClasses::java_lang_Daemons != nullptr); - DCHECK(WellKnownClasses::java_lang_Daemons_requestGC != nullptr); - env->CallStaticVoidMethod(WellKnownClasses::java_lang_Daemons, - WellKnownClasses::java_lang_Daemons_requestGC); - CHECK(!env->ExceptionCheck()); + NotifyConcurrentGCRequest(self); } void Heap::ConcurrentGC(Thread* self) { @@ -3276,5 +3274,21 @@ void Heap::ClearMarkedObjects() { } } +void Heap::WaitForConcurrentGCRequest(Thread* self) { + ScopedThreadStateChange tsc(self, kBlocked); + MutexLock mu(self, *gc_request_lock_); + while (!gc_request_pending_) { + gc_request_cond_->Wait(self); + } + gc_request_pending_ = false; +} + +void Heap::NotifyConcurrentGCRequest(Thread* self) { + ScopedThreadStateChange tsc(self, kBlocked); + MutexLock mu(self, *gc_request_lock_); + gc_request_pending_ = true; + gc_request_cond_->Signal(self); +} + } // namespace gc } // namespace art |