Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::IsolateMessageHandler Class Reference
Inheritance diagram for dart::IsolateMessageHandler:
dart::MessageHandler

Public Member Functions

 IsolateMessageHandler (Isolate *isolate)
 
 ~IsolateMessageHandler ()
 
const char * name () const
 
void MessageNotify (Message::Priority priority)
 
MessageStatus HandleMessage (std::unique_ptr< Message > message)
 
void NotifyPauseOnStart ()
 
void NotifyPauseOnExit ()
 
bool IsCurrentIsolate () const
 
virtual Isolateisolate () const
 
virtual IsolateGroupisolate_group () const
 
virtual bool KeepAliveLocked ()
 
- Public Member Functions inherited from dart::MessageHandler
virtual ~MessageHandler ()
 
virtual const char * name () const
 
bool Run (ThreadPool *pool, StartCallback start_callback, EndCallback end_callback, CallbackData data)
 
MessageStatus HandleNextMessage ()
 
MessageStatus HandleOOBMessages ()
 
MessageStatus PauseAndHandleAllMessages (int64_t timeout_millis)
 
bool HasOOBMessages ()
 
bool HasMessages ()
 
virtual bool KeepAliveLocked ()
 
void RequestDeletion ()
 
bool paused () const
 
void increment_paused ()
 
void decrement_paused ()
 
void DebugDump ()
 
bool should_pause_on_start () const
 
void set_should_pause_on_start (bool should_pause_on_start)
 
bool is_paused_on_start () const
 
bool should_pause_on_exit () const
 
void set_should_pause_on_exit (bool should_pause_on_exit)
 
bool is_paused_on_exit () const
 
int64_t paused_timestamp () const
 
bool ShouldPauseOnStart (MessageStatus status) const
 
bool ShouldPauseOnExit (MessageStatus status) const
 
void PausedOnStart (bool paused)
 
void PausedOnExit (bool paused)
 

Additional Inherited Members

- Public Types inherited from dart::MessageHandler
enum  MessageStatus { kOK , kError , kShutdown }
 
typedef uword CallbackData
 
typedef MessageStatus(* StartCallback) (CallbackData data)
 
typedef void(* EndCallback) (CallbackData data)
 
- Static Public Member Functions inherited from dart::MessageHandler
static const char * MessageStatusString (MessageStatus status)
 
- Protected Member Functions inherited from dart::MessageHandler
 MessageHandler ()
 
virtual bool IsCurrentIsolate () const
 
virtual Isolateisolate () const
 
void PostMessage (std::unique_ptr< Message > message, bool before_events=false)
 
void ClosePort (Dart_Port port)
 
void CloseAllPorts ()
 
virtual void MessageNotify (Message::Priority priority)
 
virtual MessageStatus HandleMessage (std::unique_ptr< Message > message)=0
 
virtual void NotifyPauseOnStart ()
 
virtual void NotifyPauseOnExit ()
 
Threadthread () const
 

Detailed Description

Definition at line 1076 of file isolate.cc.

Constructor & Destructor Documentation

◆ IsolateMessageHandler()

dart::IsolateMessageHandler::IsolateMessageHandler ( Isolate isolate)
explicit

Definition at line 1114 of file isolate.cc.

1115 : isolate_(isolate) {}
virtual Isolate * isolate() const
Definition: isolate.cc:1094

◆ ~IsolateMessageHandler()

dart::IsolateMessageHandler::~IsolateMessageHandler ( )

Definition at line 1117 of file isolate.cc.

1117{}

Member Function Documentation

◆ HandleMessage()

MessageHandler::MessageStatus dart::IsolateMessageHandler::HandleMessage ( std::unique_ptr< Message message)
virtual

Implements dart::MessageHandler.

Definition at line 1360 of file isolate.cc.

1361 {
1363 Thread* thread = Thread::Current();
1364 StackZone stack_zone(thread);
1365 Zone* zone = stack_zone.GetZone();
1366 HandleScope handle_scope(thread);
1367#if defined(SUPPORT_TIMELINE)
1368 TimelineBeginEndScope tbes(
1369 thread, Timeline::GetIsolateStream(),
1370 message->IsOOB() ? "HandleOOBMessage" : "HandleMessage");
1371 tbes.SetNumArguments(1);
1372 tbes.CopyArgument(0, "isolateName", I->name());
1373#endif
1374
1375 // Parse the message.
1376 Object& msg_obj = Object::Handle(zone, ReadMessage(thread, message.get()));
1377 if (msg_obj.IsError()) {
1378 // An error occurred while reading the message.
1379 return ProcessUnhandledException(Error::Cast(msg_obj));
1380 }
1381 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) {
1382 // TODO(turnidge): We need to decide what an isolate does with
1383 // malformed messages. If they (eventually) come from a remote
1384 // machine, then it might make sense to drop the message entirely.
1385 // In the case that the message originated locally, which is
1386 // always true for now, then this should never occur.
1387 UNREACHABLE();
1388 }
1389 Instance& msg = Instance::Handle(zone);
1390 msg ^= msg_obj.ptr(); // Can't use Instance::Cast because may be null.
1391
1392 MessageStatus status = kOK;
1393 if (message->IsOOB()) {
1394 // OOB messages are expected to be fixed length arrays where the first
1395 // element is a Smi describing the OOB destination. Messages that do not
1396 // confirm to this layout are silently ignored.
1397 if (msg.IsArray()) {
1398 const Array& oob_msg = Array::Cast(msg);
1399 if (oob_msg.Length() > 0) {
1400 const Object& oob_tag = Object::Handle(zone, oob_msg.At(0));
1401 if (oob_tag.IsSmi()) {
1402 switch (Smi::Cast(oob_tag).Value()) {
1404#ifndef PRODUCT
1405 const Error& error =
1407 if (!error.IsNull()) {
1408 status = ProcessUnhandledException(error);
1409 }
1410#else
1411 UNREACHABLE();
1412#endif
1413 break;
1414 }
1416 const Error& error = Error::Handle(HandleLibMessage(oob_msg));
1417 if (!error.IsNull()) {
1418 status = ProcessUnhandledException(error);
1419 }
1420 break;
1421 }
1422#if defined(DEBUG)
1423 // Malformed OOB messages are silently ignored in release builds.
1424 default: {
1425 UNREACHABLE();
1426 break;
1427 }
1428#endif // defined(DEBUG)
1429 }
1430 }
1431 }
1432 }
1433 } else if (message->IsFinalizerInvocationRequest()) {
1434 const Object& msg_handler = Object::Handle(
1435 zone,
1436 DartLibraryCalls::HandleFinalizerMessage(FinalizerBase::Cast(msg)));
1437 if (msg_handler.IsError()) {
1438 status = ProcessUnhandledException(Error::Cast(msg_handler));
1439 } else {
1440 // The handler closure which was used to successfully handle the message.
1441 }
1442 } else if (message->dest_port() == Message::kIllegalPort) {
1443 // Check whether this is a delayed OOB message which needed handling as
1444 // part of the regular message dispatch. All other messages are dropped on
1445 // the floor.
1446 if (msg.IsArray()) {
1447 const Array& msg_arr = Array::Cast(msg);
1448 if (msg_arr.Length() > 0) {
1449 const Object& oob_tag = Object::Handle(zone, msg_arr.At(0));
1450 if (oob_tag.IsSmi() &&
1451 (Smi::Cast(oob_tag).Value() == Message::kDelayedIsolateLibOOBMsg)) {
1452 const Error& error = Error::Handle(HandleLibMessage(msg_arr));
1453 if (!error.IsNull()) {
1454 status = ProcessUnhandledException(error);
1455 }
1456 }
1457 }
1458 }
1459 } else {
1460 const Object& msg_handler = Object::Handle(
1461 zone, DartLibraryCalls::HandleMessage(message->dest_port(), msg));
1462 if (msg_handler.IsError()) {
1463 status = ProcessUnhandledException(Error::Cast(msg_handler));
1464 } else if (msg_handler.IsNull()) {
1465 // If the port has been closed then the message will be dropped at this
1466 // point. Make sure to post to the delivery failure port in that case.
1467 } else {
1468 // The handler closure which was used to successfully handle the message.
1469 }
1470 }
1471 return status;
1472}
#define UNREACHABLE()
Definition: assert.h:248
static ObjectPtr HandleMessage(Dart_Port port_id, const Instance &message)
Definition: dart_entry.cc:701
static ObjectPtr HandleFinalizerMessage(const FinalizerBase &finalizer)
Definition: dart_entry.cc:721
bool IsCurrentIsolate() const
Definition: isolate.cc:1514
Thread * thread() const
@ kServiceOOBMsg
Definition: message.h:41
@ kDelayedIsolateLibOOBMsg
Definition: message.h:43
@ kIsolateLibOOBMsg
Definition: message.h:42
static const Dart_Port kIllegalPort
Definition: message.h:47
static Object & Handle()
Definition: object.h:407
static ErrorPtr HandleIsolateMessage(Isolate *isolate, const Array &message)
Definition: service.cc:1069
static Thread * Current()
Definition: thread.h:362
#define ASSERT(E)
const uint8_t uint32_t uint32_t GError ** error
Win32Message message
ObjectPtr ReadMessage(Thread *thread, Message *message)
Definition: SkMD5.cpp:134

◆ IsCurrentIsolate()

bool dart::IsolateMessageHandler::IsCurrentIsolate ( ) const
virtual

Reimplemented from dart::MessageHandler.

Definition at line 1514 of file isolate.cc.

1514 {
1515 return (I == Isolate::Current());
1516}
static Isolate * Current()
Definition: isolate.h:986

◆ isolate()

virtual Isolate * dart::IsolateMessageHandler::isolate ( ) const
inlinevirtual

Reimplemented from dart::MessageHandler.

Definition at line 1094 of file isolate.cc.

1094{ return isolate_; }

◆ isolate_group()

virtual IsolateGroup * dart::IsolateMessageHandler::isolate_group ( ) const
inlinevirtual

Definition at line 1095 of file isolate.cc.

1095{ return isolate_->group(); }
IsolateGroup * group() const
Definition: isolate.h:1037

◆ KeepAliveLocked()

virtual bool dart::IsolateMessageHandler::KeepAliveLocked ( )
inlinevirtual

Reimplemented from dart::MessageHandler.

Definition at line 1097 of file isolate.cc.

1097 {
1098 // If the message handler was asked to shutdown we shut down.
1099 if (!MessageHandler::KeepAliveLocked()) return false;
1100 // Otherwise we only stay alive as long as there's active receive ports, or
1101 // there are FFI callbacks keeping the isolate alive.
1102 return isolate_->HasLivePorts() || isolate_->HasOpenNativeCallables();
1103 }
bool HasLivePorts()
Definition: isolate.cc:3752
bool HasOpenNativeCallables()
Definition: isolate.cc:3811
virtual bool KeepAliveLocked()

◆ MessageNotify()

void dart::IsolateMessageHandler::MessageNotify ( Message::Priority  priority)
virtual

Reimplemented from dart::MessageHandler.

Definition at line 1344 of file isolate.cc.

1344 {
1345 if (priority >= Message::kOOBPriority) {
1346 // Handle out of band messages even if the mutator thread is busy.
1347 I->ScheduleInterrupts(Thread::kMessageInterrupt);
1348 }
1349 Dart_MessageNotifyCallback callback = I->message_notify_callback();
1350 if (callback != nullptr) {
1351 // Allow the embedder to handle message notification.
1352 (*callback)(Api::CastIsolate(I));
1353 }
1354}
static Dart_Isolate CastIsolate(Isolate *isolate)
@ kOOBPriority
Definition: message.h:29
@ kMessageInterrupt
Definition: thread.h:489
void(* Dart_MessageNotifyCallback)(Dart_Isolate destination_isolate)
Definition: dart_api.h:1546
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ name()

const char * dart::IsolateMessageHandler::name ( ) const
virtual

Reimplemented from dart::MessageHandler.

Definition at line 1119 of file isolate.cc.

1119 {
1120 return isolate_->name();
1121}
const char * name() const
Definition: isolate.h:1043

◆ NotifyPauseOnExit()

void dart::IsolateMessageHandler::NotifyPauseOnExit ( )
virtual

Reimplemented from dart::MessageHandler.

Definition at line 1491 of file isolate.cc.

1491 {
1493 return;
1494 }
1495 if (Service::debug_stream.enabled() || FLAG_warn_on_pause_with_no_debugger) {
1496 StartIsolateScope start_isolate(I);
1497 StackZone zone(T);
1498 HandleScope handle_scope(T);
1499 ServiceEvent pause_event(I, ServiceEvent::kPauseExit);
1500 Service::HandleEvent(&pause_event);
1501 } else if (FLAG_trace_service) {
1502 OS::PrintErr("vm-service: Dropping event of type PauseExit (%s)\n",
1503 I->name());
1504 }
1505}
static bool IsSystemIsolate(const Isolate *isolate)
Definition: isolate.h:1445
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static void HandleEvent(ServiceEvent *event, bool enter_safepoint=true)
Definition: service.cc:1206
static StreamInfo debug_stream
Definition: service.h:181
#define T
Definition: isolate.cc:102

◆ NotifyPauseOnStart()

void dart::IsolateMessageHandler::NotifyPauseOnStart ( )
virtual

Reimplemented from dart::MessageHandler.

Definition at line 1475 of file isolate.cc.

1475 {
1477 return;
1478 }
1479 if (Service::debug_stream.enabled() || FLAG_warn_on_pause_with_no_debugger) {
1480 StartIsolateScope start_isolate(I);
1481 StackZone zone(T);
1482 HandleScope handle_scope(T);
1483 ServiceEvent pause_event(I, ServiceEvent::kPauseStart);
1484 Service::HandleEvent(&pause_event);
1485 } else if (FLAG_trace_service) {
1486 OS::PrintErr("vm-service: Dropping event of type PauseStart (%s)\n",
1487 I->name());
1488 }
1489}

The documentation for this class was generated from the following file: