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 "vm/code_observers.h" | 10 #include "vm/code_observers.h" |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 #define REUSABLE_HANDLE_SCOPE_INIT(object) \ | 529 #define REUSABLE_HANDLE_SCOPE_INIT(object) \ |
530 reusable_##object##_handle_scope_active_(false), | 530 reusable_##object##_handle_scope_active_(false), |
531 #else | 531 #else |
532 #define REUSABLE_HANDLE_SCOPE_INIT(object) | 532 #define REUSABLE_HANDLE_SCOPE_INIT(object) |
533 #endif // defined(DEBUG) | 533 #endif // defined(DEBUG) |
534 | 534 |
535 #define REUSABLE_HANDLE_INITIALIZERS(object) \ | 535 #define REUSABLE_HANDLE_INITIALIZERS(object) \ |
536 object##_handle_(NULL), | 536 object##_handle_(NULL), |
537 | 537 |
538 Isolate::Isolate() | 538 Isolate::Isolate() |
539 : mutator_thread_(new Thread(this)), | 539 : mutator_thread_(NULL), |
540 vm_tag_(0), | 540 vm_tag_(0), |
541 store_buffer_(), | 541 store_buffer_(), |
542 message_notify_callback_(NULL), | 542 message_notify_callback_(NULL), |
543 name_(NULL), | 543 name_(NULL), |
544 debugger_name_(NULL), | 544 debugger_name_(NULL), |
545 start_time_(OS::GetCurrentTimeMicros()), | 545 start_time_(OS::GetCurrentTimeMicros()), |
546 main_port_(0), | 546 main_port_(0), |
547 origin_id_(0), | 547 origin_id_(0), |
548 pause_capability_(0), | 548 pause_capability_(0), |
549 terminate_capability_(0), | 549 terminate_capability_(0), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 metrics_list_head_(NULL), | 597 metrics_list_head_(NULL), |
598 next_(NULL), | 598 next_(NULL), |
599 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) | 599 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) |
600 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT) | 600 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT) |
601 reusable_handles_() { | 601 reusable_handles_() { |
602 set_vm_tag(VMTag::kIdleTagId); | 602 set_vm_tag(VMTag::kIdleTagId); |
603 set_user_tag(UserTags::kDefaultUserTag); | 603 set_user_tag(UserTags::kDefaultUserTag); |
604 } | 604 } |
605 | 605 |
606 Isolate::Isolate(Isolate* original) | 606 Isolate::Isolate(Isolate* original) |
607 : mutator_thread_(new Thread(this)), | 607 : mutator_thread_(NULL), |
608 vm_tag_(0), | 608 vm_tag_(0), |
609 store_buffer_(true), | 609 store_buffer_(true), |
610 class_table_(original->class_table()), | 610 class_table_(original->class_table()), |
611 message_notify_callback_(NULL), | 611 message_notify_callback_(NULL), |
612 name_(NULL), | 612 name_(NULL), |
613 debugger_name_(NULL), | 613 debugger_name_(NULL), |
614 start_time_(OS::GetCurrentTimeMicros()), | 614 start_time_(OS::GetCurrentTimeMicros()), |
615 main_port_(0), | 615 main_port_(0), |
616 pause_capability_(0), | 616 pause_capability_(0), |
617 terminate_capability_(0), | 617 terminate_capability_(0), |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 delete simulator_; | 678 delete simulator_; |
679 #endif | 679 #endif |
680 delete mutex_; | 680 delete mutex_; |
681 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. | 681 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. |
682 delete message_handler_; | 682 delete message_handler_; |
683 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. | 683 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. |
684 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. | 684 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. |
685 delete spawn_state_; | 685 delete spawn_state_; |
686 delete log_; | 686 delete log_; |
687 log_ = NULL; | 687 log_ = NULL; |
688 delete mutator_thread_; | |
689 } | 688 } |
690 | 689 |
691 | 690 |
692 #if defined(DEBUG) | 691 #if defined(DEBUG) |
693 bool Isolate::IsIsolateOf(Thread* thread) { | 692 bool Isolate::IsIsolateOf(Thread* thread) { |
694 return this == thread->isolate(); | 693 return this == thread->isolate(); |
695 } | 694 } |
696 #endif // DEBUG | 695 #endif // DEBUG |
697 | 696 |
698 | 697 |
699 void Isolate::SetCurrent(Isolate* current) { | |
700 Isolate* old_current = Current(); | |
701 if (old_current != NULL) { | |
702 old_current->set_vm_tag(VMTag::kIdleTagId); | |
703 old_current->set_thread_state(NULL); | |
704 Profiler::EndExecution(old_current); | |
705 } | |
706 if (current != NULL) { | |
707 Thread::SetCurrent(current->mutator_thread()); | |
708 ASSERT(current->thread_state() == NULL); | |
709 InterruptableThreadState* thread_state = | |
710 ThreadInterrupter::GetCurrentThreadState(); | |
711 #if defined(DEBUG) | |
712 CheckForDuplicateThreadState(thread_state); | |
713 #endif | |
714 ASSERT(thread_state != NULL); | |
715 Profiler::BeginExecution(current); | |
716 current->set_thread_state(thread_state); | |
717 current->set_vm_tag(VMTag::kVMTagId); | |
718 } else { | |
719 Thread::SetCurrent(NULL); | |
720 } | |
721 } | |
722 | |
723 | |
724 void Isolate::InitOnce() { | 698 void Isolate::InitOnce() { |
725 create_callback_ = NULL; | 699 create_callback_ = NULL; |
726 isolates_list_monitor_ = new Monitor(); | 700 isolates_list_monitor_ = new Monitor(); |
727 ASSERT(isolates_list_monitor_ != NULL); | 701 ASSERT(isolates_list_monitor_ != NULL); |
728 } | 702 } |
729 | 703 |
730 | 704 |
731 Isolate* Isolate::Init(const char* name_prefix, bool is_vm_isolate) { | 705 Isolate* Isolate::Init(const char* name_prefix, bool is_vm_isolate) { |
732 Isolate* result = new Isolate(); | 706 Isolate* result = new Isolate(); |
733 ASSERT(result != NULL); | 707 ASSERT(result != NULL); |
734 | 708 |
735 // Initialize metrics. | 709 // Initialize metrics. |
736 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \ | 710 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \ |
737 result->metric_##variable##_.Init(result, name, NULL, Metric::unit); | 711 result->metric_##variable##_.Init(result, name, NULL, Metric::unit); |
738 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); | 712 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); |
739 #undef ISOLATE_METRIC_INIT | 713 #undef ISOLATE_METRIC_INIT |
740 | 714 |
741 // TODO(5411455): For now just set the recently created isolate as | 715 // TODO(5411455): For now just set the recently created isolate as |
742 // the current isolate. | 716 // the current isolate. |
743 SetCurrent(result); | 717 Thread::EnterIsolate(result); |
744 | 718 |
745 // Setup the isolate specific resuable handles. | 719 // Setup the isolate specific resuable handles. |
746 #define REUSABLE_HANDLE_ALLOCATION(object) \ | 720 #define REUSABLE_HANDLE_ALLOCATION(object) \ |
747 result->object##_handle_ = result->AllocateReusableHandle<object>(); | 721 result->object##_handle_ = result->AllocateReusableHandle<object>(); |
748 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) | 722 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) |
749 #undef REUSABLE_HANDLE_ALLOCATION | 723 #undef REUSABLE_HANDLE_ALLOCATION |
750 | 724 |
751 // Setup the isolate message handler. | 725 // Setup the isolate message handler. |
752 MessageHandler* handler = new IsolateMessageHandler(result); | 726 MessageHandler* handler = new IsolateMessageHandler(result); |
753 ASSERT(handler != NULL); | 727 ASSERT(handler != NULL); |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 heap()->PrintSizes(); | 1408 heap()->PrintSizes(); |
1435 megamorphic_cache_table()->PrintSizes(); | 1409 megamorphic_cache_table()->PrintSizes(); |
1436 Symbols::DumpStats(); | 1410 Symbols::DumpStats(); |
1437 OS::Print("[-] Stopping isolate:\n" | 1411 OS::Print("[-] Stopping isolate:\n" |
1438 "\tisolate: %s\n", name()); | 1412 "\tisolate: %s\n", name()); |
1439 } | 1413 } |
1440 } | 1414 } |
1441 | 1415 |
1442 // TODO(5411455): For now just make sure there are no current isolates | 1416 // TODO(5411455): For now just make sure there are no current isolates |
1443 // as we are shutting down the isolate. | 1417 // as we are shutting down the isolate. |
1444 SetCurrent(NULL); | 1418 Thread::ExitIsolate(); |
1445 Profiler::ShutdownProfilingForIsolate(this); | 1419 Profiler::ShutdownProfilingForIsolate(this); |
1446 } | 1420 } |
1447 | 1421 |
1448 | 1422 |
1449 Isolate* Isolate::ShallowCopy() { | 1423 Isolate* Isolate::ShallowCopy() { |
1450 return new Isolate(this); | 1424 return new Isolate(this); |
1451 } | 1425 } |
1452 | 1426 |
1453 | 1427 |
1454 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; | 1428 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 serialized_message_, serialized_message_len_); | 1953 serialized_message_, serialized_message_len_); |
1980 } | 1954 } |
1981 | 1955 |
1982 | 1956 |
1983 void IsolateSpawnState::Cleanup() { | 1957 void IsolateSpawnState::Cleanup() { |
1984 SwitchIsolateScope switch_scope(I); | 1958 SwitchIsolateScope switch_scope(I); |
1985 Dart::ShutdownIsolate(); | 1959 Dart::ShutdownIsolate(); |
1986 } | 1960 } |
1987 | 1961 |
1988 } // namespace dart | 1962 } // namespace dart |
OLD | NEW |