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

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

Issue 25909002: Sampling profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
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"
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/coverage.h"
14 #include "vm/dart_api_state.h" 14 #include "vm/dart_api_state.h"
15 #include "vm/dart_entry.h" 15 #include "vm/dart_entry.h"
16 #include "vm/debugger.h" 16 #include "vm/debugger.h"
17 #include "vm/deopt_instructions.h" 17 #include "vm/deopt_instructions.h"
18 #include "vm/heap.h" 18 #include "vm/heap.h"
19 #include "vm/heap_histogram.h" 19 #include "vm/heap_histogram.h"
20 #include "vm/message_handler.h" 20 #include "vm/message_handler.h"
21 #include "vm/object_id_ring.h" 21 #include "vm/object_id_ring.h"
22 #include "vm/object_store.h" 22 #include "vm/object_store.h"
23 #include "vm/parser.h" 23 #include "vm/parser.h"
24 #include "vm/port.h" 24 #include "vm/port.h"
25 #include "vm/profiler.h"
25 #include "vm/reusable_handles.h" 26 #include "vm/reusable_handles.h"
26 #include "vm/service.h" 27 #include "vm/service.h"
28 #include "vm/signal_handler.h"
27 #include "vm/simulator.h" 29 #include "vm/simulator.h"
28 #include "vm/stack_frame.h" 30 #include "vm/stack_frame.h"
29 #include "vm/stub_code.h" 31 #include "vm/stub_code.h"
30 #include "vm/symbols.h" 32 #include "vm/symbols.h"
31 #include "vm/thread.h" 33 #include "vm/thread.h"
32 #include "vm/timer.h" 34 #include "vm/timer.h"
33 #include "vm/visitor.h" 35 #include "vm/visitor.h"
34 36
35 37
36 namespace dart { 38 namespace dart {
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 spawn_data_(0), 302 spawn_data_(0),
301 is_runnable_(false), 303 is_runnable_(false),
302 gc_prologue_callbacks_(), 304 gc_prologue_callbacks_(),
303 gc_epilogue_callbacks_(), 305 gc_epilogue_callbacks_(),
304 defer_finalization_count_(0), 306 defer_finalization_count_(0),
305 deopt_context_(NULL), 307 deopt_context_(NULL),
306 stacktrace_(NULL), 308 stacktrace_(NULL),
307 stack_frame_index_(-1), 309 stack_frame_index_(-1),
308 object_histogram_(NULL), 310 object_histogram_(NULL),
309 object_id_ring_(NULL), 311 object_id_ring_(NULL),
312 profiler_data_(NULL),
313 profiler_data_mutex_(new Mutex()),
310 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) 314 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS)
311 reusable_handles_() { 315 reusable_handles_() {
312 if (FLAG_print_object_histogram && (Dart::vm_isolate() != NULL)) { 316 if (FLAG_print_object_histogram && (Dart::vm_isolate() != NULL)) {
313 object_histogram_ = new ObjectHistogram(this); 317 object_histogram_ = new ObjectHistogram(this);
314 } 318 }
315 } 319 }
316 #undef REUSABLE_HANDLE_INITIALIZERS 320 #undef REUSABLE_HANDLE_INITIALIZERS
317 321
318 322
319 Isolate::~Isolate() { 323 Isolate::~Isolate() {
320 delete [] name_; 324 delete [] name_;
321 delete heap_; 325 delete heap_;
322 delete object_store_; 326 delete object_store_;
323 delete api_state_; 327 delete api_state_;
324 delete stub_code_; 328 delete stub_code_;
325 delete debugger_; 329 delete debugger_;
326 #if defined(USING_SIMULATOR) 330 #if defined(USING_SIMULATOR)
327 delete simulator_; 331 delete simulator_;
328 #endif 332 #endif
329 delete mutex_; 333 delete mutex_;
330 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. 334 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate.
335 delete profiler_data_mutex_;
336 profiler_data_mutex_ = NULL;
331 delete message_handler_; 337 delete message_handler_;
332 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. 338 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate.
333 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. 339 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted.
334 delete object_histogram_; 340 delete object_histogram_;
335 } 341 }
336 342
337 void Isolate::SetCurrent(Isolate* current) { 343 void Isolate::SetCurrent(Isolate* current) {
344 ScopedSignalBlocker ssb;
345 Isolate* old_isolate = Current();
346 if (old_isolate != NULL) {
347 ProfilerManager::DescheduleIsolate(old_isolate);
348 }
338 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current)); 349 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current));
350 if (current != NULL) {
351 ProfilerManager::ScheduleIsolate(current);
352 }
339 } 353 }
340 354
341 355
342 // The single thread local key which stores all the thread local data 356 // The single thread local key which stores all the thread local data
343 // for a thread. Since an Isolate is the central repository for 357 // for a thread. Since an Isolate is the central repository for
344 // storing all isolate specific information a single thread local key 358 // storing all isolate specific information a single thread local key
345 // is sufficient. 359 // is sufficient.
346 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey; 360 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey;
347 361
348 362
349 void Isolate::InitOnce() { 363 void Isolate::InitOnce() {
350 ASSERT(isolate_key == Thread::kUnsetThreadLocalKey); 364 ASSERT(isolate_key == Thread::kUnsetThreadLocalKey);
351 isolate_key = Thread::CreateThreadLocal(); 365 isolate_key = Thread::CreateThreadLocal();
352 ASSERT(isolate_key != Thread::kUnsetThreadLocalKey); 366 ASSERT(isolate_key != Thread::kUnsetThreadLocalKey);
353 create_callback_ = NULL; 367 create_callback_ = NULL;
354 } 368 }
355 369
356 370
357 Isolate* Isolate::Init(const char* name_prefix) { 371 Isolate* Isolate::Init(const char* name_prefix) {
358 Isolate* result = new Isolate(); 372 Isolate* result = new Isolate();
359 ASSERT(result != NULL); 373 ASSERT(result != NULL);
360 374
375 // Setup for profiling.
376 ProfilerManager::SetupIsolateForProfiling(result);
377
361 // TODO(5411455): For now just set the recently created isolate as 378 // TODO(5411455): For now just set the recently created isolate as
362 // the current isolate. 379 // the current isolate.
363 SetCurrent(result); 380 SetCurrent(result);
364 381
365 // Setup the isolate specific resuable handles. 382 // Setup the isolate specific resuable handles.
366 #define REUSABLE_HANDLE_ALLOCATION(object) \ 383 #define REUSABLE_HANDLE_ALLOCATION(object) \
367 result->object##_handle_ = result->AllocateReusableHandle<object>(); \ 384 result->object##_handle_ = result->AllocateReusableHandle<object>(); \
368 385
369 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) 386 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION)
370 #undef REUSABLE_HANDLE_ALLOCATION 387 #undef REUSABLE_HANDLE_ALLOCATION
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 void Isolate::Shutdown() { 660 void Isolate::Shutdown() {
644 ASSERT(this == Isolate::Current()); 661 ASSERT(this == Isolate::Current());
645 ASSERT(top_resource() == NULL); 662 ASSERT(top_resource() == NULL);
646 ASSERT((heap_ == NULL) || heap_->Verify()); 663 ASSERT((heap_ == NULL) || heap_->Verify());
647 664
648 // Create an area where we do have a zone and a handle scope so that we can 665 // Create an area where we do have a zone and a handle scope so that we can
649 // call VM functions while tearing this isolate down. 666 // call VM functions while tearing this isolate down.
650 { 667 {
651 StackZone stack_zone(this); 668 StackZone stack_zone(this);
652 HandleScope handle_scope(this); 669 HandleScope handle_scope(this);
670 #if 0
671 ScopedSignalBlocker ssb;
672
673 ProfilerManager::DescheduleIsolate(this);
674
675 ProfilerManager::WriteTracing(this, this->name(), this->main_port());
676 #endif
siva 2013/10/28 05:19:21 Why is this #ifdefed out.
Cutch 2013/11/04 20:36:05 Debug only dumping of data in about:tracing format
677
653 678
654 if (FLAG_print_object_histogram) { 679 if (FLAG_print_object_histogram) {
655 heap()->CollectAllGarbage(); 680 heap()->CollectAllGarbage();
656 object_histogram()->Print(); 681 object_histogram()->Print();
657 } 682 }
658 683
659 // Clean up debugger resources. 684 // Clean up debugger resources.
660 debugger()->Shutdown(); 685 debugger()->Shutdown();
661 686
662 // Close all the ports owned by this isolate. 687 // Close all the ports owned by this isolate.
(...skipping 22 matching lines...) Expand all
685 megamorphic_cache_table()->PrintSizes(); 710 megamorphic_cache_table()->PrintSizes();
686 Symbols::DumpStats(); 711 Symbols::DumpStats();
687 OS::Print("[-] Stopping isolate:\n" 712 OS::Print("[-] Stopping isolate:\n"
688 "\tisolate: %s\n", name()); 713 "\tisolate: %s\n", name());
689 } 714 }
690 } 715 }
691 716
692 // TODO(5411455): For now just make sure there are no current isolates 717 // TODO(5411455): For now just make sure there are no current isolates
693 // as we are shutting down the isolate. 718 // as we are shutting down the isolate.
694 SetCurrent(NULL); 719 SetCurrent(NULL);
720 ProfilerManager::ShutdownIsolate(this);
695 } 721 }
696 722
697 723
698 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; 724 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL;
699 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL; 725 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL;
700 Dart_IsolateUnhandledExceptionCallback 726 Dart_IsolateUnhandledExceptionCallback
701 Isolate::unhandled_exception_callback_ = NULL; 727 Isolate::unhandled_exception_callback_ = NULL;
702 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; 728 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL;
703 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; 729 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL;
704 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; 730 Dart_FileReadCallback Isolate::file_read_callback_ = NULL;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 return func.raw(); 1077 return func.raw();
1052 } 1078 }
1053 1079
1054 1080
1055 void IsolateSpawnState::Cleanup() { 1081 void IsolateSpawnState::Cleanup() {
1056 SwitchIsolateScope switch_scope(isolate()); 1082 SwitchIsolateScope switch_scope(isolate());
1057 Dart::ShutdownIsolate(); 1083 Dart::ShutdownIsolate();
1058 } 1084 }
1059 1085
1060 } // namespace dart 1086 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698