Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::MessageSerializer Class Reference
Inheritance diagram for dart::MessageSerializer:
dart::BaseSerializer dart::StackResource

Public Member Functions

 MessageSerializer (Thread *thread)
 
 ~MessageSerializer ()
 
bool MarkObjectId (ObjectPtr object, intptr_t id)
 
void SetObjectId (ObjectPtr object, intptr_t id)
 
intptr_t GetObjectId (ObjectPtr object) const
 
DART_NOINLINE void AddBaseObject (ObjectPtr base_object)
 
DART_NOINLINE void AssignRef (ObjectPtr object)
 
void AssignRef (Object *object)
 
void Push (ObjectPtr object)
 
void Trace (const Object &root, Object *object)
 
void IllegalObject (const Object &object, const char *message)
 
void AddBaseObjects ()
 
void Serialize (const Object &root)
 
DART_NOINLINE void WriteRef (ObjectPtr object)
 
Threadthread () const
 
Isolateisolate () const
 
IsolateGroupisolate_group () const
 
bool HasRef (ObjectPtr object) const
 
- Public Member Functions inherited from dart::BaseSerializer
 BaseSerializer (Thread *thread, Zone *zone)
 
 ~BaseSerializer ()
 
template<typename T >
void Write (T value)
 
void WriteUnsigned (intptr_t value)
 
void WriteWordWith32BitWrites (uword value)
 
void WriteBytes (const void *addr, intptr_t len)
 
void WriteAscii (const String &str)
 
MessageSerializationClusterNewClusterForClass (intptr_t cid, bool is_canonical)
 
void WriteCluster (MessageSerializationCluster *cluster)
 
std::unique_ptr< MessageFinish (Dart_Port dest_port, Message::Priority priority)
 
Zonezone () const
 
MessageFinalizableDatafinalizable_data () const
 
intptr_t next_ref_index () const
 
- Public Member Functions inherited from dart::StackResource
 StackResource (ThreadState *thread)
 
virtual ~StackResource ()
 
ThreadStatethread () const
 

Additional Inherited Members

- Static Public Member Functions inherited from dart::StackResource
static void Unwind (ThreadState *thread)
 
static void UnwindAbove (ThreadState *thread, StackResource *new_top)
 
- Protected Attributes inherited from dart::BaseSerializer
Zone *const zone_
 
MallocWriteStream stream_
 
MessageFinalizableDatafinalizable_data_
 
GrowableArray< MessageSerializationCluster * > clusters_
 
intptr_t num_base_objects_
 
intptr_t num_written_objects_
 
intptr_t next_ref_index_
 

Detailed Description

Definition at line 204 of file message_snapshot.cc.

Constructor & Destructor Documentation

◆ MessageSerializer()

dart::MessageSerializer::MessageSerializer ( Thread thread)
explicit

Definition at line 2705 of file message_snapshot.cc.

2707 forward_table_new_(),
2708 forward_table_old_(),
2709 stack_(thread->zone(), 0) {
2710 isolate()->set_forward_table_new(new WeakTable());
2711 isolate()->set_forward_table_old(new WeakTable());
2712}
BaseSerializer(Thread *thread, Zone *zone)
void set_forward_table_old(WeakTable *table)
Definition: isolate.cc:2552
void set_forward_table_new(WeakTable *table)
Definition: isolate.cc:2548
Isolate * isolate() const
Zone * zone() const
Definition: thread_state.h:37

◆ ~MessageSerializer()

dart::MessageSerializer::~MessageSerializer ( )

Definition at line 2714 of file message_snapshot.cc.

2714 {
2715 isolate()->set_forward_table_new(nullptr);
2716 isolate()->set_forward_table_old(nullptr);
2717}

Member Function Documentation

◆ AddBaseObject()

DART_NOINLINE void dart::MessageSerializer::AddBaseObject ( ObjectPtr  base_object)
inline

Definition at line 241 of file message_snapshot.cc.

241 {
242 AssignRef(base_object);
244 }
DART_NOINLINE void AssignRef(ObjectPtr object)

◆ AddBaseObjects()

void dart::MessageSerializer::AddBaseObjects ( )

Definition at line 3216 of file message_snapshot.cc.

3216 {
3218 AddBaseObject(Object::sentinel().ptr());
3219 AddBaseObject(Object::transition_sentinel().ptr());
3220 AddBaseObject(Object::empty_array().ptr());
3221 AddBaseObject(Object::dynamic_type().ptr());
3222 AddBaseObject(Object::void_type().ptr());
3223 AddBaseObject(Object::empty_type_arguments().ptr());
3224 AddBaseObject(Bool::True().ptr());
3225 AddBaseObject(Bool::False().ptr());
3226}
static const Bool & False()
Definition: object.h:10799
static const Bool & True()
Definition: object.h:10797
DART_NOINLINE void AddBaseObject(ObjectPtr base_object)
static ObjectPtr null()
Definition: object.h:433

◆ AssignRef() [1/2]

void dart::MessageSerializer::AssignRef ( Object object)
inline

Definition at line 249 of file message_snapshot.cc.

249{ AssignRef(object->ptr()); }

◆ AssignRef() [2/2]

DART_NOINLINE void dart::MessageSerializer::AssignRef ( ObjectPtr  object)
inline

Definition at line 245 of file message_snapshot.cc.

245 {
248 }
void SetObjectId(ObjectPtr object, intptr_t id)

◆ GetObjectId()

intptr_t dart::MessageSerializer::GetObjectId ( ObjectPtr  object) const
inline

Definition at line 231 of file message_snapshot.cc.

231 {
232 const WeakTable* table;
233 if (object->IsImmediateOrOldObject()) {
235 } else {
237 }
238 return table->GetValueExclusive(object);
239 }
SI F table(const skcms_Curve *curve, F v)
WeakTable * forward_table_old()
Definition: isolate.h:1461
WeakTable * forward_table_new()
Definition: isolate.h:1458

◆ HasRef()

bool dart::MessageSerializer::HasRef ( ObjectPtr  object) const
inline

Definition at line 272 of file message_snapshot.cc.

272 {
273 return GetObjectId(object) != WeakTable::kNoValue;
274 }
intptr_t GetObjectId(ObjectPtr object) const
static constexpr intptr_t kNoValue
Definition: weak_table.h:18

◆ IllegalObject()

void dart::MessageSerializer::IllegalObject ( const Object object,
const char *  message 
)

Definition at line 3053 of file message_snapshot.cc.

3054 {
3055 const Array& args = Array::Handle(zone(), Array::New(3));
3056 args.SetAt(0, object);
3059}
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.h:10959
static DART_NORETURN void ThrowByType(ExceptionType type, const Array &arguments)
Definition: exceptions.cc:1052
static Object & Handle()
Definition: object.h:407
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Win32Message message

◆ isolate()

Isolate * dart::MessageSerializer::isolate ( ) const
inline

Definition at line 269 of file message_snapshot.cc.

269{ return thread()->isolate(); }
Isolate * isolate() const
Definition: thread.h:534

◆ isolate_group()

IsolateGroup * dart::MessageSerializer::isolate_group ( ) const
inline

Definition at line 270 of file message_snapshot.cc.

270{ return thread()->isolate_group(); }
IsolateGroup * isolate_group() const
Definition: thread.h:541

◆ MarkObjectId()

bool dart::MessageSerializer::MarkObjectId ( ObjectPtr  object,
intptr_t  id 
)
inline

Definition at line 209 of file message_snapshot.cc.

209 {
211 WeakTable* table;
212 if (object->IsImmediateOrOldObject()) {
214 } else {
216 }
217 return table->MarkValueExclusive(object, id);
218 }
#define ASSERT(E)

◆ Push()

void dart::MessageSerializer::Push ( ObjectPtr  object)

Definition at line 2724 of file message_snapshot.cc.

2724 {
2725 if (MarkObjectId(object, kUnallocatedReference)) {
2726 stack_.Add(&Object::ZoneHandle(zone_, object));
2728 }
2729}
bool MarkObjectId(ObjectPtr object, intptr_t id)
static Object & ZoneHandle()
Definition: object.h:419
static constexpr intptr_t kUnallocatedReference

◆ Serialize()

void dart::MessageSerializer::Serialize ( const Object root)

Definition at line 3264 of file message_snapshot.cc.

3264 {
3266
3267 Push(root.ptr());
3268
3269 while (stack_.length() > 0) {
3270 Trace(root, stack_.RemoveLast());
3271 }
3272
3273 intptr_t num_objects = num_base_objects_ + num_written_objects_;
3275 WriteUnsigned(num_objects);
3276
3277 for (intptr_t i = 0; i < static_cast<intptr_t>(MessagePhase::kNumPhases);
3278 i++) {
3279 intptr_t num_clusters = 0;
3280 for (MessageSerializationCluster* cluster : clusters_) {
3281 if (static_cast<intptr_t>(cluster->phase()) != i) continue;
3282 num_clusters++;
3283 }
3284 WriteUnsigned(num_clusters);
3285 for (MessageSerializationCluster* cluster : clusters_) {
3286 if (static_cast<intptr_t>(cluster->phase()) != i) continue;
3287 WriteCluster(cluster);
3288 cluster->WriteNodes(this);
3289 }
3290 for (MessageSerializationCluster* cluster : clusters_) {
3291 if (static_cast<intptr_t>(cluster->phase()) != i) continue;
3292 cluster->WriteEdges(this);
3293 }
3294 }
3295
3296 // We should have assigned a ref to every object we pushed.
3297 ASSERT((next_ref_index_ - 1) == num_objects);
3298
3299 WriteRef(root.ptr());
3300}
GrowableArray< MessageSerializationCluster * > clusters_
void WriteCluster(MessageSerializationCluster *cluster)
void WriteUnsigned(intptr_t value)
DART_NOINLINE void WriteRef(ObjectPtr object)
void Push(ObjectPtr object)
void Trace(const Object &root, Object *object)
string root
Definition: scale_cpu.py:20

◆ SetObjectId()

void dart::MessageSerializer::SetObjectId ( ObjectPtr  object,
intptr_t  id 
)
inline

Definition at line 220 of file message_snapshot.cc.

220 {
222 WeakTable* table;
223 if (object->IsImmediateOrOldObject()) {
225 } else {
227 }
228 table->SetValueExclusive(object, id);
229 }

◆ thread()

Thread * dart::MessageSerializer::thread ( ) const
inline

Definition at line 266 of file message_snapshot.cc.

266 {
267 return static_cast<Thread*>(StackResource::thread());
268 }
ThreadState * thread() const
Definition: allocation.h:33

◆ Trace()

void dart::MessageSerializer::Trace ( const Object root,
Object object 
)

Definition at line 2738 of file message_snapshot.cc.

2738 {
2739 intptr_t cid;
2740 bool is_canonical;
2741 if (!object->ptr()->IsHeapObject()) {
2742 cid = kSmiCid;
2743 is_canonical = true;
2744 } else {
2745 cid = object->GetClassId();
2746 is_canonical = object->ptr()->untag()->IsCanonical();
2747 }
2748
2749 MessageSerializationCluster* cluster = nullptr;
2750 for (MessageSerializationCluster* c : clusters_) {
2751 if ((c->cid() == cid) && (c->is_canonical() == is_canonical)) {
2752 cluster = c;
2753 break;
2754 }
2755 }
2756 if (cluster == nullptr) {
2757 if (cid >= kNumPredefinedCids || cid == kInstanceCid) {
2758 // Will stomp over forward_table_new/old WeakTables, which should be ok,
2759 // as they are not going to be used again here.
2760 const char* message = OS::SCreate(
2761 zone_, "is a regular instance reachable via %s",
2762 FindRetainingPath(zone_, isolate(), root, *object,
2764 IllegalObject(*object, message);
2765 }
2766
2767 const char* illegal_cid_string = nullptr;
2768 // Keep the list in sync with the one in lib/isolate.cc,
2769 // vm/object_graph_copy.cc
2770#define ILLEGAL(type) \
2771 case k##type##Cid: \
2772 illegal_cid_string = #type; \
2773 break;
2774
2775 switch (cid) {
2776 ILLEGAL(Closure)
2778 ILLEGAL(FinalizerEntry)
2779 ILLEGAL(FunctionType)
2780 ILLEGAL(MirrorReference)
2781 ILLEGAL(NativeFinalizer)
2782 ILLEGAL(ReceivePort)
2783 ILLEGAL(Record)
2784 ILLEGAL(RecordType)
2785 ILLEGAL(RegExp)
2786 ILLEGAL(StackTrace)
2787 ILLEGAL(SuspendState)
2788 ILLEGAL(UserTag)
2789 ILLEGAL(WeakProperty)
2790 ILLEGAL(WeakReference)
2791 ILLEGAL(WeakArray)
2792
2793 // From "dart:ffi" we handle only Pointer/DynamicLibrary specially, since
2794 // those are the only non-abstract classes (so we avoid checking more cids
2795 // here that cannot happen in reality)
2796 ILLEGAL(DynamicLibrary)
2797 ILLEGAL(Pointer)
2798
2799#undef ILLEGAL
2800 }
2801
2802 if (illegal_cid_string != nullptr) {
2803 // Will stomp over forward_table_new/old WeakTables, which should be ok,
2804 // as they are not going to be used again here.
2805 const char* message = OS::SCreate(
2806 zone_, "is a %s reachable via %s", illegal_cid_string,
2807 FindRetainingPath(zone_, isolate(), root, *object,
2809 IllegalObject(*object, message);
2810 }
2811
2812 cluster = NewClusterForClass(cid, is_canonical);
2813 clusters_.Add(cluster);
2814 }
2815
2816 cluster->Trace(this, object);
2817}
MessageSerializationCluster * NewClusterForClass(intptr_t cid, bool is_canonical)
void IllegalObject(const Object &object, const char *message)
static char * SCreate(Zone *zone, const char *format,...) PRINTF_ATTRIBUTE(2
#define ILLEGAL(type)
@ kExternalBetweenIsolateGroups
const char * FindRetainingPath(Zone *zone_, Isolate *isolate, const Object &from, const Object &to, TraversalRules traversal_rules)
@ kNumPredefinedCids
Definition: class_id.h:257
static void Finalizer(void *isolate_callback_data, void *buffer)
Definition: json_stream.cc:192
const intptr_t cid

◆ WriteRef()

DART_NOINLINE void dart::MessageSerializer::WriteRef ( ObjectPtr  object)
inline

Definition at line 260 of file message_snapshot.cc.

260 {
261 intptr_t index = GetObjectId(object);
262 ASSERT(index != WeakTable::kNoValue);
263 WriteUnsigned(index);
264 }

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