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 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 #endif // defined(DEBUG) | 532 #endif // defined(DEBUG) |
533 | 533 |
534 #define REUSABLE_HANDLE_INITIALIZERS(object) \ | 534 #define REUSABLE_HANDLE_INITIALIZERS(object) \ |
535 object##_handle_(NULL), | 535 object##_handle_(NULL), |
536 | 536 |
537 Isolate::Isolate() | 537 Isolate::Isolate() |
538 : vm_tag_(0), | 538 : vm_tag_(0), |
539 store_buffer_(), | 539 store_buffer_(), |
540 message_notify_callback_(NULL), | 540 message_notify_callback_(NULL), |
541 name_(NULL), | 541 name_(NULL), |
542 debugger_name_(NULL), | |
542 start_time_(OS::GetCurrentTimeMicros()), | 543 start_time_(OS::GetCurrentTimeMicros()), |
543 main_port_(0), | 544 main_port_(0), |
544 origin_id_(0), | 545 origin_id_(0), |
545 pause_capability_(0), | 546 pause_capability_(0), |
546 terminate_capability_(0), | 547 terminate_capability_(0), |
547 errors_fatal_(true), | 548 errors_fatal_(true), |
548 heap_(NULL), | 549 heap_(NULL), |
549 object_store_(NULL), | 550 object_store_(NULL), |
550 top_exit_frame_info_(0), | 551 top_exit_frame_info_(0), |
551 init_callback_data_(NULL), | 552 init_callback_data_(NULL), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 set_vm_tag(VMTag::kIdleTagId); | 600 set_vm_tag(VMTag::kIdleTagId); |
600 set_user_tag(UserTags::kDefaultUserTag); | 601 set_user_tag(UserTags::kDefaultUserTag); |
601 } | 602 } |
602 | 603 |
603 Isolate::Isolate(Isolate* original) | 604 Isolate::Isolate(Isolate* original) |
604 : vm_tag_(0), | 605 : vm_tag_(0), |
605 store_buffer_(true), | 606 store_buffer_(true), |
606 class_table_(original->class_table()), | 607 class_table_(original->class_table()), |
607 message_notify_callback_(NULL), | 608 message_notify_callback_(NULL), |
608 name_(NULL), | 609 name_(NULL), |
610 debugger_name_(NULL), | |
609 start_time_(OS::GetCurrentTimeMicros()), | 611 start_time_(OS::GetCurrentTimeMicros()), |
610 main_port_(0), | 612 main_port_(0), |
611 pause_capability_(0), | 613 pause_capability_(0), |
612 terminate_capability_(0), | 614 terminate_capability_(0), |
613 errors_fatal_(true), | 615 errors_fatal_(true), |
614 heap_(NULL), | 616 heap_(NULL), |
615 object_store_(NULL), | 617 object_store_(NULL), |
616 top_exit_frame_info_(0), | 618 top_exit_frame_info_(0), |
617 init_callback_data_(NULL), | 619 init_callback_data_(NULL), |
618 environment_callback_(NULL), | 620 environment_callback_(NULL), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 next_(NULL), | 659 next_(NULL), |
658 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) | 660 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) |
659 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT) | 661 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT) |
660 reusable_handles_() { | 662 reusable_handles_() { |
661 } | 663 } |
662 #undef REUSABLE_HANDLE_SCOPE_INIT | 664 #undef REUSABLE_HANDLE_SCOPE_INIT |
663 #undef REUSABLE_HANDLE_INITIALIZERS | 665 #undef REUSABLE_HANDLE_INITIALIZERS |
664 | 666 |
665 Isolate::~Isolate() { | 667 Isolate::~Isolate() { |
666 free(name_); | 668 free(name_); |
669 free(debugger_name_); | |
667 delete heap_; | 670 delete heap_; |
668 delete object_store_; | 671 delete object_store_; |
669 delete api_state_; | 672 delete api_state_; |
670 delete stub_code_; | 673 delete stub_code_; |
671 delete debugger_; | 674 delete debugger_; |
672 #if defined(USING_SIMULATOR) | 675 #if defined(USING_SIMULATOR) |
673 delete simulator_; | 676 delete simulator_; |
674 #endif | 677 #endif |
675 delete mutex_; | 678 delete mutex_; |
676 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. | 679 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 #if defined(DEBUG) | 765 #if defined(DEBUG) |
763 // Verify that we are never reusing a live origin id. | 766 // Verify that we are never reusing a live origin id. |
764 VerifyOriginId id_verifier(result->main_port()); | 767 VerifyOriginId id_verifier(result->main_port()); |
765 Isolate::VisitIsolates(&id_verifier); | 768 Isolate::VisitIsolates(&id_verifier); |
766 #endif | 769 #endif |
767 result->set_origin_id(result->main_port()); | 770 result->set_origin_id(result->main_port()); |
768 result->set_pause_capability(result->random()->NextUInt64()); | 771 result->set_pause_capability(result->random()->NextUInt64()); |
769 result->set_terminate_capability(result->random()->NextUInt64()); | 772 result->set_terminate_capability(result->random()->NextUInt64()); |
770 | 773 |
771 result->BuildName(name_prefix); | 774 result->BuildName(name_prefix); |
772 | |
773 result->debugger_ = new Debugger(); | 775 result->debugger_ = new Debugger(); |
774 result->debugger_->Initialize(result); | 776 result->debugger_->Initialize(result); |
775 if (FLAG_trace_isolates) { | 777 if (FLAG_trace_isolates) { |
776 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { | 778 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { |
777 OS::Print("[+] Starting isolate:\n" | 779 OS::Print("[+] Starting isolate:\n" |
778 "\tisolate: %s\n", result->name()); | 780 "\tisolate: %s\n", result->name()); |
779 } | 781 } |
780 } | 782 } |
781 | 783 |
782 // Add to isolate list. | 784 // Add to isolate list. |
(...skipping 23 matching lines...) Expand all Loading... | |
806 uword stack_allocated_local_address = reinterpret_cast<uword>(&func); | 808 uword stack_allocated_local_address = reinterpret_cast<uword>(&func); |
807 return stack_allocated_local_address; | 809 return stack_allocated_local_address; |
808 #endif | 810 #endif |
809 #else | 811 #else |
810 uword stack_allocated_local_address = reinterpret_cast<uword>(&func); | 812 uword stack_allocated_local_address = reinterpret_cast<uword>(&func); |
811 return stack_allocated_local_address; | 813 return stack_allocated_local_address; |
812 #endif | 814 #endif |
813 } | 815 } |
814 | 816 |
815 | 817 |
818 void Isolate::set_debugger_name(const char* name) { | |
819 free(debugger_name_); | |
820 debugger_name_ = strdup(name); | |
821 } | |
822 | |
823 | |
816 void Isolate::BuildName(const char* name_prefix) { | 824 void Isolate::BuildName(const char* name_prefix) { |
817 ASSERT(name_ == NULL); | 825 ASSERT(name_ == NULL); |
818 if (name_prefix == NULL) { | 826 if (name_prefix == NULL) { |
819 name_prefix = "isolate"; | 827 name_prefix = "isolate"; |
820 } | 828 } |
829 set_debugger_name(name_prefix); | |
821 if (ServiceIsolate::NameEquals(name_prefix)) { | 830 if (ServiceIsolate::NameEquals(name_prefix)) { |
822 name_ = strdup(name_prefix); | 831 name_ = strdup(name_prefix); |
823 return; | 832 return; |
824 } | 833 } |
825 const char* kFormat = "%s-%lld"; | 834 const char* kFormat = "%s-%lld"; |
826 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name_prefix, main_port()) + 1; | 835 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name_prefix, main_port()) + 1; |
827 name_ = reinterpret_cast<char*>(malloc(len)); | 836 name_ = reinterpret_cast<char*>(malloc(len)); |
828 OS::SNPrint(name_, len, kFormat, name_prefix, main_port()); | 837 OS::SNPrint(name_, len, kFormat, name_prefix, main_port()); |
829 } | 838 } |
830 | 839 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 // as 'load in progres'. Set the status to 'loaded'. | 931 // as 'load in progres'. Set the status to 'loaded'. |
923 if (lib.LoadInProgress()) { | 932 if (lib.LoadInProgress()) { |
924 lib.SetLoaded(); | 933 lib.SetLoaded(); |
925 } | 934 } |
926 } | 935 } |
927 } | 936 } |
928 | 937 |
929 | 938 |
930 bool Isolate::MakeRunnable() { | 939 bool Isolate::MakeRunnable() { |
931 ASSERT(Isolate::Current() == NULL); | 940 ASSERT(Isolate::Current() == NULL); |
941 | |
932 MutexLocker ml(mutex_); | 942 MutexLocker ml(mutex_); |
933 // Check if we are in a valid state to make the isolate runnable. | 943 // Check if we are in a valid state to make the isolate runnable. |
934 if (is_runnable_ == true) { | 944 if (is_runnable_ == true) { |
935 return false; // Already runnable. | 945 return false; // Already runnable. |
936 } | 946 } |
937 // Set the isolate as runnable and if we are being spawned schedule | 947 // Set the isolate as runnable and if we are being spawned schedule |
938 // isolate on thread pool for execution. | 948 // isolate on thread pool for execution. |
939 is_runnable_ = true; | 949 is_runnable_ = true; |
940 if (!ServiceIsolate::IsServiceIsolate(this)) { | 950 if (!ServiceIsolate::IsServiceIsolate(this)) { |
941 message_handler()->set_pause_on_start(FLAG_pause_isolates_on_start); | 951 message_handler()->set_pause_on_start(FLAG_pause_isolates_on_start); |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1528 void Isolate::PrintJSON(JSONStream* stream, bool ref) { | 1538 void Isolate::PrintJSON(JSONStream* stream, bool ref) { |
1529 JSONObject jsobj(stream); | 1539 JSONObject jsobj(stream); |
1530 jsobj.AddProperty("type", (ref ? "@Isolate" : "Isolate")); | 1540 jsobj.AddProperty("type", (ref ? "@Isolate" : "Isolate")); |
1531 jsobj.AddPropertyF("id", "isolates/%" Pd "", | 1541 jsobj.AddPropertyF("id", "isolates/%" Pd "", |
1532 static_cast<intptr_t>(main_port())); | 1542 static_cast<intptr_t>(main_port())); |
1533 jsobj.AddPropertyF("mainPort", "%" Pd "", | 1543 jsobj.AddPropertyF("mainPort", "%" Pd "", |
1534 static_cast<intptr_t>(main_port())); | 1544 static_cast<intptr_t>(main_port())); |
1535 | 1545 |
1536 // Assign an isolate name based on the entry function. | 1546 // Assign an isolate name based on the entry function. |
1537 IsolateSpawnState* state = spawn_state(); | 1547 IsolateSpawnState* state = spawn_state(); |
1538 if (state == NULL) { | 1548 jsobj.AddProperty("name", debugger_name()); |
1539 jsobj.AddPropertyF("name", "root"); | 1549 jsobj.AddPropertyF("number", "%" Pd "", |
Cutch
2015/03/18 20:05:48
This is the same as "mainPort" above. Consider dro
turnidge
2015/03/26 17:46:58
Dropped mainPort. Leaving number as-is for now af
| |
1540 } else if (state->class_name() != NULL) { | 1550 static_cast<intptr_t>(main_port())); |
1541 jsobj.AddPropertyF("name", "%s.%s", | |
1542 state->class_name(), | |
1543 state->function_name()); | |
1544 } else { | |
1545 jsobj.AddPropertyF("name", "%s", state->function_name()); | |
1546 } | |
1547 if (ref) { | 1551 if (ref) { |
1548 return; | 1552 return; |
1549 } | 1553 } |
1554 int64_t start_time_millis = start_time() / kMicrosecondsPerMillisecond; | |
1555 jsobj.AddProperty64("startTime", start_time_millis); | |
1550 if (state != NULL) { | 1556 if (state != NULL) { |
1551 const Object& entry = Object::Handle(this, state->ResolveFunction()); | 1557 const Object& entry = Object::Handle(this, state->ResolveFunction()); |
1552 if (!entry.IsNull() && entry.IsFunction()) { | 1558 if (!entry.IsNull() && entry.IsFunction()) { |
1553 Function& func = Function::Handle(this); | 1559 Function& func = Function::Handle(this); |
1554 func ^= entry.raw(); | 1560 func ^= entry.raw(); |
1555 jsobj.AddProperty("entry", func); | 1561 jsobj.AddProperty("entry", func); |
1556 } | 1562 } |
1557 } | 1563 } |
1558 { | 1564 { |
1559 JSONObject jsheap(&jsobj, "heaps"); | 1565 JSONObject jsheap(&jsobj, "heaps"); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1969 serialized_message_, serialized_message_len_); | 1975 serialized_message_, serialized_message_len_); |
1970 } | 1976 } |
1971 | 1977 |
1972 | 1978 |
1973 void IsolateSpawnState::Cleanup() { | 1979 void IsolateSpawnState::Cleanup() { |
1974 SwitchIsolateScope switch_scope(I); | 1980 SwitchIsolateScope switch_scope(I); |
1975 Dart::ShutdownIsolate(); | 1981 Dart::ShutdownIsolate(); |
1976 } | 1982 } |
1977 | 1983 |
1978 } // namespace dart | 1984 } // namespace dart |
OLD | NEW |