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

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, 1 month 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 spawn_data_(0), 304 spawn_data_(0),
303 is_runnable_(false), 305 is_runnable_(false),
304 gc_prologue_callbacks_(), 306 gc_prologue_callbacks_(),
305 gc_epilogue_callbacks_(), 307 gc_epilogue_callbacks_(),
306 defer_finalization_count_(0), 308 defer_finalization_count_(0),
307 deopt_context_(NULL), 309 deopt_context_(NULL),
308 stacktrace_(NULL), 310 stacktrace_(NULL),
309 stack_frame_index_(-1), 311 stack_frame_index_(-1),
310 object_histogram_(NULL), 312 object_histogram_(NULL),
311 object_id_ring_(NULL), 313 object_id_ring_(NULL),
314 profiler_data_(NULL),
315 profiler_data_mutex_(new Mutex()),
312 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) 316 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS)
313 reusable_handles_() { 317 reusable_handles_() {
314 if (FLAG_print_object_histogram && (Dart::vm_isolate() != NULL)) { 318 if (FLAG_print_object_histogram && (Dart::vm_isolate() != NULL)) {
315 object_histogram_ = new ObjectHistogram(this); 319 object_histogram_ = new ObjectHistogram(this);
316 } 320 }
317 } 321 }
318 #undef REUSABLE_HANDLE_INITIALIZERS 322 #undef REUSABLE_HANDLE_INITIALIZERS
319 323
320 324
321 Isolate::~Isolate() { 325 Isolate::~Isolate() {
322 delete [] name_; 326 delete [] name_;
323 delete heap_; 327 delete heap_;
324 delete object_store_; 328 delete object_store_;
325 delete api_state_; 329 delete api_state_;
326 delete stub_code_; 330 delete stub_code_;
327 delete debugger_; 331 delete debugger_;
328 #if defined(USING_SIMULATOR) 332 #if defined(USING_SIMULATOR)
329 delete simulator_; 333 delete simulator_;
330 #endif 334 #endif
331 delete mutex_; 335 delete mutex_;
332 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. 336 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate.
337 delete profiler_data_mutex_;
338 profiler_data_mutex_ = NULL;
333 delete message_handler_; 339 delete message_handler_;
334 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. 340 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate.
335 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. 341 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted.
336 delete object_histogram_; 342 delete object_histogram_;
337 } 343 }
338 344
339 void Isolate::SetCurrent(Isolate* current) { 345 void Isolate::SetCurrent(Isolate* current) {
346 ScopedSignalBlocker ssb;
347 Isolate* old_isolate = Current();
348 if (old_isolate != NULL) {
349 ProfilerManager::DescheduleIsolate(old_isolate);
350 }
340 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current)); 351 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current));
352 if (current != NULL) {
353 ProfilerManager::ScheduleIsolate(current);
354 }
341 } 355 }
342 356
343 357
344 // The single thread local key which stores all the thread local data 358 // The single thread local key which stores all the thread local data
345 // for a thread. Since an Isolate is the central repository for 359 // for a thread. Since an Isolate is the central repository for
346 // storing all isolate specific information a single thread local key 360 // storing all isolate specific information a single thread local key
347 // is sufficient. 361 // is sufficient.
348 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey; 362 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey;
349 363
350 364
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 result->BuildName(name_prefix); 404 result->BuildName(name_prefix);
391 405
392 result->debugger_ = new Debugger(); 406 result->debugger_ = new Debugger();
393 result->debugger_->Initialize(result); 407 result->debugger_->Initialize(result);
394 if (FLAG_trace_isolates) { 408 if (FLAG_trace_isolates) {
395 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { 409 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) {
396 OS::Print("[+] Starting isolate:\n" 410 OS::Print("[+] Starting isolate:\n"
397 "\tisolate: %s\n", result->name()); 411 "\tisolate: %s\n", result->name());
398 } 412 }
399 } 413 }
414
415 // Setup for profiling.
416 ProfilerManager::SetupIsolateForProfiling(result);
417
400 return result; 418 return result;
401 } 419 }
402 420
403 421
404 void Isolate::BuildName(const char* name_prefix) { 422 void Isolate::BuildName(const char* name_prefix) {
405 ASSERT(name_ == NULL); 423 ASSERT(name_ == NULL);
406 if (name_prefix == NULL) { 424 if (name_prefix == NULL) {
407 name_prefix = "isolate"; 425 name_prefix = "isolate";
408 } 426 }
409 const char* kFormat = "%s-%lld"; 427 const char* kFormat = "%s-%lld";
(...skipping 27 matching lines...) Expand all
437 void Isolate::SetStackLimit(uword limit) { 455 void Isolate::SetStackLimit(uword limit) {
438 MutexLocker ml(mutex_); 456 MutexLocker ml(mutex_);
439 if (stack_limit_ == saved_stack_limit_) { 457 if (stack_limit_ == saved_stack_limit_) {
440 // No interrupt pending, set stack_limit_ too. 458 // No interrupt pending, set stack_limit_ too.
441 stack_limit_ = limit; 459 stack_limit_ = limit;
442 } 460 }
443 saved_stack_limit_ = limit; 461 saved_stack_limit_ = limit;
444 } 462 }
445 463
446 464
465 bool Isolate::GetStackBounds(uintptr_t* lower, uintptr_t* upper) {
466 uintptr_t stack_lower = stack_limit();
467 if (stack_lower == static_cast<uintptr_t>(~0)) {
468 stack_lower = saved_stack_limit();
469 }
470 if (stack_lower == static_cast<uintptr_t>(~0)) {
471 return false;
472 }
473 uintptr_t stack_upper = stack_lower + GetSpecifiedStackSize();
474 *lower = stack_lower;
475 *upper = stack_upper;
476 return true;
477 }
478
479
447 void Isolate::ScheduleInterrupts(uword interrupt_bits) { 480 void Isolate::ScheduleInterrupts(uword interrupt_bits) {
448 // TODO(turnidge): Can't use MutexLocker here because MutexLocker is 481 // TODO(turnidge): Can't use MutexLocker here because MutexLocker is
449 // a StackResource, which requires a current isolate. Should 482 // a StackResource, which requires a current isolate. Should
450 // MutexLocker really be a StackResource? 483 // MutexLocker really be a StackResource?
451 mutex_->Lock(); 484 mutex_->Lock();
452 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask. 485 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask.
453 if (stack_limit_ == saved_stack_limit_) { 486 if (stack_limit_ == saved_stack_limit_) {
454 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask; 487 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask;
455 } 488 }
456 stack_limit_ |= interrupt_bits; 489 stack_limit_ |= interrupt_bits;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 ASSERT(this == Isolate::Current()); 700 ASSERT(this == Isolate::Current());
668 ASSERT(top_resource() == NULL); 701 ASSERT(top_resource() == NULL);
669 ASSERT((heap_ == NULL) || heap_->Verify()); 702 ASSERT((heap_ == NULL) || heap_->Verify());
670 703
671 // Create an area where we do have a zone and a handle scope so that we can 704 // Create an area where we do have a zone and a handle scope so that we can
672 // call VM functions while tearing this isolate down. 705 // call VM functions while tearing this isolate down.
673 { 706 {
674 StackZone stack_zone(this); 707 StackZone stack_zone(this);
675 HandleScope handle_scope(this); 708 HandleScope handle_scope(this);
676 709
710 ScopedSignalBlocker ssb;
711
712 ProfilerManager::DescheduleIsolate(this);
713
714 // ProfilerManager::WriteTracing(this, this->name(), this->main_port());
siva 2013/11/11 03:51:54 why is this commented out?
Cutch 2013/11/18 20:48:54 Was for debugging. Removed.
715
716
677 if (FLAG_print_object_histogram) { 717 if (FLAG_print_object_histogram) {
678 heap()->CollectAllGarbage(); 718 heap()->CollectAllGarbage();
679 object_histogram()->Print(); 719 object_histogram()->Print();
680 } 720 }
681 721
682 // Clean up debugger resources. 722 // Clean up debugger resources.
683 debugger()->Shutdown(); 723 debugger()->Shutdown();
684 724
685 // Close all the ports owned by this isolate. 725 // Close all the ports owned by this isolate.
686 PortMap::ClosePorts(message_handler()); 726 PortMap::ClosePorts(message_handler());
(...skipping 21 matching lines...) Expand all
708 megamorphic_cache_table()->PrintSizes(); 748 megamorphic_cache_table()->PrintSizes();
709 Symbols::DumpStats(); 749 Symbols::DumpStats();
710 OS::Print("[-] Stopping isolate:\n" 750 OS::Print("[-] Stopping isolate:\n"
711 "\tisolate: %s\n", name()); 751 "\tisolate: %s\n", name());
712 } 752 }
713 } 753 }
714 754
715 // TODO(5411455): For now just make sure there are no current isolates 755 // TODO(5411455): For now just make sure there are no current isolates
716 // as we are shutting down the isolate. 756 // as we are shutting down the isolate.
717 SetCurrent(NULL); 757 SetCurrent(NULL);
758 ProfilerManager::ShutdownIsolateForProfiling(this);
718 } 759 }
719 760
720 761
721 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; 762 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL;
722 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL; 763 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL;
723 Dart_IsolateUnhandledExceptionCallback 764 Dart_IsolateUnhandledExceptionCallback
724 Isolate::unhandled_exception_callback_ = NULL; 765 Isolate::unhandled_exception_callback_ = NULL;
725 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; 766 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL;
726 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; 767 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL;
727 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; 768 Dart_FileReadCallback Isolate::file_read_callback_ = NULL;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 return func.raw(); 1101 return func.raw();
1061 } 1102 }
1062 1103
1063 1104
1064 void IsolateSpawnState::Cleanup() { 1105 void IsolateSpawnState::Cleanup() {
1065 SwitchIsolateScope switch_scope(isolate()); 1106 SwitchIsolateScope switch_scope(isolate());
1066 Dart::ShutdownIsolate(); 1107 Dart::ShutdownIsolate();
1067 } 1108 }
1068 1109
1069 } // namespace dart 1110 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698