26 ASSERT(handler !=
nullptr);
30 ASSERT(handler_ !=
nullptr);
31 handler_->TaskCallback();
58 oob_message_handling_allowed_(
true),
59 paused_for_messages_(
false),
62 should_pause_on_start_(
false),
63 should_pause_on_exit_(
false),
64 is_paused_on_start_(
false),
65 is_paused_on_exit_(
false),
66 remembered_paused_on_exit_status_(kOK),
67 paused_timestamp_(-1),
72 start_callback_(nullptr),
73 end_callback_(nullptr),
76 ASSERT(oob_queue_ !=
nullptr);
92void MessageHandler::CheckAccess()
const {
102 StartCallback start_callback,
103 EndCallback end_callback,
106 if (FLAG_trace_isolates) {
108 "[+] Starting message handler:\n"
115 start_callback_ = start_callback;
116 end_callback_ = end_callback;
117 callback_data_ =
data;
118 task_running_ =
true;
122 start_callback_ =
nullptr;
123 end_callback_ =
nullptr;
125 task_running_ =
false;
131 bool before_events) {
136 if (FLAG_trace_isolates) {
138 if (source_isolate !=
nullptr) {
140 "[>] Posting message:\n"
141 "\tlen: %" Pd "\n\tsource: (%" Pd64
143 "\tdest_port: %" Pd64 "\n",
148 "[>] Posting message:\n"
150 "\n\tsource: <native code>\n"
152 "\tdest_port: %" Pd64 "\n",
157 saved_priority =
message->priority();
163 if (paused_for_messages_) {
167 if (pool_ !=
nullptr && !task_running_) {
169 task_running_ =
true;
171 ASSERT(launched_successfully);
179std::unique_ptr<Message> MessageHandler::DequeueMessage(
189void MessageHandler::ClearOOBQueue() {
195 bool allow_normal_messages,
196 bool allow_multiple_normal_messages) {
207 StartIsolateScope start_isolate(
isolate());
210 auto idle_time_handler =
217 std::unique_ptr<Message>
message = DequeueMessage(min_priority);
219 intptr_t message_len =
message->Size();
220 if (FLAG_trace_isolates) {
222 "[<] Handling message:\n"
226 "\tport: %" Pd64 "\n",
237 DisableIdleTimerScope disable_idle_timer(idle_time_handler);
240 if (status > max_status) {
244 if (FLAG_trace_isolates) {
246 "[.] Message handled (%s):\n"
250 "\tport: %" Pd64 "\n",
261 if ((FLAG_idle_timeout_micros != 0) &&
263 if (idle_time_handler !=
nullptr) {
264 idle_time_handler->UpdateStartIdleTime();
271 !allow_multiple_normal_messages) {
273 allow_normal_messages =
false;
282 min_priority = (((max_status ==
kOK) && allow_normal_messages && !
paused())
285 message = DequeueMessage(min_priority);
299 return HandleMessages(&ml,
true,
false);
303 int64_t timeout_millis) {
310 paused_for_messages_ =
true;
317 wr = ml.
Wait(timeout_millis);
329 paused_for_messages_ =
false;
334 paused_for_messages_ =
false;
335 return HandleMessages(&ml,
true,
true);
339 if (!oob_message_handling_allowed_) {
347 return HandleMessages(&ml,
false,
false);
353 if (owning_isolate ==
nullptr) {
364 if (owning_isolate ==
nullptr) {
378std::unique_ptr<Message> MessageHandler::StealOOBMessage() {
390void MessageHandler::TaskCallback() {
393 bool run_end_callback =
false;
394 bool delete_me =
false;
412 PausedOnStartLocked(&ml,
true);
415 status = HandleMessages(&ml,
false,
false);
419 task_running_ =
false;
422 PausedOnStartLocked(&ml,
false);
426 status = HandleMessages(&ml,
false,
false);
430 task_running_ =
false;
433 PausedOnExitLocked(&ml,
false);
435 status = remembered_paused_on_exit_status_;
442 if (start_callback_ !=
nullptr) {
449 status = start_callback_(callback_data_);
451 start_callback_ =
nullptr;
457 status = HandleMessages(&ml, (status ==
kOK),
true);
466 if (FLAG_trace_service_pause_events) {
468 "Isolate %s paused before exiting. "
469 "Use the Observatory to release it.\n",
472 remembered_paused_on_exit_status_ = status;
473 PausedOnExitLocked(&ml,
true);
475 status = HandleMessages(&ml,
false,
480 task_running_ =
false;
483 PausedOnExitLocked(&ml,
false);
487 if (FLAG_trace_isolates) {
488 if (status !=
kOK &&
thread() !=
nullptr) {
491 "[-] Stopping message handler (%s):\n"
497 "[-] Stopping message handler (%s):\n"
504 end_callback = end_callback_;
505 callback_data = callback_data_;
506 run_end_callback = end_callback_ !=
nullptr;
507 delete_me = delete_me_;
513 task_running_ =
false;
520 ASSERT(!delete_me || !run_end_callback);
522 if (run_end_callback) {
523 ASSERT(end_callback !=
nullptr);
524 end_callback(callback_data);
533 if (FLAG_trace_isolates) {
536 "[-] Closing port:\n"
538 "\tport: %" Pd64 "\n",
545 if (FLAG_trace_isolates) {
547 "[-] Closing all ports:\n"
576 PausedOnStartLocked(&ml,
paused);
579void MessageHandler::PausedOnStartLocked(
MonitorLocker* ml,
bool paused) {
581 ASSERT(!is_paused_on_start_);
582 ASSERT(paused_timestamp_ == -1);
591 is_paused_on_start_ =
true;
593 ASSERT(is_paused_on_start_);
594 ASSERT(paused_timestamp_ != -1);
595 paused_timestamp_ = -1;
597 Isolate* owning_isolate =
isolate();
598 if (owning_isolate !=
nullptr) {
599 owning_isolate->GetAndClearResumeRequest();
601 is_paused_on_start_ =
false;
607 PausedOnExitLocked(&ml,
paused);
610void MessageHandler::PausedOnExitLocked(
MonitorLocker* ml,
bool paused) {
612 ASSERT(!is_paused_on_exit_);
613 ASSERT(paused_timestamp_ == -1);
622 is_paused_on_exit_ =
true;
624 ASSERT(is_paused_on_exit_);
625 ASSERT(paused_timestamp_ != -1);
626 paused_timestamp_ = -1;
628 Isolate* owning_isolate =
isolate();
629 if (owning_isolate !=
nullptr) {
630 owning_isolate->GetAndClearResumeRequest();
632 is_paused_on_exit_ =
false;
638 : handler_(handler), ml_(&handler->monitor_) {
639 ASSERT(handler !=
nullptr);
640 handler_->oob_message_handling_allowed_ =
false;
644 ASSERT(handler_ !=
nullptr);
645 handler_->oob_message_handling_allowed_ =
true;
IdleTimeHandler * idle_time_handler()
static Isolate * Current()
IsolateGroup * group() const
Dart_Port main_port() const
const char * name() const
MessageHandlerTask(MessageHandler *handler)
AcquiredQueues(MessageHandler *handler)
void PausedOnStart(bool paused)
virtual bool KeepAliveLocked()
void PostMessage(std::unique_ptr< Message > message, bool before_events=false)
void(* EndCallback)(CallbackData data)
void PausedOnExit(bool paused)
virtual void NotifyPauseOnExit()
virtual const char * name() const
bool ShouldPauseOnStart(MessageStatus status) const
static const char * MessageStatusString(MessageStatus status)
bool Run(ThreadPool *pool, StartCallback start_callback, EndCallback end_callback, CallbackData data)
bool is_paused_on_start() const
virtual Isolate * isolate() const
virtual void NotifyPauseOnStart()
void ClosePort(Dart_Port port)
virtual ~MessageHandler()
MessageStatus HandleNextMessage()
MessageStatus PauseAndHandleAllMessages(int64_t timeout_millis)
bool ShouldPauseOnExit(MessageStatus status) const
bool is_paused_on_exit() const
MessageStatus HandleOOBMessages()
bool should_pause_on_start() const
virtual MessageStatus HandleMessage(std::unique_ptr< Message > message)=0
bool should_pause_on_exit() const
virtual void MessageNotify(Message::Priority priority)
void Enqueue(std::unique_ptr< Message > msg, bool before_events)
std::unique_ptr< Message > Dequeue()
Monitor::WaitResult Wait(int64_t millis=Monitor::kNoTimeout)
bool IsOwnedByCurrentThread() const
static int64_t GetCurrentTimeMillis()
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static void DebugDumpForMessageHandler(MessageHandler *handler)
bool Run(Args &&... args)
static Thread * Current()
const uint8_t uint32_t uint32_t GError ** error
static int8_t data[kExtLength]
DECLARE_FLAG(bool, show_invisible_frames)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port