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" |
22 | 23 |
23 namespace dart { | 24 namespace dart { |
24 | 25 |
25 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); | 26 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); |
26 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); | 27 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); |
27 DEFINE_FLAG(bool, verify_before_gc, false, | 28 DEFINE_FLAG(bool, verify_before_gc, false, |
28 "Enables heap verification before GC."); | 29 "Enables heap verification before GC."); |
29 DEFINE_FLAG(bool, verify_after_gc, false, | 30 DEFINE_FLAG(bool, verify_after_gc, false, |
30 "Enables heap verification after GC."); | 31 "Enables heap verification after GC."); |
31 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); | 32 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); |
32 DEFINE_FLAG(int, new_gen_heap_size, 32, "new gen heap size in MB," | 33 DEFINE_FLAG(int, new_gen_heap_size, 32, "new gen heap size in MB," |
33 "e.g: --new_gen_heap_size=64 allocates a 64MB new gen heap"); | 34 "e.g: --new_gen_heap_size=64 allocates a 64MB new gen heap"); |
34 DEFINE_FLAG(int, old_gen_heap_size, Heap::kHeapSizeInMB, | 35 DEFINE_FLAG(int, old_gen_heap_size, Heap::kHeapSizeInMB, |
35 "old gen heap size in MB," | 36 "old gen heap size in MB," |
36 "e.g: --old_gen_heap_size=1024 allocates a 1024MB old gen heap"); | 37 "e.g: --old_gen_heap_size=1024 allocates a 1024MB old gen heap"); |
37 | 38 |
38 Heap::Heap() : read_only_(false), gc_in_progress_(false) { | 39 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(); |
| 44 old_weak_tables_[sel] = new WeakTable(); |
| 45 } |
39 new_space_ = new Scavenger(this, | 46 new_space_ = new Scavenger(this, |
40 (FLAG_new_gen_heap_size * MB), | 47 (FLAG_new_gen_heap_size * MB), |
41 kNewObjectAlignmentOffset); | 48 kNewObjectAlignmentOffset); |
42 old_space_ = new PageSpace(this, (FLAG_old_gen_heap_size * MB)); | 49 old_space_ = new PageSpace(this, (FLAG_old_gen_heap_size * MB)); |
43 stats_.num_ = 0; | 50 stats_.num_ = 0; |
44 } | 51 } |
45 | 52 |
46 | 53 |
47 Heap::~Heap() { | 54 Heap::~Heap() { |
48 delete new_space_; | 55 delete new_space_; |
49 delete old_space_; | 56 delete old_space_; |
| 57 for (int sel = 0; |
| 58 sel < kNumWeakSelectors; |
| 59 sel++) { |
| 60 delete new_weak_tables_[sel]; |
| 61 delete old_weak_tables_[sel]; |
| 62 } |
50 } | 63 } |
51 | 64 |
52 | 65 |
53 uword Heap::AllocateNew(intptr_t size) { | 66 uword Heap::AllocateNew(intptr_t size) { |
54 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); | 67 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0); |
55 uword addr = new_space_->TryAllocate(size); | 68 uword addr = new_space_->TryAllocate(size); |
56 if (addr == 0) { | 69 if (addr == 0) { |
57 CollectGarbage(kNew); | 70 CollectGarbage(kNew); |
58 addr = new_space_->TryAllocate(size); | 71 addr = new_space_->TryAllocate(size); |
59 if (addr == 0) { | 72 if (addr == 0) { |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 return "debugging"; | 366 return "debugging"; |
354 case kGCTestCase: | 367 case kGCTestCase: |
355 return "test case"; | 368 return "test case"; |
356 default: | 369 default: |
357 UNREACHABLE(); | 370 UNREACHABLE(); |
358 return ""; | 371 return ""; |
359 } | 372 } |
360 } | 373 } |
361 | 374 |
362 | 375 |
363 void Heap::SetPeer(RawObject* raw_obj, void* peer) { | 376 int64_t Heap::PeerCount() const { |
| 377 return new_weak_tables_[kPeers]->count() + old_weak_tables_[kPeers]->count(); |
| 378 } |
| 379 |
| 380 |
| 381 int64_t Heap::HashCount() const { |
| 382 return |
| 383 new_weak_tables_[kHashes]->count() + old_weak_tables_[kHashes]->count(); |
| 384 } |
| 385 |
| 386 |
| 387 intptr_t Heap::GetWeakEntry(RawObject* raw_obj, WeakSelector sel) const { |
364 if (raw_obj->IsNewObject()) { | 388 if (raw_obj->IsNewObject()) { |
365 new_space_->SetPeer(raw_obj, peer); | 389 return new_weak_tables_[sel]->GetValue(raw_obj); |
| 390 } |
| 391 ASSERT(raw_obj->IsOldObject()); |
| 392 return old_weak_tables_[sel]->GetValue(raw_obj); |
| 393 } |
| 394 |
| 395 |
| 396 void Heap::SetWeakEntry(RawObject* raw_obj, WeakSelector sel, intptr_t val) { |
| 397 if (raw_obj->IsNewObject()) { |
| 398 new_weak_tables_[sel]->SetValue(raw_obj, val); |
366 } else { | 399 } else { |
367 ASSERT(raw_obj->IsOldObject()); | 400 ASSERT(raw_obj->IsOldObject()); |
368 old_space_->SetPeer(raw_obj, peer); | 401 old_weak_tables_[sel]->SetValue(raw_obj, val); |
369 } | 402 } |
370 } | 403 } |
371 | 404 |
372 | 405 |
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 | |
382 int64_t Heap::PeerCount() const { | |
383 return new_space_->PeerCount() + old_space_->PeerCount(); | |
384 } | |
385 | |
386 | |
387 void Heap::RecordBeforeGC(Space space, GCReason reason) { | 406 void Heap::RecordBeforeGC(Space space, GCReason reason) { |
388 ASSERT(!gc_in_progress_); | 407 ASSERT(!gc_in_progress_); |
389 gc_in_progress_ = true; | 408 gc_in_progress_ = true; |
390 stats_.num_++; | 409 stats_.num_++; |
391 stats_.space_ = space; | 410 stats_.space_ = space; |
392 stats_.reason_ = reason; | 411 stats_.reason_ = reason; |
393 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); | 412 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); |
394 stats_.before_.new_used_ = new_space_->in_use(); | 413 stats_.before_.new_used_ = new_space_->in_use(); |
395 stats_.before_.new_capacity_ = new_space_->capacity(); | 414 stats_.before_.new_capacity_ = new_space_->capacity(); |
396 stats_.before_.old_used_ = old_space_->in_use(); | 415 stats_.before_.old_used_ = old_space_->in_use(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 heap->DisableGrowthControl(); | 516 heap->DisableGrowthControl(); |
498 } | 517 } |
499 | 518 |
500 | 519 |
501 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 520 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
502 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 521 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
503 heap->SetGrowthControlState(current_growth_controller_state_); | 522 heap->SetGrowthControlState(current_growth_controller_state_); |
504 } | 523 } |
505 | 524 |
506 } // namespace dart | 525 } // namespace dart |
OLD | NEW |