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 #include "vm/dart_api_message.h" | 5 #include "vm/dart_api_message.h" |
6 #include "vm/object.h" | 6 #include "vm/object.h" |
7 #include "vm/snapshot_ids.h" | 7 #include "vm/snapshot_ids.h" |
8 #include "vm/symbols.h" | 8 #include "vm/symbols.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 value->value.as_array.length = length; | 155 value->value.as_array.length = length; |
156 if (length > 0) { | 156 if (length > 0) { |
157 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); | 157 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); |
158 } else { | 158 } else { |
159 value->value.as_array.values = NULL; | 159 value->value.as_array.values = NULL; |
160 } | 160 } |
161 return value; | 161 return value; |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 Dart_CObject* ApiMessageReader::AllocateDartCObjectGrowableObjectArray( | |
166 intptr_t length) { | |
167 // Allocate a Dart_CObject structure for holding the GrowableObjectArray | |
Mads Ager (google)
2012/09/10 13:28:18
Move this comment to before the method as it is a
Søren Gjesse
2012/09/10 14:02:02
Ended up removing this method.
| |
168 // length. This object will be patched to an array when the actual content | |
169 // of the GrowableObjectArray is read. | |
170 Dart_CObject* value = | |
171 reinterpret_cast<Dart_CObject*>( | |
172 alloc_(NULL, 0, sizeof(Dart_CObject))); | |
173 ASSERT(value != NULL); | |
174 // Temporarily assign an illegal type. | |
175 value->type = static_cast<Dart_CObject::Type>(Dart_CObject::kNumberOfTypes); | |
176 value->value.as_array.length = length; | |
177 value->value.as_array.values = NULL; | |
178 return value; | |
179 } | |
180 | |
181 | |
165 ApiMessageReader::BackRefNode* ApiMessageReader::AllocateBackRefNode( | 182 ApiMessageReader::BackRefNode* ApiMessageReader::AllocateBackRefNode( |
166 Dart_CObject* reference, | 183 Dart_CObject* reference, |
167 DeserializeState state) { | 184 DeserializeState state) { |
168 BackRefNode* value = | 185 BackRefNode* value = |
169 reinterpret_cast<BackRefNode*>(alloc_(NULL, 0, sizeof(BackRefNode))); | 186 reinterpret_cast<BackRefNode*>(alloc_(NULL, 0, sizeof(BackRefNode))); |
170 value->set_reference(reference); | 187 value->set_reference(reference); |
171 value->set_state(state); | 188 value->set_state(state); |
172 return value; | 189 return value; |
173 } | 190 } |
174 | 191 |
(...skipping 24 matching lines...) Expand all Loading... | |
199 // updated (currently type_arguments is leaked). | 216 // updated (currently type_arguments is leaked). |
200 Dart_CObject* type_arguments = ReadObjectImpl(); | 217 Dart_CObject* type_arguments = ReadObjectImpl(); |
201 if (type_arguments != &type_arguments_marker && | 218 if (type_arguments != &type_arguments_marker && |
202 type_arguments->type != Dart_CObject::kNull) { | 219 type_arguments->type != Dart_CObject::kNull) { |
203 return AllocateDartCObjectUnsupported(); | 220 return AllocateDartCObjectUnsupported(); |
204 } | 221 } |
205 for (int i = 0; i < len; i++) { | 222 for (int i = 0; i < len; i++) { |
206 value->value.as_array.values[i] = ReadObjectRef(); | 223 value->value.as_array.values[i] = ReadObjectRef(); |
207 } | 224 } |
208 return value; | 225 return value; |
226 } else if (class_id == kGrowableObjectArrayCid) { | |
227 // A GrowableObjectArray is serialized as its length followed by its backing | |
228 // store. The backing store is an array with a length which might be longer | |
229 // than the length of the GrowableObjectArray. | |
230 intptr_t len = ReadSmiValue(); | |
231 Dart_CObject* value = GetBackRef(object_id); | |
232 if (value == NULL) { | |
233 value = AllocateDartCObjectGrowableObjectArray(len); | |
234 AddBackRef(object_id, value, kIsDeserialized); | |
235 } | |
236 // Read the content of the GrowableObjectArray. | |
237 Dart_CObject* content = ReadObjectImpl(); | |
238 ASSERT(content->type == Dart_CObject::kArray); | |
239 // Make the GrowableObjectArray read into an array. | |
Mads Ager (google)
2012/09/10 13:28:18
I find this comment confusing. Maybe add comments
Søren Gjesse
2012/09/10 14:02:02
Simplified to just allocate an empty array for the
| |
240 value->type = content->type; | |
241 value->value.as_array.values = content->value.as_array.values; | |
242 return value; | |
209 } | 243 } |
210 | 244 |
211 return ReadInternalVMObject(class_id, object_id); | 245 return ReadInternalVMObject(class_id, object_id); |
212 } | 246 } |
213 | 247 |
214 | 248 |
215 Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) { | 249 Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) { |
216 if (Symbols::IsVMSymbolId(object_id)) { | 250 if (Symbols::IsVMSymbolId(object_id)) { |
217 RawOneByteString* str = | 251 RawOneByteString* str = |
218 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id)); | 252 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id)); |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 // Write out all objects that were added to the forward list and have | 810 // Write out all objects that were added to the forward list and have |
777 // not been serialized yet. These would typically be fields of arrays. | 811 // not been serialized yet. These would typically be fields of arrays. |
778 // NOTE: The forward list might grow as we process the list. | 812 // NOTE: The forward list might grow as we process the list. |
779 for (intptr_t i = 0; i < forward_id_; i++) { | 813 for (intptr_t i = 0; i < forward_id_; i++) { |
780 WriteForwardedCObject(forward_list_[i]); | 814 WriteForwardedCObject(forward_list_[i]); |
781 } | 815 } |
782 UnmarkAllCObjects(object); | 816 UnmarkAllCObjects(object); |
783 } | 817 } |
784 | 818 |
785 } // namespace dart | 819 } // namespace dart |
OLD | NEW |