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

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

Issue 128653004: Use list of isolates in profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/profiler.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) 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"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 gc_prologue_callbacks_(), 308 gc_prologue_callbacks_(),
309 gc_epilogue_callbacks_(), 309 gc_epilogue_callbacks_(),
310 defer_finalization_count_(0), 310 defer_finalization_count_(0),
311 deopt_context_(NULL), 311 deopt_context_(NULL),
312 stacktrace_(NULL), 312 stacktrace_(NULL),
313 stack_frame_index_(-1), 313 stack_frame_index_(-1),
314 object_histogram_(NULL), 314 object_histogram_(NULL),
315 cha_used_(false), 315 cha_used_(false),
316 object_id_ring_(NULL), 316 object_id_ring_(NULL),
317 profiler_data_(NULL), 317 profiler_data_(NULL),
318 thread_state_(NULL),
319 next_(NULL),
318 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) 320 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS)
319 reusable_handles_() { 321 reusable_handles_() {
320 if (FLAG_print_object_histogram && (Dart::vm_isolate() != NULL)) { 322 if (FLAG_print_object_histogram && (Dart::vm_isolate() != NULL)) {
321 object_histogram_ = new ObjectHistogram(this); 323 object_histogram_ = new ObjectHistogram(this);
322 } 324 }
323 } 325 }
324 #undef REUSABLE_HANDLE_INITIALIZERS 326 #undef REUSABLE_HANDLE_INITIALIZERS
325 327
326 328
327 Isolate::~Isolate() { 329 Isolate::~Isolate() {
328 delete [] name_; 330 delete [] name_;
329 delete heap_; 331 delete heap_;
330 delete object_store_; 332 delete object_store_;
331 delete api_state_; 333 delete api_state_;
332 delete stub_code_; 334 delete stub_code_;
333 delete debugger_; 335 delete debugger_;
334 #if defined(USING_SIMULATOR) 336 #if defined(USING_SIMULATOR)
335 delete simulator_; 337 delete simulator_;
336 #endif 338 #endif
337 delete mutex_; 339 delete mutex_;
338 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. 340 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate.
339 delete message_handler_; 341 delete message_handler_;
340 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. 342 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate.
341 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. 343 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted.
342 delete object_histogram_; 344 delete object_histogram_;
343 delete spawn_state_; 345 delete spawn_state_;
344 } 346 }
345 347
348
346 void Isolate::SetCurrent(Isolate* current) { 349 void Isolate::SetCurrent(Isolate* current) {
347 Isolate* old_current = Current(); 350 Isolate* old_current = Current();
348 if (old_current != current) { 351 if (old_current != NULL) {
352 old_current->set_thread_state(NULL);
349 Profiler::EndExecution(old_current); 353 Profiler::EndExecution(old_current);
350 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current)); 354 }
355 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current));
356 if (current != NULL) {
357 ASSERT(current->thread_state() == NULL);
358 InterruptableThreadState* thread_state =
359 ThreadInterrupter::GetCurrentThreadState();
360 #if defined(DEBUG)
361 CheckForDuplicateThreadState(thread_state);
362 #endif
351 Profiler::BeginExecution(current); 363 Profiler::BeginExecution(current);
364 current->set_thread_state(thread_state);
352 } 365 }
353 } 366 }
354 367
355 368
356 // The single thread local key which stores all the thread local data 369 // The single thread local key which stores all the thread local data
357 // for a thread. Since an Isolate is the central repository for 370 // for a thread. Since an Isolate is the central repository for
358 // storing all isolate specific information a single thread local key 371 // storing all isolate specific information a single thread local key
359 // is sufficient. 372 // is sufficient.
360 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey; 373 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey;
361 374
362 375
363 void Isolate::InitOnce() { 376 void Isolate::InitOnce() {
364 ASSERT(isolate_key == Thread::kUnsetThreadLocalKey); 377 ASSERT(isolate_key == Thread::kUnsetThreadLocalKey);
365 isolate_key = Thread::CreateThreadLocal(); 378 isolate_key = Thread::CreateThreadLocal();
366 ASSERT(isolate_key != Thread::kUnsetThreadLocalKey); 379 ASSERT(isolate_key != Thread::kUnsetThreadLocalKey);
367 create_callback_ = NULL; 380 create_callback_ = NULL;
381 isolates_list_monitor_ = new Monitor();
382 ASSERT(isolates_list_monitor_ != NULL);
368 } 383 }
369 384
370 385
371 Isolate* Isolate::Init(const char* name_prefix) { 386 Isolate* Isolate::Init(const char* name_prefix) {
372 Isolate* result = new Isolate(); 387 Isolate* result = new Isolate();
373 ASSERT(result != NULL); 388 ASSERT(result != NULL);
374 389
375 // Setup for profiling. 390 // Setup for profiling.
376 Profiler::InitProfilingForIsolate(result); 391 Profiler::InitProfilingForIsolate(result);
377 392
393 // Add to isolate list.
394 AddIsolateTolist(result);
395
378 // TODO(5411455): For now just set the recently created isolate as 396 // TODO(5411455): For now just set the recently created isolate as
379 // the current isolate. 397 // the current isolate.
380 SetCurrent(result); 398 SetCurrent(result);
381 399
382 // Setup the isolate specific resuable handles. 400 // Setup the isolate specific resuable handles.
383 #define REUSABLE_HANDLE_ALLOCATION(object) \ 401 #define REUSABLE_HANDLE_ALLOCATION(object) \
384 result->object##_handle_ = result->AllocateReusableHandle<object>(); \ 402 result->object##_handle_ = result->AllocateReusableHandle<object>(); \
385 403
386 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) 404 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION)
387 #undef REUSABLE_HANDLE_ALLOCATION 405 #undef REUSABLE_HANDLE_ALLOCATION
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 megamorphic_cache_table()->PrintSizes(); 760 megamorphic_cache_table()->PrintSizes();
743 Symbols::DumpStats(); 761 Symbols::DumpStats();
744 OS::Print("[-] Stopping isolate:\n" 762 OS::Print("[-] Stopping isolate:\n"
745 "\tisolate: %s\n", name()); 763 "\tisolate: %s\n", name());
746 } 764 }
747 } 765 }
748 766
749 // TODO(5411455): For now just make sure there are no current isolates 767 // TODO(5411455): For now just make sure there are no current isolates
750 // as we are shutting down the isolate. 768 // as we are shutting down the isolate.
751 SetCurrent(NULL); 769 SetCurrent(NULL);
770 RemoveIsolateFromList(this);
752 Profiler::ShutdownProfilingForIsolate(this); 771 Profiler::ShutdownProfilingForIsolate(this);
753 } 772 }
754 773
755 774
756 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; 775 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL;
757 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL; 776 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL;
758 Dart_IsolateUnhandledExceptionCallback 777 Dart_IsolateUnhandledExceptionCallback
759 Isolate::unhandled_exception_callback_ = NULL; 778 Isolate::unhandled_exception_callback_ = NULL;
760 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; 779 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL;
761 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; 780 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL;
762 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; 781 Dart_FileReadCallback Isolate::file_read_callback_ = NULL;
763 Dart_FileWriteCallback Isolate::file_write_callback_ = NULL; 782 Dart_FileWriteCallback Isolate::file_write_callback_ = NULL;
764 Dart_FileCloseCallback Isolate::file_close_callback_ = NULL; 783 Dart_FileCloseCallback Isolate::file_close_callback_ = NULL;
765 Dart_EntropySource Isolate::entropy_source_callback_ = NULL; 784 Dart_EntropySource Isolate::entropy_source_callback_ = NULL;
766 Dart_IsolateInterruptCallback Isolate::vmstats_callback_ = NULL; 785 Dart_IsolateInterruptCallback Isolate::vmstats_callback_ = NULL;
767 Dart_ServiceIsolateCreateCalback Isolate::service_create_callback_ = NULL; 786 Dart_ServiceIsolateCreateCalback Isolate::service_create_callback_ = NULL;
768 787
788 Monitor* Isolate::isolates_list_monitor_ = NULL;
789 Isolate* Isolate::isolates_list_head_ = NULL;
790
791
769 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, 792 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor,
770 bool visit_prologue_weak_handles, 793 bool visit_prologue_weak_handles,
771 bool validate_frames) { 794 bool validate_frames) {
772 ASSERT(visitor != NULL); 795 ASSERT(visitor != NULL);
773 796
774 // Visit objects in the object store. 797 // Visit objects in the object store.
775 object_store()->VisitObjectPointers(visitor); 798 object_store()->VisitObjectPointers(visitor);
776 799
777 // Visit objects in the class table. 800 // Visit objects in the class table.
778 class_table()->VisitObjectPointers(visitor); 801 class_table()->VisitObjectPointers(visitor);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 } 882 }
860 883
861 const Library& lib = 884 const Library& lib =
862 Library::Handle(object_store()->root_library()); 885 Library::Handle(object_store()->root_library());
863 jsobj.AddProperty("rootLib", lib); 886 jsobj.AddProperty("rootLib", lib);
864 887
865 timer_list().PrintTimersToJSONProperty(&jsobj); 888 timer_list().PrintTimersToJSONProperty(&jsobj);
866 } 889 }
867 890
868 891
892 void Isolate::VisitIsolates(IsolateVisitor* visitor) {
893 if (visitor == NULL) {
894 return;
895 }
896 MonitorLocker ml(isolates_list_monitor_);
897 Isolate* current = isolates_list_head_;
898 while (current) {
899 visitor->VisitIsolate(current);
900 current = current->next_;
901 }
902 }
903
904
905 void Isolate::AddIsolateTolist(Isolate* isolate) {
906 MonitorLocker ml(isolates_list_monitor_);
907 ASSERT(isolate != NULL);
908 ASSERT(isolate->next_ == NULL);
909 isolate->next_ = isolates_list_head_;
910 isolates_list_head_ = isolate;
911 }
912
913
914 void Isolate::RemoveIsolateFromList(Isolate* isolate) {
915 MonitorLocker ml(isolates_list_monitor_);
916 ASSERT(isolate != NULL);
917 if (isolate == isolates_list_head_) {
918 isolates_list_head_ = isolate->next_;
919 return;
920 }
921 Isolate* previous = NULL;
922 Isolate* current = isolates_list_head_;
923 while (current) {
924 if (current == isolate) {
925 ASSERT(previous != NULL);
926 previous->next_ = current->next_;
927 return;
928 }
929 previous = current;
930 current = current->next_;
931 }
932 UNREACHABLE();
933 }
934
935
936 #if defined(DEBUG)
937 void Isolate::CheckForDuplicateThreadState(InterruptableThreadState* state) {
938 MonitorLocker ml(isolates_list_monitor_);
939 ASSERT(state != NULL);
940 Isolate* current = isolates_list_head_;
941 while (current) {
942 ASSERT(current->thread_state() != state);
943 current = current->next_;
944 }
945 }
946 #endif
947
948
869 template<class T> 949 template<class T>
870 T* Isolate::AllocateReusableHandle() { 950 T* Isolate::AllocateReusableHandle() {
871 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); 951 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle());
872 T::initializeHandle(handle, T::null()); 952 T::initializeHandle(handle, T::null());
873 return handle; 953 return handle;
874 } 954 }
875 955
876 956
877 IsolateSpawnState::IsolateSpawnState(const Function& func) 957 IsolateSpawnState::IsolateSpawnState(const Function& func)
878 : isolate_(NULL), 958 : isolate_(NULL),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 return func.raw(); 1051 return func.raw();
972 } 1052 }
973 1053
974 1054
975 void IsolateSpawnState::Cleanup() { 1055 void IsolateSpawnState::Cleanup() {
976 SwitchIsolateScope switch_scope(isolate()); 1056 SwitchIsolateScope switch_scope(isolate());
977 Dart::ShutdownIsolate(); 1057 Dart::ShutdownIsolate();
978 } 1058 }
979 1059
980 } // namespace dart 1060 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698