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 |
11 namespace dart { | 11 namespace dart { |
12 | 12 |
13 // Use this C structure for reading internal objects in the serialized | 13 // Use this C structure for reading internal objects in the serialized |
14 // data. These are objects that we need to process in order to | 14 // data. These are objects that we need to process in order to |
15 // generate the Dart_CObject graph but that we don't want to expose in | 15 // generate the Dart_CObject graph but that we don't want to expose in |
16 // that graph. | 16 // that graph. |
17 // TODO(sjesse): Remove this when message serialization format is | 17 // TODO(sjesse): Remove this when message serialization format is |
18 // updated. | 18 // updated. |
19 struct Dart_CObject_Internal : public Dart_CObject { | 19 struct Dart_CObject_Internal : public Dart_CObject { |
20 enum Type { | 20 enum Type { |
21 kTypeArguments = Dart_CObject::kNumberOfTypes, | 21 kTypeArguments = Dart_CObject::kNumberOfTypes, |
22 kDynamicType, | 22 kDynamicType, |
23 }; | 23 }; |
24 }; | 24 }; |
25 | 25 |
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 Snapshot* snapshot, ReAlloc alloc); |
31 ~ApiMessageReader() { } | 31 ~ApiMessageReader() { } |
32 | 32 |
33 Dart_CObject* ReadMessage(); | 33 Dart_CObject* ReadMessage(); |
34 | 34 |
35 private: | 35 private: |
36 class BackRefNode { | 36 class BackRefNode { |
37 public: | 37 public: |
38 BackRefNode(Dart_CObject* reference, DeserializeState state) | 38 BackRefNode(Dart_CObject* reference, DeserializeState state) |
39 : reference_(reference), state_(state) {} | 39 : reference_(reference), state_(state) {} |
40 Dart_CObject* reference() const { return reference_; } | 40 Dart_CObject* reference() const { return reference_; } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc) | 115 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc) |
116 : BaseWriter(buffer, alloc), object_id_(0), | 116 : BaseWriter(buffer, alloc), object_id_(0), |
117 forward_list_(NULL), forward_list_length_(0), forward_id_(0) { | 117 forward_list_(NULL), forward_list_length_(0), forward_id_(0) { |
118 ASSERT(kDartCObjectTypeMask >= Dart_CObject::kNumberOfTypes - 1); | 118 ASSERT(kDartCObjectTypeMask >= Dart_CObject::kNumberOfTypes - 1); |
119 } | 119 } |
120 ~ApiMessageWriter() { | 120 ~ApiMessageWriter() { |
121 ::free(forward_list_); | 121 ::free(forward_list_); |
122 } | 122 } |
123 | 123 |
124 // Writes a message of integers. | 124 // Writes a message of integers. |
125 void WriteMessage(intptr_t field_count, intptr_t *data); | 125 intptr_t WriteMessage(intptr_t field_count, intptr_t *data); |
126 | 126 |
127 void WriteCMessage(Dart_CObject* object); | 127 intptr_t WriteCMessage(Dart_CObject* object); |
128 | 128 |
129 void FinalizeBuffer() { | 129 intptr_t FinalizeBuffer() { |
130 BaseWriter::FinalizeBuffer(Snapshot::kMessage); | 130 return BaseWriter::FinalizeBuffer(Snapshot::kMessage); |
131 } | 131 } |
132 | 132 |
133 private: | 133 private: |
134 static const intptr_t kDartCObjectTypeBits = 4; | 134 static const intptr_t kDartCObjectTypeBits = 4; |
135 static const intptr_t kDartCObjectTypeMask = (1 << kDartCObjectTypeBits) - 1; | 135 static const intptr_t kDartCObjectTypeMask = (1 << kDartCObjectTypeBits) - 1; |
136 static const intptr_t kDartCObjectMarkMask = ~kDartCObjectTypeMask; | 136 static const intptr_t kDartCObjectMarkMask = ~kDartCObjectTypeMask; |
137 static const intptr_t kDartCObjectMarkOffset = 1; | 137 static const intptr_t kDartCObjectMarkOffset = 1; |
138 | 138 |
139 void MarkCObject(Dart_CObject* object, intptr_t object_id); | 139 void MarkCObject(Dart_CObject* object, intptr_t object_id); |
140 void UnmarkCObject(Dart_CObject* object); | 140 void UnmarkCObject(Dart_CObject* object); |
(...skipping 17 matching lines...) Expand all Loading... |
158 Dart_CObject** forward_list_; | 158 Dart_CObject** forward_list_; |
159 intptr_t forward_list_length_; | 159 intptr_t forward_list_length_; |
160 intptr_t forward_id_; | 160 intptr_t forward_id_; |
161 | 161 |
162 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter); | 162 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter); |
163 }; | 163 }; |
164 | 164 |
165 } // namespace dart | 165 } // namespace dart |
166 | 166 |
167 #endif // VM_DART_API_MESSAGE_H_ | 167 #endif // VM_DART_API_MESSAGE_H_ |
OLD | NEW |