OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/scavenger.h" | 5 #include "vm/scavenger.h" |
6 | 6 |
7 #include "vm/dart.h" | 7 #include "vm/dart.h" |
8 #include "vm/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/lockers.h" | 10 #include "vm/lockers.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 SemiSpace* SemiSpace::cache_ = NULL; | 266 SemiSpace* SemiSpace::cache_ = NULL; |
267 | 267 |
268 | 268 |
269 void SemiSpace::InitOnce() { | 269 void SemiSpace::InitOnce() { |
270 ASSERT(mutex_ == NULL); | 270 ASSERT(mutex_ == NULL); |
271 mutex_ = new Mutex(); | 271 mutex_ = new Mutex(); |
272 ASSERT(mutex_ != NULL); | 272 ASSERT(mutex_ != NULL); |
273 } | 273 } |
274 | 274 |
275 | 275 |
276 SemiSpace* SemiSpace::New(intptr_t size_in_words) { | 276 SemiSpace* SemiSpace::New(intptr_t size_in_words, const char* name) { |
277 { | 277 { |
278 MutexLocker locker(mutex_); | 278 MutexLocker locker(mutex_); |
279 // TODO(koda): Cache one entry per size. | 279 // TODO(koda): Cache one entry per size. |
280 if (cache_ != NULL && cache_->size_in_words() == size_in_words) { | 280 if (cache_ != NULL && cache_->size_in_words() == size_in_words) { |
281 SemiSpace* result = cache_; | 281 SemiSpace* result = cache_; |
282 cache_ = NULL; | 282 cache_ = NULL; |
283 return result; | 283 return result; |
284 } | 284 } |
285 } | 285 } |
286 if (size_in_words == 0) { | 286 if (size_in_words == 0) { |
287 return new SemiSpace(NULL); | 287 return new SemiSpace(NULL); |
288 } else { | 288 } else { |
289 intptr_t size_in_bytes = size_in_words << kWordSizeLog2; | 289 intptr_t size_in_bytes = size_in_words << kWordSizeLog2; |
290 VirtualMemory* reserved = VirtualMemory::Reserve(size_in_bytes); | 290 VirtualMemory* reserved = VirtualMemory::Reserve(size_in_bytes); |
291 if ((reserved == NULL) || !reserved->Commit(false)) { // Not executable. | 291 const bool kExecutable = false; |
| 292 if ((reserved == NULL) || !reserved->Commit(kExecutable, name)) { |
292 // TODO(koda): If cache_ is not empty, we could try to delete it. | 293 // TODO(koda): If cache_ is not empty, we could try to delete it. |
293 delete reserved; | 294 delete reserved; |
294 return NULL; | 295 return NULL; |
295 } | 296 } |
296 #if defined(DEBUG) | 297 #if defined(DEBUG) |
297 memset(reserved->address(), Heap::kZapByte, size_in_bytes); | 298 memset(reserved->address(), Heap::kZapByte, size_in_bytes); |
298 #endif // defined(DEBUG) | 299 #endif // defined(DEBUG) |
299 return new SemiSpace(reserved); | 300 return new SemiSpace(reserved); |
300 } | 301 } |
301 } | 302 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 collections_(0), | 340 collections_(0), |
340 external_size_(0) { | 341 external_size_(0) { |
341 // Verify assumptions about the first word in objects which the scavenger is | 342 // Verify assumptions about the first word in objects which the scavenger is |
342 // going to use for forwarding pointers. | 343 // going to use for forwarding pointers. |
343 ASSERT(Object::tags_offset() == 0); | 344 ASSERT(Object::tags_offset() == 0); |
344 | 345 |
345 // Set initial size resulting in a total of three different levels. | 346 // Set initial size resulting in a total of three different levels. |
346 const intptr_t initial_semi_capacity_in_words = | 347 const intptr_t initial_semi_capacity_in_words = |
347 max_semi_capacity_in_words / | 348 max_semi_capacity_in_words / |
348 (FLAG_new_gen_growth_factor * FLAG_new_gen_growth_factor); | 349 (FLAG_new_gen_growth_factor * FLAG_new_gen_growth_factor); |
349 to_ = SemiSpace::New(initial_semi_capacity_in_words); | 350 |
| 351 const intptr_t kVmNameSize = 128; |
| 352 char vm_name[kVmNameSize]; |
| 353 Heap::RegionName(heap_, Heap::kNew, vm_name, kVmNameSize); |
| 354 to_ = SemiSpace::New(initial_semi_capacity_in_words, vm_name); |
350 if (to_ == NULL) { | 355 if (to_ == NULL) { |
351 OUT_OF_MEMORY(); | 356 OUT_OF_MEMORY(); |
352 } | 357 } |
353 // Setup local fields. | 358 // Setup local fields. |
354 top_ = FirstObjectStart(); | 359 top_ = FirstObjectStart(); |
355 resolved_top_ = top_; | 360 resolved_top_ = top_; |
356 end_ = to_->end(); | 361 end_ = to_->end(); |
357 | 362 |
358 survivor_end_ = FirstObjectStart(); | 363 survivor_end_ = FirstObjectStart(); |
359 | 364 |
(...skipping 23 matching lines...) Expand all Loading... |
383 | 388 |
384 | 389 |
385 SemiSpace* Scavenger::Prologue(Isolate* isolate, bool invoke_api_callbacks) { | 390 SemiSpace* Scavenger::Prologue(Isolate* isolate, bool invoke_api_callbacks) { |
386 if (invoke_api_callbacks && (isolate->gc_prologue_callback() != NULL)) { | 391 if (invoke_api_callbacks && (isolate->gc_prologue_callback() != NULL)) { |
387 (isolate->gc_prologue_callback())(); | 392 (isolate->gc_prologue_callback())(); |
388 } | 393 } |
389 isolate->PrepareForGC(); | 394 isolate->PrepareForGC(); |
390 // Flip the two semi-spaces so that to_ is always the space for allocating | 395 // Flip the two semi-spaces so that to_ is always the space for allocating |
391 // objects. | 396 // objects. |
392 SemiSpace* from = to_; | 397 SemiSpace* from = to_; |
393 to_ = SemiSpace::New(NewSizeInWords(from->size_in_words())); | 398 |
| 399 const intptr_t kVmNameSize = 128; |
| 400 char vm_name[kVmNameSize]; |
| 401 Heap::RegionName(heap_, Heap::kNew, vm_name, kVmNameSize); |
| 402 to_ = SemiSpace::New(NewSizeInWords(from->size_in_words()), vm_name); |
394 if (to_ == NULL) { | 403 if (to_ == NULL) { |
395 // TODO(koda): We could try to recover (collect old space, wait for another | 404 // TODO(koda): We could try to recover (collect old space, wait for another |
396 // isolate to finish scavenge, etc.). | 405 // isolate to finish scavenge, etc.). |
397 OUT_OF_MEMORY(); | 406 OUT_OF_MEMORY(); |
398 } | 407 } |
399 UpdateMaxHeapCapacity(); | 408 UpdateMaxHeapCapacity(); |
400 top_ = FirstObjectStart(); | 409 top_ = FirstObjectStart(); |
401 resolved_top_ = top_; | 410 resolved_top_ = top_; |
402 end_ = to_->end(); | 411 end_ = to_->end(); |
403 return from; | 412 return from; |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 } | 899 } |
891 | 900 |
892 | 901 |
893 void Scavenger::FreeExternal(intptr_t size) { | 902 void Scavenger::FreeExternal(intptr_t size) { |
894 ASSERT(size >= 0); | 903 ASSERT(size >= 0); |
895 external_size_ -= size; | 904 external_size_ -= size; |
896 ASSERT(external_size_ >= 0); | 905 ASSERT(external_size_ >= 0); |
897 } | 906 } |
898 | 907 |
899 } // namespace dart | 908 } // namespace dart |
OLD | NEW |