OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.h" | 5 #include "vm/isolate.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "platform/json.h" | 9 #include "platform/json.h" |
10 #include "lib/mirrors.h" | 10 #include "lib/mirrors.h" |
11 #include "vm/code_observers.h" | 11 #include "vm/code_observers.h" |
12 #include "vm/compiler_stats.h" | 12 #include "vm/compiler_stats.h" |
| 13 #include "vm/coverage.h" |
13 #include "vm/dart_api_state.h" | 14 #include "vm/dart_api_state.h" |
14 #include "vm/dart_entry.h" | 15 #include "vm/dart_entry.h" |
15 #include "vm/debugger.h" | 16 #include "vm/debugger.h" |
16 #include "vm/heap.h" | 17 #include "vm/heap.h" |
17 #include "vm/heap_histogram.h" | 18 #include "vm/heap_histogram.h" |
18 #include "vm/message_handler.h" | 19 #include "vm/message_handler.h" |
19 #include "vm/object_id_ring.h" | 20 #include "vm/object_id_ring.h" |
20 #include "vm/object_store.h" | 21 #include "vm/object_store.h" |
21 #include "vm/parser.h" | 22 #include "vm/parser.h" |
22 #include "vm/port.h" | 23 #include "vm/port.h" |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 function ^= class_functions.At(j); | 706 function ^= class_functions.At(j); |
706 if (function.usage_counter() > 0) { | 707 if (function.usage_counter() > 0) { |
707 functions->Add(&function); | 708 functions->Add(&function); |
708 } | 709 } |
709 } | 710 } |
710 } | 711 } |
711 | 712 |
712 | 713 |
713 void Isolate::PrintInvokedFunctions() { | 714 void Isolate::PrintInvokedFunctions() { |
714 ASSERT(this == Isolate::Current()); | 715 ASSERT(this == Isolate::Current()); |
715 StackZone zone(this); | |
716 HandleScope handle_scope(this); | |
717 const GrowableObjectArray& libraries = | 716 const GrowableObjectArray& libraries = |
718 GrowableObjectArray::Handle(object_store()->libraries()); | 717 GrowableObjectArray::Handle(object_store()->libraries()); |
719 Library& library = Library::Handle(); | 718 Library& library = Library::Handle(); |
720 GrowableArray<const Function*> invoked_functions; | 719 GrowableArray<const Function*> invoked_functions; |
721 for (int i = 0; i < libraries.Length(); i++) { | 720 for (int i = 0; i < libraries.Length(); i++) { |
722 library ^= libraries.At(i); | 721 library ^= libraries.At(i); |
723 Class& cls = Class::Handle(); | 722 Class& cls = Class::Handle(); |
724 ClassDictionaryIterator iter(library, | 723 ClassDictionaryIterator iter(library, |
725 ClassDictionaryIterator::kIteratePrivate); | 724 ClassDictionaryIterator::kIteratePrivate); |
726 while (iter.HasNext()) { | 725 while (iter.HasNext()) { |
(...skipping 24 matching lines...) Expand all Loading... |
751 private: | 750 private: |
752 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); | 751 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); |
753 }; | 752 }; |
754 | 753 |
755 | 754 |
756 void Isolate::Shutdown() { | 755 void Isolate::Shutdown() { |
757 ASSERT(this == Isolate::Current()); | 756 ASSERT(this == Isolate::Current()); |
758 ASSERT(top_resource() == NULL); | 757 ASSERT(top_resource() == NULL); |
759 ASSERT((heap_ == NULL) || heap_->Verify()); | 758 ASSERT((heap_ == NULL) || heap_->Verify()); |
760 | 759 |
761 if (FLAG_print_object_histogram) { | 760 // Create an area where we do have a zone and a handle scope so that we can |
| 761 // call VM functions while tearing this isolate down. |
| 762 { |
762 StackZone stack_zone(this); | 763 StackZone stack_zone(this); |
763 HandleScope handle_scope(this); | 764 HandleScope handle_scope(this); |
764 heap()->CollectAllGarbage(); | 765 |
765 object_histogram()->Print(); | 766 if (FLAG_print_object_histogram) { |
| 767 heap()->CollectAllGarbage(); |
| 768 object_histogram()->Print(); |
| 769 } |
| 770 |
| 771 // Clean up debugger resources. |
| 772 debugger()->Shutdown(); |
| 773 |
| 774 // Close all the ports owned by this isolate. |
| 775 PortMap::ClosePorts(message_handler()); |
| 776 |
| 777 // Fail fast if anybody tries to post any more messsages to this isolate. |
| 778 delete message_handler(); |
| 779 set_message_handler(NULL); |
| 780 |
| 781 // Dump all accumalated timer data for the isolate. |
| 782 timer_list_.ReportTimers(); |
| 783 if (FLAG_report_usage_count) { |
| 784 PrintInvokedFunctions(); |
| 785 } |
| 786 |
| 787 if (FLAG_print_coverage) { |
| 788 CodeCoverage::Print(this); |
| 789 } |
| 790 |
| 791 // Finalize any weak persistent handles with a non-null referent. |
| 792 FinalizeWeakPersistentHandlesVisitor visitor; |
| 793 api_state()->weak_persistent_handles().VisitHandles(&visitor); |
| 794 |
| 795 CompilerStats::Print(); |
| 796 // TODO(asiva): Move this code to Dart::Cleanup when we have that method |
| 797 // as the cleanup for Dart::InitOnce. |
| 798 CodeObservers::DeleteAll(); |
| 799 if (FLAG_trace_isolates) { |
| 800 heap()->PrintSizes(); |
| 801 megamorphic_cache_table()->PrintSizes(); |
| 802 Symbols::DumpStats(); |
| 803 OS::Print("[-] Stopping isolate:\n" |
| 804 "\tisolate: %s\n", name()); |
| 805 } |
766 } | 806 } |
767 | 807 |
768 // Clean up debugger resources. Shutting down the debugger | |
769 // requires a handle zone. We must set up a temporary zone because | |
770 // Isolate::Shutdown is called without a zone. | |
771 { | |
772 StackZone zone(this); | |
773 HandleScope handle_scope(this); | |
774 debugger_->Shutdown(); | |
775 } | |
776 | |
777 // Close all the ports owned by this isolate. | |
778 PortMap::ClosePorts(message_handler()); | |
779 | |
780 // Fail fast if anybody tries to post any more messsages to this isolate. | |
781 delete message_handler(); | |
782 set_message_handler(NULL); | |
783 | |
784 // Finalize any weak persistent handles with a non-null referent. | |
785 FinalizeWeakPersistentHandlesVisitor visitor; | |
786 api_state()->weak_persistent_handles().VisitHandles(&visitor); | |
787 | |
788 // Dump all accumalated timer data for the isolate. | |
789 timer_list_.ReportTimers(); | |
790 if (FLAG_report_usage_count) { | |
791 PrintInvokedFunctions(); | |
792 } | |
793 CompilerStats::Print(); | |
794 // TODO(asiva): Move this code to Dart::Cleanup when we have that method | |
795 // as the cleanup for Dart::InitOnce. | |
796 CodeObservers::DeleteAll(); | |
797 if (FLAG_trace_isolates) { | |
798 StackZone zone(this); | |
799 HandleScope handle_scope(this); | |
800 heap()->PrintSizes(); | |
801 megamorphic_cache_table()->PrintSizes(); | |
802 Symbols::DumpStats(); | |
803 OS::Print("[-] Stopping isolate:\n" | |
804 "\tisolate: %s\n", name()); | |
805 } | |
806 // TODO(5411455): For now just make sure there are no current isolates | 808 // TODO(5411455): For now just make sure there are no current isolates |
807 // as we are shutting down the isolate. | 809 // as we are shutting down the isolate. |
808 SetCurrent(NULL); | 810 SetCurrent(NULL); |
809 } | 811 } |
810 | 812 |
811 | 813 |
812 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; | 814 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; |
813 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL; | 815 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL; |
814 Dart_IsolateUnhandledExceptionCallback | 816 Dart_IsolateUnhandledExceptionCallback |
815 Isolate::unhandled_exception_callback_ = NULL; | 817 Isolate::unhandled_exception_callback_ = NULL; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 return func.raw(); | 1187 return func.raw(); |
1186 } | 1188 } |
1187 | 1189 |
1188 | 1190 |
1189 void IsolateSpawnState::Cleanup() { | 1191 void IsolateSpawnState::Cleanup() { |
1190 SwitchIsolateScope switch_scope(isolate()); | 1192 SwitchIsolateScope switch_scope(isolate()); |
1191 Dart::ShutdownIsolate(); | 1193 Dart::ShutdownIsolate(); |
1192 } | 1194 } |
1193 | 1195 |
1194 } // namespace dart | 1196 } // namespace dart |
OLD | NEW |