| 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 Thread* thread = Thread::Current(); | 66 uword addr = new_space_.TryAllocate(size); |
| 67 uword addr = new_space_.TryAllocateInTLAB(thread, size); | |
| 68 if (addr == 0) { | 67 if (addr == 0) { |
| 69 // This call to CollectGarbage might end up "reusing" a collection spawned | 68 // This call to CollectGarbage might end up "reusing" a collection spawned |
| 70 // 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 |
| 71 // memory with other threads being released after the collection. | 70 // memory with other threads being released after the collection. |
| 72 CollectGarbage(kNew); | 71 CollectGarbage(kNew); |
| 73 addr = new_space_.TryAllocateInTLAB(thread, size); | 72 addr = new_space_.TryAllocate(size); |
| 74 if (addr == 0) { | 73 if (addr == 0) { |
| 75 return AllocateOld(size, HeapPage::kData); | 74 return AllocateOld(size, HeapPage::kData); |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 return addr; | 77 return addr; |
| 79 } | 78 } |
| 80 | 79 |
| 81 | 80 |
| 82 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { | 81 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { |
| 83 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); | 82 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 } | 502 } |
| 504 | 503 |
| 505 | 504 |
| 506 void Heap::WriteProtect(bool read_only) { | 505 void Heap::WriteProtect(bool read_only) { |
| 507 read_only_ = read_only; | 506 read_only_ = read_only; |
| 508 new_space_.WriteProtect(read_only); | 507 new_space_.WriteProtect(read_only); |
| 509 old_space_.WriteProtect(read_only); | 508 old_space_.WriteProtect(read_only); |
| 510 } | 509 } |
| 511 | 510 |
| 512 | 511 |
| 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 |
| 513 void Heap::Init(Isolate* isolate, | 532 void Heap::Init(Isolate* isolate, |
| 514 intptr_t max_new_gen_words, | 533 intptr_t max_new_gen_words, |
| 515 intptr_t max_old_gen_words, | 534 intptr_t max_old_gen_words, |
| 516 intptr_t max_external_words) { | 535 intptr_t max_external_words) { |
| 517 ASSERT(isolate->heap() == NULL); | 536 ASSERT(isolate->heap() == NULL); |
| 518 Heap* heap = new Heap(isolate, max_new_gen_words, max_old_gen_words, | 537 Heap* heap = new Heap(isolate, max_new_gen_words, max_old_gen_words, |
| 519 max_external_words); | 538 max_external_words); |
| 520 isolate->set_heap(heap); | 539 isolate->set_heap(heap); |
| 521 } | 540 } |
| 522 | 541 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 | 600 |
| 582 | 601 |
| 583 bool Heap::Verify(MarkExpectation mark_expectation) const { | 602 bool Heap::Verify(MarkExpectation mark_expectation) const { |
| 584 HeapIterationScope heap_iteration_scope; | 603 HeapIterationScope heap_iteration_scope; |
| 585 return VerifyGC(mark_expectation); | 604 return VerifyGC(mark_expectation); |
| 586 } | 605 } |
| 587 | 606 |
| 588 | 607 |
| 589 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { | 608 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { |
| 590 StackZone stack_zone(Thread::Current()); | 609 StackZone stack_zone(Thread::Current()); |
| 591 | |
| 592 // Change the new space's top_ with the more up-to-date thread's view of top_ | |
| 593 new_space_.FlushTLS(); | |
| 594 | |
| 595 ObjectSet* allocated_set = | 610 ObjectSet* allocated_set = |
| 596 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); | 611 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); |
| 597 VerifyPointersVisitor visitor(isolate(), allocated_set); | 612 VerifyPointersVisitor visitor(isolate(), allocated_set); |
| 598 VisitObjectPointers(&visitor); | 613 VisitObjectPointers(&visitor); |
| 599 | 614 |
| 600 // Only returning a value so that Heap::Validate can be called from an ASSERT. | 615 // Only returning a value so that Heap::Validate can be called from an ASSERT. |
| 601 return true; | 616 return true; |
| 602 } | 617 } |
| 603 | 618 |
| 604 | 619 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 Dart::vm_isolate()->heap()->WriteProtect(false); | 898 Dart::vm_isolate()->heap()->WriteProtect(false); |
| 884 } | 899 } |
| 885 | 900 |
| 886 | 901 |
| 887 WritableVMIsolateScope::~WritableVMIsolateScope() { | 902 WritableVMIsolateScope::~WritableVMIsolateScope() { |
| 888 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 903 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
| 889 Dart::vm_isolate()->heap()->WriteProtect(true); | 904 Dart::vm_isolate()->heap()->WriteProtect(true); |
| 890 } | 905 } |
| 891 | 906 |
| 892 } // namespace dart | 907 } // namespace dart |
| OLD | NEW |