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, |
| 45 "Stop isolates from being destroyed automatically."); |
44 | 46 |
45 | 47 |
46 void Isolate::RegisterClass(const Class& cls) { | 48 void Isolate::RegisterClass(const Class& cls) { |
47 class_table()->Register(cls); | 49 class_table()->Register(cls); |
48 if (object_histogram() != NULL) object_histogram()->RegisterClass(cls); | 50 if (object_histogram() != NULL) object_histogram()->RegisterClass(cls); |
49 } | 51 } |
50 | 52 |
51 | 53 |
52 class IsolateMessageHandler : public MessageHandler { | 54 class IsolateMessageHandler : public MessageHandler { |
53 public: | 55 public: |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 277 |
276 | 278 |
277 #define REUSABLE_HANDLE_INITIALIZERS(object) \ | 279 #define REUSABLE_HANDLE_INITIALIZERS(object) \ |
278 object##_handle_(NULL), | 280 object##_handle_(NULL), |
279 | 281 |
280 Isolate::Isolate() | 282 Isolate::Isolate() |
281 : store_buffer_(), | 283 : store_buffer_(), |
282 message_notify_callback_(NULL), | 284 message_notify_callback_(NULL), |
283 name_(NULL), | 285 name_(NULL), |
284 start_time_(OS::GetCurrentTimeMicros()), | 286 start_time_(OS::GetCurrentTimeMicros()), |
| 287 pin_port_(0), |
285 main_port_(0), | 288 main_port_(0), |
286 heap_(NULL), | 289 heap_(NULL), |
287 object_store_(NULL), | 290 object_store_(NULL), |
288 top_context_(Context::null()), | 291 top_context_(Context::null()), |
289 top_exit_frame_info_(0), | 292 top_exit_frame_info_(0), |
290 init_callback_data_(NULL), | 293 init_callback_data_(NULL), |
291 environment_callback_(NULL), | 294 environment_callback_(NULL), |
292 library_tag_handler_(NULL), | 295 library_tag_handler_(NULL), |
293 api_state_(NULL), | 296 api_state_(NULL), |
294 stub_code_(NULL), | 297 stub_code_(NULL), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 ASSERT(state != NULL); | 417 ASSERT(state != NULL); |
415 result->set_api_state(state); | 418 result->set_api_state(state); |
416 | 419 |
417 // Initialize stack top and limit in case we are running the isolate in the | 420 // Initialize stack top and limit in case we are running the isolate in the |
418 // main thread. | 421 // main thread. |
419 // TODO(5411455): Need to figure out how to set the stack limit for the | 422 // TODO(5411455): Need to figure out how to set the stack limit for the |
420 // main thread. | 423 // main thread. |
421 result->SetStackLimitFromCurrentTOS(reinterpret_cast<uword>(&result)); | 424 result->SetStackLimitFromCurrentTOS(reinterpret_cast<uword>(&result)); |
422 result->set_main_port(PortMap::CreatePort(result->message_handler())); | 425 result->set_main_port(PortMap::CreatePort(result->message_handler())); |
423 result->BuildName(name_prefix); | 426 result->BuildName(name_prefix); |
| 427 if (FLAG_pin_isolates) { |
| 428 result->CreatePinPort(); |
| 429 } |
424 | 430 |
425 result->debugger_ = new Debugger(); | 431 result->debugger_ = new Debugger(); |
426 result->debugger_->Initialize(result); | 432 result->debugger_->Initialize(result); |
427 if (FLAG_trace_isolates) { | 433 if (FLAG_trace_isolates) { |
428 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { | 434 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { |
429 OS::Print("[+] Starting isolate:\n" | 435 OS::Print("[+] Starting isolate:\n" |
430 "\tisolate: %s\n", result->name()); | 436 "\tisolate: %s\n", result->name()); |
431 } | 437 } |
432 } | 438 } |
433 | 439 |
434 | 440 |
435 return result; | 441 return result; |
436 } | 442 } |
437 | 443 |
438 | 444 |
| 445 void Isolate::CreatePinPort() { |
| 446 ASSERT(FLAG_pin_isolates); |
| 447 // Only do this once. |
| 448 ASSERT(pin_port_ == 0); |
| 449 pin_port_ = PortMap::CreatePort(message_handler()); |
| 450 ASSERT(pin_port_ != 0); |
| 451 PortMap::SetLive(pin_port_); |
| 452 } |
| 453 |
| 454 |
| 455 void Isolate::ClosePinPort() { |
| 456 if (pin_port_ == 0) { |
| 457 // Support multiple calls to close. |
| 458 return; |
| 459 } |
| 460 ASSERT(pin_port_ != 0); |
| 461 bool r = PortMap::ClosePort(pin_port_); |
| 462 ASSERT(r); |
| 463 pin_port_ = 0; |
| 464 } |
| 465 |
| 466 |
439 void Isolate::BuildName(const char* name_prefix) { | 467 void Isolate::BuildName(const char* name_prefix) { |
440 ASSERT(name_ == NULL); | 468 ASSERT(name_ == NULL); |
441 if (name_prefix == NULL) { | 469 if (name_prefix == NULL) { |
442 name_prefix = "isolate"; | 470 name_prefix = "isolate"; |
443 } | 471 } |
444 const char* kFormat = "%s-%lld"; | 472 const char* kFormat = "%s-%lld"; |
445 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name_prefix, main_port()) + 1; | 473 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name_prefix, main_port()) + 1; |
446 name_ = new char[len]; | 474 name_ = new char[len]; |
447 OS::SNPrint(name_, len, kFormat, name_prefix, main_port()); | 475 OS::SNPrint(name_, len, kFormat, name_prefix, main_port()); |
448 } | 476 } |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 return func.raw(); | 1079 return func.raw(); |
1052 } | 1080 } |
1053 | 1081 |
1054 | 1082 |
1055 void IsolateSpawnState::Cleanup() { | 1083 void IsolateSpawnState::Cleanup() { |
1056 SwitchIsolateScope switch_scope(isolate()); | 1084 SwitchIsolateScope switch_scope(isolate()); |
1057 Dart::ShutdownIsolate(); | 1085 Dart::ShutdownIsolate(); |
1058 } | 1086 } |
1059 | 1087 |
1060 } // namespace dart | 1088 } // namespace dart |
OLD | NEW |