| 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 "lib/mirrors.h" | 10 #include "lib/mirrors.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "vm/timer.h" | 34 #include "vm/timer.h" |
| 35 #include "vm/visitor.h" | 35 #include "vm/visitor.h" |
| 36 | 36 |
| 37 | 37 |
| 38 namespace dart { | 38 namespace dart { |
| 39 | 39 |
| 40 DEFINE_FLAG(bool, report_usage_count, false, | 40 DEFINE_FLAG(bool, report_usage_count, false, |
| 41 "Track function usage and report."); | 41 "Track function usage and report."); |
| 42 DEFINE_FLAG(bool, trace_isolates, false, | 42 DEFINE_FLAG(bool, trace_isolates, false, |
| 43 "Trace isolate creation and shut down."); | 43 "Trace isolate creation and shut down."); |
| 44 DEFINE_FLAG(bool, pin_isolates, false, | 44 DEFINE_FLAG(bool, pause_isolates_on_start, false, |
| 45 "Stop isolates from being destroyed automatically."); | 45 "Pause isolates before starting."); |
| 46 DEFINE_FLAG(bool, pause_isolates_on_exit, false, |
| 47 "Pause isolates exiting."); |
| 46 | 48 |
| 47 | 49 |
| 48 void Isolate::RegisterClass(const Class& cls) { | 50 void Isolate::RegisterClass(const Class& cls) { |
| 49 class_table()->Register(cls); | 51 class_table()->Register(cls); |
| 50 } | 52 } |
| 51 | 53 |
| 52 | 54 |
| 53 void Isolate::RegisterClassAt(intptr_t index, const Class& cls) { | 55 void Isolate::RegisterClassAt(intptr_t index, const Class& cls) { |
| 54 class_table()->RegisterAt(index, cls); | 56 class_table()->RegisterAt(index, cls); |
| 55 } | 57 } |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 #endif // defined(DEBUG) | 294 #endif // defined(DEBUG) |
| 293 | 295 |
| 294 #define REUSABLE_HANDLE_INITIALIZERS(object) \ | 296 #define REUSABLE_HANDLE_INITIALIZERS(object) \ |
| 295 object##_handle_(NULL), | 297 object##_handle_(NULL), |
| 296 | 298 |
| 297 Isolate::Isolate() | 299 Isolate::Isolate() |
| 298 : store_buffer_(), | 300 : store_buffer_(), |
| 299 message_notify_callback_(NULL), | 301 message_notify_callback_(NULL), |
| 300 name_(NULL), | 302 name_(NULL), |
| 301 start_time_(OS::GetCurrentTimeMicros()), | 303 start_time_(OS::GetCurrentTimeMicros()), |
| 302 pin_port_(0), | |
| 303 main_port_(0), | 304 main_port_(0), |
| 304 heap_(NULL), | 305 heap_(NULL), |
| 305 object_store_(NULL), | 306 object_store_(NULL), |
| 306 top_context_(Context::null()), | 307 top_context_(Context::null()), |
| 307 top_exit_frame_info_(0), | 308 top_exit_frame_info_(0), |
| 308 init_callback_data_(NULL), | 309 init_callback_data_(NULL), |
| 309 environment_callback_(NULL), | 310 environment_callback_(NULL), |
| 310 library_tag_handler_(NULL), | 311 library_tag_handler_(NULL), |
| 311 api_state_(NULL), | 312 api_state_(NULL), |
| 312 stub_code_(NULL), | 313 stub_code_(NULL), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 ASSERT(state != NULL); | 430 ASSERT(state != NULL); |
| 430 result->set_api_state(state); | 431 result->set_api_state(state); |
| 431 | 432 |
| 432 // Initialize stack top and limit in case we are running the isolate in the | 433 // Initialize stack top and limit in case we are running the isolate in the |
| 433 // main thread. | 434 // main thread. |
| 434 // TODO(5411455): Need to figure out how to set the stack limit for the | 435 // TODO(5411455): Need to figure out how to set the stack limit for the |
| 435 // main thread. | 436 // main thread. |
| 436 result->SetStackLimitFromCurrentTOS(reinterpret_cast<uword>(&result)); | 437 result->SetStackLimitFromCurrentTOS(reinterpret_cast<uword>(&result)); |
| 437 result->set_main_port(PortMap::CreatePort(result->message_handler())); | 438 result->set_main_port(PortMap::CreatePort(result->message_handler())); |
| 438 result->BuildName(name_prefix); | 439 result->BuildName(name_prefix); |
| 439 if (FLAG_pin_isolates) { | 440 result->message_handler()->set_pause_on_start(FLAG_pause_isolates_on_start); |
| 440 result->CreatePinPort(); | 441 result->message_handler()->set_pause_on_exit(FLAG_pause_isolates_on_exit); |
| 441 } | |
| 442 | 442 |
| 443 result->debugger_ = new Debugger(); | 443 result->debugger_ = new Debugger(); |
| 444 result->debugger_->Initialize(result); | 444 result->debugger_->Initialize(result); |
| 445 if (FLAG_trace_isolates) { | 445 if (FLAG_trace_isolates) { |
| 446 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { | 446 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { |
| 447 OS::Print("[+] Starting isolate:\n" | 447 OS::Print("[+] Starting isolate:\n" |
| 448 "\tisolate: %s\n", result->name()); | 448 "\tisolate: %s\n", result->name()); |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 | 451 |
| 452 | 452 |
| 453 return result; | 453 return result; |
| 454 } | 454 } |
| 455 | 455 |
| 456 | 456 |
| 457 void Isolate::CreatePinPort() { | |
| 458 ASSERT(FLAG_pin_isolates); | |
| 459 // Only do this once. | |
| 460 ASSERT(pin_port_ == 0); | |
| 461 pin_port_ = PortMap::CreatePort(message_handler()); | |
| 462 ASSERT(pin_port_ != 0); | |
| 463 PortMap::SetLive(pin_port_); | |
| 464 } | |
| 465 | |
| 466 | |
| 467 void Isolate::ClosePinPort() { | |
| 468 if (pin_port_ == 0) { | |
| 469 // Support multiple calls to close. | |
| 470 return; | |
| 471 } | |
| 472 ASSERT(pin_port_ != 0); | |
| 473 bool r = PortMap::ClosePort(pin_port_); | |
| 474 ASSERT(r); | |
| 475 pin_port_ = 0; | |
| 476 } | |
| 477 | |
| 478 | |
| 479 void Isolate::BuildName(const char* name_prefix) { | 457 void Isolate::BuildName(const char* name_prefix) { |
| 480 ASSERT(name_ == NULL); | 458 ASSERT(name_ == NULL); |
| 481 if (name_prefix == NULL) { | 459 if (name_prefix == NULL) { |
| 482 name_prefix = "isolate"; | 460 name_prefix = "isolate"; |
| 483 } | 461 } |
| 484 const char* kFormat = "%s-%lld"; | 462 const char* kFormat = "%s-%lld"; |
| 485 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name_prefix, main_port()) + 1; | 463 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name_prefix, main_port()) + 1; |
| 486 name_ = new char[len]; | 464 name_ = new char[len]; |
| 487 OS::SNPrint(name_, len, kFormat, name_prefix, main_port()); | 465 OS::SNPrint(name_, len, kFormat, name_prefix, main_port()); |
| 488 } | 466 } |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 DebuggerStackTrace* stack = debugger()->StackTrace(); | 887 DebuggerStackTrace* stack = debugger()->StackTrace(); |
| 910 if (stack->Length() > 0) { | 888 if (stack->Length() > 0) { |
| 911 JSONObject jsframe(&jsobj, "topFrame"); | 889 JSONObject jsframe(&jsobj, "topFrame"); |
| 912 | 890 |
| 913 ActivationFrame* frame = stack->FrameAt(0); | 891 ActivationFrame* frame = stack->FrameAt(0); |
| 914 frame->PrintToJSONObject(&jsobj); | 892 frame->PrintToJSONObject(&jsobj); |
| 915 // TODO(turnidge): Implement depth differently -- differentiate | 893 // TODO(turnidge): Implement depth differently -- differentiate |
| 916 // inlined frames. | 894 // inlined frames. |
| 917 jsobj.AddProperty("depth", (intptr_t)0); | 895 jsobj.AddProperty("depth", (intptr_t)0); |
| 918 } | 896 } |
| 919 | 897 intptr_t live_ports = message_handler()->live_ports(); |
| 898 intptr_t control_ports = message_handler()->control_ports(); |
| 899 bool paused_on_exit = message_handler()->paused_on_exit(); |
| 900 bool pause_on_start = message_handler()->pause_on_start(); |
| 901 bool pause_on_exit = message_handler()->pause_on_exit(); |
| 902 jsobj.AddProperty("live_ports", live_ports); |
| 903 jsobj.AddProperty("control_ports", control_ports); |
| 904 jsobj.AddProperty("paused_on_exit", paused_on_exit); |
| 905 jsobj.AddProperty("paused_on_start", pause_on_start); |
| 906 jsobj.AddProperty("pause_on_exit", pause_on_exit); |
| 920 const Library& lib = | 907 const Library& lib = |
| 921 Library::Handle(object_store()->root_library()); | 908 Library::Handle(object_store()->root_library()); |
| 922 jsobj.AddProperty("rootLib", lib); | 909 jsobj.AddProperty("rootLib", lib); |
| 923 | 910 |
| 924 timer_list().PrintTimersToJSONProperty(&jsobj); | 911 timer_list().PrintTimersToJSONProperty(&jsobj); |
| 925 } | 912 } |
| 926 | 913 |
| 927 | 914 |
| 928 void Isolate::VisitIsolates(IsolateVisitor* visitor) { | 915 void Isolate::VisitIsolates(IsolateVisitor* visitor) { |
| 929 if (visitor == NULL) { | 916 if (visitor == NULL) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 return func.raw(); | 1074 return func.raw(); |
| 1088 } | 1075 } |
| 1089 | 1076 |
| 1090 | 1077 |
| 1091 void IsolateSpawnState::Cleanup() { | 1078 void IsolateSpawnState::Cleanup() { |
| 1092 SwitchIsolateScope switch_scope(isolate()); | 1079 SwitchIsolateScope switch_scope(isolate()); |
| 1093 Dart::ShutdownIsolate(); | 1080 Dart::ShutdownIsolate(); |
| 1094 } | 1081 } |
| 1095 | 1082 |
| 1096 } // namespace dart | 1083 } // namespace dart |
| OLD | NEW |