Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dart::ApiMessageSerializer Class Reference
Inheritance diagram for dart::ApiMessageSerializer:
dart::BaseSerializer dart::StackResource

Public Member Functions

 ApiMessageSerializer (Zone *zone)
 
 ~ApiMessageSerializer ()
 
bool MarkObjectId (Dart_CObject *object, intptr_t id)
 
void SetObjectId (Dart_CObject *object, intptr_t id)
 
intptr_t GetObjectId (Dart_CObject *object) const
 
DART_NOINLINE void AddBaseObject (Dart_CObject *base_object)
 
DART_NOINLINE intptr_t AssignRef (Dart_CObject *object)
 
void ForwardRef (Dart_CObject *old, Dart_CObject *nue)
 
void Push (Dart_CObject *object)
 
bool Trace (Dart_CObject *object)
 
void AddBaseObjects ()
 
bool Serialize (Dart_CObject *root)
 
void WriteRef (Dart_CObject *object)
 
bool Fail (const char *message)
 
- 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 282 of file message_snapshot.cc.

Constructor & Destructor Documentation

◆ ApiMessageSerializer()

dart::ApiMessageSerializer::ApiMessageSerializer ( Zone zone)
explicit

Definition at line 2719 of file message_snapshot.cc.

2720 : BaseSerializer(nullptr, zone), forward_table_(), stack_(zone, 0) {}
BaseSerializer(Thread *thread, Zone *zone)

◆ ~ApiMessageSerializer()

dart::ApiMessageSerializer::~ApiMessageSerializer ( )

Definition at line 2722 of file message_snapshot.cc.

2722{}

Member Function Documentation

◆ AddBaseObject()

DART_NOINLINE void dart::ApiMessageSerializer::AddBaseObject ( Dart_CObject base_object)
inline

Definition at line 304 of file message_snapshot.cc.

304 {
305 AssignRef(base_object);
307 }
DART_NOINLINE intptr_t AssignRef(Dart_CObject *object)

◆ AddBaseObjects()

void dart::ApiMessageSerializer::AddBaseObjects ( )

Definition at line 3240 of file message_snapshot.cc.

3240 {
3250}
DART_NOINLINE void AddBaseObject(Dart_CObject *base_object)
static Dart_CObject * cobj_empty_array()
static Dart_CObject * cobj_null()
static Dart_CObject cobj_transition_sentinel
static Dart_CObject cobj_empty_type_arguments
static Dart_CObject cobj_true
static Dart_CObject cobj_false
static Dart_CObject cobj_dynamic_type
static Dart_CObject cobj_void_type
static Dart_CObject cobj_sentinel

◆ AssignRef()

DART_NOINLINE intptr_t dart::ApiMessageSerializer::AssignRef ( Dart_CObject object)
inline

Definition at line 308 of file message_snapshot.cc.

308 {
310 return next_ref_index_++;
311 }
void SetObjectId(Dart_CObject *object, intptr_t id)

◆ Fail()

bool dart::ApiMessageSerializer::Fail ( const char *  message)
inline

Definition at line 332 of file message_snapshot.cc.

332 {
333 exception_message_ = message;
334 return false;
335 }
Win32Message message

◆ ForwardRef()

void dart::ApiMessageSerializer::ForwardRef ( Dart_CObject old,
Dart_CObject nue 
)
inline

Definition at line 312 of file message_snapshot.cc.

312 {
313 intptr_t id = GetObjectId(nue);
315 SetObjectId(old, id);
317 }
intptr_t GetObjectId(Dart_CObject *object) const
static constexpr intptr_t kNoValue
Definition weak_table.h:18
#define ASSERT(E)

◆ GetObjectId()

intptr_t dart::ApiMessageSerializer::GetObjectId ( Dart_CObject object) const
inline

Definition at line 299 of file message_snapshot.cc.

299 {
300 return forward_table_.GetValueExclusive(
301 static_cast<ObjectPtr>(reinterpret_cast<uword>(object)));
302 }
intptr_t GetValueExclusive(ObjectPtr key) const
Definition weak_table.h:109
uintptr_t uword
Definition globals.h:501

◆ MarkObjectId()

bool dart::ApiMessageSerializer::MarkObjectId ( Dart_CObject object,
intptr_t  id 
)
inline

Definition at line 287 of file message_snapshot.cc.

287 {
289 return forward_table_.MarkValueExclusive(
290 static_cast<ObjectPtr>(reinterpret_cast<uword>(object)), id);
291 }
bool MarkValueExclusive(ObjectPtr key, intptr_t val)
Definition weak_table.cc:78

◆ Push()

void dart::ApiMessageSerializer::Push ( Dart_CObject object)

Definition at line 2731 of file message_snapshot.cc.

2731 {
2732 if (MarkObjectId(object, kUnallocatedReference)) {
2733 stack_.Add(object);
2735 }
2736}
bool MarkObjectId(Dart_CObject *object, intptr_t id)
static constexpr intptr_t kUnallocatedReference

◆ Serialize()

bool dart::ApiMessageSerializer::Serialize ( Dart_CObject root)

Definition at line 3302 of file message_snapshot.cc.

3302 {
3304
3305 Push(root);
3306
3307 // Strong references only.
3308 while (stack_.length() > 0) {
3309 if (!Trace(stack_.RemoveLast())) {
3310 return false;
3311 }
3312 }
3313
3314 intptr_t num_objects = num_base_objects_ + num_written_objects_;
3316 WriteUnsigned(num_objects);
3317
3318 for (intptr_t i = 0; i < static_cast<intptr_t>(MessagePhase::kNumPhases);
3319 i++) {
3320 intptr_t num_clusters = 0;
3321 for (MessageSerializationCluster* cluster : clusters_) {
3322 if (static_cast<intptr_t>(cluster->phase()) != i) continue;
3323 num_clusters++;
3324 }
3325 WriteUnsigned(num_clusters);
3326 for (MessageSerializationCluster* cluster : clusters_) {
3327 if (static_cast<intptr_t>(cluster->phase()) != i) continue;
3328 WriteCluster(cluster);
3329 cluster->WriteNodesApi(this);
3330 }
3331 for (MessageSerializationCluster* cluster : clusters_) {
3332 if (static_cast<intptr_t>(cluster->phase()) != i) continue;
3333 cluster->WriteEdgesApi(this);
3334 }
3335 }
3336
3337 // We should have assigned a ref to every object we pushed.
3338 ASSERT((next_ref_index_ - 1) == num_objects);
3339
3340 WriteRef(root);
3341 return true;
3342}
void Push(Dart_CObject *object)
void WriteRef(Dart_CObject *object)
bool Trace(Dart_CObject *object)
GrowableArray< MessageSerializationCluster * > clusters_
void WriteCluster(MessageSerializationCluster *cluster)
void WriteUnsigned(intptr_t value)

◆ SetObjectId()

void dart::ApiMessageSerializer::SetObjectId ( Dart_CObject object,
intptr_t  id 
)
inline

Definition at line 293 of file message_snapshot.cc.

293 {
295 forward_table_.SetValueExclusive(
296 static_cast<ObjectPtr>(reinterpret_cast<uword>(object)), id);
297 }
void SetValueExclusive(ObjectPtr key, intptr_t val)
Definition weak_table.cc:33

◆ Trace()

bool dart::ApiMessageSerializer::Trace ( Dart_CObject object)

Definition at line 2819 of file message_snapshot.cc.

2819 {
2820 const bool is_canonical = false;
2821 intptr_t cid;
2822 switch (object->type) {
2823 case Dart_CObject_kNull:
2825 return true;
2826 case Dart_CObject_kBool:
2827 ForwardRef(object, object->value.as_bool ? &cobj_true : &cobj_false);
2828 return true;
2830 cid = Smi::IsValid(object->value.as_int32) ? kSmiCid : kMintCid;
2831 break;
2833 cid = Smi::IsValid(object->value.as_int64) ? kSmiCid : kMintCid;
2834 break;
2836 cid = kDoubleCid;
2837 break;
2838 case Dart_CObject_kString: {
2839 RELEASE_ASSERT(object->value.as_string != nullptr);
2840 const uint8_t* utf8_str =
2841 reinterpret_cast<const uint8_t*>(object->value.as_string);
2842 intptr_t utf8_len = strlen(object->value.as_string);
2843 if (!Utf8::IsValid(utf8_str, utf8_len)) {
2844 return Fail("invalid utf8");
2845 }
2847 intptr_t len = Utf8::CodeUnitCount(utf8_str, utf8_len, &type);
2848 if (len > String::kMaxElements) {
2849 return Fail("invalid string length");
2850 }
2851 cid = type == Utf8::kLatin1 ? kOneByteStringCid : kTwoByteStringCid;
2852 break;
2853 }
2855 cid = kArrayCid;
2856 if (!Array::IsValidLength(object->value.as_array.length)) {
2857 return Fail("invalid array length");
2858 }
2859 break;
2861 switch (object->value.as_typed_data.type) {
2863 cid = kTypedDataInt8ArrayCid;
2864 break;
2866 cid = kTypedDataUint8ArrayCid;
2867 break;
2869 cid = kTypedDataUint8ClampedArrayCid;
2870 break;
2872 cid = kTypedDataInt16ArrayCid;
2873 break;
2875 cid = kTypedDataUint16ArrayCid;
2876 break;
2878 cid = kTypedDataInt32ArrayCid;
2879 break;
2881 cid = kTypedDataUint32ArrayCid;
2882 break;
2884 cid = kTypedDataInt64ArrayCid;
2885 break;
2887 cid = kTypedDataUint64ArrayCid;
2888 break;
2890 cid = kTypedDataFloat32ArrayCid;
2891 break;
2893 cid = kTypedDataFloat64ArrayCid;
2894 break;
2896 cid = kTypedDataInt32x4ArrayCid;
2897 break;
2899 cid = kTypedDataFloat32x4ArrayCid;
2900 break;
2902 cid = kTypedDataFloat64x2ArrayCid;
2903 break;
2904 default:
2905 return Fail("invalid TypedData type");
2906 }
2907 {
2908 intptr_t len = object->value.as_typed_data.length;
2909 if (len < 0 || len > TypedData::MaxElements(cid)) {
2910 return Fail("invalid typeddata length");
2911 }
2912 }
2913 break;
2915 switch (object->value.as_external_typed_data.type) {
2917 cid = kExternalTypedDataInt8ArrayCid;
2918 break;
2920 cid = kExternalTypedDataUint8ArrayCid;
2921 break;
2923 cid = kExternalTypedDataUint8ClampedArrayCid;
2924 break;
2926 cid = kExternalTypedDataInt16ArrayCid;
2927 break;
2929 cid = kExternalTypedDataUint16ArrayCid;
2930 break;
2932 cid = kExternalTypedDataInt32ArrayCid;
2933 break;
2935 cid = kExternalTypedDataUint32ArrayCid;
2936 break;
2938 cid = kExternalTypedDataInt64ArrayCid;
2939 break;
2941 cid = kExternalTypedDataUint64ArrayCid;
2942 break;
2944 cid = kExternalTypedDataFloat32ArrayCid;
2945 break;
2947 cid = kExternalTypedDataFloat64ArrayCid;
2948 break;
2950 cid = kExternalTypedDataInt32x4ArrayCid;
2951 break;
2953 cid = kExternalTypedDataFloat32x4ArrayCid;
2954 break;
2956 cid = kExternalTypedDataFloat64x2ArrayCid;
2957 break;
2958 default:
2959 return Fail("invalid TypedData type");
2960 }
2961 {
2962 intptr_t len = object->value.as_typed_data.length;
2963 if (len < 0 || len > ExternalTypedData::MaxElements(cid)) {
2964 return Fail("invalid typeddata length");
2965 }
2966 }
2967 break;
2969 switch (object->value.as_external_typed_data.type) {
2971 cid = kUnmodifiableTypedDataInt8ArrayViewCid;
2972 break;
2974 cid = kUnmodifiableTypedDataUint8ArrayViewCid;
2975 break;
2977 cid = kUnmodifiableTypedDataUint8ClampedArrayViewCid;
2978 break;
2980 cid = kUnmodifiableTypedDataInt16ArrayViewCid;
2981 break;
2983 cid = kUnmodifiableTypedDataUint16ArrayViewCid;
2984 break;
2986 cid = kUnmodifiableTypedDataInt32ArrayViewCid;
2987 break;
2989 cid = kUnmodifiableTypedDataUint32ArrayViewCid;
2990 break;
2992 cid = kUnmodifiableTypedDataInt64ArrayViewCid;
2993 break;
2995 cid = kUnmodifiableTypedDataUint64ArrayViewCid;
2996 break;
2998 cid = kUnmodifiableTypedDataFloat32ArrayViewCid;
2999 break;
3001 cid = kUnmodifiableTypedDataFloat64ArrayViewCid;
3002 break;
3004 cid = kUnmodifiableTypedDataInt32x4ArrayViewCid;
3005 break;
3007 cid = kUnmodifiableTypedDataFloat32x4ArrayViewCid;
3008 break;
3010 cid = kUnmodifiableTypedDataFloat64x2ArrayViewCid;
3011 break;
3012 default:
3013 return Fail("invalid TypedData type");
3014 }
3015 {
3016 intptr_t len = object->value.as_typed_data.length;
3017 if (len < 0 || len > TypedData::MaxElements(
3020 return Fail("invalid typeddata length");
3021 }
3022 }
3023 break;
3025 cid = kSendPortCid;
3026 break;
3028 cid = kCapabilityCid;
3029 break;
3032 break;
3033 default:
3034 return Fail("invalid Dart_CObject type");
3035 }
3036
3037 MessageSerializationCluster* cluster = nullptr;
3038 for (MessageSerializationCluster* c : clusters_) {
3039 if (c->cid() == cid) {
3040 cluster = c;
3041 break;
3042 }
3043 }
3044 if (cluster == nullptr) {
3045 cluster = NewClusterForClass(cid, is_canonical);
3046 clusters_.Add(cluster);
3047 }
3048
3049 cluster->TraceApi(this, object);
3050 return true;
3051}
#define RELEASE_ASSERT(cond)
Definition assert.h:327
void ForwardRef(Dart_CObject *old, Dart_CObject *nue)
bool Fail(const char *message)
static constexpr bool IsValidLength(intptr_t len)
Definition object.h:10906
MessageSerializationCluster * NewClusterForClass(intptr_t cid, bool is_canonical)
static intptr_t MaxElements(intptr_t class_id)
Definition object.h:11718
static bool IsValid(int64_t value)
Definition object.h:10005
static constexpr intptr_t kMaxElements
Definition object.h:10152
static intptr_t MaxElements(intptr_t class_id)
Definition object.h:11658
static intptr_t CodeUnitCount(const uint8_t *utf8_array, intptr_t array_len, Type *type)
Definition unicode.cc:46
static bool IsValid(const uint8_t *utf8_array, intptr_t array_len)
Definition unicode.cc:70
@ Dart_TypedData_kFloat32x4
Definition dart_api.h:2617
@ Dart_TypedData_kInt32x4
Definition dart_api.h:2616
@ Dart_TypedData_kUint8
Definition dart_api.h:2606
@ Dart_TypedData_kUint32
Definition dart_api.h:2611
@ Dart_TypedData_kInt32
Definition dart_api.h:2610
@ Dart_TypedData_kUint16
Definition dart_api.h:2609
@ Dart_TypedData_kFloat64x2
Definition dart_api.h:2618
@ Dart_TypedData_kUint64
Definition dart_api.h:2613
@ Dart_TypedData_kFloat32
Definition dart_api.h:2614
@ Dart_TypedData_kInt16
Definition dart_api.h:2608
@ Dart_TypedData_kFloat64
Definition dart_api.h:2615
@ Dart_TypedData_kUint8Clamped
Definition dart_api.h:2607
@ Dart_TypedData_kInt8
Definition dart_api.h:2605
@ Dart_TypedData_kInt64
Definition dart_api.h:2612
@ Dart_CObject_kInt64
@ Dart_CObject_kNativePointer
@ Dart_CObject_kDouble
@ Dart_CObject_kUnmodifiableExternalTypedData
@ Dart_CObject_kTypedData
@ Dart_CObject_kSendPort
@ Dart_CObject_kString
@ Dart_CObject_kArray
@ Dart_CObject_kNull
@ Dart_CObject_kExternalTypedData
@ Dart_CObject_kInt32
@ Dart_CObject_kBool
@ Dart_CObject_kCapability
const int kTypedDataCidRemainderUnmodifiable
Definition class_id.h:264
const int kTypedDataCidRemainderInternal
Definition class_id.h:261
@ kNativePointer
Definition class_id.h:218
const intptr_t cid
union _Dart_CObject::@86 value
Dart_CObject_Type type
struct _Dart_CObject::@86::@90 as_typed_data
const char * as_string
struct _Dart_CObject::@86::@91 as_external_typed_data
struct _Dart_CObject::@86::@89 as_array

◆ WriteRef()

void dart::ApiMessageSerializer::WriteRef ( Dart_CObject object)
inline

Definition at line 326 of file message_snapshot.cc.

326 {
327 intptr_t index = GetObjectId(object);
328 ASSERT(index != WeakTable::kNoValue);
329 WriteUnsigned(index);
330 }

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