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 17 matching lines...) Expand all Loading... | |
28 #include "vm/reusable_handles.h" | 28 #include "vm/reusable_handles.h" |
29 #include "vm/service.h" | 29 #include "vm/service.h" |
30 #include "vm/service_event.h" | 30 #include "vm/service_event.h" |
31 #include "vm/service_isolate.h" | 31 #include "vm/service_isolate.h" |
32 #include "vm/simulator.h" | 32 #include "vm/simulator.h" |
33 #include "vm/stack_frame.h" | 33 #include "vm/stack_frame.h" |
34 #include "vm/stub_code.h" | 34 #include "vm/stub_code.h" |
35 #include "vm/symbols.h" | 35 #include "vm/symbols.h" |
36 #include "vm/tags.h" | 36 #include "vm/tags.h" |
37 #include "vm/thread_interrupter.h" | 37 #include "vm/thread_interrupter.h" |
38 #include "vm/timeline.h" | |
38 #include "vm/timer.h" | 39 #include "vm/timer.h" |
39 #include "vm/visitor.h" | 40 #include "vm/visitor.h" |
40 | 41 |
41 | 42 |
42 namespace dart { | 43 namespace dart { |
43 | 44 |
44 DEFINE_FLAG(bool, trace_isolates, false, | 45 DEFINE_FLAG(bool, trace_isolates, false, |
45 "Trace isolate creation and shut down."); | 46 "Trace isolate creation and shut down."); |
46 DEFINE_FLAG(bool, pause_isolates_on_start, false, | 47 DEFINE_FLAG(bool, pause_isolates_on_start, false, |
47 "Pause isolates before starting."); | 48 "Pause isolates before starting."); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 if (callback) { | 362 if (callback) { |
362 // Allow the embedder to handle message notification. | 363 // Allow the embedder to handle message notification. |
363 (*callback)(Api::CastIsolate(I)); | 364 (*callback)(Api::CastIsolate(I)); |
364 } | 365 } |
365 } | 366 } |
366 | 367 |
367 | 368 |
368 bool IsolateMessageHandler::HandleMessage(Message* message) { | 369 bool IsolateMessageHandler::HandleMessage(Message* message) { |
369 StackZone zone(I); | 370 StackZone zone(I); |
370 HandleScope handle_scope(I); | 371 HandleScope handle_scope(I); |
372 TimelineDurationScope tds(I, I->GetIsolateStream(), "HandleMessage"); | |
373 | |
371 // TODO(turnidge): Rework collection total dart execution. This can | 374 // TODO(turnidge): Rework collection total dart execution. This can |
372 // overcount when other things (gc, compilation) are active. | 375 // overcount when other things (gc, compilation) are active. |
373 TIMERSCOPE(isolate_, time_dart_execution); | 376 TIMERSCOPE(isolate_, time_dart_execution); |
374 | 377 |
375 // If the message is in band we lookup the handler to dispatch to. If the | 378 // If the message is in band we lookup the handler to dispatch to. If the |
376 // receive port was closed, we drop the message without deserializing it. | 379 // receive port was closed, we drop the message without deserializing it. |
377 // Illegal port is a special case for artificially enqueued isolate library | 380 // Illegal port is a special case for artificially enqueued isolate library |
378 // messages which are handled in C++ code below. | 381 // messages which are handled in C++ code below. |
379 Object& msg_handler = Object::Handle(I); | 382 Object& msg_handler = Object::Handle(I); |
380 if (!message->IsOOB() && (message->dest_port() != Message::kIllegalPort)) { | 383 if (!message->IsOOB() && (message->dest_port() != Message::kIllegalPort)) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 edge_counter_increment_size_(-1), | 658 edge_counter_increment_size_(-1), |
656 compiler_stats_(NULL), | 659 compiler_stats_(NULL), |
657 is_service_isolate_(false), | 660 is_service_isolate_(false), |
658 log_(new class Log()), | 661 log_(new class Log()), |
659 stacktrace_(NULL), | 662 stacktrace_(NULL), |
660 stack_frame_index_(-1), | 663 stack_frame_index_(-1), |
661 last_allocationprofile_accumulator_reset_timestamp_(0), | 664 last_allocationprofile_accumulator_reset_timestamp_(0), |
662 last_allocationprofile_gc_timestamp_(0), | 665 last_allocationprofile_gc_timestamp_(0), |
663 object_id_ring_(NULL), | 666 object_id_ring_(NULL), |
664 trace_buffer_(NULL), | 667 trace_buffer_(NULL), |
668 timeline_event_buffer_(NULL), | |
665 profiler_data_(NULL), | 669 profiler_data_(NULL), |
666 thread_state_(NULL), | 670 thread_state_(NULL), |
667 tag_table_(GrowableObjectArray::null()), | 671 tag_table_(GrowableObjectArray::null()), |
668 current_tag_(UserTag::null()), | 672 current_tag_(UserTag::null()), |
669 default_tag_(UserTag::null()), | 673 default_tag_(UserTag::null()), |
670 deoptimized_code_array_(GrowableObjectArray::null()), | 674 deoptimized_code_array_(GrowableObjectArray::null()), |
671 metrics_list_head_(NULL), | 675 metrics_list_head_(NULL), |
672 cha_(NULL), | 676 cha_(NULL), |
673 next_(NULL), | 677 next_(NULL), |
674 pause_loop_monitor_(NULL), | 678 pause_loop_monitor_(NULL), |
(...skipping 28 matching lines...) Expand all Loading... | |
703 delete log_; | 707 delete log_; |
704 log_ = NULL; | 708 log_ = NULL; |
705 delete object_id_ring_; | 709 delete object_id_ring_; |
706 object_id_ring_ = NULL; | 710 object_id_ring_ = NULL; |
707 delete pause_loop_monitor_; | 711 delete pause_loop_monitor_; |
708 pause_loop_monitor_ = NULL; | 712 pause_loop_monitor_ = NULL; |
709 if (compiler_stats_ != NULL) { | 713 if (compiler_stats_ != NULL) { |
710 delete compiler_stats_; | 714 delete compiler_stats_; |
711 compiler_stats_ = NULL; | 715 compiler_stats_ = NULL; |
712 } | 716 } |
717 RemoveTimelineEventBuffer(); | |
713 } | 718 } |
714 | 719 |
715 | 720 |
716 #if defined(DEBUG) | 721 #if defined(DEBUG) |
717 bool Isolate::IsIsolateOf(Thread* thread) { | 722 bool Isolate::IsIsolateOf(Thread* thread) { |
718 return this == thread->isolate(); | 723 return this == thread->isolate(); |
719 } | 724 } |
720 #endif // DEBUG | 725 #endif // DEBUG |
721 | 726 |
722 | 727 |
723 void Isolate::InitOnce() { | 728 void Isolate::InitOnce() { |
724 create_callback_ = NULL; | 729 create_callback_ = NULL; |
725 isolates_list_monitor_ = new Monitor(); | 730 isolates_list_monitor_ = new Monitor(); |
726 ASSERT(isolates_list_monitor_ != NULL); | 731 ASSERT(isolates_list_monitor_ != NULL); |
727 } | 732 } |
728 | 733 |
729 | 734 |
730 Isolate* Isolate::Init(const char* name_prefix, | 735 Isolate* Isolate::Init(const char* name_prefix, |
731 const Dart_IsolateFlags& api_flags, | 736 const Dart_IsolateFlags& api_flags, |
732 bool is_vm_isolate) { | 737 bool is_vm_isolate) { |
733 Isolate* result = new Isolate(api_flags); | 738 Isolate* result = new Isolate(api_flags); |
734 ASSERT(result != NULL); | 739 ASSERT(result != NULL); |
735 | 740 |
736 // Initialize metrics. | 741 // Initialize metrics. |
737 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \ | 742 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \ |
738 result->metric_##variable##_.Init(result, name, NULL, Metric::unit); | 743 result->metric_##variable##_.Init(result, name, NULL, Metric::unit); |
739 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); | 744 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); |
740 #undef ISOLATE_METRIC_INIT | 745 #undef ISOLATE_METRIC_INIT |
741 | 746 |
747 // Initialize Timeline streams. | |
748 #define ISOLATE_TIMELINE_STREAM_INIT(name, enabled_by_default) \ | |
749 result->stream_##name##_.Init(#name, enabled_by_default); | |
750 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_INIT); | |
751 #undef ISOLATE_TIMELINE_STREAM_INIT | |
752 | |
742 // TODO(5411455): For now just set the recently created isolate as | 753 // TODO(5411455): For now just set the recently created isolate as |
743 // the current isolate. | 754 // the current isolate. |
744 Thread::EnterIsolate(result); | 755 Thread::EnterIsolate(result); |
745 | 756 |
746 // Setup the isolate specific resuable handles. | 757 // Setup the isolate specific resuable handles. |
747 #define REUSABLE_HANDLE_ALLOCATION(object) \ | 758 #define REUSABLE_HANDLE_ALLOCATION(object) \ |
748 result->object##_handle_ = result->AllocateReusableHandle<object>(); | 759 result->object##_handle_ = result->AllocateReusableHandle<object>(); |
749 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) | 760 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) |
750 #undef REUSABLE_HANDLE_ALLOCATION | 761 #undef REUSABLE_HANDLE_ALLOCATION |
751 | 762 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 set_is_runnable(true); | 967 set_is_runnable(true); |
957 if (!ServiceIsolate::IsServiceIsolate(this)) { | 968 if (!ServiceIsolate::IsServiceIsolate(this)) { |
958 message_handler()->set_pause_on_start(FLAG_pause_isolates_on_start); | 969 message_handler()->set_pause_on_start(FLAG_pause_isolates_on_start); |
959 message_handler()->set_pause_on_exit(FLAG_pause_isolates_on_exit); | 970 message_handler()->set_pause_on_exit(FLAG_pause_isolates_on_exit); |
960 } | 971 } |
961 IsolateSpawnState* state = spawn_state(); | 972 IsolateSpawnState* state = spawn_state(); |
962 if (state != NULL) { | 973 if (state != NULL) { |
963 ASSERT(this == state->isolate()); | 974 ASSERT(this == state->isolate()); |
964 Run(); | 975 Run(); |
965 } | 976 } |
977 TimelineStream* stream = GetIsolateStream(); | |
978 ASSERT(stream != NULL); | |
979 TimelineEvent* event = stream->RecordEvent(); | |
980 if (event != NULL) { | |
981 event->Instant(stream, "Runnable"); | |
982 } | |
966 return true; | 983 return true; |
967 } | 984 } |
968 | 985 |
969 | 986 |
970 bool Isolate::VerifyPauseCapability(const Object& capability) const { | 987 bool Isolate::VerifyPauseCapability(const Object& capability) const { |
971 return !capability.IsNull() && | 988 return !capability.IsNull() && |
972 capability.IsCapability() && | 989 capability.IsCapability() && |
973 (pause_capability() == Capability::Cast(capability).Id()); | 990 (pause_capability() == Capability::Cast(capability).Id()); |
974 } | 991 } |
975 | 992 |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1445 api_state()->weak_persistent_handles().VisitHandles(&visitor); | 1462 api_state()->weak_persistent_handles().VisitHandles(&visitor); |
1446 api_state()->prologue_weak_persistent_handles().VisitHandles(&visitor); | 1463 api_state()->prologue_weak_persistent_handles().VisitHandles(&visitor); |
1447 | 1464 |
1448 if (FLAG_trace_isolates) { | 1465 if (FLAG_trace_isolates) { |
1449 heap()->PrintSizes(); | 1466 heap()->PrintSizes(); |
1450 megamorphic_cache_table()->PrintSizes(); | 1467 megamorphic_cache_table()->PrintSizes(); |
1451 Symbols::DumpStats(); | 1468 Symbols::DumpStats(); |
1452 OS::Print("[-] Stopping isolate:\n" | 1469 OS::Print("[-] Stopping isolate:\n" |
1453 "\tisolate: %s\n", name()); | 1470 "\tisolate: %s\n", name()); |
1454 } | 1471 } |
1472 | |
1473 if (timeline_event_buffer_ != NULL) { | |
rmacnak
2015/06/10 20:25:14
Behind a flag
Cutch
2015/06/10 21:20:57
This will be gone before I commit.
| |
1474 timeline_event_buffer_->Dump(); | |
1475 } | |
1455 } | 1476 } |
1456 | 1477 |
1457 // TODO(5411455): For now just make sure there are no current isolates | 1478 // TODO(5411455): For now just make sure there are no current isolates |
1458 // as we are shutting down the isolate. | 1479 // as we are shutting down the isolate. |
1459 Thread::ExitIsolate(); | 1480 Thread::ExitIsolate(); |
1460 Profiler::ShutdownProfilingForIsolate(this); | 1481 Profiler::ShutdownProfilingForIsolate(this); |
1461 } | 1482 } |
1462 | 1483 |
1463 | 1484 |
1464 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; | 1485 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1543 } | 1564 } |
1544 | 1565 |
1545 | 1566 |
1546 void Isolate::VisitPrologueWeakPersistentHandles(HandleVisitor* visitor) { | 1567 void Isolate::VisitPrologueWeakPersistentHandles(HandleVisitor* visitor) { |
1547 if (api_state() != NULL) { | 1568 if (api_state() != NULL) { |
1548 api_state()->VisitPrologueWeakHandles(visitor); | 1569 api_state()->VisitPrologueWeakHandles(visitor); |
1549 } | 1570 } |
1550 } | 1571 } |
1551 | 1572 |
1552 | 1573 |
1574 void Isolate::SetTimelineEventBuffer( | |
1575 TimelineEventBuffer* timeline_event_buffer) { | |
1576 #define ISOLATE_TIMELINE_STREAM_SET_BUFFER(name, enabled_by_default) \ | |
1577 stream_##name##_.set_buffer(timeline_event_buffer); | |
1578 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_SET_BUFFER) | |
1579 #undef ISOLATE_TIMELINE_STREAM_SET_BUFFER | |
1580 timeline_event_buffer_ = timeline_event_buffer; | |
1581 } | |
1582 | |
1583 void Isolate::RemoveTimelineEventBuffer() { | |
1584 SetTimelineEventBuffer(NULL); | |
1585 delete timeline_event_buffer_; | |
1586 } | |
1587 | |
1588 | |
1553 void Isolate::PrintJSON(JSONStream* stream, bool ref) { | 1589 void Isolate::PrintJSON(JSONStream* stream, bool ref) { |
1554 JSONObject jsobj(stream); | 1590 JSONObject jsobj(stream); |
1555 jsobj.AddProperty("type", (ref ? "@Isolate" : "Isolate")); | 1591 jsobj.AddProperty("type", (ref ? "@Isolate" : "Isolate")); |
1556 jsobj.AddFixedServiceId("isolates/%" Pd "", | 1592 jsobj.AddFixedServiceId("isolates/%" Pd "", |
1557 static_cast<intptr_t>(main_port())); | 1593 static_cast<intptr_t>(main_port())); |
1558 | 1594 |
1559 jsobj.AddProperty("name", debugger_name()); | 1595 jsobj.AddProperty("name", debugger_name()); |
1560 jsobj.AddPropertyF("number", "%" Pd "", | 1596 jsobj.AddPropertyF("number", "%" Pd "", |
1561 static_cast<intptr_t>(main_port())); | 1597 static_cast<intptr_t>(main_port())); |
1562 if (ref) { | 1598 if (ref) { |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2026 serialized_message_, serialized_message_len_); | 2062 serialized_message_, serialized_message_len_); |
2027 } | 2063 } |
2028 | 2064 |
2029 | 2065 |
2030 void IsolateSpawnState::Cleanup() { | 2066 void IsolateSpawnState::Cleanup() { |
2031 SwitchIsolateScope switch_scope(I); | 2067 SwitchIsolateScope switch_scope(I); |
2032 Dart::ShutdownIsolate(); | 2068 Dart::ShutdownIsolate(); |
2033 } | 2069 } |
2034 | 2070 |
2035 } // namespace dart | 2071 } // namespace dart |
OLD | NEW |