Chromium Code Reviews| 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/common/discardable_shared_memory_heap.h" | 5 #include "content/common/discardable_shared_memory_heap.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/discardable_shared_memory.h" | 9 #include "base/memory/discardable_shared_memory.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 InsertIntoFreeList(span.Pass()); | 142 InsertIntoFreeList(span.Pass()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 scoped_ptr<DiscardableSharedMemoryHeap::Span> | 145 scoped_ptr<DiscardableSharedMemoryHeap::Span> |
| 146 DiscardableSharedMemoryHeap::Split(Span* span, size_t blocks) { | 146 DiscardableSharedMemoryHeap::Split(Span* span, size_t blocks) { |
| 147 DCHECK(blocks); | 147 DCHECK(blocks); |
| 148 DCHECK_LT(blocks, span->length_); | 148 DCHECK_LT(blocks, span->length_); |
| 149 | 149 |
| 150 scoped_ptr<Span> leftover(new Span( | 150 scoped_ptr<Span> leftover(new Span( |
| 151 span->shared_memory_, span->start_ + blocks, span->length_ - blocks)); | 151 span->shared_memory_, span->start_ + blocks, span->length_ - blocks)); |
| 152 DCHECK_IMPLIES(leftover->length_ > 1, | 152 DCHECK((leftover->length_ <= 1) || |
|
danakj
2015/06/29 19:30:58
can you make this == 1? I think that blocks<span->
| |
| 153 spans_.find(leftover->start_) == spans_.end()); | 153 (spans_.find(leftover->start_) == spans_.end())); |
| 154 RegisterSpan(leftover.get()); | 154 RegisterSpan(leftover.get()); |
| 155 spans_[span->start_ + blocks - 1] = span; | 155 spans_[span->start_ + blocks - 1] = span; |
| 156 span->length_ = blocks; | 156 span->length_ = blocks; |
| 157 return leftover.Pass(); | 157 return leftover.Pass(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 scoped_ptr<DiscardableSharedMemoryHeap::Span> | 160 scoped_ptr<DiscardableSharedMemoryHeap::Span> |
| 161 DiscardableSharedMemoryHeap::SearchFreeLists(size_t blocks, size_t slack) { | 161 DiscardableSharedMemoryHeap::SearchFreeLists(size_t blocks, size_t slack) { |
| 162 DCHECK(blocks); | 162 DCHECK(blocks); |
| 163 | 163 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 } | 246 } |
| 247 | 247 |
| 248 scoped_ptr<DiscardableSharedMemoryHeap::Span> | 248 scoped_ptr<DiscardableSharedMemoryHeap::Span> |
| 249 DiscardableSharedMemoryHeap::Carve(Span* span, size_t blocks) { | 249 DiscardableSharedMemoryHeap::Carve(Span* span, size_t blocks) { |
| 250 scoped_ptr<Span> serving = RemoveFromFreeList(span); | 250 scoped_ptr<Span> serving = RemoveFromFreeList(span); |
| 251 | 251 |
| 252 const int extra = serving->length_ - blocks; | 252 const int extra = serving->length_ - blocks; |
| 253 if (extra) { | 253 if (extra) { |
| 254 scoped_ptr<Span> leftover( | 254 scoped_ptr<Span> leftover( |
| 255 new Span(serving->shared_memory_, serving->start_ + blocks, extra)); | 255 new Span(serving->shared_memory_, serving->start_ + blocks, extra)); |
| 256 DCHECK_IMPLIES(extra > 1, spans_.find(leftover->start_) == spans_.end()); | 256 DCHECK((extra <= 1) || (spans_.find(leftover->start_) == spans_.end())); |
|
danakj
2015/06/29 19:30:58
can you make this == 1
| |
| 257 RegisterSpan(leftover.get()); | 257 RegisterSpan(leftover.get()); |
| 258 | 258 |
| 259 // No need to coalesce as the previous span of |leftover| was just split | 259 // No need to coalesce as the previous span of |leftover| was just split |
| 260 // and the next span of |leftover| was not previously coalesced with | 260 // and the next span of |leftover| was not previously coalesced with |
| 261 // |span|. | 261 // |span|. |
| 262 InsertIntoFreeList(leftover.Pass()); | 262 InsertIntoFreeList(leftover.Pass()); |
| 263 | 263 |
| 264 serving->length_ = blocks; | 264 serving->length_ = blocks; |
| 265 spans_[serving->start_ + blocks - 1] = serving.get(); | 265 spans_[serving->start_ + blocks - 1] = serving.get(); |
| 266 } | 266 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 pmd->CreateAllocatorDump(segment_dump_name + "/allocated_objects"); | 366 pmd->CreateAllocatorDump(segment_dump_name + "/allocated_objects"); |
| 367 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectsCount, | 367 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectsCount, |
| 368 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | 368 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 369 static_cast<uint64_t>(allocated_objects_count)); | 369 static_cast<uint64_t>(allocated_objects_count)); |
| 370 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 370 obj_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 371 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 371 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 372 static_cast<uint64_t>(allocated_objects_size_in_bytes)); | 372 static_cast<uint64_t>(allocated_objects_size_in_bytes)); |
| 373 } | 373 } |
| 374 | 374 |
| 375 } // namespace content | 375 } // namespace content |
| OLD | NEW |