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

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

Issue 2201093002: Make all reload zone allocations use the same zone (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 | « runtime/vm/isolate_reload.h ('k') | runtime/vm/object_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/isolate_reload.h" 5 #include "vm/isolate_reload.h"
6 6
7 #include "vm/become.h" 7 #include "vm/become.h"
8 #include "vm/bit_vector.h" 8 #include "vm/bit_vector.h"
9 #include "vm/code_generator.h" 9 #include "vm/code_generator.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 29 matching lines...) Expand all
40 40
41 #define I (isolate()) 41 #define I (isolate())
42 #define Z (thread->zone()) 42 #define Z (thread->zone())
43 43
44 #define TIMELINE_SCOPE(name) \ 44 #define TIMELINE_SCOPE(name) \
45 TimelineDurationScope tds##name(Thread::Current(), \ 45 TimelineDurationScope tds##name(Thread::Current(), \
46 Timeline::GetIsolateStream(), \ 46 Timeline::GetIsolateStream(), \
47 #name) 47 #name)
48 48
49 49
50 InstanceMorpher::InstanceMorpher(const Class& from, const Class& to) 50 InstanceMorpher::InstanceMorpher(Zone* zone, const Class& from, const Class& to)
51 : from_(from), to_(to), mapping_() { 51 : from_(from), to_(to), mapping_() {
52 ComputeMapping(); 52 ComputeMapping();
53 before_ = new ZoneGrowableArray<const Instance*>(); 53 before_ = new ZoneGrowableArray<const Instance*>(zone, 0);
54 after_ = new ZoneGrowableArray<const Instance*>(); 54 after_ = new ZoneGrowableArray<const Instance*>(zone, 0);
55 ASSERT(from_.id() == to_.id()); 55 ASSERT(from_.id() == to_.id());
56 cid_ = from_.id(); 56 cid_ = from_.id();
57 } 57 }
58 58
59 59
60 void InstanceMorpher::AddObject(RawObject* object) const { 60 void InstanceMorpher::AddObject(RawObject* object) const {
61 ASSERT(object->GetClassId() == cid()); 61 ASSERT(object->GetClassId() == cid());
62 const Instance& instance = Instance::Cast(Object::Handle(object)); 62 const Instance& instance = Instance::Cast(Object::Handle(object));
63 before_->Add(&instance); 63 before_->Add(&instance);
64 } 64 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void ClassReasonForCancelling::AppendTo(JSONArray* array) { 209 void ClassReasonForCancelling::AppendTo(JSONArray* array) {
210 JSONObject jsobj(array); 210 JSONObject jsobj(array);
211 jsobj.AddProperty("type", "ReasonForCancelling"); 211 jsobj.AddProperty("type", "ReasonForCancelling");
212 jsobj.AddProperty("class", from_); 212 jsobj.AddProperty("class", from_);
213 const String& message = String::Handle(ToString()); 213 const String& message = String::Handle(ToString());
214 jsobj.AddProperty("message", message); 214 jsobj.AddProperty("message", message);
215 } 215 }
216 216
217 217
218 RawError* IsolateReloadContext::error() const { 218 RawError* IsolateReloadContext::error() const {
219 ASSERT(has_error()); 219 ASSERT(reload_aborted());
220 // Report the first error to the surroundings. 220 // Report the first error to the surroundings.
221 const Error& error = 221 const Error& error =
222 Error::Handle(reasons_to_cancel_reload_.At(0)->ToError()); 222 Error::Handle(reasons_to_cancel_reload_.At(0)->ToError());
223 return error.raw(); 223 return error.raw();
224 } 224 }
225 225
226 226
227 class ScriptUrlSetTraits { 227 class ScriptUrlSetTraits {
228 public: 228 public:
229 static bool ReportStats() { return false; } 229 static bool ReportStats() { return false; }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 const String& a_lib_url = 352 const String& a_lib_url =
353 String::Handle(a_lib.IsNull() ? String::null() : a_lib.url()); 353 String::Handle(a_lib.IsNull() ? String::null() : a_lib.url());
354 const String& b_lib_url = 354 const String& b_lib_url =
355 String::Handle(b_lib.IsNull() ? String::null() : b_lib.url()); 355 String::Handle(b_lib.IsNull() ? String::null() : b_lib.url());
356 return a_lib_url.Equals(b_lib_url); 356 return a_lib_url.Equals(b_lib_url);
357 } 357 }
358 358
359 359
360 IsolateReloadContext::IsolateReloadContext(Isolate* isolate, 360 IsolateReloadContext::IsolateReloadContext(Isolate* isolate,
361 JSONStream* js) 361 JSONStream* js)
362 : start_time_micros_(OS::GetCurrentMonotonicMicros()), 362 : zone_(Thread::Current()->zone()),
363 start_time_micros_(OS::GetCurrentMonotonicMicros()),
363 reload_timestamp_(OS::GetCurrentTimeMillis()), 364 reload_timestamp_(OS::GetCurrentTimeMillis()),
364 isolate_(isolate), 365 isolate_(isolate),
365 reload_skipped_(false), 366 reload_skipped_(false),
367 reload_aborted_(false),
366 js_(js), 368 js_(js),
367 saved_num_cids_(-1), 369 saved_num_cids_(-1),
368 saved_class_table_(NULL), 370 saved_class_table_(NULL),
369 num_saved_libs_(-1), 371 num_saved_libs_(-1),
370 instance_morphers_(), 372 instance_morphers_(),
371 reasons_to_cancel_reload_(), 373 reasons_to_cancel_reload_(),
372 cid_mapper_(), 374 cid_mapper_(),
373 modified_libs_(NULL), 375 modified_libs_(NULL),
374 script_uri_(String::null()), 376 script_uri_(String::null()),
375 error_(Error::null()), 377 error_(Error::null()),
376 old_classes_set_storage_(Array::null()), 378 old_classes_set_storage_(Array::null()),
377 class_map_storage_(Array::null()), 379 class_map_storage_(Array::null()),
378 old_libraries_set_storage_(Array::null()), 380 old_libraries_set_storage_(Array::null()),
379 library_map_storage_(Array::null()), 381 library_map_storage_(Array::null()),
380 become_map_storage_(Array::null()), 382 become_map_storage_(Array::null()),
381 become_enum_mappings_(GrowableObjectArray::null()), 383 become_enum_mappings_(GrowableObjectArray::null()),
382 saved_root_library_(Library::null()), 384 saved_root_library_(Library::null()),
383 saved_libraries_(GrowableObjectArray::null()) { 385 saved_libraries_(GrowableObjectArray::null()) {
384 // NOTE: DO NOT ALLOCATE ANY RAW OBJECTS HERE. The IsolateReloadContext is not 386 // NOTE: DO NOT ALLOCATE ANY RAW OBJECTS HERE. The IsolateReloadContext is not
385 // associated with the isolate yet and if a GC is triggered here the raw 387 // associated with the isolate yet and if a GC is triggered here the raw
386 // objects will not be properly accounted for. 388 // objects will not be properly accounted for.
389 ASSERT(zone_ != NULL);
387 } 390 }
388 391
389 392
390 IsolateReloadContext::~IsolateReloadContext() { 393 IsolateReloadContext::~IsolateReloadContext() {
391 } 394 }
392 395
393 396
394 void IsolateReloadContext::ReportError(const Error& error) { 397 void IsolateReloadContext::ReportError(const Error& error) {
395 if (FLAG_trace_reload) { 398 if (FLAG_trace_reload) {
396 THR_Print("ISO-RELOAD: Error: %s\n", error.ToErrorCString()); 399 THR_Print("ISO-RELOAD: Error: %s\n", error.ToErrorCString());
397 } 400 }
398 ServiceEvent service_event(I, ServiceEvent::kIsolateReload); 401 ServiceEvent service_event(I, ServiceEvent::kIsolateReload);
399 service_event.set_reload_error(&error); 402 service_event.set_reload_error(&error);
400 Service::HandleEvent(&service_event); 403 Service::HandleEvent(&service_event);
401 } 404 }
402 405
403 406
404 void IsolateReloadContext::ReportSuccess() { 407 void IsolateReloadContext::ReportSuccess() {
405 ServiceEvent service_event(I, ServiceEvent::kIsolateReload); 408 ServiceEvent service_event(I, ServiceEvent::kIsolateReload);
406 Service::HandleEvent(&service_event); 409 Service::HandleEvent(&service_event);
407 } 410 }
408 411
409 412
410 class Aborted : public ReasonForCancelling { 413 class Aborted : public ReasonForCancelling {
411 public: 414 public:
412 explicit Aborted(const Error& error) 415 explicit Aborted(Zone* zone, const Error& error)
413 : ReasonForCancelling(), error_(error) { } 416 : ReasonForCancelling(zone), error_(error) { }
414 417
415 private: 418 private:
416 const Error& error_; 419 const Error& error_;
417 420
418 RawError* ToError() { return error_.raw(); } 421 RawError* ToError() { return error_.raw(); }
419 RawString* ToString() { 422 RawString* ToString() {
420 return String::NewFormatted("%s", error_.ToErrorCString()); 423 return String::NewFormatted("%s", error_.ToErrorCString());
421 } 424 }
422 }; 425 };
423 426
424 427
425 void IsolateReloadContext::StartReload(bool force_reload) { 428 // NOTE: This function returns *after* FinalizeLoading is called.
429 void IsolateReloadContext::Reload(bool force_reload) {
426 TIMELINE_SCOPE(Reload); 430 TIMELINE_SCOPE(Reload);
427 Thread* thread = Thread::Current(); 431 Thread* thread = Thread::Current();
428 ASSERT(isolate() == thread->isolate()); 432 ASSERT(isolate() == thread->isolate());
433 fprintf(stderr, "Reload\n");
rmacnak 2016/08/02 16:30:22 Remove
Cutch 2016/08/02 16:32:33 Done.
429 434
430 // Grab root library before calling CheckpointBeforeReload. 435 // Grab root library before calling CheckpointBeforeReload.
431 const Library& root_lib = Library::Handle(object_store()->root_library()); 436 const Library& root_lib = Library::Handle(object_store()->root_library());
432 ASSERT(!root_lib.IsNull()); 437 ASSERT(!root_lib.IsNull());
433 const String& root_lib_url = String::Handle(root_lib.url()); 438 const String& root_lib_url = String::Handle(root_lib.url());
434 439
435 // Check to see which libraries have been modified. 440 // Check to see which libraries have been modified.
436 modified_libs_ = FindModifiedLibraries(force_reload); 441 modified_libs_ = FindModifiedLibraries(force_reload);
437 if (!modified_libs_->Contains(root_lib.index())) { 442 if (!modified_libs_->Contains(root_lib.index())) {
438 ASSERT(modified_libs_->IsEmpty()); 443 ASSERT(modified_libs_->IsEmpty());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 Api::Scope api_scope(thread); 484 Api::Scope api_scope(thread);
480 485
481 Dart_Handle retval = 486 Dart_Handle retval =
482 (I->library_tag_handler())(Dart_kScriptTag, 487 (I->library_tag_handler())(Dart_kScriptTag,
483 Api::NewHandle(thread, Library::null()), 488 Api::NewHandle(thread, Library::null()),
484 Api::NewHandle(thread, root_lib_url.raw())); 489 Api::NewHandle(thread, root_lib_url.raw()));
485 result = Api::UnwrapHandle(retval); 490 result = Api::UnwrapHandle(retval);
486 } 491 }
487 if (result.IsError()) { 492 if (result.IsError()) {
488 const Error& error = Error::Cast(result); 493 const Error& error = Error::Cast(result);
489 AddReasonForCancelling(new Aborted(error)); 494 AddReasonForCancelling(new Aborted(zone_, error));
490 } 495 }
491 } 496 }
492 497
493 498
494 void IsolateReloadContext::RegisterClass(const Class& new_cls) { 499 void IsolateReloadContext::RegisterClass(const Class& new_cls) {
495 const Class& old_cls = Class::Handle(OldClassOrNull(new_cls)); 500 const Class& old_cls = Class::Handle(OldClassOrNull(new_cls));
496 if (old_cls.IsNull()) { 501 if (old_cls.IsNull()) {
497 I->class_table()->Register(new_cls); 502 I->class_table()->Register(new_cls);
498 503
499 if (FLAG_identity_reload) { 504 if (FLAG_identity_reload) {
(...skipping 10 matching lines...) Expand all
510 isolate()->class_table()->SetAt(old_cls.id(), new_cls.raw()); 515 isolate()->class_table()->SetAt(old_cls.id(), new_cls.raw());
511 if (!old_cls.is_enum_class()) { 516 if (!old_cls.is_enum_class()) {
512 new_cls.CopyCanonicalConstants(old_cls); 517 new_cls.CopyCanonicalConstants(old_cls);
513 } 518 }
514 new_cls.CopyCanonicalType(old_cls); 519 new_cls.CopyCanonicalType(old_cls);
515 AddBecomeMapping(old_cls, new_cls); 520 AddBecomeMapping(old_cls, new_cls);
516 AddClassMapping(new_cls, old_cls); 521 AddClassMapping(new_cls, old_cls);
517 } 522 }
518 523
519 524
520 void IsolateReloadContext::FinishReload() { 525 // FinalizeLoading will be called *before* Reload() returns.
526 void IsolateReloadContext::FinalizeLoading() {
521 if (reload_skipped_) { 527 if (reload_skipped_) {
522 return; 528 return;
523 } 529 }
530 fprintf(stderr, "FinalizeLoading\n");
rmacnak 2016/08/02 16:30:22 "
Cutch 2016/08/02 16:32:33 Done.
524 BuildLibraryMapping(); 531 BuildLibraryMapping();
525 TIR_Print("---- DONE FINALIZING\n"); 532 TIR_Print("---- DONE FINALIZING\n");
526 if (ValidateReload()) { 533 if (ValidateReload()) {
527 Commit(); 534 Commit();
528 PostCommit(); 535 PostCommit();
529 isolate()->set_last_reload_timestamp(reload_timestamp_); 536 isolate()->set_last_reload_timestamp(reload_timestamp_);
530 } else { 537 } else {
531 ReportReasonsForCancelling(); 538 ReportReasonsForCancelling();
532 Rollback(); 539 Rollback();
533 } 540 }
534 // ValidateReload mutates the direct subclass information and does 541 // ValidateReload mutates the direct subclass information and does
535 // not remove dead subclasses. Rebuild the direct subclass 542 // not remove dead subclasses. Rebuild the direct subclass
536 // information from scratch. 543 // information from scratch.
537 RebuildDirectSubclasses(); 544 RebuildDirectSubclasses();
538 545
539 if (FLAG_write_protect_code) { 546 if (FLAG_write_protect_code) {
540 // Re-enable code page write protection. 547 // Re-enable code page write protection.
541 I->heap()->WriteProtectCode(true); 548 I->heap()->WriteProtectCode(true);
542 } 549 }
543 550
544 BackgroundCompiler::Enable(); 551 BackgroundCompiler::Enable();
545 552
553 reload_aborted_ = HasReasonsForCancelling();
546 ReportOnJSON(js_); 554 ReportOnJSON(js_);
547 } 555 }
548 556
549 557
550 void IsolateReloadContext::ReportOnJSON(JSONStream* stream) { 558 void IsolateReloadContext::ReportOnJSON(JSONStream* stream) {
551 JSONObject jsobj(stream); 559 JSONObject jsobj(stream);
552 jsobj.AddProperty("type", "ReloadReport"); 560 jsobj.AddProperty("type", "ReloadReport");
553 jsobj.AddProperty("success", !HasReasonsForCancelling()); 561 jsobj.AddProperty("success", !HasReasonsForCancelling());
554 { 562 {
555 JSONObject details(&jsobj, "details"); 563 JSONObject details(&jsobj, "details");
(...skipping 17 matching lines...) Expand all
573 JSONArray array(&jsobj, "shapeChangeMappings"); 581 JSONArray array(&jsobj, "shapeChangeMappings");
574 for (intptr_t i = 0; i < instance_morphers_.length(); i++) { 582 for (intptr_t i = 0; i < instance_morphers_.length(); i++) {
575 instance_morphers_.At(i)->AppendTo(&array); 583 instance_morphers_.At(i)->AppendTo(&array);
576 } 584 }
577 } 585 }
578 } 586 }
579 } 587 }
580 588
581 589
582 void IsolateReloadContext::AbortReload(const Error& error) { 590 void IsolateReloadContext::AbortReload(const Error& error) {
583 AddReasonForCancelling(new Aborted(error)); 591 AddReasonForCancelling(new Aborted(zone_, error));
584 ReportReasonsForCancelling(); 592 ReportReasonsForCancelling();
585 Rollback(); 593 Rollback();
586 } 594 }
587 595
588 596
589 void IsolateReloadContext::EnsuredUnoptimizedCodeForStack() { 597 void IsolateReloadContext::EnsuredUnoptimizedCodeForStack() {
590 TIMELINE_SCOPE(EnsuredUnoptimizedCodeForStack); 598 TIMELINE_SCOPE(EnsuredUnoptimizedCodeForStack);
591 StackFrameIterator it(StackFrameIterator::kDontValidateFrames); 599 StackFrameIterator it(StackFrameIterator::kDontValidateFrames);
592 600
593 Function& func = Function::Handle(); 601 Function& func = Function::Handle();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 723
716 const GrowableObjectArray& libs = 724 const GrowableObjectArray& libs =
717 GrowableObjectArray::Handle(object_store()->libraries()); 725 GrowableObjectArray::Handle(object_store()->libraries());
718 Library& lib = Library::Handle(); 726 Library& lib = Library::Handle();
719 Array& scripts = Array::Handle(); 727 Array& scripts = Array::Handle();
720 Script& script = Script::Handle(); 728 Script& script = Script::Handle();
721 intptr_t num_libs = libs.Length(); 729 intptr_t num_libs = libs.Length();
722 730
723 // Construct the imported-by graph. 731 // Construct the imported-by graph.
724 ZoneGrowableArray<ZoneGrowableArray<intptr_t>* >* imported_by = 732 ZoneGrowableArray<ZoneGrowableArray<intptr_t>* >* imported_by =
725 new ZoneGrowableArray<ZoneGrowableArray<intptr_t>* >(num_libs); 733 new ZoneGrowableArray<ZoneGrowableArray<intptr_t>* >(zone_, num_libs);
726 imported_by->SetLength(num_libs); 734 imported_by->SetLength(num_libs);
727 for (intptr_t i = 0; i < num_libs; i++) { 735 for (intptr_t i = 0; i < num_libs; i++) {
728 (*imported_by)[i] = new ZoneGrowableArray<intptr_t>(); 736 (*imported_by)[i] = new ZoneGrowableArray<intptr_t>(zone_, 0);
729 } 737 }
730 Array& imports = Array::Handle(); 738 Array& imports = Array::Handle();
731 Namespace& ns = Namespace::Handle(); 739 Namespace& ns = Namespace::Handle();
732 Library& target = Library::Handle(); 740 Library& target = Library::Handle();
733 741
734 for (intptr_t lib_idx = 0; lib_idx < num_libs; lib_idx++) { 742 for (intptr_t lib_idx = 0; lib_idx < num_libs; lib_idx++) {
735 lib ^= libs.At(lib_idx); 743 lib ^= libs.At(lib_idx);
736 ASSERT(lib_idx == lib.index()); 744 ASSERT(lib_idx == lib.index());
737 if (lib.is_dart_scheme()) { 745 if (lib.is_dart_scheme()) {
738 // We don't care about imports among dart scheme libraries. 746 // We don't care about imports among dart scheme libraries.
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 // must be zapped to prevent the forwarding in GetClassForHeapWalkAt. 1208 // must be zapped to prevent the forwarding in GetClassForHeapWalkAt.
1201 // Instance will from now be described by the isolate's class table. 1209 // Instance will from now be described by the isolate's class table.
1202 free(saved_class_table_); 1210 free(saved_class_table_);
1203 saved_class_table_ = NULL; 1211 saved_class_table_ = NULL;
1204 Become::ElementsForwardIdentity(before, after); 1212 Become::ElementsForwardIdentity(before, after);
1205 } 1213 }
1206 1214
1207 1215
1208 bool IsolateReloadContext::ValidateReload() { 1216 bool IsolateReloadContext::ValidateReload() {
1209 TIMELINE_SCOPE(ValidateReload); 1217 TIMELINE_SCOPE(ValidateReload);
1210 if (has_error()) return false; 1218 if (reload_aborted()) return false;
1211 1219
1212 // Validate libraries. 1220 // Validate libraries.
1213 { 1221 {
1214 ASSERT(library_map_storage_ != Array::null()); 1222 ASSERT(library_map_storage_ != Array::null());
1215 UnorderedHashMap<LibraryMapTraits> map(library_map_storage_); 1223 UnorderedHashMap<LibraryMapTraits> map(library_map_storage_);
1216 UnorderedHashMap<LibraryMapTraits>::Iterator it(&map); 1224 UnorderedHashMap<LibraryMapTraits>::Iterator it(&map);
1217 Library& lib = Library::Handle(); 1225 Library& lib = Library::Handle();
1218 Library& new_lib = Library::Handle(); 1226 Library& new_lib = Library::Handle();
1219 while (it.MoveNext()) { 1227 while (it.MoveNext()) {
1220 const intptr_t entry = it.Current(); 1228 const intptr_t entry = it.Current();
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 ASSERT(!super_cls.IsNull()); 1594 ASSERT(!super_cls.IsNull());
1587 super_cls.AddDirectSubclass(cls); 1595 super_cls.AddDirectSubclass(cls);
1588 } 1596 }
1589 } 1597 }
1590 } 1598 }
1591 } 1599 }
1592 1600
1593 #endif // !PRODUCT 1601 #endif // !PRODUCT
1594 1602
1595 } // namespace dart 1603 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate_reload.h ('k') | runtime/vm/object_reload.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698