diff options
author | Mathieu Chartier <mathieuc@google.com> | 2014-03-31 16:36:35 -0700 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2014-04-07 13:44:36 -0700 |
commit | 440e4ceb310349ee8eb569495bc04d3d7fbe71cb (patch) | |
tree | db278d463f0c2440e9c8e8cb80e53d2b2effe196 /runtime/gc | |
parent | 4d3dc8a04da8a80251b381cdb482190363171dc1 (diff) | |
download | art-440e4ceb310349ee8eb569495bc04d3d7fbe71cb.zip art-440e4ceb310349ee8eb569495bc04d3d7fbe71cb.tar.gz art-440e4ceb310349ee8eb569495bc04d3d7fbe71cb.tar.bz2 |
Add monitor deflation.
We now deflate the monitors when we perform a heap trim. This causes
a pause but it shouldn't matter since we should be in a state where
we don't care about pauses. Memory savings are hard to measure.
Fixed integer overflow bug in GetEstimatedLastIterationThroughput.
Bug: 13733906
Change-Id: I4e0e68add02e7f43370b3a5ea763d6fe8a5b212c
Diffstat (limited to 'runtime/gc')
-rw-r--r-- | runtime/gc/collector/garbage_collector.cc | 2 | ||||
-rw-r--r-- | runtime/gc/heap.cc | 38 |
2 files changed, 24 insertions, 16 deletions
diff --git a/runtime/gc/collector/garbage_collector.cc b/runtime/gc/collector/garbage_collector.cc index 07951e0..82340f5 100644 --- a/runtime/gc/collector/garbage_collector.cc +++ b/runtime/gc/collector/garbage_collector.cc @@ -201,7 +201,7 @@ uint64_t GarbageCollector::GetEstimatedMeanThroughput() const { uint64_t GarbageCollector::GetEstimatedLastIterationThroughput() const { // Add 1ms to prevent possible division by 0. - return (freed_bytes_ * 1000) / (NsToMs(GetDurationNs()) + 1); + return (static_cast<uint64_t>(freed_bytes_) * 1000) / (NsToMs(GetDurationNs()) + 1); } } // namespace collector diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 915e54f..e3fa834 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -914,8 +914,16 @@ void Heap::DoPendingTransitionOrTrim() { // Transition the collector if the desired collector type is not the same as the current // collector type. TransitionCollector(desired_collector_type); - // Do a heap trim if it is needed. - Trim(); + if (!CareAboutPauseTimes()) { + // Deflate the monitors, this can cause a pause but shouldn't matter since we don't care + // about pauses. + Runtime* runtime = Runtime::Current(); + runtime->GetThreadList()->SuspendAll(); + runtime->GetMonitorList()->DeflateMonitors(); + runtime->GetThreadList()->ResumeAll(); + // Do a heap trim if it is needed. + Trim(); + } } void Heap::Trim() { @@ -2663,6 +2671,10 @@ void Heap::RequestCollectorTransition(CollectorType desired_collector_type, uint } void Heap::RequestHeapTrim() { + // Request a heap trim only if we do not currently care about pause times. + if (CareAboutPauseTimes()) { + return; + } // GC completed and now we must decide whether to request a heap trim (advising pages back to the // kernel) or not. Issuing a request will also cause trimming of the libc heap. As a trim scans // a space it will hold its lock and can become a cause of jank. @@ -2684,21 +2696,17 @@ void Heap::RequestHeapTrim() { // as we don't hold the lock while requesting the trim). return; } - - // Request a heap trim only if we do not currently care about pause times. - if (!CareAboutPauseTimes()) { - { - MutexLock mu(self, *heap_trim_request_lock_); - if (last_trim_time_ + kHeapTrimWait >= NanoTime()) { - // We have done a heap trim in the last kHeapTrimWait nanosecs, don't request another one - // just yet. - return; - } - heap_trim_request_pending_ = true; + { + MutexLock mu(self, *heap_trim_request_lock_); + if (last_trim_time_ + kHeapTrimWait >= NanoTime()) { + // We have done a heap trim in the last kHeapTrimWait nanosecs, don't request another one + // just yet. + return; } - // Notify the daemon thread which will actually do the heap trim. - SignalHeapTrimDaemon(self); + heap_trim_request_pending_ = true; } + // Notify the daemon thread which will actually do the heap trim. + SignalHeapTrimDaemon(self); } void Heap::SignalHeapTrimDaemon(Thread* self) { |