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 (WeakSelector sel = static_cast<WeakSelector>(0); |
| 41 sel < kNumWeakSelectors; |
| 42 sel++) { |
| 43 new_weak_tables_[sel] = new WeakTable(0); |
| 44 old_weak_tables_[sel] = new WeakTable(0); |
| 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_; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 return "debugging"; | 360 return "debugging"; |
354 case kGCTestCase: | 361 case kGCTestCase: |
355 return "test case"; | 362 return "test case"; |
356 default: | 363 default: |
357 UNREACHABLE(); | 364 UNREACHABLE(); |
358 return ""; | 365 return ""; |
359 } | 366 } |
360 } | 367 } |
361 | 368 |
362 | 369 |
363 void Heap::SetPeer(RawObject* raw_obj, void* peer) { | 370 int64_t Heap::PeerCount() const { |
| 371 return new_weak_tables_[kPeers]->count() + old_weak_tables_[kPeers]->count(); |
| 372 } |
| 373 |
| 374 |
| 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 { |
364 if (raw_obj->IsNewObject()) { | 382 if (raw_obj->IsNewObject()) { |
365 new_space_->SetPeer(raw_obj, peer); | 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); |
366 } else { | 393 } else { |
367 ASSERT(raw_obj->IsOldObject()); | 394 ASSERT(raw_obj->IsOldObject()); |
368 old_space_->SetPeer(raw_obj, peer); | 395 old_weak_tables_[sel] = old_weak_tables_[sel]->SetValue(raw_obj, val); |
369 } | 396 } |
370 } | 397 } |
371 | 398 |
372 | 399 |
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) { | 400 void Heap::RecordBeforeGC(Space space, GCReason reason) { |
388 ASSERT(!gc_in_progress_); | 401 ASSERT(!gc_in_progress_); |
389 gc_in_progress_ = true; | 402 gc_in_progress_ = true; |
390 stats_.num_++; | 403 stats_.num_++; |
391 stats_.space_ = space; | 404 stats_.space_ = space; |
392 stats_.reason_ = reason; | 405 stats_.reason_ = reason; |
393 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); | 406 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); |
394 stats_.before_.new_used_ = new_space_->in_use(); | 407 stats_.before_.new_used_ = new_space_->in_use(); |
395 stats_.before_.new_capacity_ = new_space_->capacity(); | 408 stats_.before_.new_capacity_ = new_space_->capacity(); |
396 stats_.before_.old_used_ = old_space_->in_use(); | 409 stats_.before_.old_used_ = old_space_->in_use(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 heap->DisableGrowthControl(); | 510 heap->DisableGrowthControl(); |
498 } | 511 } |
499 | 512 |
500 | 513 |
501 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 514 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
502 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 515 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
503 heap->SetGrowthControlState(current_growth_controller_state_); | 516 heap->SetGrowthControlState(current_growth_controller_state_); |
504 } | 517 } |
505 | 518 |
506 } // namespace dart | 519 } // namespace dart |
OLD | NEW |