| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // updated (currently type_arguments is leaked). | 199 // updated (currently type_arguments is leaked). |
| 200 Dart_CObject* type_arguments = ReadObjectImpl(); | 200 Dart_CObject* type_arguments = ReadObjectImpl(); |
| 201 if (type_arguments != &type_arguments_marker && | 201 if (type_arguments != &type_arguments_marker && |
| 202 type_arguments->type != Dart_CObject::kNull) { | 202 type_arguments->type != Dart_CObject::kNull) { |
| 203 return AllocateDartCObjectUnsupported(); | 203 return AllocateDartCObjectUnsupported(); |
| 204 } | 204 } |
| 205 for (int i = 0; i < len; i++) { | 205 for (int i = 0; i < len; i++) { |
| 206 value->value.as_array.values[i] = ReadObjectRef(); | 206 value->value.as_array.values[i] = ReadObjectRef(); |
| 207 } | 207 } |
| 208 return value; | 208 return value; |
| 209 } else if (class_id == kGrowableObjectArrayCid) { | |
| 210 // A GrowableObjectArray is serialized as its length followed by its backing | |
| 211 // store. The backing store is an array with a length which might be longer | |
| 212 // than the length of the GrowableObjectArray. | |
| 213 intptr_t len = ReadSmiValue(); | |
| 214 Dart_CObject* value = GetBackRef(object_id); | |
| 215 ASSERT(value == NULL); | |
| 216 // Allocate an empty array for the GrowableObjectArray which will be updated | |
| 217 // to point to the content when the backing store has been deserialized. | |
| 218 value = AllocateDartCObjectArray(0); | |
| 219 AddBackRef(object_id, value, kIsDeserialized); | |
| 220 // Read the content of the GrowableObjectArray. | |
| 221 Dart_CObject* content = ReadObjectImpl(); | |
| 222 ASSERT(content->type == Dart_CObject::kArray); | |
| 223 // Make the empty array allocated point to the backing store content. | |
| 224 value->value.as_array.length = len; | |
| 225 value->value.as_array.values = content->value.as_array.values; | |
| 226 return value; | |
| 227 } | 209 } |
| 228 | 210 |
| 229 return ReadInternalVMObject(class_id, object_id); | 211 return ReadInternalVMObject(class_id, object_id); |
| 230 } | 212 } |
| 231 | 213 |
| 232 | 214 |
| 233 Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) { | 215 Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) { |
| 234 if (Symbols::IsVMSymbolId(object_id)) { | 216 if (Symbols::IsVMSymbolId(object_id)) { |
| 235 RawOneByteString* str = | 217 RawOneByteString* str = |
| 236 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id)); | 218 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 ASSERT((class_header & kSmiTagMask) != 0); | 260 ASSERT((class_header & kSmiTagMask) != 0); |
| 279 intptr_t object_id = SerializedHeaderData::decode(value); | 261 intptr_t object_id = SerializedHeaderData::decode(value); |
| 280 intptr_t class_id = LookupInternalClass(class_header); | 262 intptr_t class_id = LookupInternalClass(class_header); |
| 281 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { | 263 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { |
| 282 ASSERT(GetBackRef(object_id) == NULL); | 264 ASSERT(GetBackRef(object_id) == NULL); |
| 283 intptr_t len = ReadSmiValue(); | 265 intptr_t len = ReadSmiValue(); |
| 284 Dart_CObject* value = AllocateDartCObjectArray(len); | 266 Dart_CObject* value = AllocateDartCObjectArray(len); |
| 285 AddBackRef(object_id, value, kIsNotDeserialized); | 267 AddBackRef(object_id, value, kIsNotDeserialized); |
| 286 return value; | 268 return value; |
| 287 } | 269 } |
| 270 |
| 288 intptr_t tags = ReadIntptrValue(); | 271 intptr_t tags = ReadIntptrValue(); |
| 289 USE(tags); | 272 USE(tags); |
| 290 | 273 |
| 291 return ReadInternalVMObject(class_id, object_id); | 274 return ReadInternalVMObject(class_id, object_id); |
| 292 } | 275 } |
| 293 | 276 |
| 294 | 277 |
| 295 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, | 278 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, |
| 296 intptr_t object_id) { | 279 intptr_t object_id) { |
| 297 switch (class_id) { | 280 switch (class_id) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 Dart_CObject* object = AllocateDartCObjectUint8Array(len); | 366 Dart_CObject* object = AllocateDartCObjectUint8Array(len); |
| 384 AddBackRef(object_id, object, kIsDeserialized); | 367 AddBackRef(object_id, object, kIsDeserialized); |
| 385 if (len > 0) { | 368 if (len > 0) { |
| 386 uint8_t* p = object->value.as_byte_array.values; | 369 uint8_t* p = object->value.as_byte_array.values; |
| 387 for (intptr_t i = 0; i < len; i++) { | 370 for (intptr_t i = 0; i < len; i++) { |
| 388 p[i] = Read<uint8_t>(); | 371 p[i] = Read<uint8_t>(); |
| 389 } | 372 } |
| 390 } | 373 } |
| 391 return object; | 374 return object; |
| 392 } | 375 } |
| 376 case kGrowableObjectArrayCid: { |
| 377 // A GrowableObjectArray is serialized as its length followed by |
| 378 // its backing store. The backing store is an array with a |
| 379 // length which might be longer than the length of the |
| 380 // GrowableObjectArray. |
| 381 intptr_t len = ReadSmiValue(); |
| 382 |
| 383 Dart_CObject* value = GetBackRef(object_id); |
| 384 ASSERT(value == NULL); |
| 385 // Allocate an empty array for the GrowableObjectArray which |
| 386 // will be updated to point to the content when the backing |
| 387 // store has been deserialized. |
| 388 value = AllocateDartCObjectArray(0); |
| 389 AddBackRef(object_id, value, kIsDeserialized); |
| 390 // Read the content of the GrowableObjectArray. |
| 391 Dart_CObject* content = ReadObjectImpl(); |
| 392 ASSERT(content->type == Dart_CObject::kArray); |
| 393 // Make the empty array allocated point to the backing store content. |
| 394 value->value.as_array.length = len; |
| 395 value->value.as_array.values = content->value.as_array.values; |
| 396 return value; |
| 397 } |
| 393 default: | 398 default: |
| 394 // Everything else not supported. | 399 // Everything else not supported. |
| 395 return AllocateDartCObjectUnsupported(); | 400 return AllocateDartCObjectUnsupported(); |
| 396 } | 401 } |
| 397 } | 402 } |
| 398 | 403 |
| 399 | 404 |
| 400 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { | 405 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { |
| 401 if (object_id == kTrueValue) { | 406 if (object_id == kTrueValue) { |
| 402 return AllocateDartCObjectBool(true); | 407 return AllocateDartCObjectBool(true); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 // Write out all objects that were added to the forward list and have | 799 // Write out all objects that were added to the forward list and have |
| 795 // not been serialized yet. These would typically be fields of arrays. | 800 // not been serialized yet. These would typically be fields of arrays. |
| 796 // NOTE: The forward list might grow as we process the list. | 801 // NOTE: The forward list might grow as we process the list. |
| 797 for (intptr_t i = 0; i < forward_id_; i++) { | 802 for (intptr_t i = 0; i < forward_id_; i++) { |
| 798 WriteForwardedCObject(forward_list_[i]); | 803 WriteForwardedCObject(forward_list_[i]); |
| 799 } | 804 } |
| 800 UnmarkAllCObjects(object); | 805 UnmarkAllCObjects(object); |
| 801 } | 806 } |
| 802 | 807 |
| 803 } // namespace dart | 808 } // namespace dart |
| OLD | NEW |