Flutter Engine
The Flutter Engine
message.h
Go to the documentation of this file.
1// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5#ifndef RUNTIME_VM_MESSAGE_H_
6#define RUNTIME_VM_MESSAGE_H_
7
8#include <memory>
9#include <utility>
10
11#include "platform/assert.h"
12#include "vm/allocation.h"
13#include "vm/finalizable_data.h"
14#include "vm/globals.h"
15#include "vm/tagged_pointer.h"
16
17// Duplicated from dart_api.h to avoid including the whole header.
18typedef int64_t Dart_Port;
19
20namespace dart {
21
22class JSONStream;
23class PersistentHandle;
24
25class Message {
26 public:
27 typedef enum {
28 kNormalPriority = 0, // Deliver message when idle.
29 kOOBPriority = 1, // Deliver message asap.
30
31 // Iteration.
34 } Priority;
35
36 // Values defining the type of OOB messages. OOB messages can only be
37 // fixed length arrays where the first element is a Smi with one of the
38 // valid values below.
39 typedef enum {
44 } OOBMsgTag;
45
46 // A port number which is never used.
47 static const Dart_Port kIllegalPort;
48
49 // A new message to be sent between two isolates. The data handed to this
50 // message will be disposed by calling free() once the message object is
51 // being destructed (after delivery or when the receiving port is closed).
53 uint8_t* snapshot,
54 intptr_t snapshot_length,
57
58 // Message objects can also carry raw ObjectPtr for Smis and objects in
59 // the VM heap. This is indicated by setting the len_ field to 0.
61
62 // A message sent from SendPort.send or SendPort.sendAndExit where sender and
63 // receiver are in the same isolate group.
65
66 // A message sent from GC to run a finalizer.
68
69 ~Message();
70
71 template <typename... Args>
72 static std::unique_ptr<Message> New(Args&&... args) {
73 return std::unique_ptr<Message>(new Message(std::forward<Args>(args)...));
74 }
75
76 Dart_Port dest_port() const { return dest_port_; }
77
78 uint8_t* snapshot() const {
80 return payload_.snapshot_;
81 }
82 intptr_t snapshot_length() const { return snapshot_length_; }
83
84 MessageFinalizableData* finalizable_data() { return finalizable_data_; }
85
86 intptr_t Size() const {
87 intptr_t size = snapshot_length_;
88 if (finalizable_data_ != nullptr) {
89 size += finalizable_data_->external_size();
90 }
91 return size;
92 }
93
95 ASSERT(IsRaw());
96 return payload_.raw_obj_;
97 }
100 return payload_.persistent_handle_;
101 }
102 Priority priority() const { return priority_; }
103
104 // A message processed at any interrupt point (stack overflow check) instead
105 // of at the top of the message loop. Control messages from dart:isolate or
106 // vm-service requests.
107 bool IsOOB() const { return priority_ == Message::kOOBPriority; }
108 bool IsSnapshot() const {
110 }
111 // A message whose object is an immortal object from the vm-isolate's heap.
112 bool IsRaw() const { return snapshot_length_ == 0; }
113 // A message sent from SendPort.send or SendPort.sendAndExit where sender and
114 // receiver are in the same isolate group.
115 bool IsPersistentHandle() const {
116 return snapshot_length_ == kPersistentHandleSnapshotLen;
117 }
118 // A message sent from GC to run a finalizer.
120 return snapshot_length_ == kFinalizerSnapshotLen;
121 }
122
124 if (finalizable_data_ != nullptr) {
125 finalizable_data_->DropFinalizers();
126 }
127 }
128
129 intptr_t Id() const;
130
131 static const char* PriorityAsString(Priority priority);
132
133 private:
134 static intptr_t const kPersistentHandleSnapshotLen = -1;
135 static intptr_t const kFinalizerSnapshotLen = -2;
136
137 friend class MessageQueue;
138
139 Message* next_ = nullptr;
140 Dart_Port dest_port_;
141 union Payload {
142 Payload(uint8_t* snapshot) : snapshot_(snapshot) {}
143 Payload(ObjectPtr raw_obj) : raw_obj_(raw_obj) {}
144 Payload(PersistentHandle* persistent_handle)
145 : persistent_handle_(persistent_handle) {}
146
147 uint8_t* snapshot_;
148 ObjectPtr raw_obj_;
149 PersistentHandle* persistent_handle_;
150 } payload_;
151 intptr_t snapshot_length_ = 0;
152 MessageFinalizableData* finalizable_data_ = nullptr;
153 Priority priority_;
154
155 DISALLOW_COPY_AND_ASSIGN(Message);
156};
157
158// There is a message queue per isolate.
160 public:
161 MessageQueue();
163
164 void Enqueue(std::unique_ptr<Message> msg, bool before_events);
165
166 // Gets the next message from the message queue or nullptr if no
167 // message is available. This function will not block.
168 std::unique_ptr<Message> Dequeue();
169
170 bool IsEmpty() { return head_ == nullptr; }
171
172 // Clear all messages from the message queue.
173 void Clear();
174
175 // Iterator class.
176 class Iterator : public ValueObject {
177 public:
178 explicit Iterator(const MessageQueue* queue);
179 virtual ~Iterator();
180
181 void Reset(const MessageQueue* queue);
182
183 // Returns false when there are no more messages left.
184 bool HasNext();
185
186 // Returns the current message and moves forward.
187 Message* Next();
188
189 private:
190 Message* next_;
191 };
192
193 intptr_t Length() const;
194
195 // Returns the message with id or nullptr.
196 Message* FindMessageById(intptr_t id);
197
199
200 private:
201 Message* head_;
202 Message* tail_;
203
204 DISALLOW_COPY_AND_ASSIGN(MessageQueue);
205};
206
207} // namespace dart
208
209#endif // RUNTIME_VM_MESSAGE_H_
Iterator(const MessageQueue *queue)
Definition: message.cc:168
void Reset(const MessageQueue *queue)
Definition: message.cc:174
Message * FindMessageById(intptr_t id)
Definition: message.cc:201
intptr_t Length() const
Definition: message.cc:191
void Enqueue(std::unique_ptr< Message > msg, bool before_events)
Definition: message.cc:98
void PrintJSON(JSONStream *stream)
Definition: message.cc:213
std::unique_ptr< Message > Dequeue()
Definition: message.cc:142
bool IsSnapshot() const
Definition: message.h:108
PersistentHandle * persistent_handle() const
Definition: message.h:98
bool IsPersistentHandle() const
Definition: message.h:115
Priority priority() const
Definition: message.h:102
bool IsOOB() const
Definition: message.h:107
void DropFinalizers()
Definition: message.h:123
static std::unique_ptr< Message > New(Args &&... args)
Definition: message.h:72
intptr_t Id() const
Definition: message.cc:68
MessageFinalizableData * finalizable_data()
Definition: message.h:84
ObjectPtr raw_obj() const
Definition: message.h:94
@ kServiceOOBMsg
Definition: message.h:41
@ kDelayedIsolateLibOOBMsg
Definition: message.h:43
@ kIsolateLibOOBMsg
Definition: message.h:42
intptr_t Size() const
Definition: message.h:86
intptr_t snapshot_length() const
Definition: message.h:82
Dart_Port dest_port() const
Definition: message.h:76
static const Dart_Port kIllegalPort
Definition: message.h:47
bool IsRaw() const
Definition: message.h:112
uint8_t * snapshot() const
Definition: message.h:78
@ kNormalPriority
Definition: message.h:28
@ kNumPriorities
Definition: message.h:33
@ kFirstPriority
Definition: message.h:32
@ kOOBPriority
Definition: message.h:29
Message(Dart_Port dest_port, uint8_t *snapshot, intptr_t snapshot_length, MessageFinalizableData *finalizable_data, Priority priority)
Definition: message.cc:19
static const char * PriorityAsString(Priority priority)
Definition: message.cc:73
bool IsFinalizerInvocationRequest() const
Definition: message.h:119
int64_t Dart_Port
Definition: dart_api.h:1525
#define ASSERT(E)
VkQueue queue
Definition: main.cc:55
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
int64_t Dart_Port
Definition: message.h:18
Definition: dart_vm.cc:33
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259