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

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

Issue 2208553002: Simplify reload error reporting (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
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 30 matching lines...) Expand all
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(Zone* zone, 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_(zone, 0) {
52 ComputeMapping(); 52 ComputeMapping();
53 before_ = new ZoneGrowableArray<const Instance*>(zone, 0); 53 before_ = new(zone) ZoneGrowableArray<const Instance*>(zone, 0);
54 after_ = new ZoneGrowableArray<const Instance*>(zone, 0); 54 after_ = new(zone) 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 : zone_(Thread::Current()->zone()), 362 : zone_(Thread::Current()->zone()),
363 start_time_micros_(OS::GetCurrentMonotonicMicros()), 363 start_time_micros_(OS::GetCurrentMonotonicMicros()),
364 reload_timestamp_(OS::GetCurrentTimeMillis()), 364 reload_timestamp_(OS::GetCurrentTimeMillis()),
365 isolate_(isolate), 365 isolate_(isolate),
366 reload_skipped_(false), 366 reload_skipped_(false),
367 reload_aborted_(false), 367 reload_aborted_(false),
368 js_(js), 368 js_(js),
369 saved_num_cids_(-1), 369 saved_num_cids_(-1),
370 saved_class_table_(NULL), 370 saved_class_table_(NULL),
371 num_saved_libs_(-1), 371 num_saved_libs_(-1),
372 instance_morphers_(), 372 instance_morphers_(zone_, 0),
373 reasons_to_cancel_reload_(), 373 reasons_to_cancel_reload_(zone_, 0),
374 cid_mapper_(), 374 cid_mapper_(),
375 modified_libs_(NULL), 375 modified_libs_(NULL),
376 script_uri_(String::null()), 376 script_uri_(String::null()),
377 error_(Error::null()), 377 error_(Error::null()),
378 old_classes_set_storage_(Array::null()), 378 old_classes_set_storage_(Array::null()),
379 class_map_storage_(Array::null()), 379 class_map_storage_(Array::null()),
380 old_libraries_set_storage_(Array::null()), 380 old_libraries_set_storage_(Array::null()),
381 library_map_storage_(Array::null()), 381 library_map_storage_(Array::null()),
382 become_map_storage_(Array::null()), 382 become_map_storage_(Array::null()),
383 become_enum_mappings_(GrowableObjectArray::null()), 383 become_enum_mappings_(GrowableObjectArray::null()),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 { 476 {
477 TransitionVMToNative transition(thread); 477 TransitionVMToNative transition(thread);
478 Api::Scope api_scope(thread); 478 Api::Scope api_scope(thread);
479 479
480 Dart_Handle retval = 480 Dart_Handle retval =
481 (I->library_tag_handler())(Dart_kScriptTag, 481 (I->library_tag_handler())(Dart_kScriptTag,
482 Api::NewHandle(thread, Library::null()), 482 Api::NewHandle(thread, Library::null()),
483 Api::NewHandle(thread, root_lib_url.raw())); 483 Api::NewHandle(thread, root_lib_url.raw()));
484 result = Api::UnwrapHandle(retval); 484 result = Api::UnwrapHandle(retval);
485 } 485 }
486 if (result.IsUnwindError()) {
487 // Ignore an unwind error because the isolate is dead.
488 return;
489 }
486 if (result.IsError()) { 490 if (result.IsError()) {
487 const Error& error = Error::Cast(result); 491 FinalizeFailedLoad(Error::Cast(result));
488 AddReasonForCancelling(new Aborted(zone_, error));
489 // We call report on JSON here because we won't ever execute
490 // FinalizeLoading.
491 ReportOnJSON(js_);
492 } 492 }
493 } 493 }
494 494
495 495
496 void IsolateReloadContext::RegisterClass(const Class& new_cls) { 496 void IsolateReloadContext::RegisterClass(const Class& new_cls) {
497 const Class& old_cls = Class::Handle(OldClassOrNull(new_cls)); 497 const Class& old_cls = Class::Handle(OldClassOrNull(new_cls));
498 if (old_cls.IsNull()) { 498 if (old_cls.IsNull()) {
499 I->class_table()->Register(new_cls); 499 I->class_table()->Register(new_cls);
500 500
501 if (FLAG_identity_reload) { 501 if (FLAG_identity_reload) {
(...skipping 10 matching lines...) Expand all
512 isolate()->class_table()->SetAt(old_cls.id(), new_cls.raw()); 512 isolate()->class_table()->SetAt(old_cls.id(), new_cls.raw());
513 if (!old_cls.is_enum_class()) { 513 if (!old_cls.is_enum_class()) {
514 new_cls.CopyCanonicalConstants(old_cls); 514 new_cls.CopyCanonicalConstants(old_cls);
515 } 515 }
516 new_cls.CopyCanonicalType(old_cls); 516 new_cls.CopyCanonicalType(old_cls);
517 AddBecomeMapping(old_cls, new_cls); 517 AddBecomeMapping(old_cls, new_cls);
518 AddClassMapping(new_cls, old_cls); 518 AddClassMapping(new_cls, old_cls);
519 } 519 }
520 520
521 521
522 // FinalizeLoading will be called *before* Reload() returns. 522 // FinalizeLoading will be called *before* Reload() returns but will not be
523 // called if the embedder fails to load sources.
523 void IsolateReloadContext::FinalizeLoading() { 524 void IsolateReloadContext::FinalizeLoading() {
524 if (reload_skipped_) { 525 if (reload_skipped_) {
525 return; 526 return;
526 } 527 }
527 BuildLibraryMapping(); 528 BuildLibraryMapping();
528 TIR_Print("---- DONE FINALIZING\n"); 529 TIR_Print("---- DONE FINALIZING\n");
529 if (ValidateReload()) { 530 if (ValidateReload()) {
530 Commit(); 531 Commit();
531 PostCommit(); 532 PostCommit();
532 isolate()->set_last_reload_timestamp(reload_timestamp_); 533 isolate()->set_last_reload_timestamp(reload_timestamp_);
533 } else { 534 } else {
534 ReportReasonsForCancelling(); 535 ReportReasonsForCancelling();
535 Rollback(); 536 Rollback();
536 } 537 }
537 // ValidateReload mutates the direct subclass information and does 538 // ValidateReload mutates the direct subclass information and does
538 // not remove dead subclasses. Rebuild the direct subclass 539 // not remove dead subclasses. Rebuild the direct subclass
539 // information from scratch. 540 // information from scratch.
540 RebuildDirectSubclasses(); 541 RebuildDirectSubclasses();
541 542
542 BackgroundCompiler::Enable(); 543 CommonFinalizeTail();
543 } 544 }
544 545
545 546
547 // FinalizeFailedLoad will be called *before* Reload() returns and will only
548 // be called if the embedder fails to load sources.
549 void IsolateReloadContext::FinalizeFailedLoad(const Error& error) {
550 AddReasonForCancelling(new Aborted(zone_, error));
551 ReportReasonsForCancelling();
552 Rollback();
553 CommonFinalizeTail();
554 }
555
556
557 void IsolateReloadContext::CommonFinalizeTail() {
558 BackgroundCompiler::Enable();
559 ReportOnJSON(js_);
560 }
561
546 void IsolateReloadContext::ReportOnJSON(JSONStream* stream) { 562 void IsolateReloadContext::ReportOnJSON(JSONStream* stream) {
547 JSONObject jsobj(stream); 563 JSONObject jsobj(stream);
548 jsobj.AddProperty("type", "ReloadReport"); 564 jsobj.AddProperty("type", "ReloadReport");
549 jsobj.AddProperty("success", !HasReasonsForCancelling()); 565 jsobj.AddProperty("success", !HasReasonsForCancelling());
550 { 566 {
551 JSONObject details(&jsobj, "details"); 567 JSONObject details(&jsobj, "details");
552 if (HasReasonsForCancelling()) { 568 if (HasReasonsForCancelling()) {
553 // Reload was rejected. 569 // Reload was rejected.
554 JSONArray array(&jsobj, "notices"); 570 JSONArray array(&jsobj, "notices");
555 for (intptr_t i = 0; i < reasons_to_cancel_reload_.length(); i++) { 571 for (intptr_t i = 0; i < reasons_to_cancel_reload_.length(); i++) {
(...skipping 12 matching lines...) Expand all
568 details.AddProperty("finalLibraryCount", final_library_count); 584 details.AddProperty("finalLibraryCount", final_library_count);
569 JSONArray array(&jsobj, "shapeChangeMappings"); 585 JSONArray array(&jsobj, "shapeChangeMappings");
570 for (intptr_t i = 0; i < instance_morphers_.length(); i++) { 586 for (intptr_t i = 0; i < instance_morphers_.length(); i++) {
571 instance_morphers_.At(i)->AppendTo(&array); 587 instance_morphers_.At(i)->AppendTo(&array);
572 } 588 }
573 } 589 }
574 } 590 }
575 } 591 }
576 592
577 593
578 void IsolateReloadContext::AbortReload(const Error& error) {
579 AddReasonForCancelling(new Aborted(zone_, error));
580 ReportReasonsForCancelling();
581 Rollback();
582 }
583
584
585 void IsolateReloadContext::EnsuredUnoptimizedCodeForStack() { 594 void IsolateReloadContext::EnsuredUnoptimizedCodeForStack() {
586 TIMELINE_SCOPE(EnsuredUnoptimizedCodeForStack); 595 TIMELINE_SCOPE(EnsuredUnoptimizedCodeForStack);
587 StackFrameIterator it(StackFrameIterator::kDontValidateFrames); 596 StackFrameIterator it(StackFrameIterator::kDontValidateFrames);
588 597
589 Function& func = Function::Handle(); 598 Function& func = Function::Handle();
590 while (it.HasNextFrame()) { 599 while (it.HasNextFrame()) {
591 StackFrame* frame = it.NextFrame(); 600 StackFrame* frame = it.NextFrame();
592 if (frame->IsDartFrame()) { 601 if (frame->IsDartFrame()) {
593 func = frame->LookupDartFunction(); 602 func = frame->LookupDartFunction();
594 ASSERT(!func.IsNull()); 603 ASSERT(!func.IsNull());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 720
712 const GrowableObjectArray& libs = 721 const GrowableObjectArray& libs =
713 GrowableObjectArray::Handle(object_store()->libraries()); 722 GrowableObjectArray::Handle(object_store()->libraries());
714 Library& lib = Library::Handle(); 723 Library& lib = Library::Handle();
715 Array& scripts = Array::Handle(); 724 Array& scripts = Array::Handle();
716 Script& script = Script::Handle(); 725 Script& script = Script::Handle();
717 intptr_t num_libs = libs.Length(); 726 intptr_t num_libs = libs.Length();
718 727
719 // Construct the imported-by graph. 728 // Construct the imported-by graph.
720 ZoneGrowableArray<ZoneGrowableArray<intptr_t>* >* imported_by = 729 ZoneGrowableArray<ZoneGrowableArray<intptr_t>* >* imported_by =
721 new ZoneGrowableArray<ZoneGrowableArray<intptr_t>* >(zone_, num_libs); 730 new(zone_) ZoneGrowableArray<ZoneGrowableArray<intptr_t>* >(
731 zone_, num_libs);
722 imported_by->SetLength(num_libs); 732 imported_by->SetLength(num_libs);
723 for (intptr_t i = 0; i < num_libs; i++) { 733 for (intptr_t i = 0; i < num_libs; i++) {
724 (*imported_by)[i] = new ZoneGrowableArray<intptr_t>(zone_, 0); 734 (*imported_by)[i] = new(zone_) ZoneGrowableArray<intptr_t>(zone_, 0);
725 } 735 }
726 Array& ports = Array::Handle(); 736 Array& ports = Array::Handle();
727 Namespace& ns = Namespace::Handle(); 737 Namespace& ns = Namespace::Handle();
728 Library& target = Library::Handle(); 738 Library& target = Library::Handle();
729 739
730 for (intptr_t lib_idx = 0; lib_idx < num_libs; lib_idx++) { 740 for (intptr_t lib_idx = 0; lib_idx < num_libs; lib_idx++) {
731 lib ^= libs.At(lib_idx); 741 lib ^= libs.At(lib_idx);
732 ASSERT(lib_idx == lib.index()); 742 ASSERT(lib_idx == lib.index());
733 if (lib.is_dart_scheme()) { 743 if (lib.is_dart_scheme()) {
734 // We don't care about imports among dart scheme libraries. 744 // We don't care about imports among dart scheme libraries.
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 ASSERT(!super_cls.IsNull()); 1603 ASSERT(!super_cls.IsNull());
1594 super_cls.AddDirectSubclass(cls); 1604 super_cls.AddDirectSubclass(cls);
1595 } 1605 }
1596 } 1606 }
1597 } 1607 }
1598 } 1608 }
1599 1609
1600 #endif // !PRODUCT 1610 #endif // !PRODUCT
1601 1611
1602 } // namespace dart 1612 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate_reload.h ('k') | runtime/vm/unit_test.cc » ('j') | runtime/vm/unit_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698