Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: src/zone.cc

Issue 1847543002: Expose a lower bound of malloc'd memory via heap statistics (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/zone.h ('k') | test/cctest/cctest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project 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 "src/zone.h" 5 #include "src/zone.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 #include "src/v8.h" 9 #include "src/v8.h"
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 Address end() const { return address(size_); } 65 Address end() const { return address(size_); }
66 66
67 private: 67 private:
68 // Computes the address of the nth byte in this segment. 68 // Computes the address of the nth byte in this segment.
69 Address address(size_t n) const { return Address(this) + n; } 69 Address address(size_t n) const { return Address(this) + n; }
70 70
71 Segment* next_; 71 Segment* next_;
72 size_t size_; 72 size_t size_;
73 }; 73 };
74 74
75 75 Zone::Zone(base::AccountingAllocator* allocator)
76 Zone::Zone()
77 : allocation_size_(0), 76 : allocation_size_(0),
78 segment_bytes_allocated_(0), 77 segment_bytes_allocated_(0),
79 position_(0), 78 position_(0),
80 limit_(0), 79 limit_(0),
80 allocator_(allocator),
81 segment_head_(nullptr) {} 81 segment_head_(nullptr) {}
82 82
83
84 Zone::~Zone() { 83 Zone::~Zone() {
85 DeleteAll(); 84 DeleteAll();
86 DeleteKeptSegment(); 85 DeleteKeptSegment();
87 86
88 DCHECK(segment_bytes_allocated_ == 0); 87 DCHECK(segment_bytes_allocated_ == 0);
89 } 88 }
90 89
91 90
92 void* Zone::New(size_t size) { 91 void* Zone::New(size_t size) {
93 // Round up the requested size to fit the alignment. 92 // Round up the requested size to fit the alignment.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 segment_head_ = nullptr; 193 segment_head_ = nullptr;
195 } 194 }
196 195
197 DCHECK(segment_bytes_allocated_ == 0); 196 DCHECK(segment_bytes_allocated_ == 0);
198 } 197 }
199 198
200 199
201 // Creates a new segment, sets it size, and pushes it to the front 200 // Creates a new segment, sets it size, and pushes it to the front
202 // of the segment chain. Returns the new segment. 201 // of the segment chain. Returns the new segment.
203 Segment* Zone::NewSegment(size_t size) { 202 Segment* Zone::NewSegment(size_t size) {
204 Segment* result = reinterpret_cast<Segment*>(Malloced::New(size)); 203 Segment* result = reinterpret_cast<Segment*>(allocator_->Allocate(size));
205 segment_bytes_allocated_ += size; 204 segment_bytes_allocated_ += size;
206 if (result != nullptr) { 205 if (result != nullptr) {
207 result->Initialize(segment_head_, size); 206 result->Initialize(segment_head_, size);
208 segment_head_ = result; 207 segment_head_ = result;
209 } 208 }
210 return result; 209 return result;
211 } 210 }
212 211
213 212
214 // Deletes the given segment. Does not touch the segment chain. 213 // Deletes the given segment. Does not touch the segment chain.
215 void Zone::DeleteSegment(Segment* segment, size_t size) { 214 void Zone::DeleteSegment(Segment* segment, size_t size) {
216 segment_bytes_allocated_ -= size; 215 segment_bytes_allocated_ -= size;
217 Malloced::Delete(segment); 216 allocator_->Free(segment, size);
218 } 217 }
219 218
220 219
221 Address Zone::NewExpand(size_t size) { 220 Address Zone::NewExpand(size_t size) {
222 // Make sure the requested size is already properly aligned and that 221 // Make sure the requested size is already properly aligned and that
223 // there isn't enough room in the Zone to satisfy the request. 222 // there isn't enough room in the Zone to satisfy the request.
224 DCHECK_EQ(size, RoundDown(size, kAlignment)); 223 DCHECK_EQ(size, RoundDown(size, kAlignment));
225 DCHECK_LT(limit_, position_ + size); 224 DCHECK_LT(limit_, position_ + size);
226 225
227 // Compute the new segment size. We use a 'high water mark' 226 // Compute the new segment size. We use a 'high water mark'
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // size bytes + header and alignment padding) 265 // size bytes + header and alignment padding)
267 DCHECK(reinterpret_cast<uintptr_t>(position_) >= 266 DCHECK(reinterpret_cast<uintptr_t>(position_) >=
268 reinterpret_cast<uintptr_t>(result)); 267 reinterpret_cast<uintptr_t>(result));
269 limit_ = segment->end(); 268 limit_ = segment->end();
270 DCHECK(position_ <= limit_); 269 DCHECK(position_ <= limit_);
271 return result; 270 return result;
272 } 271 }
273 272
274 } // namespace internal 273 } // namespace internal
275 } // namespace v8 274 } // namespace v8
OLDNEW
« no previous file with comments | « src/zone.h ('k') | test/cctest/cctest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698