| Index: src/zone/zone.cc
|
| diff --git a/src/zone/zone.cc b/src/zone/zone.cc
|
| index 4272e17fd2eba2ef2389350b15ae05fd6abfed31..5b458c6746c124e8561a5406e6d472ddabc7e7ee 100644
|
| --- a/src/zone/zone.cc
|
| +++ b/src/zone/zone.cc
|
| @@ -51,7 +51,6 @@ Zone::Zone(AccountingAllocator* allocator)
|
|
|
| Zone::~Zone() {
|
| DeleteAll();
|
| - DeleteKeptSegment();
|
|
|
| DCHECK(segment_bytes_allocated_ == 0);
|
| }
|
| @@ -92,73 +91,35 @@ void* Zone::New(size_t size) {
|
| }
|
|
|
| void Zone::DeleteAll() {
|
| - // Find a segment with a suitable size to keep around.
|
| - Segment* keep = nullptr;
|
| - // Traverse the chained list of segments, zapping (in debug mode)
|
| - // and freeing every segment except the one we wish to keep.
|
| + // Traverse the chained list of segments and return them all to the allocator.
|
| for (Segment* current = segment_head_; current;) {
|
| Segment* next = current->next();
|
| - if (!keep && current->size() <= kMaximumKeptSegmentSize) {
|
| - // Unlink the segment we wish to keep from the list.
|
| - keep = current;
|
| - keep->set_next(nullptr);
|
| - } else {
|
| - size_t size = current->size();
|
| -#ifdef DEBUG
|
| - // Un-poison first so the zapping doesn't trigger ASan complaints.
|
| - ASAN_UNPOISON_MEMORY_REGION(current, size);
|
| -#endif
|
| - current->ZapContents();
|
| - segment_bytes_allocated_ -= size;
|
| - allocator_->FreeSegment(current);
|
| - }
|
| + size_t size = current->size();
|
| +
|
| + // Un-poison the segment content so we can re-use or zap it later.
|
| + ASAN_UNPOISON_MEMORY_REGION(current->start(), current->capacity());
|
| +
|
| + segment_bytes_allocated_ -= size;
|
| + allocator_->ReturnSegment(current);
|
| current = next;
|
| }
|
|
|
| - // If we have found a segment we want to keep, we must recompute the
|
| - // variables 'position' and 'limit' to prepare for future allocate
|
| - // attempts. Otherwise, we must clear the position and limit to
|
| - // force a new segment to be allocated on demand.
|
| - if (keep) {
|
| - Address start = keep->start();
|
| - position_ = RoundUp(start, kAlignment);
|
| - limit_ = keep->end();
|
| - // Un-poison so we can re-use the segment later.
|
| - ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity());
|
| - keep->ZapContents();
|
| - } else {
|
| - position_ = limit_ = 0;
|
| - }
|
| + position_ = limit_ = 0;
|
|
|
| allocation_size_ = 0;
|
| // Update the head segment to be the kept segment (if any).
|
| - segment_head_ = keep;
|
| -}
|
| -
|
| -void Zone::DeleteKeptSegment() {
|
| - DCHECK(segment_head_ == nullptr || segment_head_->next() == nullptr);
|
| - if (segment_head_ != nullptr) {
|
| - size_t size = segment_head_->size();
|
| -#ifdef DEBUG
|
| - // Un-poison first so the zapping doesn't trigger ASan complaints.
|
| - ASAN_UNPOISON_MEMORY_REGION(segment_head_, size);
|
| -#endif
|
| - segment_head_->ZapContents();
|
| - segment_bytes_allocated_ -= size;
|
| - allocator_->FreeSegment(segment_head_);
|
| - segment_head_ = nullptr;
|
| - }
|
| -
|
| - DCHECK(segment_bytes_allocated_ == 0);
|
| + segment_head_ = nullptr;
|
| }
|
|
|
| // Creates a new segment, sets it size, and pushes it to the front
|
| // of the segment chain. Returns the new segment.
|
| -Segment* Zone::NewSegment(size_t size) {
|
| - Segment* result = allocator_->AllocateSegment(size);
|
| - segment_bytes_allocated_ += size;
|
| +Segment* Zone::NewSegment(size_t requested_size) {
|
| + Segment* result = allocator_->GetSegment(requested_size);
|
| + DCHECK_GE(result->size(), requested_size);
|
| + segment_bytes_allocated_ += result->size();
|
| if (result != nullptr) {
|
| - result->Initialize(segment_head_, size, this);
|
| + result->set_zone(this);
|
| + result->set_next(segment_head_);
|
| segment_head_ = result;
|
| }
|
| return result;
|
|
|