Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 ()
 
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 ()
 
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 ()
 
void PostMessage (std::unique_ptr< Message > message, bool before_events=false)
 
void ClosePort (Dart_Port port)
 
void CloseAllPorts ()
 
Threadthread () const
 

Detailed Description

Definition at line 1040 of file isolate.cc.

Constructor & Destructor Documentation

◆ IsolateMessageHandler()

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

Definition at line 1078 of file isolate.cc.

1079 : isolate_(isolate) {}
virtual Isolate * isolate() const
Definition isolate.cc:1058

◆ ~IsolateMessageHandler()

dart::IsolateMessageHandler::~IsolateMessageHandler ( )

Definition at line 1081 of file isolate.cc.

1081{}

Member Function Documentation

◆ HandleMessage()

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

Implements dart::MessageHandler.

Definition at line 1324 of file isolate.cc.

1325 {
1327 Thread* thread = Thread::Current();
1328 StackZone stack_zone(thread);
1329 Zone* zone = stack_zone.GetZone();
1330 HandleScope handle_scope(thread);
1331#if defined(SUPPORT_TIMELINE)
1332 TimelineBeginEndScope tbes(
1333 thread, Timeline::GetIsolateStream(),
1334 message->IsOOB() ? "HandleOOBMessage" : "HandleMessage");
1335 tbes.SetNumArguments(1);
1336 tbes.CopyArgument(0, "isolateName", I->name());
1337#endif
1338
1339 // Parse the message.
1340 Object& msg_obj = Object::Handle(zone, ReadMessage(thread, message.get()));
1341 if (msg_obj.IsError()) {
1342 // An error occurred while reading the message.
1343 return ProcessUnhandledException(Error::Cast(msg_obj));
1344 }
1345 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) {
1346 // TODO(turnidge): We need to decide what an isolate does with
1347 // malformed messages. If they (eventually) come from a remote
1348 // machine, then it might make sense to drop the message entirely.
1349 // In the case that the message originated locally, which is
1350 // always true for now, then this should never occur.
1351 UNREACHABLE();
1352 }
1353 Instance& msg = Instance::Handle(zone);
1354 msg ^= msg_obj.ptr(); // Can't use Instance::Cast because may be null.
1355
1356 MessageStatus status = kOK;
1357 if (message->IsOOB()) {
1358 // OOB messages are expected to be fixed length arrays where the first
1359 // element is a Smi describing the OOB destination. Messages that do not
1360 // confirm to this layout are silently ignored.
1361 if (msg.IsArray()) {
1362 const Array& oob_msg = Array::Cast(msg);
1363 if (oob_msg.Length() > 0) {
1364 const Object& oob_tag = Object::Handle(zone, oob_msg.At(0));
1365 if (oob_tag.IsSmi()) {
1366 switch (Smi::Cast(oob_tag).Value()) {
1368#ifndef PRODUCT
1369 const Error& error =
1371 if (!error.IsNull()) {
1372 status = ProcessUnhandledException(error);
1373 }
1374#else
1375 UNREACHABLE();
1376#endif
1377 break;
1378 }
1380 const Error& error = Error::Handle(HandleLibMessage(oob_msg));
1381 if (!error.IsNull()) {
1382 status = ProcessUnhandledException(error);
1383 }
1384 break;
1385 }
1386#if defined(DEBUG)
1387 // Malformed OOB messages are silently ignored in release builds.
1388 default: {
1389 UNREACHABLE();
1390 break;
1391 }
1392#endif // defined(DEBUG)
1393 }
1394 }
1395 }
1396 }
1397 } else if (message->IsFinalizerInvocationRequest()) {
1398 const Object& msg_handler = Object::Handle(
1399 zone,
1400 DartLibraryCalls::HandleFinalizerMessage(FinalizerBase::Cast(msg)));
1401 if (msg_handler.IsError()) {
1402 status = ProcessUnhandledException(Error::Cast(msg_handler));
1403 } else {
1404 // The handler closure which was used to successfully handle the message.
1405 }
1406 } else if (message->dest_port() == Message::kIllegalPort) {
1407 // Check whether this is a delayed OOB message which needed handling as
1408 // part of the regular message dispatch. All other messages are dropped on
1409 // the floor.
1410 if (msg.IsArray()) {
1411 const Array& msg_arr = Array::Cast(msg);
1412 if (msg_arr.Length() > 0) {
1413 const Object& oob_tag = Object::Handle(zone, msg_arr.At(0));
1414 if (oob_tag.IsSmi() &&
1415 (Smi::Cast(oob_tag).Value() == Message::kDelayedIsolateLibOOBMsg)) {
1416 const Error& error = Error::Handle(HandleLibMessage(msg_arr));
1417 if (!error.IsNull()) {
1418 status = ProcessUnhandledException(error);
1419 }
1420 }
1421 }
1422 }
1423 } else {
1424 const Object& msg_handler = Object::Handle(
1425 zone, DartLibraryCalls::HandleMessage(message->dest_port(), msg));
1426 if (msg_handler.IsError()) {
1427 status = ProcessUnhandledException(Error::Cast(msg_handler));
1428 } else if (msg_handler.IsNull()) {
1429 // If the port has been closed then the message will be dropped at this
1430 // point. Make sure to post to the delivery failure port in that case.
1431 } else {
1432 // The handler closure which was used to successfully handle the message.
1433 }
1434 }
1435 return status;
1436}
#define UNREACHABLE()
Definition assert.h:248
static ObjectPtr HandleMessage(Dart_Port port_id, const Instance &message)
static ObjectPtr HandleFinalizerMessage(const FinalizerBase &finalizer)
bool IsCurrentIsolate() const
Definition isolate.cc:1478
Thread * thread() const
@ 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:361
#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 1478 of file isolate.cc.

1478 {
1479 return (I == Isolate::Current());
1480}
static Isolate * Current()
Definition isolate.h:939

◆ isolate()

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

Reimplemented from dart::MessageHandler.

Definition at line 1058 of file isolate.cc.

1058{ return isolate_; }

◆ isolate_group()

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

Definition at line 1059 of file isolate.cc.

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

◆ KeepAliveLocked()

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

Reimplemented from dart::MessageHandler.

Definition at line 1061 of file isolate.cc.

1061 {
1062 // If the message handler was asked to shutdown we shut down.
1063 if (!MessageHandler::KeepAliveLocked()) return false;
1064 // Otherwise we only stay alive as long as there's active receive ports, or
1065 // there are FFI callbacks keeping the isolate alive.
1066 return isolate_->HasLivePorts() || isolate_->HasOpenNativeCallables();
1067 }
bool HasLivePorts()
Definition isolate.cc:3706
bool HasOpenNativeCallables()
Definition isolate.cc:3765
virtual bool KeepAliveLocked()

◆ MessageNotify()

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

Reimplemented from dart::MessageHandler.

Definition at line 1308 of file isolate.cc.

1308 {
1309 if (priority >= Message::kOOBPriority) {
1310 // Handle out of band messages even if the mutator thread is busy.
1311 I->ScheduleInterrupts(Thread::kMessageInterrupt);
1312 }
1313 Dart_MessageNotifyCallback callback = I->message_notify_callback();
1314 if (callback != nullptr) {
1315 // Allow the embedder to handle message notification.
1316 (*callback)(Api::CastIsolate(I));
1317 }
1318}
static Dart_Isolate CastIsolate(Isolate *isolate)
@ kMessageInterrupt
Definition thread.h:488
void(* Dart_MessageNotifyCallback)(Dart_Isolate destination_isolate)
Definition dart_api.h:1541
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ name()

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

Reimplemented from dart::MessageHandler.

Definition at line 1083 of file isolate.cc.

1083 {
1084 return isolate_->name();
1085}
const char * name() const
Definition isolate.h:996

◆ NotifyPauseOnExit()

void dart::IsolateMessageHandler::NotifyPauseOnExit ( )
virtual

Reimplemented from dart::MessageHandler.

Definition at line 1455 of file isolate.cc.

1455 {
1457 return;
1458 }
1459 if (Service::debug_stream.enabled() || FLAG_warn_on_pause_with_no_debugger) {
1460 StartIsolateScope start_isolate(I);
1461 StackZone zone(T);
1462 HandleScope handle_scope(T);
1463 ServiceEvent pause_event(I, ServiceEvent::kPauseExit);
1464 Service::HandleEvent(&pause_event);
1465 } else if (FLAG_trace_service) {
1466 OS::PrintErr("vm-service: Dropping event of type PauseExit (%s)\n",
1467 I->name());
1468 }
1469}
static bool IsSystemIsolate(const Isolate *isolate)
Definition isolate.h:1398
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

◆ NotifyPauseOnStart()

void dart::IsolateMessageHandler::NotifyPauseOnStart ( )
virtual

Reimplemented from dart::MessageHandler.

Definition at line 1439 of file isolate.cc.

1439 {
1441 return;
1442 }
1443 if (Service::debug_stream.enabled() || FLAG_warn_on_pause_with_no_debugger) {
1444 StartIsolateScope start_isolate(I);
1445 StackZone zone(T);
1446 HandleScope handle_scope(T);
1447 ServiceEvent pause_event(I, ServiceEvent::kPauseStart);
1448 Service::HandleEvent(&pause_event);
1449 } else if (FLAG_trace_service) {
1450 OS::PrintErr("vm-service: Dropping event of type PauseStart (%s)\n",
1451 I->name());
1452 }
1453}

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