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

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

Issue 2207643002: Narrow the scope of writable code to the forwarding phase of become instead of the whole isolate re… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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 | « no previous file | runtime/vm/isolate_reload.cc » ('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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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/become.h" 5 #include "vm/become.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 9
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 intptr_t count() const { return count_; } 142 intptr_t count() const { return count_; }
143 143
144 private: 144 private:
145 int count_; 145 int count_;
146 146
147 DISALLOW_COPY_AND_ASSIGN(ForwardHeapPointersHandleVisitor); 147 DISALLOW_COPY_AND_ASSIGN(ForwardHeapPointersHandleVisitor);
148 }; 148 };
149 149
150 150
151 // On IA32, object pointers are embedded directly in the instruction stream,
152 // which is normally write-protected, so we need to make it temporarily writable
153 // to forward the pointers. On all other architectures, object pointers are
154 // accessed through ObjectPools.
155 class WritableCodeLiteralsScope : public ValueObject {
156 public:
157 explicit WritableCodeLiteralsScope(Heap* heap) : heap_(heap) {
158 #if defined(TARGET_ARCH_IA32)
159 if (FLAG_write_protect_code) {
160 heap_->WriteProtectCode(false);
161 }
162 #endif
163 }
164
165 ~WritableCodeLiteralsScope() {
166 #if defined(TARGET_ARCH_IA32)
167 if (FLAG_write_protect_code) {
168 heap_->WriteProtectCode(true);
169 }
170 #endif
171 }
172
173 private:
174 Heap* heap_;
175 };
176
177
151 void Become::MakeDummyObject(const Instance& instance) { 178 void Become::MakeDummyObject(const Instance& instance) {
152 // Make the forward pointer point to itself. 179 // Make the forward pointer point to itself.
153 // This is needed to distinguish it from a real forward object. 180 // This is needed to distinguish it from a real forward object.
154 ForwardObjectTo(instance.raw(), instance.raw()); 181 ForwardObjectTo(instance.raw(), instance.raw());
155 } 182 }
156 183
184
157 static bool IsDummyObject(RawObject* object) { 185 static bool IsDummyObject(RawObject* object) {
158 if (!object->IsForwardingCorpse()) return false; 186 if (!object->IsForwardingCorpse()) return false;
159 return GetForwardedObject(object) == object; 187 return GetForwardedObject(object) == object;
160 } 188 }
161 189
190
162 void Become::ElementsForwardIdentity(const Array& before, const Array& after) { 191 void Become::ElementsForwardIdentity(const Array& before, const Array& after) {
163 Thread* thread = Thread::Current(); 192 Thread* thread = Thread::Current();
164 Isolate* isolate = thread->isolate(); 193 Isolate* isolate = thread->isolate();
165 Heap* heap = isolate->heap(); 194 Heap* heap = isolate->heap();
166 195
167 TIMELINE_FUNCTION_GC_DURATION(thread, "Become::ElementsForwardIdentity"); 196 TIMELINE_FUNCTION_GC_DURATION(thread, "Become::ElementsForwardIdentity");
168 HeapIterationScope his; 197 HeapIterationScope his;
169 198
170 // Setup forwarding pointers. 199 // Setup forwarding pointers.
171 ASSERT(before.Length() == after.Length()); 200 ASSERT(before.Length() == after.Length());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 232
204 // C++ pointers 233 // C++ pointers
205 ForwardPointersVisitor pointer_visitor(isolate); 234 ForwardPointersVisitor pointer_visitor(isolate);
206 isolate->VisitObjectPointers(&pointer_visitor, true); 235 isolate->VisitObjectPointers(&pointer_visitor, true);
207 236
208 // Weak persistent handles. 237 // Weak persistent handles.
209 ForwardHeapPointersHandleVisitor handle_visitor; 238 ForwardHeapPointersHandleVisitor handle_visitor;
210 isolate->VisitWeakPersistentHandles(&handle_visitor); 239 isolate->VisitWeakPersistentHandles(&handle_visitor);
211 240
212 // Heap pointers (may require updating the remembered set) 241 // Heap pointers (may require updating the remembered set)
213 ForwardHeapPointersVisitor object_visitor(&pointer_visitor); 242 {
214 heap->VisitObjects(&object_visitor); 243 WritableCodeLiteralsScope writable_code(heap);
215 pointer_visitor.VisitingObject(NULL); 244 ForwardHeapPointersVisitor object_visitor(&pointer_visitor);
245 heap->VisitObjects(&object_visitor);
246 pointer_visitor.VisitingObject(NULL);
247 }
216 248
217 #if !defined(PRODUCT) 249 #if !defined(PRODUCT)
218 tds.SetNumArguments(2); 250 tds.SetNumArguments(2);
219 tds.FormatArgument(0, "Remapped objects", "%" Pd, before.Length()); 251 tds.FormatArgument(0, "Remapped objects", "%" Pd, before.Length());
220 tds.FormatArgument(1, "Remapped references", "%" Pd, 252 tds.FormatArgument(1, "Remapped references", "%" Pd,
221 pointer_visitor.count() + handle_visitor.count()); 253 pointer_visitor.count() + handle_visitor.count());
222 #endif 254 #endif
223 } 255 }
224 256
225 #if defined(DEBUG) 257 #if defined(DEBUG)
226 for (intptr_t i = 0; i < before.Length(); i++) { 258 for (intptr_t i = 0; i < before.Length(); i++) {
227 ASSERT(before.At(i) == after.At(i)); 259 ASSERT(before.At(i) == after.At(i));
228 } 260 }
229 #endif 261 #endif
230 } 262 }
231 263
232 } // namespace dart 264 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/isolate_reload.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698