Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: runtime/vm/pages.cc

Issue 1584443002: VM: Precompiled rodata snapshot. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: compute string hash if necessary Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/pages.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 bool is_executable = (type == kExecutable); 52 bool is_executable = (type == kExecutable);
53 // Create the new page executable (RWX) only if we're not in W^X mode 53 // Create the new page executable (RWX) only if we're not in W^X mode
54 bool create_executable = !FLAG_write_protect_code && is_executable; 54 bool create_executable = !FLAG_write_protect_code && is_executable;
55 if (!memory->Commit(create_executable)) { 55 if (!memory->Commit(create_executable)) {
56 return NULL; 56 return NULL;
57 } 57 }
58 HeapPage* result = reinterpret_cast<HeapPage*>(memory->address()); 58 HeapPage* result = reinterpret_cast<HeapPage*>(memory->address());
59 ASSERT(result != NULL); 59 ASSERT(result != NULL);
60 result->memory_ = memory; 60 result->memory_ = memory;
61 result->next_ = NULL; 61 result->next_ = NULL;
62 result->executable_ = is_executable; 62 result->type_ = type;
63 return result; 63 return result;
64 } 64 }
65 65
66 66
67 HeapPage* HeapPage::Allocate(intptr_t size_in_words, PageType type) { 67 HeapPage* HeapPage::Allocate(intptr_t size_in_words, PageType type) {
68 VirtualMemory* memory = 68 VirtualMemory* memory =
69 VerifiedMemory::Reserve(size_in_words << kWordSizeLog2); 69 VerifiedMemory::Reserve(size_in_words << kWordSizeLog2);
70 if (memory == NULL) { 70 if (memory == NULL) {
71 return NULL; 71 return NULL;
72 } 72 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 ASSERT(obj_addr == end_addr); 126 ASSERT(obj_addr == end_addr);
127 } 127 }
128 return Object::null(); 128 return Object::null();
129 } 129 }
130 130
131 131
132 void HeapPage::WriteProtect(bool read_only) { 132 void HeapPage::WriteProtect(bool read_only) {
133 VirtualMemory::Protection prot; 133 VirtualMemory::Protection prot;
134 if (read_only) { 134 if (read_only) {
135 if (executable_) { 135 if (type_ == kExecutable) {
136 prot = VirtualMemory::kReadExecute; 136 prot = VirtualMemory::kReadExecute;
137 } else { 137 } else {
138 prot = VirtualMemory::kReadOnly; 138 prot = VirtualMemory::kReadOnly;
139 } 139 }
140 } else { 140 } else {
141 prot = VirtualMemory::kReadWrite; 141 prot = VirtualMemory::kReadWrite;
142 } 142 }
143 bool status = memory_->Protect(prot); 143 bool status = memory_->Protect(prot);
144 ASSERT(status); 144 ASSERT(status);
145 } 145 }
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 return Object::null(); 658 return Object::null();
659 } 659 }
660 660
661 661
662 void PageSpace::WriteProtect(bool read_only, bool include_code_pages) { 662 void PageSpace::WriteProtect(bool read_only, bool include_code_pages) {
663 if (read_only) { 663 if (read_only) {
664 // Avoid MakeIterable trying to write to the heap. 664 // Avoid MakeIterable trying to write to the heap.
665 AbandonBumpAllocation(); 665 AbandonBumpAllocation();
666 } 666 }
667 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) { 667 for (ExclusivePageIterator it(this); !it.Done(); it.Advance()) {
668 if ((it.page()->type() != HeapPage::kExecutable) || include_code_pages) { 668 HeapPage::PageType page_type = it.page()->type();
669 if ((page_type != HeapPage::kReadOnlyData) &&
670 ((page_type != HeapPage::kExecutable) || include_code_pages)) {
669 it.page()->WriteProtect(read_only); 671 it.page()->WriteProtect(read_only);
670 } 672 }
671 } 673 }
672 } 674 }
673 675
674 676
675 void PageSpace::PrintToJSONObject(JSONObject* object) const { 677 void PageSpace::PrintToJSONObject(JSONObject* object) const {
676 if (!FLAG_support_service) { 678 if (!FLAG_support_service) {
677 return; 679 return;
678 } 680 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 RawObject** begin = reinterpret_cast<RawObject**>(result); 1066 RawObject** begin = reinterpret_cast<RawObject**>(result);
1065 RawObject** end = reinterpret_cast<RawObject**>(result + size); 1067 RawObject** end = reinterpret_cast<RawObject**>(result + size);
1066 for (RawObject** current = begin; current < end; ++current) { 1068 for (RawObject** current = begin; current < end; ++current) {
1067 ASSERT(!(*current)->IsHeapObject()); 1069 ASSERT(!(*current)->IsHeapObject());
1068 } 1070 }
1069 #endif 1071 #endif
1070 return result; 1072 return result;
1071 } 1073 }
1072 1074
1073 1075
1074 void PageSpace::SetupInstructionsSnapshotPage(void* pointer, uword size) { 1076 void PageSpace::SetupExternalPage(void* pointer,
1077 uword size,
1078 bool is_executable) {
1075 // Setup a HeapPage so precompiled Instructions can be traversed. 1079 // Setup a HeapPage so precompiled Instructions can be traversed.
1076 // Instructions are contiguous at [pointer, pointer + size). HeapPage 1080 // Instructions are contiguous at [pointer, pointer + size). HeapPage
1077 // expects to find objects at [memory->start() + ObjectStartOffset, 1081 // expects to find objects at [memory->start() + ObjectStartOffset,
1078 // memory->end()). 1082 // memory->end()).
1079 uword offset = HeapPage::ObjectStartOffset(); 1083 uword offset = HeapPage::ObjectStartOffset();
1080 pointer = reinterpret_cast<void*>(reinterpret_cast<uword>(pointer) - offset); 1084 pointer = reinterpret_cast<void*>(reinterpret_cast<uword>(pointer) - offset);
1081 size += offset; 1085 size += offset;
1082 1086
1083 ASSERT(Utils::IsAligned(pointer, OS::PreferredCodeAlignment())); 1087 VirtualMemory* memory = VirtualMemory::ForExternalPage(pointer, size);
1084
1085 VirtualMemory* memory = VirtualMemory::ForInstructionsSnapshot(pointer, size);
1086 ASSERT(memory != NULL); 1088 ASSERT(memory != NULL);
1087 HeapPage* page = reinterpret_cast<HeapPage*>(malloc(sizeof(HeapPage))); 1089 HeapPage* page = reinterpret_cast<HeapPage*>(malloc(sizeof(HeapPage)));
1088 page->memory_ = memory; 1090 page->memory_ = memory;
1089 page->next_ = NULL; 1091 page->next_ = NULL;
1090 page->object_end_ = memory->end(); 1092 page->object_end_ = memory->end();
1091 page->executable_ = true;
1092 1093
1093 MutexLocker ml(pages_lock_); 1094 MutexLocker ml(pages_lock_);
1094 if (exec_pages_ == NULL) { 1095 HeapPage** first, **tail;
1095 exec_pages_ = page; 1096 if (is_executable) {
1097 ASSERT(Utils::IsAligned(pointer, OS::PreferredCodeAlignment()));
1098 page->type_ = HeapPage::kExecutable;
1099 first = &exec_pages_;
1100 tail = &exec_pages_tail_;
1096 } else { 1101 } else {
1097 exec_pages_tail_->set_next(page); 1102 page->type_ = HeapPage::kReadOnlyData;
1103 first = &pages_;
1104 tail = &pages_tail_;
1098 } 1105 }
1099 exec_pages_tail_ = page; 1106 if (*first == NULL) {
1107 *first = page;
1108 } else {
1109 (*tail)->set_next(page);
1110 }
1111 (*tail) = page;
1100 } 1112 }
1101 1113
1102 1114
1103 PageSpaceController::PageSpaceController(Heap* heap, 1115 PageSpaceController::PageSpaceController(Heap* heap,
1104 int heap_growth_ratio, 1116 int heap_growth_ratio,
1105 int heap_growth_max, 1117 int heap_growth_max,
1106 int garbage_collection_time_ratio) 1118 int garbage_collection_time_ratio)
1107 : heap_(heap), 1119 : heap_(heap),
1108 is_enabled_(false), 1120 is_enabled_(false),
1109 grow_heap_(heap_growth_max / 2), 1121 grow_heap_(heap_growth_max / 2),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 return 0; 1237 return 0;
1226 } else { 1238 } else {
1227 ASSERT(total_time >= gc_time); 1239 ASSERT(total_time >= gc_time);
1228 int result = static_cast<int>((static_cast<double>(gc_time) / 1240 int result = static_cast<int>((static_cast<double>(gc_time) /
1229 static_cast<double>(total_time)) * 100); 1241 static_cast<double>(total_time)) * 100);
1230 return result; 1242 return result;
1231 } 1243 }
1232 } 1244 }
1233 1245
1234 } // namespace dart 1246 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/pages.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698