OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/child_discardable_shared_memory_manager.h" | 5 #include "content/child/child_discardable_shared_memory_manager.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
10 #include "base/memory/discardable_memory.h" | 10 #include "base/memory/discardable_memory.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 DCHECK(is_locked_); | 54 DCHECK(is_locked_); |
55 | 55 |
56 manager_->UnlockSpan(span_.get()); | 56 manager_->UnlockSpan(span_.get()); |
57 is_locked_ = false; | 57 is_locked_ = false; |
58 } | 58 } |
59 void* data() const override { | 59 void* data() const override { |
60 DCHECK(is_locked_); | 60 DCHECK(is_locked_); |
61 return reinterpret_cast<void*>(span_->start() * base::GetPageSize()); | 61 return reinterpret_cast<void*>(span_->start() * base::GetPageSize()); |
62 } | 62 } |
63 | 63 |
| 64 base::trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump( |
| 65 const char* name, |
| 66 base::trace_event::ProcessMemoryDump* pmd) const override { |
| 67 return manager_->CreateMemoryAllocatorDump(span_.get(), name, pmd); |
| 68 } |
| 69 |
64 private: | 70 private: |
65 ChildDiscardableSharedMemoryManager* const manager_; | 71 ChildDiscardableSharedMemoryManager* const manager_; |
66 scoped_ptr<DiscardableSharedMemoryHeap::Span> span_; | 72 scoped_ptr<DiscardableSharedMemoryHeap::Span> span_; |
67 bool is_locked_; | 73 bool is_locked_; |
68 | 74 |
69 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl); | 75 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl); |
70 }; | 76 }; |
71 | 77 |
72 void SendDeletedDiscardableSharedMemoryMessage( | 78 void SendDeletedDiscardableSharedMemoryMessage( |
73 scoped_refptr<ThreadSafeSender> sender, | 79 scoped_refptr<ThreadSafeSender> sender, |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // Delete span instead of merging it into free lists if memory is gone. | 260 // Delete span instead of merging it into free lists if memory is gone. |
255 if (!span->shared_memory()) | 261 if (!span->shared_memory()) |
256 return; | 262 return; |
257 | 263 |
258 heap_.MergeIntoFreeLists(span.Pass()); | 264 heap_.MergeIntoFreeLists(span.Pass()); |
259 | 265 |
260 // Bytes of free memory changed. | 266 // Bytes of free memory changed. |
261 MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists()); | 267 MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists()); |
262 } | 268 } |
263 | 269 |
| 270 base::trace_event::MemoryAllocatorDump* |
| 271 ChildDiscardableSharedMemoryManager::CreateMemoryAllocatorDump( |
| 272 DiscardableSharedMemoryHeap::Span* span, |
| 273 const char* name, |
| 274 base::trace_event::ProcessMemoryDump* pmd) const { |
| 275 base::AutoLock lock(lock_); |
| 276 return heap_.CreateMemoryAllocatorDump(span, name, pmd); |
| 277 } |
| 278 |
264 scoped_ptr<base::DiscardableSharedMemory> | 279 scoped_ptr<base::DiscardableSharedMemory> |
265 ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory( | 280 ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory( |
266 size_t size, | 281 size_t size, |
267 DiscardableSharedMemoryId id) { | 282 DiscardableSharedMemoryId id) { |
268 TRACE_EVENT2("renderer", | 283 TRACE_EVENT2("renderer", |
269 "ChildDiscardableSharedMemoryManager::" | 284 "ChildDiscardableSharedMemoryManager::" |
270 "AllocateLockedDiscardableSharedMemory", | 285 "AllocateLockedDiscardableSharedMemory", |
271 "size", size, "id", id); | 286 "size", size, "id", id); |
272 | 287 |
273 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle(); | 288 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle(); |
(...skipping 17 matching lines...) Expand all Loading... |
291 "discardable-memory-allocated"; | 306 "discardable-memory-allocated"; |
292 base::debug::SetCrashKeyValue(kDiscardableMemoryAllocatedKey, | 307 base::debug::SetCrashKeyValue(kDiscardableMemoryAllocatedKey, |
293 base::Uint64ToString(new_bytes_total)); | 308 base::Uint64ToString(new_bytes_total)); |
294 | 309 |
295 static const char kDiscardableMemoryFreeKey[] = "discardable-memory-free"; | 310 static const char kDiscardableMemoryFreeKey[] = "discardable-memory-free"; |
296 base::debug::SetCrashKeyValue(kDiscardableMemoryFreeKey, | 311 base::debug::SetCrashKeyValue(kDiscardableMemoryFreeKey, |
297 base::Uint64ToString(new_bytes_free)); | 312 base::Uint64ToString(new_bytes_free)); |
298 } | 313 } |
299 | 314 |
300 } // namespace content | 315 } // namespace content |
OLD | NEW |