| 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/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 delete new_weak_tables_[sel]; | 56 delete new_weak_tables_[sel]; |
| 57 delete old_weak_tables_[sel]; | 57 delete old_weak_tables_[sel]; |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 uword Heap::AllocateNew(intptr_t size) { | 62 uword Heap::AllocateNew(intptr_t size) { |
| 63 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); | 63 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); |
| 64 // Currently, only the Dart thread may allocate in new space. | 64 // Currently, only the Dart thread may allocate in new space. |
| 65 isolate()->AssertCurrentThreadIsMutator(); | 65 isolate()->AssertCurrentThreadIsMutator(); |
| 66 uword addr = new_space_.TryAllocate(size); | 66 uword addr = new_space_.TryAllocateInTLAB(Thread::Current(), size); |
| 67 if (addr == 0) { | 67 if (addr == 0) { |
| 68 // This call to CollectGarbage might end up "reusing" a collection spawned | 68 // This call to CollectGarbage might end up "reusing" a collection spawned |
| 69 // from a different thread and will be racing to allocate the requested | 69 // from a different thread and will be racing to allocate the requested |
| 70 // memory with other threads being released after the collection. | 70 // memory with other threads being released after the collection. |
| 71 CollectGarbage(kNew); | 71 CollectGarbage(kNew); |
| 72 addr = new_space_.TryAllocate(size); | 72 addr = new_space_.TryAllocateInTLAB(Thread::Current(), size); |
| 73 if (addr == 0) { | 73 if (addr == 0) { |
| 74 return AllocateOld(size, HeapPage::kData); | 74 return AllocateOld(size, HeapPage::kData); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 return addr; | 77 return addr; |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { | 81 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { |
| 82 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); | 82 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 #endif | 241 #endif |
| 242 ASSERT(old_space_->tasks() == 1); | 242 ASSERT(old_space_->tasks() == 1); |
| 243 old_space_->set_tasks(0); | 243 old_space_->set_tasks(0); |
| 244 ml.NotifyAll(); | 244 ml.NotifyAll(); |
| 245 } | 245 } |
| 246 | 246 |
| 247 | 247 |
| 248 void Heap::IterateObjects(ObjectVisitor* visitor) const { | 248 void Heap::IterateObjects(ObjectVisitor* visitor) const { |
| 249 // The visitor must not allocate from the heap. | 249 // The visitor must not allocate from the heap. |
| 250 NoSafepointScope no_safepoint_scope_; | 250 NoSafepointScope no_safepoint_scope_; |
| 251 IterateNewObjects(visitor); |
| 252 IterateOldObjects(visitor); |
| 253 } |
| 254 |
| 255 |
| 256 void Heap::IterateNewObjects(ObjectVisitor* visitor) const { |
| 251 new_space_.VisitObjects(visitor); | 257 new_space_.VisitObjects(visitor); |
| 252 IterateOldObjects(visitor); | |
| 253 } | 258 } |
| 254 | 259 |
| 255 | 260 |
| 256 void Heap::IterateOldObjects(ObjectVisitor* visitor) const { | 261 void Heap::IterateOldObjects(ObjectVisitor* visitor) const { |
| 257 HeapIterationScope heap_iteration_scope; | 262 HeapIterationScope heap_iteration_scope; |
| 258 old_space_.VisitObjects(visitor); | 263 old_space_.VisitObjects(visitor); |
| 259 } | 264 } |
| 260 | 265 |
| 261 | 266 |
| 262 void Heap::IterateOldObjectsNoImagePages(ObjectVisitor* visitor) const { | 267 void Heap::IterateOldObjectsNoImagePages(ObjectVisitor* visitor) const { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 #endif | 370 #endif |
| 366 | 371 |
| 367 | 372 |
| 368 void Heap::EvacuateNewSpace(Thread* thread, GCReason reason) { | 373 void Heap::EvacuateNewSpace(Thread* thread, GCReason reason) { |
| 369 ASSERT(reason == kFull); | 374 ASSERT(reason == kFull); |
| 370 if (BeginNewSpaceGC(thread)) { | 375 if (BeginNewSpaceGC(thread)) { |
| 371 RecordBeforeGC(kNew, kFull); | 376 RecordBeforeGC(kNew, kFull); |
| 372 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); | 377 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); |
| 373 TIMELINE_FUNCTION_GC_DURATION(thread, "EvacuateNewGeneration"); | 378 TIMELINE_FUNCTION_GC_DURATION(thread, "EvacuateNewGeneration"); |
| 374 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); | 379 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); |
| 375 new_space_.Evacuate(); | 380 new_space_.Evacuate(isolate()->mutator_thread()); |
| 376 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); | 381 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); |
| 377 RecordAfterGC(kNew); | 382 RecordAfterGC(kNew); |
| 378 PrintStats(); | 383 PrintStats(); |
| 379 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); | 384 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); |
| 380 EndNewSpaceGC(); | 385 EndNewSpaceGC(); |
| 381 } | 386 } |
| 382 } | 387 } |
| 383 | 388 |
| 384 | 389 |
| 385 void Heap::CollectNewSpaceGarbage(Thread* thread, | 390 void Heap::CollectNewSpaceGarbage(Thread* thread, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 } | 507 } |
| 503 | 508 |
| 504 | 509 |
| 505 void Heap::WriteProtect(bool read_only) { | 510 void Heap::WriteProtect(bool read_only) { |
| 506 read_only_ = read_only; | 511 read_only_ = read_only; |
| 507 new_space_.WriteProtect(read_only); | 512 new_space_.WriteProtect(read_only); |
| 508 old_space_.WriteProtect(read_only); | 513 old_space_.WriteProtect(read_only); |
| 509 } | 514 } |
| 510 | 515 |
| 511 | 516 |
| 512 intptr_t Heap::TopOffset(Heap::Space space) { | |
| 513 if (space == kNew) { | |
| 514 return OFFSET_OF(Heap, new_space_) + Scavenger::top_offset(); | |
| 515 } else { | |
| 516 ASSERT(space == kOld); | |
| 517 return OFFSET_OF(Heap, old_space_) + PageSpace::top_offset(); | |
| 518 } | |
| 519 } | |
| 520 | |
| 521 | |
| 522 intptr_t Heap::EndOffset(Heap::Space space) { | |
| 523 if (space == kNew) { | |
| 524 return OFFSET_OF(Heap, new_space_) + Scavenger::end_offset(); | |
| 525 } else { | |
| 526 ASSERT(space == kOld); | |
| 527 return OFFSET_OF(Heap, old_space_) + PageSpace::end_offset(); | |
| 528 } | |
| 529 } | |
| 530 | |
| 531 | |
| 532 void Heap::Init(Isolate* isolate, | 517 void Heap::Init(Isolate* isolate, |
| 533 intptr_t max_new_gen_words, | 518 intptr_t max_new_gen_words, |
| 534 intptr_t max_old_gen_words, | 519 intptr_t max_old_gen_words, |
| 535 intptr_t max_external_words) { | 520 intptr_t max_external_words) { |
| 536 ASSERT(isolate->heap() == NULL); | 521 ASSERT(isolate->heap() == NULL); |
| 537 Heap* heap = new Heap(isolate, max_new_gen_words, max_old_gen_words, | 522 Heap* heap = new Heap(isolate, max_new_gen_words, max_old_gen_words, |
| 538 max_external_words); | 523 max_external_words); |
| 539 isolate->set_heap(heap); | 524 isolate->set_heap(heap); |
| 540 } | 525 } |
| 541 | 526 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 | 585 |
| 601 | 586 |
| 602 bool Heap::Verify(MarkExpectation mark_expectation) const { | 587 bool Heap::Verify(MarkExpectation mark_expectation) const { |
| 603 HeapIterationScope heap_iteration_scope; | 588 HeapIterationScope heap_iteration_scope; |
| 604 return VerifyGC(mark_expectation); | 589 return VerifyGC(mark_expectation); |
| 605 } | 590 } |
| 606 | 591 |
| 607 | 592 |
| 608 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { | 593 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { |
| 609 StackZone stack_zone(Thread::Current()); | 594 StackZone stack_zone(Thread::Current()); |
| 595 |
| 596 // Synchronize the top_ of the heap's new space with the thread's top_ |
| 597 new_space_.FlushTLS(); |
| 598 |
| 610 ObjectSet* allocated_set = | 599 ObjectSet* allocated_set = |
| 611 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); | 600 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); |
| 612 VerifyPointersVisitor visitor(isolate(), allocated_set); | 601 VerifyPointersVisitor visitor(isolate(), allocated_set); |
| 613 VisitObjectPointers(&visitor); | 602 VisitObjectPointers(&visitor); |
| 614 | 603 |
| 615 // Only returning a value so that Heap::Validate can be called from an ASSERT. | 604 // Only returning a value so that Heap::Validate can be called from an ASSERT. |
| 616 return true; | 605 return true; |
| 617 } | 606 } |
| 618 | 607 |
| 619 | 608 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 Dart::vm_isolate()->heap()->WriteProtect(false); | 887 Dart::vm_isolate()->heap()->WriteProtect(false); |
| 899 } | 888 } |
| 900 | 889 |
| 901 | 890 |
| 902 WritableVMIsolateScope::~WritableVMIsolateScope() { | 891 WritableVMIsolateScope::~WritableVMIsolateScope() { |
| 903 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 892 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
| 904 Dart::vm_isolate()->heap()->WriteProtect(true); | 893 Dart::vm_isolate()->heap()->WriteProtect(true); |
| 905 } | 894 } |
| 906 | 895 |
| 907 } // namespace dart | 896 } // namespace dart |
| OLD | NEW |