| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (addr == 0) { | 84 if (addr == 0) { |
| 85 return AllocateOld(size, HeapPage::kData); | 85 return AllocateOld(size, HeapPage::kData); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 return addr; | 88 return addr; |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { | 92 uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) { |
| 93 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); | 93 ASSERT(Thread::Current()->no_safepoint_scope_depth() == 0); |
| 94 #if defined(DEBUG) | |
| 95 // Currently, allocation from non-Dart threads must not trigger GC. | |
| 96 if (GrowthControlState()) { | |
| 97 isolate()->AssertCurrentThreadIsMutator(); | |
| 98 } | |
| 99 #endif | |
| 100 uword addr = old_space_.TryAllocate(size, type); | 94 uword addr = old_space_.TryAllocate(size, type); |
| 101 if (addr != 0) { | 95 if (addr != 0) { |
| 102 return addr; | 96 return addr; |
| 103 } | 97 } |
| 104 // If we are in the process of running a sweep wait for the sweeper to free | 98 // If we are in the process of running a sweep wait for the sweeper to free |
| 105 // memory. | 99 // memory. |
| 106 { | 100 { |
| 107 MonitorLocker ml(old_space_.tasks_lock()); | 101 MonitorLocker ml(old_space_.tasks_lock()); |
| 108 addr = old_space_.TryAllocate(size, type); | 102 addr = old_space_.TryAllocate(size, type); |
| 109 while ((addr == 0) && (old_space_.tasks() > 0)) { | 103 while ((addr == 0) && (old_space_.tasks() > 0)) { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 return pretenure_policy_ > 0; | 427 return pretenure_policy_ > 0; |
| 434 } else { | 428 } else { |
| 435 return false; | 429 return false; |
| 436 } | 430 } |
| 437 } | 431 } |
| 438 | 432 |
| 439 | 433 |
| 440 void Heap::UpdatePretenurePolicy() { | 434 void Heap::UpdatePretenurePolicy() { |
| 441 if (FLAG_disable_alloc_stubs_after_gc) { | 435 if (FLAG_disable_alloc_stubs_after_gc) { |
| 442 ClassTable* table = isolate_->class_table(); | 436 ClassTable* table = isolate_->class_table(); |
| 437 Zone* zone = Thread::Current()->zone(); |
| 443 for (intptr_t cid = 1; cid < table->NumCids(); ++cid) { | 438 for (intptr_t cid = 1; cid < table->NumCids(); ++cid) { |
| 444 if (((cid >= kNumPredefinedCids) || (cid == kArrayCid)) && | 439 if (((cid >= kNumPredefinedCids) || (cid == kArrayCid)) && |
| 445 table->IsValidIndex(cid) && | 440 table->IsValidIndex(cid) && |
| 446 table->HasValidClassAt(cid)) { | 441 table->HasValidClassAt(cid)) { |
| 447 const Class& cls = Class::Handle(isolate_, table->At(cid)); | 442 const Class& cls = Class::Handle(zone, table->At(cid)); |
| 448 cls.DisableAllocationStub(); | 443 cls.DisableAllocationStub(); |
| 449 } | 444 } |
| 450 } | 445 } |
| 451 } | 446 } |
| 452 ClassHeapStats* stats = | 447 ClassHeapStats* stats = |
| 453 isolate_->class_table()->StatsWithUpdatedSize(kOneByteStringCid); | 448 isolate_->class_table()->StatsWithUpdatedSize(kOneByteStringCid); |
| 454 int allocated = stats->pre_gc.new_count; | 449 int allocated = stats->pre_gc.new_count; |
| 455 int promo_percent = (allocated == 0) ? 0 : | 450 int promo_percent = (allocated == 0) ? 0 : |
| 456 (100 * stats->promoted_count) / allocated; | 451 (100 * stats->promoted_count) / allocated; |
| 457 if (promo_percent >= FLAG_pretenure_threshold) { | 452 if (promo_percent >= FLAG_pretenure_threshold) { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 heap->DisableGrowthControl(); | 773 heap->DisableGrowthControl(); |
| 779 } | 774 } |
| 780 | 775 |
| 781 | 776 |
| 782 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 777 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 783 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 778 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 784 heap->SetGrowthControlState(current_growth_controller_state_); | 779 heap->SetGrowthControlState(current_growth_controller_state_); |
| 785 } | 780 } |
| 786 | 781 |
| 787 } // namespace dart | 782 } // namespace dart |
| OLD | NEW |