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

Side by Side Diff: runtime/vm/zone.cc

Issue 2570763002: Fixed bad calculations for determining total allocated size of a zone. (Closed)
Patch Set: Created 4 years 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 | « runtime/vm/zone.h ('k') | runtime/vm/zone_test.cc » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/zone.h" 5 #include "vm/zone.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/flags.h" 9 #include "vm/flags.h"
10 #include "vm/handles_impl.h" 10 #include "vm/handles_impl.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 return size + (position_ - initial_buffer_.start()); 129 return size + (position_ - initial_buffer_.start());
130 } 130 }
131 size += initial_buffer_.size(); 131 size += initial_buffer_.size();
132 for (Segment* s = head_->next(); s != NULL; s = s->next()) { 132 for (Segment* s = head_->next(); s != NULL; s = s->next()) {
133 size += s->size(); 133 size += s->size();
134 } 134 }
135 return size + (position_ - head_->start()); 135 return size + (position_ - head_->start());
136 } 136 }
137 137
138 138
139 intptr_t Zone::CapacityInBytes() const {
140 intptr_t size = 0;
141 for (Segment* s = large_segments_; s != NULL; s = s->next()) {
142 size += s->size();
143 }
144 if (head_ == NULL) {
145 return size + initial_buffer_.size();
146 }
147 size += initial_buffer_.size();
148 for (Segment* s = head_; s != NULL; s = s->next()) {
149 size += s->size();
150 }
151 return size;
152 }
153
154
139 uword Zone::AllocateExpand(intptr_t size) { 155 uword Zone::AllocateExpand(intptr_t size) {
140 ASSERT(size >= 0); 156 ASSERT(size >= 0);
141 if (FLAG_trace_zones) { 157 if (FLAG_trace_zones) {
142 OS::PrintErr("*** Expanding zone 0x%" Px "\n", 158 OS::PrintErr("*** Expanding zone 0x%" Px "\n",
143 reinterpret_cast<intptr_t>(this)); 159 reinterpret_cast<intptr_t>(this));
144 DumpZoneSizes(); 160 DumpZoneSizes();
145 } 161 }
146 // Make sure the requested size is already properly aligned and that 162 // Make sure the requested size is already properly aligned and that
147 // there isn't enough room in the Zone to satisfy the request. 163 // there isn't enough room in the Zone to satisfy the request.
148 ASSERT(Utils::IsAligned(size, kAlignment)); 164 ASSERT(Utils::IsAligned(size, kAlignment));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 272
257 273
258 char* Zone::VPrint(const char* format, va_list args) { 274 char* Zone::VPrint(const char* format, va_list args) {
259 return OS::VSCreate(this, format, args); 275 return OS::VSCreate(this, format, args);
260 } 276 }
261 277
262 278
263 #ifndef PRODUCT 279 #ifndef PRODUCT
264 void Zone::PrintJSON(JSONStream* stream) const { 280 void Zone::PrintJSON(JSONStream* stream) const {
265 JSONObject jsobj(stream); 281 JSONObject jsobj(stream);
266 intptr_t capacity = SizeInBytes(); 282 intptr_t capacity = CapacityInBytes();
267 intptr_t used_size = UsedSizeInBytes(); 283 intptr_t used_size = SizeInBytes();
268 jsobj.AddProperty("type", "_Zone"); 284 jsobj.AddProperty("type", "_Zone");
269 jsobj.AddProperty("capacity", capacity); 285 jsobj.AddProperty("capacity", capacity);
270 jsobj.AddProperty("used", used_size); 286 jsobj.AddProperty("used", used_size);
271 } 287 }
272 #endif 288 #endif
273 289
274 290
275 StackZone::StackZone(Thread* thread) : StackResource(thread), zone_() { 291 StackZone::StackZone(Thread* thread) : StackResource(thread), zone_() {
276 if (FLAG_trace_zones) { 292 if (FLAG_trace_zones) {
277 OS::PrintErr("*** Starting a new Stack zone 0x%" Px "(0x%" Px ")\n", 293 OS::PrintErr("*** Starting a new Stack zone 0x%" Px "(0x%" Px ")\n",
278 reinterpret_cast<intptr_t>(this), 294 reinterpret_cast<intptr_t>(this),
279 reinterpret_cast<intptr_t>(&zone_)); 295 reinterpret_cast<intptr_t>(&zone_));
280 } 296 }
281 zone_.Link(thread->zone()); 297 zone_.Link(thread->zone());
282 thread->set_zone(&zone_); 298 thread->set_zone(&zone_);
283 } 299 }
284 300
285 301
286 StackZone::~StackZone() { 302 StackZone::~StackZone() {
287 ASSERT(thread()->zone() == &zone_); 303 ASSERT(thread()->zone() == &zone_);
288 thread()->set_zone(zone_.previous_); 304 thread()->set_zone(zone_.previous_);
289 if (FLAG_trace_zones) { 305 if (FLAG_trace_zones) {
290 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n", 306 OS::PrintErr("*** Deleting Stack zone 0x%" Px "(0x%" Px ")\n",
291 reinterpret_cast<intptr_t>(this), 307 reinterpret_cast<intptr_t>(this),
292 reinterpret_cast<intptr_t>(&zone_)); 308 reinterpret_cast<intptr_t>(&zone_));
293 } 309 }
294 } 310 }
295 311
296 } // namespace dart 312 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/zone.h ('k') | runtime/vm/zone_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698