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

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

Issue 10836061: Change the zone allocation api. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« 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/isolate.h" 10 #include "vm/isolate.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 size += sizeof(Segment); // Account for book keeping fields in size. 179 size += sizeof(Segment); // Account for book keeping fields in size.
180 large_segments_ = Segment::New(size, large_segments_); 180 large_segments_ = Segment::New(size, large_segments_);
181 181
182 uword result = Utils::RoundUp(large_segments_->start(), kAlignment); 182 uword result = Utils::RoundUp(large_segments_->start(), kAlignment);
183 return result; 183 return result;
184 } 184 }
185 185
186 186
187 char* BaseZone::MakeCopyOfString(const char* str) { 187 char* BaseZone::MakeCopyOfString(const char* str) {
188 intptr_t len = strlen(str) + 1; // '\0'-terminated. 188 intptr_t len = strlen(str) + 1; // '\0'-terminated.
189 char* copy = reinterpret_cast<char*>(Allocate(len)); 189 char* copy = Alloc<char>(len);
190 strncpy(copy, str, len); 190 strncpy(copy, str, len);
191 return copy; 191 return copy;
192 } 192 }
193 193
194 194
195 uword BaseZone::Reallocate(uword data, intptr_t old_size, intptr_t new_size) {
196 ASSERT(new_size >= 0);
197 uword new_data = Allocate(new_size);
198 if (data != 0) {
199 memmove(reinterpret_cast<void*>(new_data),
200 reinterpret_cast<void*>(data),
201 Utils::Minimum(old_size, new_size));
202 }
203 return new_data;
204 }
205
206
207 #if defined(DEBUG) 195 #if defined(DEBUG)
208 void BaseZone::DumpZoneSizes() { 196 void BaseZone::DumpZoneSizes() {
209 intptr_t size = 0; 197 intptr_t size = 0;
210 for (Segment* s = large_segments_; s != NULL; s = s->next()) { 198 for (Segment* s = large_segments_; s != NULL; s = s->next()) {
211 size += s->size(); 199 size += s->size();
212 } 200 }
213 OS::Print("Size in bytes allocated, Total = %d Large Segments = %d\n", 201 OS::Print("Size in bytes allocated, Total = %d Large Segments = %d\n",
214 SizeInBytes(), size); 202 SizeInBytes(), size);
215 } 203 }
216 #endif 204 #endif
(...skipping 26 matching lines...) Expand all
243 } 231 }
244 } 232 }
245 233
246 234
247 char* Zone::PrintToString(const char* format, ...) { 235 char* Zone::PrintToString(const char* format, ...) {
248 va_list args; 236 va_list args;
249 va_start(args, format); 237 va_start(args, format);
250 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 238 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
251 va_end(args); 239 va_end(args);
252 240
253 char* buffer = reinterpret_cast<char*>(Allocate(len + 1)); 241 char* buffer = Alloc<char>(len + 1);
254 va_list args2; 242 va_list args2;
255 va_start(args2, format); 243 va_start(args2, format);
256 OS::VSNPrint(buffer, (len + 1), format, args2); 244 OS::VSNPrint(buffer, (len + 1), format, args2);
257 va_end(args2); 245 va_end(args2);
258 246
259 return buffer; 247 return buffer;
260 } 248 }
261 249
262 250
263 } // namespace dart 251 } // 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