Chromium Code Reviews| 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); |
|
rmacnak
2017/07/12 20:30:06
Hoist Thread::Current() so it is only called once.
danunez
2017/07/12 21:02:12
Done.
| |
| 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 } | 502 } |
| 503 | 503 |
| 504 | 504 |
| 505 void Heap::WriteProtect(bool read_only) { | 505 void Heap::WriteProtect(bool read_only) { |
| 506 read_only_ = read_only; | 506 read_only_ = read_only; |
| 507 new_space_.WriteProtect(read_only); | 507 new_space_.WriteProtect(read_only); |
| 508 old_space_.WriteProtect(read_only); | 508 old_space_.WriteProtect(read_only); |
| 509 } | 509 } |
| 510 | 510 |
| 511 | 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 | |
| 532 void Heap::Init(Isolate* isolate, | 512 void Heap::Init(Isolate* isolate, |
| 533 intptr_t max_new_gen_words, | 513 intptr_t max_new_gen_words, |
| 534 intptr_t max_old_gen_words, | 514 intptr_t max_old_gen_words, |
| 535 intptr_t max_external_words) { | 515 intptr_t max_external_words) { |
| 536 ASSERT(isolate->heap() == NULL); | 516 ASSERT(isolate->heap() == NULL); |
| 537 Heap* heap = new Heap(isolate, max_new_gen_words, max_old_gen_words, | 517 Heap* heap = new Heap(isolate, max_new_gen_words, max_old_gen_words, |
| 538 max_external_words); | 518 max_external_words); |
| 539 isolate->set_heap(heap); | 519 isolate->set_heap(heap); |
| 540 } | 520 } |
| 541 | 521 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 | 580 |
| 601 | 581 |
| 602 bool Heap::Verify(MarkExpectation mark_expectation) const { | 582 bool Heap::Verify(MarkExpectation mark_expectation) const { |
| 603 HeapIterationScope heap_iteration_scope; | 583 HeapIterationScope heap_iteration_scope; |
| 604 return VerifyGC(mark_expectation); | 584 return VerifyGC(mark_expectation); |
| 605 } | 585 } |
| 606 | 586 |
| 607 | 587 |
| 608 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { | 588 bool Heap::VerifyGC(MarkExpectation mark_expectation) const { |
| 609 StackZone stack_zone(Thread::Current()); | 589 StackZone stack_zone(Thread::Current()); |
| 590 | |
| 591 // Change the new space's top_ with the more up-to-date thread's view of top_ | |
| 592 new_space_.FlushTLS(); | |
| 593 | |
| 610 ObjectSet* allocated_set = | 594 ObjectSet* allocated_set = |
| 611 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); | 595 CreateAllocatedObjectSet(stack_zone.GetZone(), mark_expectation); |
| 612 VerifyPointersVisitor visitor(isolate(), allocated_set); | 596 VerifyPointersVisitor visitor(isolate(), allocated_set); |
| 613 VisitObjectPointers(&visitor); | 597 VisitObjectPointers(&visitor); |
| 614 | 598 |
| 615 // Only returning a value so that Heap::Validate can be called from an ASSERT. | 599 // Only returning a value so that Heap::Validate can be called from an ASSERT. |
| 616 return true; | 600 return true; |
| 617 } | 601 } |
| 618 | 602 |
| 619 | 603 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 898 Dart::vm_isolate()->heap()->WriteProtect(false); | 882 Dart::vm_isolate()->heap()->WriteProtect(false); |
| 899 } | 883 } |
| 900 | 884 |
| 901 | 885 |
| 902 WritableVMIsolateScope::~WritableVMIsolateScope() { | 886 WritableVMIsolateScope::~WritableVMIsolateScope() { |
| 903 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 887 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
| 904 Dart::vm_isolate()->heap()->WriteProtect(true); | 888 Dart::vm_isolate()->heap()->WriteProtect(true); |
| 905 } | 889 } |
| 906 | 890 |
| 907 } // namespace dart | 891 } // namespace dart |
| OLD | NEW |