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/pages.h" | 5 #include "vm/pages.h" |
6 | 6 |
7 #include "platform/address_sanitizer.h" | 7 #include "platform/address_sanitizer.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/compiler_stats.h" | 9 #include "vm/compiler_stats.h" |
10 #include "vm/gc_marker.h" | 10 #include "vm/gc_marker.h" |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 536 |
537 void PageSpace::AbandonBumpAllocation() { | 537 void PageSpace::AbandonBumpAllocation() { |
538 if (bump_top_ < bump_end_) { | 538 if (bump_top_ < bump_end_) { |
539 freelist_[HeapPage::kData].Free(bump_top_, bump_end_ - bump_top_); | 539 freelist_[HeapPage::kData].Free(bump_top_, bump_end_ - bump_top_); |
540 bump_top_ = 0; | 540 bump_top_ = 0; |
541 bump_end_ = 0; | 541 bump_end_ = 0; |
542 } | 542 } |
543 } | 543 } |
544 | 544 |
545 void PageSpace::UpdateMaxCapacityLocked() { | 545 void PageSpace::UpdateMaxCapacityLocked() { |
546 #if !defined(PRODUCT) | |
547 if (heap_ == NULL) { | 546 if (heap_ == NULL) { |
548 // Some unit tests. | 547 // Some unit tests. |
549 return; | 548 return; |
550 } | 549 } |
551 ASSERT(heap_ != NULL); | 550 ASSERT(heap_ != NULL); |
552 ASSERT(heap_->isolate() != NULL); | 551 ASSERT(heap_->isolate() != NULL); |
553 Isolate* isolate = heap_->isolate(); | 552 Isolate* isolate = heap_->isolate(); |
554 isolate->GetHeapOldCapacityMaxMetric()->SetValue( | 553 isolate->GetHeapOldCapacityMaxMetric()->SetValue( |
555 static_cast<int64_t>(usage_.capacity_in_words) * kWordSize); | 554 static_cast<int64_t>(usage_.capacity_in_words) * kWordSize); |
556 #endif // !defined(PRODUCT) | |
557 } | 555 } |
558 | 556 |
559 void PageSpace::UpdateMaxUsed() { | 557 void PageSpace::UpdateMaxUsed() { |
560 #if !defined(PRODUCT) | |
561 if (heap_ == NULL) { | 558 if (heap_ == NULL) { |
562 // Some unit tests. | 559 // Some unit tests. |
563 return; | 560 return; |
564 } | 561 } |
565 ASSERT(heap_ != NULL); | 562 ASSERT(heap_ != NULL); |
566 ASSERT(heap_->isolate() != NULL); | 563 ASSERT(heap_->isolate() != NULL); |
567 Isolate* isolate = heap_->isolate(); | 564 Isolate* isolate = heap_->isolate(); |
568 isolate->GetHeapOldUsedMaxMetric()->SetValue(UsedInWords() * kWordSize); | 565 isolate->GetHeapOldUsedMaxMetric()->SetValue(UsedInWords() * kWordSize); |
569 #endif // !defined(PRODUCT) | |
570 } | 566 } |
571 | 567 |
572 bool PageSpace::Contains(uword addr) const { | 568 bool PageSpace::Contains(uword addr) const { |
573 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { | 569 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { |
574 if (it.page()->Contains(addr)) { | 570 if (it.page()->Contains(addr)) { |
575 return true; | 571 return true; |
576 } | 572 } |
577 } | 573 } |
578 return false; | 574 return false; |
579 } | 575 } |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 OS::PrintErr(" done.\n"); | 857 OS::PrintErr(" done.\n"); |
862 } | 858 } |
863 | 859 |
864 // Make code pages writable. | 860 // Make code pages writable. |
865 WriteProtectCode(false); | 861 WriteProtectCode(false); |
866 | 862 |
867 // Save old value before GCMarker visits the weak persistent handles. | 863 // Save old value before GCMarker visits the weak persistent handles. |
868 SpaceUsage usage_before = GetCurrentUsage(); | 864 SpaceUsage usage_before = GetCurrentUsage(); |
869 | 865 |
870 // Mark all reachable old-gen objects. | 866 // Mark all reachable old-gen objects. |
871 #if defined(PRODUCT) | |
872 bool collect_code = FLAG_collect_code && ShouldCollectCode(); | |
873 #else | |
874 bool collect_code = FLAG_collect_code && ShouldCollectCode() && | 867 bool collect_code = FLAG_collect_code && ShouldCollectCode() && |
875 !isolate->HasAttemptedReload(); | 868 !isolate->HasAttemptedReload(); |
876 #endif // !defined(PRODUCT) | |
877 GCMarker marker(heap_); | 869 GCMarker marker(heap_); |
878 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code); | 870 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code); |
879 usage_.used_in_words = marker.marked_words(); | 871 usage_.used_in_words = marker.marked_words(); |
880 | 872 |
881 int64_t mid1 = OS::GetCurrentMonotonicMicros(); | 873 int64_t mid1 = OS::GetCurrentMonotonicMicros(); |
882 | 874 |
883 // Abandon the remainder of the bump allocation block. | 875 // Abandon the remainder of the bump allocation block. |
884 AbandonBumpAllocation(); | 876 AbandonBumpAllocation(); |
885 // Reset the freelists and setup sweeping. | 877 // Reset the freelists and setup sweeping. |
886 freelist_[HeapPage::kData].Reset(); | 878 freelist_[HeapPage::kData].Reset(); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 intptr_t capacity_increase_in_words = | 1134 intptr_t capacity_increase_in_words = |
1143 after.capacity_in_words - last_usage_.capacity_in_words; | 1135 after.capacity_in_words - last_usage_.capacity_in_words; |
1144 // The concurrent sweeper might have freed more capacity than was allocated. | 1136 // The concurrent sweeper might have freed more capacity than was allocated. |
1145 capacity_increase_in_words = | 1137 capacity_increase_in_words = |
1146 Utils::Maximum<intptr_t>(0, capacity_increase_in_words); | 1138 Utils::Maximum<intptr_t>(0, capacity_increase_in_words); |
1147 capacity_increase_in_words = | 1139 capacity_increase_in_words = |
1148 Utils::RoundUp(capacity_increase_in_words, PageSpace::kPageSizeInWords); | 1140 Utils::RoundUp(capacity_increase_in_words, PageSpace::kPageSizeInWords); |
1149 intptr_t capacity_increase_in_pages = | 1141 intptr_t capacity_increase_in_pages = |
1150 capacity_increase_in_words / PageSpace::kPageSizeInWords; | 1142 capacity_increase_in_words / PageSpace::kPageSizeInWords; |
1151 double multiplier = 1.0; | 1143 double multiplier = 1.0; |
1152 #if !defined(PRODUCT) | |
1153 // To avoid waste, the first GC should be triggered before too long. After | 1144 // To avoid waste, the first GC should be triggered before too long. After |
1154 // kInitialTimeoutSeconds, gradually lower the capacity limit. | 1145 // kInitialTimeoutSeconds, gradually lower the capacity limit. |
1155 static const double kInitialTimeoutSeconds = 1.00; | 1146 static const double kInitialTimeoutSeconds = 1.00; |
1156 if (history_.IsEmpty()) { | 1147 if (history_.IsEmpty()) { |
1157 double seconds_since_init = | 1148 double seconds_since_init = |
1158 MicrosecondsToSeconds(heap_->isolate()->UptimeMicros()); | 1149 MicrosecondsToSeconds(heap_->isolate()->UptimeMicros()); |
1159 if (seconds_since_init > kInitialTimeoutSeconds) { | 1150 if (seconds_since_init > kInitialTimeoutSeconds) { |
1160 multiplier *= seconds_since_init / kInitialTimeoutSeconds; | 1151 multiplier *= seconds_since_init / kInitialTimeoutSeconds; |
1161 } | 1152 } |
1162 } | 1153 } |
1163 #endif // !defined(PRODUCT) | |
1164 bool needs_gc = capacity_increase_in_pages * multiplier > grow_heap_; | 1154 bool needs_gc = capacity_increase_in_pages * multiplier > grow_heap_; |
1165 if (FLAG_log_growth) { | 1155 if (FLAG_log_growth) { |
1166 OS::PrintErr("%s: %" Pd " * %f %s %" Pd "\n", | 1156 OS::PrintErr("%s: %" Pd " * %f %s %" Pd "\n", |
1167 needs_gc ? "NEEDS GC" : "grow", capacity_increase_in_pages, | 1157 needs_gc ? "NEEDS GC" : "grow", capacity_increase_in_pages, |
1168 multiplier, needs_gc ? ">" : "<=", grow_heap_); | 1158 multiplier, needs_gc ? ">" : "<=", grow_heap_); |
1169 } | 1159 } |
1170 return needs_gc; | 1160 return needs_gc; |
1171 } | 1161 } |
1172 | 1162 |
1173 void PageSpaceController::EvaluateGarbageCollection(SpaceUsage before, | 1163 void PageSpaceController::EvaluateGarbageCollection(SpaceUsage before, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 return 0; | 1264 return 0; |
1275 } else { | 1265 } else { |
1276 ASSERT(total_time >= gc_time); | 1266 ASSERT(total_time >= gc_time); |
1277 int result = static_cast<int>( | 1267 int result = static_cast<int>( |
1278 (static_cast<double>(gc_time) / static_cast<double>(total_time)) * 100); | 1268 (static_cast<double>(gc_time) / static_cast<double>(total_time)) * 100); |
1279 return result; | 1269 return result; |
1280 } | 1270 } |
1281 } | 1271 } |
1282 | 1272 |
1283 } // namespace dart | 1273 } // namespace dart |
OLD | NEW |