OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_DART_API_MESSAGE_H_ | 5 #ifndef VM_DART_API_MESSAGE_H_ |
6 #define VM_DART_API_MESSAGE_H_ | 6 #define VM_DART_API_MESSAGE_H_ |
7 | 7 |
8 #include "vm/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
9 #include "vm/snapshot.h" | 9 #include "vm/snapshot.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 // Reads a message snapshot into a C structure. | 27 // Reads a message snapshot into a C structure. |
28 class ApiMessageReader : public BaseReader { | 28 class ApiMessageReader : public BaseReader { |
29 public: | 29 public: |
30 ApiMessageReader(const uint8_t* buffer, intptr_t length, ReAlloc alloc); | 30 ApiMessageReader(const uint8_t* buffer, intptr_t length, ReAlloc alloc); |
31 ~ApiMessageReader() { } | 31 ~ApiMessageReader() { } |
32 | 32 |
33 Dart_CObject* ReadMessage(); | 33 Dart_CObject* ReadMessage(); |
34 | 34 |
35 private: | 35 private: |
36 class BackwardReferenceNode { | |
37 public: | |
38 BackwardReferenceNode(Dart_CObject* reference, bool is_deserialized) | |
39 : reference_(reference), is_deserialized_(is_deserialized) {} | |
40 Dart_CObject* reference() const { return reference_; } | |
41 void set_reference(Dart_CObject* reference) { reference_ = reference; } | |
42 bool is_deserialized() const { return is_deserialized_; } | |
43 void set_is_deserialized(bool value) { is_deserialized_ = value; } | |
44 | |
45 private: | |
46 Dart_CObject* reference_; | |
47 bool is_deserialized_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(BackwardReferenceNode); | |
50 }; | |
51 | |
36 // Allocates a Dart_CObject object. | 52 // Allocates a Dart_CObject object. |
37 Dart_CObject* AllocateDartCObject(); | 53 Dart_CObject* AllocateDartCObject(); |
38 // Allocates a Dart_CObject object with the specified type. | 54 // Allocates a Dart_CObject object with the specified type. |
39 Dart_CObject* AllocateDartCObject(Dart_CObject::Type type); | 55 Dart_CObject* AllocateDartCObject(Dart_CObject::Type type); |
40 // Allocates a Dart_CObject object representing an unsupported | 56 // Allocates a Dart_CObject object representing an unsupported |
41 // object in the API message. | 57 // object in the API message. |
42 Dart_CObject* AllocateDartCObjectUnsupported(); | 58 Dart_CObject* AllocateDartCObjectUnsupported(); |
43 // Allocates a Dart_CObject object for the null object. | 59 // Allocates a Dart_CObject object for the null object. |
44 Dart_CObject* AllocateDartCObjectNull(); | 60 Dart_CObject* AllocateDartCObjectNull(); |
45 // Allocates a Dart_CObject object for a boolean object. | 61 // Allocates a Dart_CObject object for a boolean object. |
46 Dart_CObject* AllocateDartCObjectBool(bool value); | 62 Dart_CObject* AllocateDartCObjectBool(bool value); |
47 // Allocates a Dart_CObject object for for a 32-bit integer. | 63 // Allocates a Dart_CObject object for for a 32-bit integer. |
48 Dart_CObject* AllocateDartCObjectInt32(int32_t value); | 64 Dart_CObject* AllocateDartCObjectInt32(int32_t value); |
49 // Allocates a Dart_CObject object for for a 64-bit integer. | 65 // Allocates a Dart_CObject object for for a 64-bit integer. |
50 Dart_CObject* AllocateDartCObjectInt64(int64_t value); | 66 Dart_CObject* AllocateDartCObjectInt64(int64_t value); |
51 // Allocates a Dart_CObject object for bigint data. | 67 // Allocates a Dart_CObject object for bigint data. |
52 Dart_CObject* AllocateDartCObjectBigint(intptr_t length); | 68 Dart_CObject* AllocateDartCObjectBigint(intptr_t length); |
53 // Allocates a Dart_CObject object for a double. | 69 // Allocates a Dart_CObject object for a double. |
54 Dart_CObject* AllocateDartCObjectDouble(double value); | 70 Dart_CObject* AllocateDartCObjectDouble(double value); |
55 // Allocates a Dart_CObject object for string data. | 71 // Allocates a Dart_CObject object for string data. |
56 Dart_CObject* AllocateDartCObjectString(intptr_t length); | 72 Dart_CObject* AllocateDartCObjectString(intptr_t length); |
57 // Allocates a C Dart_CObject object for byte data. | 73 // Allocates a C Dart_CObject object for byte data. |
58 Dart_CObject* AllocateDartCObjectUint8Array(intptr_t length); | 74 Dart_CObject* AllocateDartCObjectUint8Array(intptr_t length); |
59 // Allocates a C array of Dart_CObject objects. | 75 // Allocates a C array of Dart_CObject objects. |
60 Dart_CObject* AllocateDartCObjectArray(intptr_t length); | 76 Dart_CObject* AllocateDartCObjectArray(intptr_t length); |
77 // Allocates a backwards reference node. | |
78 BackwardReferenceNode* AllocateBackwardReferenceNode(Dart_CObject* reference, | |
cshapiro
2012/06/08 22:04:39
Just a suggestion: we already shorten "Reference"
siva
2012/06/11 20:49:06
Done.
| |
79 bool is_deserialized); | |
61 | 80 |
62 void Init(); | 81 void Init(); |
63 | 82 |
64 intptr_t LookupInternalClass(intptr_t class_header); | 83 intptr_t LookupInternalClass(intptr_t class_header); |
84 Dart_CObject* ReadInternalVMObject(intptr_t class_id, intptr_t object_id); | |
65 Dart_CObject* ReadInlinedObject(intptr_t object_id); | 85 Dart_CObject* ReadInlinedObject(intptr_t object_id); |
66 Dart_CObject* ReadObjectImpl(intptr_t header); | 86 Dart_CObject* ReadObjectImpl(); |
67 Dart_CObject* ReadIndexedObject(intptr_t object_id); | 87 Dart_CObject* ReadIndexedObject(intptr_t object_id); |
88 Dart_CObject* ReadObjectRef(); | |
68 Dart_CObject* ReadObject(); | 89 Dart_CObject* ReadObject(); |
69 | 90 |
70 // Add object to backward references. | 91 // Add object to backward references. |
71 void AddBackwardReference(intptr_t id, Dart_CObject* obj); | 92 void AddBackwardReference(intptr_t id, |
93 Dart_CObject* obj, | |
94 bool is_deserialized); | |
95 | |
96 // Get an object from the backward references list. | |
97 Dart_CObject* GetBackwardReference(intptr_t id); | |
72 | 98 |
73 Dart_CObject_Internal* AsInternal(Dart_CObject* object) { | 99 Dart_CObject_Internal* AsInternal(Dart_CObject* object) { |
74 ASSERT(object->type >= Dart_CObject::kNumberOfTypes); | 100 ASSERT(object->type >= Dart_CObject::kNumberOfTypes); |
75 return reinterpret_cast<Dart_CObject_Internal*>(object); | 101 return reinterpret_cast<Dart_CObject_Internal*>(object); |
76 } | 102 } |
77 | 103 |
78 // Allocation of the structures for the decoded message happens | 104 // Allocation of the structures for the decoded message happens |
79 // either in the supplied zone or using the supplied allocation | 105 // either in the supplied zone or using the supplied allocation |
80 // function. | 106 // function. |
81 ReAlloc alloc_; | 107 ReAlloc alloc_; |
82 ApiGrowableArray<Dart_CObject*> backward_references_; | 108 ApiGrowableArray<BackwardReferenceNode*> backward_references_; |
83 | 109 |
84 Dart_CObject type_arguments_marker; | 110 Dart_CObject type_arguments_marker; |
85 Dart_CObject dynamic_type_marker; | 111 Dart_CObject dynamic_type_marker; |
86 }; | 112 }; |
87 | 113 |
88 | 114 |
89 class ApiMessageWriter : public BaseWriter { | 115 class ApiMessageWriter : public BaseWriter { |
90 public: | 116 public: |
91 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc) | 117 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc) |
92 : BaseWriter(buffer, alloc), object_id_(0) { | 118 : BaseWriter(buffer, alloc), object_id_(0), |
119 forward_list_(NULL), forward_list_length_(0), forward_id_(0) { | |
93 ASSERT(kDartCObjectTypeMask >= Dart_CObject::kNumberOfTypes - 1); | 120 ASSERT(kDartCObjectTypeMask >= Dart_CObject::kNumberOfTypes - 1); |
94 } | 121 } |
95 ~ApiMessageWriter() { } | 122 ~ApiMessageWriter() { |
123 delete forward_list_; | |
124 } | |
96 | 125 |
97 // Writes a message of integers. | 126 // Writes a message of integers. |
98 void WriteMessage(intptr_t field_count, intptr_t *data); | 127 void WriteMessage(intptr_t field_count, intptr_t *data); |
99 | 128 |
100 void WriteCMessage(Dart_CObject* object); | 129 void WriteCMessage(Dart_CObject* object); |
101 | 130 |
102 void FinalizeBuffer() { | 131 void FinalizeBuffer() { |
103 BaseWriter::FinalizeBuffer(Snapshot::kMessage); | 132 BaseWriter::FinalizeBuffer(Snapshot::kMessage); |
104 } | 133 } |
105 | 134 |
106 private: | 135 private: |
107 static const intptr_t kDartCObjectTypeBits = 4; | 136 static const intptr_t kDartCObjectTypeBits = 4; |
108 static const intptr_t kDartCObjectTypeMask = (1 << kDartCObjectTypeBits) - 1; | 137 static const intptr_t kDartCObjectTypeMask = (1 << kDartCObjectTypeBits) - 1; |
109 static const intptr_t kDartCObjectMarkMask = ~kDartCObjectTypeMask; | 138 static const intptr_t kDartCObjectMarkMask = ~kDartCObjectTypeMask; |
110 static const intptr_t kDartCObjectMarkOffset = 1; | 139 static const intptr_t kDartCObjectMarkOffset = 1; |
111 | 140 |
112 void MarkCObject(Dart_CObject* object, intptr_t object_id); | 141 void MarkCObject(Dart_CObject* object, intptr_t object_id); |
113 void UnmarkCObject(Dart_CObject* object); | 142 void UnmarkCObject(Dart_CObject* object); |
114 bool IsCObjectMarked(Dart_CObject* object); | 143 bool IsCObjectMarked(Dart_CObject* object); |
115 intptr_t GetMarkedCObjectMark(Dart_CObject* object); | 144 intptr_t GetMarkedCObjectMark(Dart_CObject* object); |
116 void UnmarkAllCObjects(Dart_CObject* object); | 145 void UnmarkAllCObjects(Dart_CObject* object); |
146 void AddToForwardList(Dart_CObject* object); | |
117 | 147 |
118 void WriteSmi(int64_t value); | 148 void WriteSmi(int64_t value); |
119 void WriteMint(Dart_CObject* object, int64_t value); | 149 void WriteMint(Dart_CObject* object, int64_t value); |
120 void WriteInt32(Dart_CObject* object); | 150 void WriteInt32(Dart_CObject* object); |
121 void WriteInt64(Dart_CObject* object); | 151 void WriteInt64(Dart_CObject* object); |
122 void WriteInlinedHeader(Dart_CObject* object); | 152 void WriteInlinedHeader(Dart_CObject* object); |
123 void WriteCObject(Dart_CObject* object); | 153 void WriteCObject(Dart_CObject* object); |
154 void WriteCObjectRef(Dart_CObject* object); | |
155 void WriteForwardedCObject(Dart_CObject* object); | |
156 void WriteCObjectInlined(Dart_CObject* object, Dart_CObject::Type type); | |
124 | 157 |
125 intptr_t object_id_; | 158 intptr_t object_id_; |
159 Dart_CObject** forward_list_; | |
160 intptr_t forward_list_length_; | |
161 intptr_t forward_id_; | |
126 | 162 |
127 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter); | 163 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter); |
128 }; | 164 }; |
129 | 165 |
130 } // namespace dart | 166 } // namespace dart |
131 | 167 |
132 #endif // VM_DART_API_MESSAGE_H_ | 168 #endif // VM_DART_API_MESSAGE_H_ |
OLD | NEW |