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