| 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/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/compiler_stats.h" | 8 #include "vm/compiler_stats.h" |
| 9 #include "vm/gc_marker.h" | 9 #include "vm/gc_marker.h" |
| 10 #include "vm/gc_sweeper.h" | 10 #include "vm/gc_sweeper.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 if (!is_exec) { | 222 if (!is_exec) { |
| 223 if (pages_ == NULL) { | 223 if (pages_ == NULL) { |
| 224 pages_ = page; | 224 pages_ = page; |
| 225 } else { | 225 } else { |
| 226 pages_tail_->set_next(page); | 226 pages_tail_->set_next(page); |
| 227 } | 227 } |
| 228 pages_tail_ = page; | 228 pages_tail_ = page; |
| 229 } else { | 229 } else { |
| 230 // Should not allocate executable pages when running from a precompiled | 230 // Should not allocate executable pages when running from a precompiled |
| 231 // snapshot. | 231 // snapshot. |
| 232 ASSERT(Dart::snapshot_kind() != Snapshot::kAppAOT); | 232 ASSERT(Dart::vm_snapshot_kind() != Snapshot::kAppAOT); |
| 233 | 233 |
| 234 if (exec_pages_ == NULL) { | 234 if (exec_pages_ == NULL) { |
| 235 exec_pages_ = page; | 235 exec_pages_ = page; |
| 236 } else { | 236 } else { |
| 237 if (FLAG_write_protect_code) { | 237 if (FLAG_write_protect_code && !exec_pages_tail_->embedder_allocated()) { |
| 238 exec_pages_tail_->WriteProtect(false); | 238 exec_pages_tail_->WriteProtect(false); |
| 239 } | 239 } |
| 240 exec_pages_tail_->set_next(page); | 240 exec_pages_tail_->set_next(page); |
| 241 if (FLAG_write_protect_code) { | 241 if (FLAG_write_protect_code && !exec_pages_tail_->embedder_allocated()) { |
| 242 exec_pages_tail_->WriteProtect(true); | 242 exec_pages_tail_->WriteProtect(true); |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 exec_pages_tail_ = page; | 245 exec_pages_tail_ = page; |
| 246 } | 246 } |
| 247 IncreaseCapacityInWordsLocked(kPageSizeInWords); | 247 IncreaseCapacityInWordsLocked(kPageSizeInWords); |
| 248 page->set_object_end(page->memory_->end()); | 248 page->set_object_end(page->memory_->end()); |
| 249 return page; | 249 return page; |
| 250 } | 250 } |
| 251 | 251 |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 } | 619 } |
| 620 | 620 |
| 621 | 621 |
| 622 void PageSpace::VisitObjects(ObjectVisitor* visitor) const { | 622 void PageSpace::VisitObjects(ObjectVisitor* visitor) const { |
| 623 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { | 623 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { |
| 624 it.page()->VisitObjects(visitor); | 624 it.page()->VisitObjects(visitor); |
| 625 } | 625 } |
| 626 } | 626 } |
| 627 | 627 |
| 628 | 628 |
| 629 void PageSpace::VisitObjectsNoEmbedderPages(ObjectVisitor* visitor) const { | 629 void PageSpace::VisitObjectsNoExternalPages(ObjectVisitor* visitor) const { |
| 630 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { | 630 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { |
| 631 if (!it.page()->embedder_allocated()) { | 631 if (!it.page()->embedder_allocated()) { |
| 632 it.page()->VisitObjects(visitor); | 632 it.page()->VisitObjects(visitor); |
| 633 } | 633 } |
| 634 } | 634 } |
| 635 } | 635 } |
| 636 | 636 |
| 637 | 637 |
| 638 void PageSpace::VisitObjectsExternalPages(ObjectVisitor* visitor) const { |
| 639 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { |
| 640 if (it.page()->embedder_allocated()) { |
| 641 it.page()->VisitObjects(visitor); |
| 642 } |
| 643 } |
| 644 } |
| 645 |
| 646 |
| 638 void PageSpace::VisitObjectPointers(ObjectPointerVisitor* visitor) const { | 647 void PageSpace::VisitObjectPointers(ObjectPointerVisitor* visitor) const { |
| 639 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { | 648 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { |
| 640 it.page()->VisitObjectPointers(visitor); | 649 it.page()->VisitObjectPointers(visitor); |
| 641 } | 650 } |
| 642 } | 651 } |
| 643 | 652 |
| 644 | 653 |
| 645 RawObject* PageSpace::FindObject(FindObjectVisitor* visitor, | 654 RawObject* PageSpace::FindObject(FindObjectVisitor* visitor, |
| 646 HeapPage::PageType type) const { | 655 HeapPage::PageType type) const { |
| 647 if (type == HeapPage::kExecutable) { | 656 if (type == HeapPage::kExecutable) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 | 804 |
| 796 | 805 |
| 797 void PageSpace::WriteProtectCode(bool read_only) { | 806 void PageSpace::WriteProtectCode(bool read_only) { |
| 798 if (FLAG_write_protect_code) { | 807 if (FLAG_write_protect_code) { |
| 799 MutexLocker ml(pages_lock_); | 808 MutexLocker ml(pages_lock_); |
| 800 NoSafepointScope no_safepoint; | 809 NoSafepointScope no_safepoint; |
| 801 // No need to go through all of the data pages first. | 810 // No need to go through all of the data pages first. |
| 802 HeapPage* page = exec_pages_; | 811 HeapPage* page = exec_pages_; |
| 803 while (page != NULL) { | 812 while (page != NULL) { |
| 804 ASSERT(page->type() == HeapPage::kExecutable); | 813 ASSERT(page->type() == HeapPage::kExecutable); |
| 805 page->WriteProtect(read_only); | 814 if (!page->embedder_allocated()) { |
| 815 page->WriteProtect(read_only); |
| 816 } |
| 806 page = page->next(); | 817 page = page->next(); |
| 807 } | 818 } |
| 808 page = large_pages_; | 819 page = large_pages_; |
| 809 while (page != NULL) { | 820 while (page != NULL) { |
| 810 if (page->type() == HeapPage::kExecutable) { | 821 if (page->type() == HeapPage::kExecutable && |
| 822 !page->embedder_allocated()) { |
| 811 page->WriteProtect(read_only); | 823 page->WriteProtect(read_only); |
| 812 } | 824 } |
| 813 page = page->next(); | 825 page = page->next(); |
| 814 } | 826 } |
| 815 } | 827 } |
| 816 } | 828 } |
| 817 | 829 |
| 818 | 830 |
| 819 void PageSpace::MarkSweep(bool invoke_api_callbacks) { | 831 void PageSpace::MarkSweep(bool invoke_api_callbacks) { |
| 820 Thread* thread = Thread::Current(); | 832 Thread* thread = Thread::Current(); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 page->object_end_ = memory->end(); | 1100 page->object_end_ = memory->end(); |
| 1089 | 1101 |
| 1090 MutexLocker ml(pages_lock_); | 1102 MutexLocker ml(pages_lock_); |
| 1091 HeapPage **first, **tail; | 1103 HeapPage **first, **tail; |
| 1092 if (is_executable) { | 1104 if (is_executable) { |
| 1093 ASSERT(Utils::IsAligned(pointer, OS::PreferredCodeAlignment())); | 1105 ASSERT(Utils::IsAligned(pointer, OS::PreferredCodeAlignment())); |
| 1094 page->type_ = HeapPage::kExecutable; | 1106 page->type_ = HeapPage::kExecutable; |
| 1095 first = &exec_pages_; | 1107 first = &exec_pages_; |
| 1096 tail = &exec_pages_tail_; | 1108 tail = &exec_pages_tail_; |
| 1097 } else { | 1109 } else { |
| 1098 page->type_ = HeapPage::kReadOnlyData; | 1110 page->type_ = HeapPage::kData; |
| 1099 first = &pages_; | 1111 first = &pages_; |
| 1100 tail = &pages_tail_; | 1112 tail = &pages_tail_; |
| 1101 } | 1113 } |
| 1102 if (*first == NULL) { | 1114 if (*first == NULL) { |
| 1103 *first = page; | 1115 *first = page; |
| 1104 } else { | 1116 } else { |
| 1105 if (is_executable && FLAG_write_protect_code) { | 1117 if (is_executable && FLAG_write_protect_code && |
| 1118 !(*tail)->embedder_allocated()) { |
| 1106 (*tail)->WriteProtect(false); | 1119 (*tail)->WriteProtect(false); |
| 1107 } | 1120 } |
| 1108 (*tail)->set_next(page); | 1121 (*tail)->set_next(page); |
| 1109 if (is_executable && FLAG_write_protect_code) { | 1122 if (is_executable && FLAG_write_protect_code && |
| 1123 !(*tail)->embedder_allocated()) { |
| 1110 (*tail)->WriteProtect(true); | 1124 (*tail)->WriteProtect(true); |
| 1111 } | 1125 } |
| 1112 } | 1126 } |
| 1113 (*tail) = page; | 1127 (*tail) = page; |
| 1114 } | 1128 } |
| 1115 | 1129 |
| 1116 | 1130 |
| 1117 PageSpaceController::PageSpaceController(Heap* heap, | 1131 PageSpaceController::PageSpaceController(Heap* heap, |
| 1118 int heap_growth_ratio, | 1132 int heap_growth_ratio, |
| 1119 int heap_growth_max, | 1133 int heap_growth_max, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 return 0; | 1283 return 0; |
| 1270 } else { | 1284 } else { |
| 1271 ASSERT(total_time >= gc_time); | 1285 ASSERT(total_time >= gc_time); |
| 1272 int result = static_cast<int>( | 1286 int result = static_cast<int>( |
| 1273 (static_cast<double>(gc_time) / static_cast<double>(total_time)) * 100); | 1287 (static_cast<double>(gc_time) / static_cast<double>(total_time)) * 100); |
| 1274 return result; | 1288 return result; |
| 1275 } | 1289 } |
| 1276 } | 1290 } |
| 1277 | 1291 |
| 1278 } // namespace dart | 1292 } // namespace dart |
| OLD | NEW |