| OLD | NEW |
| 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/heap.h" | 5 #include "vm/heap.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/heap_histogram.h" | 10 #include "vm/heap_histogram.h" |
| 11 #include "vm/heap_profiler.h" | 11 #include "vm/heap_profiler.h" |
| 12 #include "vm/isolate.h" | 12 #include "vm/isolate.h" |
| 13 #include "vm/object.h" | 13 #include "vm/object.h" |
| 14 #include "vm/object_set.h" | 14 #include "vm/object_set.h" |
| 15 #include "vm/os.h" | 15 #include "vm/os.h" |
| 16 #include "vm/pages.h" | 16 #include "vm/pages.h" |
| 17 #include "vm/raw_object.h" | 17 #include "vm/raw_object.h" |
| 18 #include "vm/scavenger.h" | 18 #include "vm/scavenger.h" |
| 19 #include "vm/stack_frame.h" | 19 #include "vm/stack_frame.h" |
| 20 #include "vm/verifier.h" | 20 #include "vm/verifier.h" |
| 21 #include "vm/virtual_memory.h" | 21 #include "vm/virtual_memory.h" |
| 22 #include "vm/weak_table.h" | |
| 23 | 22 |
| 24 namespace dart { | 23 namespace dart { |
| 25 | 24 |
| 26 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); | 25 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); |
| 27 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); | 26 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); |
| 28 DEFINE_FLAG(bool, verify_before_gc, false, | 27 DEFINE_FLAG(bool, verify_before_gc, false, |
| 29 "Enables heap verification before GC."); | 28 "Enables heap verification before GC."); |
| 30 DEFINE_FLAG(bool, verify_after_gc, false, | 29 DEFINE_FLAG(bool, verify_after_gc, false, |
| 31 "Enables heap verification after GC."); | 30 "Enables heap verification after GC."); |
| 32 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); | 31 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); |
| 33 DEFINE_FLAG(int, new_gen_heap_size, 32, "new gen heap size in MB," | 32 DEFINE_FLAG(int, new_gen_heap_size, 32, "new gen heap size in MB," |
| 34 "e.g: --new_gen_heap_size=64 allocates a 64MB new gen heap"); | 33 "e.g: --new_gen_heap_size=64 allocates a 64MB new gen heap"); |
| 35 DEFINE_FLAG(int, old_gen_heap_size, Heap::kHeapSizeInMB, | 34 DEFINE_FLAG(int, old_gen_heap_size, Heap::kHeapSizeInMB, |
| 36 "old gen heap size in MB," | 35 "old gen heap size in MB," |
| 37 "e.g: --old_gen_heap_size=1024 allocates a 1024MB old gen heap"); | 36 "e.g: --old_gen_heap_size=1024 allocates a 1024MB old gen heap"); |
| 38 | 37 |
| 39 Heap::Heap() : read_only_(false), gc_in_progress_(false) { | 38 Heap::Heap() : read_only_(false), gc_in_progress_(false) { |
| 40 for (int sel = 0; | |
| 41 sel < kNumWeakSelectors; | |
| 42 sel++) { | |
| 43 new_weak_tables_[sel] = new WeakTable(0); | |
| 44 old_weak_tables_[sel] = new WeakTable(0); | |
| 45 } | |
| 46 new_space_ = new Scavenger(this, | 39 new_space_ = new Scavenger(this, |
| 47 (FLAG_new_gen_heap_size * MB), | 40 (FLAG_new_gen_heap_size * MB), |
| 48 kNewObjectAlignmentOffset); | 41 kNewObjectAlignmentOffset); |
| 49 old_space_ = new PageSpace(this, (FLAG_old_gen_heap_size * MB)); | 42 old_space_ = new PageSpace(this, (FLAG_old_gen_heap_size * MB)); |
| 50 stats_.num_ = 0; | 43 stats_.num_ = 0; |
| 51 } | 44 } |
| 52 | 45 |
| 53 | 46 |
| 54 Heap::~Heap() { | 47 Heap::~Heap() { |
| 55 delete new_space_; | 48 delete new_space_; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 return "debugging"; | 353 return "debugging"; |
| 361 case kGCTestCase: | 354 case kGCTestCase: |
| 362 return "test case"; | 355 return "test case"; |
| 363 default: | 356 default: |
| 364 UNREACHABLE(); | 357 UNREACHABLE(); |
| 365 return ""; | 358 return ""; |
| 366 } | 359 } |
| 367 } | 360 } |
| 368 | 361 |
| 369 | 362 |
| 363 void Heap::SetPeer(RawObject* raw_obj, void* peer) { |
| 364 if (raw_obj->IsNewObject()) { |
| 365 new_space_->SetPeer(raw_obj, peer); |
| 366 } else { |
| 367 ASSERT(raw_obj->IsOldObject()); |
| 368 old_space_->SetPeer(raw_obj, peer); |
| 369 } |
| 370 } |
| 371 |
| 372 |
| 373 void* Heap::GetPeer(RawObject* raw_obj) { |
| 374 if (raw_obj->IsNewObject()) { |
| 375 return new_space_->GetPeer(raw_obj); |
| 376 } |
| 377 ASSERT(raw_obj->IsOldObject()); |
| 378 return old_space_->GetPeer(raw_obj); |
| 379 } |
| 380 |
| 381 |
| 370 int64_t Heap::PeerCount() const { | 382 int64_t Heap::PeerCount() const { |
| 371 return new_weak_tables_[kPeers]->count() + old_weak_tables_[kPeers]->count(); | 383 return new_space_->PeerCount() + old_space_->PeerCount(); |
| 372 } | 384 } |
| 373 | 385 |
| 374 | 386 |
| 375 int64_t Heap::HashCount() const { | |
| 376 return | |
| 377 new_weak_tables_[kHashes]->count() + old_weak_tables_[kHashes]->count(); | |
| 378 } | |
| 379 | |
| 380 | |
| 381 intptr_t Heap::GetWeakEntry(RawObject* raw_obj, WeakSelector sel) const { | |
| 382 if (raw_obj->IsNewObject()) { | |
| 383 return new_weak_tables_[sel]->GetValue(raw_obj); | |
| 384 } | |
| 385 ASSERT(raw_obj->IsOldObject()); | |
| 386 return old_weak_tables_[sel]->GetValue(raw_obj); | |
| 387 } | |
| 388 | |
| 389 | |
| 390 void Heap::SetWeakEntry(RawObject* raw_obj, WeakSelector sel, intptr_t val) { | |
| 391 if (raw_obj->IsNewObject()) { | |
| 392 new_weak_tables_[sel] = new_weak_tables_[sel]->SetValue(raw_obj, val); | |
| 393 } else { | |
| 394 ASSERT(raw_obj->IsOldObject()); | |
| 395 old_weak_tables_[sel] = old_weak_tables_[sel]->SetValue(raw_obj, val); | |
| 396 } | |
| 397 } | |
| 398 | |
| 399 | |
| 400 void Heap::RecordBeforeGC(Space space, GCReason reason) { | 387 void Heap::RecordBeforeGC(Space space, GCReason reason) { |
| 401 ASSERT(!gc_in_progress_); | 388 ASSERT(!gc_in_progress_); |
| 402 gc_in_progress_ = true; | 389 gc_in_progress_ = true; |
| 403 stats_.num_++; | 390 stats_.num_++; |
| 404 stats_.space_ = space; | 391 stats_.space_ = space; |
| 405 stats_.reason_ = reason; | 392 stats_.reason_ = reason; |
| 406 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); | 393 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); |
| 407 stats_.before_.new_used_ = new_space_->in_use(); | 394 stats_.before_.new_used_ = new_space_->in_use(); |
| 408 stats_.before_.new_capacity_ = new_space_->capacity(); | 395 stats_.before_.new_capacity_ = new_space_->capacity(); |
| 409 stats_.before_.old_used_ = old_space_->in_use(); | 396 stats_.before_.old_used_ = old_space_->in_use(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 heap->DisableGrowthControl(); | 497 heap->DisableGrowthControl(); |
| 511 } | 498 } |
| 512 | 499 |
| 513 | 500 |
| 514 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 501 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 515 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 502 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 516 heap->SetGrowthControlState(current_growth_controller_state_); | 503 heap->SetGrowthControlState(current_growth_controller_state_); |
| 517 } | 504 } |
| 518 | 505 |
| 519 } // namespace dart | 506 } // namespace dart |
| OLD | NEW |