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