Chromium Code Reviews| 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/object_store.h" | 7 #include "vm/object_store.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 value->value.as_array.length = length; | 159 value->value.as_array.length = length; |
| 160 if (length > 0) { | 160 if (length > 0) { |
| 161 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); | 161 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); |
| 162 } else { | 162 } else { |
| 163 value->value.as_array.values = NULL; | 163 value->value.as_array.values = NULL; |
| 164 } | 164 } |
| 165 return value; | 165 return value; |
| 166 } | 166 } |
| 167 | 167 |
| 168 | 168 |
| 169 ApiMessageReader::BackwardReferenceNode* | |
| 170 ApiMessageReader::AllocateBackwardReferenceNode( | |
| 171 Dart_CObject* reference, bool is_deserialized) { | |
| 172 BackwardReferenceNode* value = | |
| 173 reinterpret_cast<BackwardReferenceNode*>( | |
| 174 alloc_(NULL, 0, sizeof(BackwardReferenceNode))); | |
| 175 value->set_reference(reference); | |
| 176 value->set_is_deserialized(is_deserialized); | |
| 177 return value; | |
| 178 } | |
| 179 | |
| 180 | |
| 169 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { | 181 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { |
| 170 // Read the class header information and lookup the class. | 182 // Read the class header information and lookup the class. |
| 171 intptr_t class_header = ReadIntptrValue(); | 183 intptr_t class_header = ReadIntptrValue(); |
| 172 intptr_t tags = ReadIntptrValue(); | 184 intptr_t tags = ReadIntptrValue(); |
| 173 USE(tags); | 185 USE(tags); |
| 174 intptr_t class_id; | 186 intptr_t class_id; |
| 175 | 187 |
| 176 // Reading of regular dart instances is not supported. | 188 // Reading of regular dart instances is not supported. |
| 177 if (SerializedHeaderData::decode(class_header) == kInstanceId) { | 189 if (SerializedHeaderData::decode(class_header) == kInstanceId) { |
| 178 return AllocateDartCObjectUnsupported(); | 190 return AllocateDartCObjectUnsupported(); |
| 179 } | 191 } |
| 180 | 192 |
| 181 ASSERT((class_header & kSmiTagMask) != 0); | 193 ASSERT((class_header & kSmiTagMask) != 0); |
| 182 class_id = LookupInternalClass(class_header); | 194 class_id = LookupInternalClass(class_header); |
| 195 if (class_id == ObjectStore::kArrayClass || | |
| 196 class_id == ObjectStore::kImmutableArrayClass) { | |
| 197 intptr_t len = ReadSmiValue(); | |
| 198 Dart_CObject* value = GetBackwardReference(object_id); | |
| 199 if (value == NULL) { | |
| 200 value = AllocateDartCObjectArray(len); | |
| 201 AddBackwardReference(object_id, value, true); | |
| 202 } | |
| 203 // Skip type arguments. | |
| 204 // TODO(sjesse): Remove this when message serialization format is | |
| 205 // updated (currently type_arguments is leaked). | |
| 206 Dart_CObject* type_arguments = ReadObjectImpl(); | |
| 207 if (type_arguments != &type_arguments_marker && | |
| 208 type_arguments->type != Dart_CObject::kNull) { | |
| 209 return AllocateDartCObjectUnsupported(); | |
| 210 } | |
| 211 for (int i = 0; i < len; i++) { | |
| 212 value->value.as_array.values[i] = ReadObjectRef(); | |
| 213 } | |
| 214 return value; | |
| 215 } | |
| 216 | |
| 217 return ReadInternalVMObject(class_id, object_id); | |
| 218 } | |
| 219 | |
| 220 | |
| 221 Dart_CObject* ApiMessageReader::ReadObjectRef() { | |
| 222 int64_t value = Read<int64_t>(); | |
| 223 if ((value & kSmiTagMask) == 0) { | |
| 224 int64_t untagged_value = value >> kSmiTagShift; | |
| 225 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { | |
| 226 return AllocateDartCObjectInt32(untagged_value); | |
| 227 } else { | |
| 228 return AllocateDartCObjectInt64(untagged_value); | |
| 229 } | |
| 230 } | |
| 231 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | |
| 232 SerializedHeaderType header_type = SerializedHeaderTag::decode(value); | |
| 233 intptr_t header_value = SerializedHeaderData::decode(value); | |
| 234 | |
| 235 if (header_type == kObjectId) { | |
| 236 return ReadIndexedObject(header_value); | |
| 237 } | |
| 238 ASSERT(header_type == kInlined); | |
| 239 // Read the class header information and lookup the class. | |
| 240 intptr_t class_header = ReadIntptrValue(); | |
| 241 | |
| 242 // Reading of regular dart instances is not supported. | |
| 243 if (SerializedHeaderData::decode(class_header) == kInstanceId) { | |
| 244 return AllocateDartCObjectUnsupported(); | |
| 245 } | |
| 246 ASSERT((class_header & kSmiTagMask) != 0); | |
| 247 intptr_t object_id = header_value; | |
| 248 intptr_t class_id = LookupInternalClass(class_header); | |
| 249 if (class_id == ObjectStore::kArrayClass || | |
| 250 class_id == ObjectStore::kImmutableArrayClass) { | |
| 251 ASSERT(GetBackwardReference(object_id) == NULL); | |
| 252 intptr_t len = ReadSmiValue(); | |
| 253 Dart_CObject* value = AllocateDartCObjectArray(len); | |
| 254 AddBackwardReference(object_id, value, false); | |
| 255 return value; | |
| 256 } | |
| 257 intptr_t tags = ReadIntptrValue(); | |
| 258 USE(tags); | |
| 259 | |
| 260 return ReadInternalVMObject(class_id, object_id); | |
| 261 } | |
| 262 | |
| 263 | |
| 264 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, | |
| 265 intptr_t object_id) { | |
| 183 switch (class_id) { | 266 switch (class_id) { |
| 184 case Object::kClassClass: { | 267 case Object::kClassClass: { |
| 185 return AllocateDartCObjectUnsupported(); | 268 return AllocateDartCObjectUnsupported(); |
| 186 } | 269 } |
| 187 case Object::kTypeArgumentsClass: { | 270 case Object::kTypeArgumentsClass: { |
| 188 // TODO(sjesse): Remove this when message serialization format is | 271 // TODO(sjesse): Remove this when message serialization format is |
| 189 // updated (currently length is leaked). | 272 // updated (currently length is leaked). |
| 190 Dart_CObject* value = &type_arguments_marker; | 273 Dart_CObject* value = &type_arguments_marker; |
| 191 AddBackwardReference(object_id, value); | 274 AddBackwardReference(object_id, value, true); |
| 192 Dart_CObject* length = ReadObject(); | 275 Dart_CObject* length = ReadObjectImpl(); |
| 193 ASSERT(length->type == Dart_CObject::kInt32); | 276 ASSERT(length->type == Dart_CObject::kInt32); |
| 194 for (int i = 0; i < length->value.as_int32; i++) { | 277 for (int i = 0; i < length->value.as_int32; i++) { |
| 195 Dart_CObject* type = ReadObject(); | 278 Dart_CObject* type = ReadObjectImpl(); |
| 196 if (type != &dynamic_type_marker) { | 279 if (type != &dynamic_type_marker) { |
| 197 return AllocateDartCObjectUnsupported(); | 280 return AllocateDartCObjectUnsupported(); |
| 198 } | 281 } |
| 199 } | 282 } |
| 200 return value; | 283 return value; |
| 201 } | 284 } |
| 202 case Object::kTypeParameterClass: { | 285 case Object::kTypeParameterClass: { |
| 203 // TODO(sgjesse): Fix this workaround ignoring the type parameter. | 286 // TODO(sgjesse): Fix this workaround ignoring the type parameter. |
| 204 Dart_CObject* value = &dynamic_type_marker; | 287 Dart_CObject* value = &dynamic_type_marker; |
| 205 AddBackwardReference(object_id, value); | 288 AddBackwardReference(object_id, value, true); |
| 206 intptr_t index = ReadIntptrValue(); | 289 intptr_t index = ReadIntptrValue(); |
| 207 USE(index); | 290 USE(index); |
| 208 intptr_t token_index = ReadIntptrValue(); | 291 intptr_t token_index = ReadIntptrValue(); |
| 209 USE(token_index); | 292 USE(token_index); |
| 210 int8_t type_state = Read<int8_t>(); | 293 int8_t type_state = Read<int8_t>(); |
| 211 USE(type_state); | 294 USE(type_state); |
| 212 Dart_CObject* parameterized_class = ReadObject(); | 295 Dart_CObject* parameterized_class = ReadObjectImpl(); |
| 213 // The type parameter is finalized, therefore parameterized_class is null. | 296 // The type parameter is finalized, therefore parameterized_class is null. |
| 214 ASSERT(parameterized_class->type == Dart_CObject::kNull); | 297 ASSERT(parameterized_class->type == Dart_CObject::kNull); |
| 215 Dart_CObject* name = ReadObject(); | 298 Dart_CObject* name = ReadObjectImpl(); |
| 216 ASSERT(name->type == Dart_CObject::kString); | 299 ASSERT(name->type == Dart_CObject::kString); |
| 217 return value; | 300 return value; |
| 218 } | 301 } |
| 219 case ObjectStore::kArrayClass: { | |
| 220 intptr_t len = ReadSmiValue(); | |
| 221 Dart_CObject* value = AllocateDartCObjectArray(len); | |
| 222 AddBackwardReference(object_id, value); | |
| 223 // Skip type arguments. | |
| 224 // TODO(sjesse): Remove this when message serialization format is | |
| 225 // updated (currently type_arguments is leaked). | |
| 226 Dart_CObject* type_arguments = ReadObject(); | |
| 227 if (type_arguments != &type_arguments_marker && | |
| 228 type_arguments->type != Dart_CObject::kNull) { | |
| 229 return AllocateDartCObjectUnsupported(); | |
| 230 } | |
| 231 for (int i = 0; i < len; i++) { | |
| 232 value->value.as_array.values[i] = ReadObject(); | |
| 233 } | |
| 234 return value; | |
| 235 } | |
| 236 case ObjectStore::kMintClass: { | 302 case ObjectStore::kMintClass: { |
| 237 int64_t value = Read<int64_t>(); | 303 int64_t value = Read<int64_t>(); |
| 238 Dart_CObject* object; | 304 Dart_CObject* object; |
| 239 if (kMinInt32 <= value && value <= kMaxInt32) { | 305 if (kMinInt32 <= value && value <= kMaxInt32) { |
| 240 object = AllocateDartCObjectInt32(value); | 306 object = AllocateDartCObjectInt32(value); |
| 241 } else { | 307 } else { |
| 242 object = AllocateDartCObjectInt64(value); | 308 object = AllocateDartCObjectInt64(value); |
| 243 } | 309 } |
| 244 AddBackwardReference(object_id, object); | 310 AddBackwardReference(object_id, object, true); |
| 245 return object; | 311 return object; |
| 246 } | 312 } |
| 247 case ObjectStore::kBigintClass: { | 313 case ObjectStore::kBigintClass: { |
| 248 // Read in the hex string representation of the bigint. | 314 // Read in the hex string representation of the bigint. |
| 249 intptr_t len = ReadIntptrValue(); | 315 intptr_t len = ReadIntptrValue(); |
| 250 Dart_CObject* object = AllocateDartCObjectBigint(len); | 316 Dart_CObject* object = AllocateDartCObjectBigint(len); |
| 251 AddBackwardReference(object_id, object); | 317 AddBackwardReference(object_id, object, true); |
| 252 char* p = object->value.as_bigint; | 318 char* p = object->value.as_bigint; |
| 253 for (intptr_t i = 0; i < len; i++) { | 319 for (intptr_t i = 0; i < len; i++) { |
| 254 p[i] = Read<uint8_t>(); | 320 p[i] = Read<uint8_t>(); |
| 255 } | 321 } |
| 256 p[len] = '\0'; | 322 p[len] = '\0'; |
| 257 return object; | 323 return object; |
| 258 } | 324 } |
| 259 case ObjectStore::kDoubleClass: { | 325 case ObjectStore::kDoubleClass: { |
| 260 // Read the double value for the object. | 326 // Read the double value for the object. |
| 261 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); | 327 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); |
| 262 AddBackwardReference(object_id, object); | 328 AddBackwardReference(object_id, object, true); |
| 263 return object; | 329 return object; |
| 264 } | 330 } |
| 265 case ObjectStore::kOneByteStringClass: { | 331 case ObjectStore::kOneByteStringClass: { |
| 266 intptr_t len = ReadSmiValue(); | 332 intptr_t len = ReadSmiValue(); |
| 267 intptr_t hash = ReadSmiValue(); | 333 intptr_t hash = ReadSmiValue(); |
| 268 USE(hash); | 334 USE(hash); |
| 269 Dart_CObject* object = AllocateDartCObjectString(len); | 335 Dart_CObject* object = AllocateDartCObjectString(len); |
| 270 AddBackwardReference(object_id, object); | 336 AddBackwardReference(object_id, object, true); |
| 271 char* p = object->value.as_string; | 337 char* p = object->value.as_string; |
| 272 for (intptr_t i = 0; i < len; i++) { | 338 for (intptr_t i = 0; i < len; i++) { |
| 273 p[i] = Read<uint8_t>(); | 339 p[i] = Read<uint8_t>(); |
| 274 } | 340 } |
| 275 p[len] = '\0'; | 341 p[len] = '\0'; |
| 276 return object; | 342 return object; |
| 277 } | 343 } |
| 278 case ObjectStore::kTwoByteStringClass: | 344 case ObjectStore::kTwoByteStringClass: |
| 279 // Two byte strings not supported. | 345 // Two byte strings not supported. |
| 280 return AllocateDartCObjectUnsupported(); | 346 return AllocateDartCObjectUnsupported(); |
| 281 case ObjectStore::kFourByteStringClass: | 347 case ObjectStore::kFourByteStringClass: |
| 282 // Four byte strings not supported. | 348 // Four byte strings not supported. |
| 283 return AllocateDartCObjectUnsupported(); | 349 return AllocateDartCObjectUnsupported(); |
| 284 case ObjectStore::kUint8ArrayClass: { | 350 case ObjectStore::kUint8ArrayClass: { |
| 285 intptr_t len = ReadSmiValue(); | 351 intptr_t len = ReadSmiValue(); |
| 286 Dart_CObject* object = AllocateDartCObjectUint8Array(len); | 352 Dart_CObject* object = AllocateDartCObjectUint8Array(len); |
| 287 AddBackwardReference(object_id, object); | 353 AddBackwardReference(object_id, object, true); |
| 288 if (len > 0) { | 354 if (len > 0) { |
| 289 uint8_t* p = object->value.as_byte_array.values; | 355 uint8_t* p = object->value.as_byte_array.values; |
| 290 for (intptr_t i = 0; i < len; i++) { | 356 for (intptr_t i = 0; i < len; i++) { |
| 291 p[i] = Read<uint8_t>(); | 357 p[i] = Read<uint8_t>(); |
| 292 } | 358 } |
| 293 } | 359 } |
| 294 return object; | 360 return object; |
| 295 } | 361 } |
| 296 default: | 362 default: |
| 297 // Everything else not supported. | 363 // Everything else not supported. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 313 if (object_id == ObjectStore::kDynamicType || | 379 if (object_id == ObjectStore::kDynamicType || |
| 314 object_id == ObjectStore::kDoubleInterface || | 380 object_id == ObjectStore::kDoubleInterface || |
| 315 object_id == ObjectStore::kIntInterface || | 381 object_id == ObjectStore::kIntInterface || |
| 316 object_id == ObjectStore::kBoolInterface || | 382 object_id == ObjectStore::kBoolInterface || |
| 317 object_id == ObjectStore::kStringInterface) { | 383 object_id == ObjectStore::kStringInterface) { |
| 318 // Always return dynamic type (this is only a marker). | 384 // Always return dynamic type (this is only a marker). |
| 319 return &dynamic_type_marker; | 385 return &dynamic_type_marker; |
| 320 } | 386 } |
| 321 intptr_t index = object_id - kMaxPredefinedObjectIds; | 387 intptr_t index = object_id - kMaxPredefinedObjectIds; |
| 322 ASSERT((0 <= index) && (index < backward_references_.length())); | 388 ASSERT((0 <= index) && (index < backward_references_.length())); |
| 323 ASSERT(backward_references_[index] != NULL); | 389 ASSERT(backward_references_[index]->reference() != NULL); |
| 324 return backward_references_[index]; | 390 return backward_references_[index]->reference(); |
| 325 } | |
| 326 | |
| 327 | |
| 328 Dart_CObject* ApiMessageReader::ReadObjectImpl(intptr_t header) { | |
| 329 SerializedHeaderType header_type = SerializedHeaderTag::decode(header); | |
| 330 intptr_t header_value = SerializedHeaderData::decode(header); | |
| 331 | |
| 332 if (header_type == kObjectId) { | |
| 333 return ReadIndexedObject(header_value); | |
| 334 } | |
| 335 ASSERT(header_type == kInlined); | |
| 336 return ReadInlinedObject(header_value); | |
| 337 } | 391 } |
| 338 | 392 |
| 339 | 393 |
| 340 Dart_CObject* ApiMessageReader::ReadObject() { | 394 Dart_CObject* ApiMessageReader::ReadObject() { |
| 395 Dart_CObject* value = ReadObjectImpl(); | |
| 396 for (intptr_t i = 0; i < backward_references_.length(); i++) { | |
| 397 if (!backward_references_[i]->is_deserialized()) { | |
| 398 ReadObjectImpl(); | |
| 399 backward_references_[i]->set_is_deserialized(true); | |
| 400 } | |
| 401 } | |
| 402 return value; | |
| 403 } | |
| 404 | |
| 405 | |
| 406 Dart_CObject* ApiMessageReader::ReadObjectImpl() { | |
| 341 int64_t value = Read<int64_t>(); | 407 int64_t value = Read<int64_t>(); |
| 342 if ((value & kSmiTagMask) == 0) { | 408 if ((value & kSmiTagMask) == 0) { |
| 343 int64_t untagged_value = value >> kSmiTagShift; | 409 int64_t untagged_value = value >> kSmiTagShift; |
| 344 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { | 410 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { |
| 345 return AllocateDartCObjectInt32(untagged_value); | 411 return AllocateDartCObjectInt32(untagged_value); |
| 346 } else { | 412 } else { |
| 347 return AllocateDartCObjectInt64(untagged_value); | 413 return AllocateDartCObjectInt64(untagged_value); |
| 348 } | 414 } |
| 349 } | 415 } |
| 350 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 416 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
| 351 return ReadObjectImpl(value); | 417 SerializedHeaderType header_type = SerializedHeaderTag::decode(value); |
| 418 intptr_t header_value = SerializedHeaderData::decode(value); | |
| 419 | |
| 420 if (header_type == kObjectId) { | |
| 421 return ReadIndexedObject(header_value); | |
| 422 } | |
| 423 ASSERT(header_type == kInlined); | |
| 424 return ReadInlinedObject(header_value); | |
| 352 } | 425 } |
| 353 | 426 |
| 354 | 427 |
| 355 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { | 428 void ApiMessageReader::AddBackwardReference(intptr_t id, |
| 356 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); | 429 Dart_CObject* obj, |
| 357 backward_references_.Add(obj); | 430 bool is_deserialized) { |
| 431 intptr_t index = (id - kMaxPredefinedObjectIds); | |
| 432 ASSERT(index == backward_references_.length()); | |
| 433 BackwardReferenceNode* node = AllocateBackwardReferenceNode(obj, | |
| 434 is_deserialized); | |
| 435 ASSERT(node != NULL); | |
| 436 backward_references_.Add(node); | |
| 358 } | 437 } |
| 359 | 438 |
| 439 | |
| 440 Dart_CObject* ApiMessageReader::GetBackwardReference(intptr_t id) { | |
| 441 ASSERT(id >= kMaxPredefinedObjectIds); | |
| 442 intptr_t index = (id - kMaxPredefinedObjectIds); | |
| 443 if (index < backward_references_.length()) { | |
| 444 return backward_references_[index]->reference(); | |
| 445 } | |
| 446 return NULL; | |
| 447 } | |
| 448 | |
| 449 | |
| 360 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { | 450 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { |
| 361 // Write out the serialization header value for this object. | 451 // Write out the serialization header value for this object. |
| 362 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds); | 452 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds); |
| 363 | 453 |
| 364 // Write out the class and tags information. | 454 // Write out the class and tags information. |
| 365 WriteObjectHeader(ObjectStore::kArrayClass, 0); | 455 WriteObjectHeader(ObjectStore::kArrayClass, 0); |
| 366 | 456 |
| 367 // Write out the length field. | 457 // Write out the length field. |
| 368 Write<RawObject*>(Smi::New(field_count)); | 458 Write<RawObject*>(Smi::New(field_count)); |
| 369 | 459 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 397 } | 487 } |
| 398 | 488 |
| 399 | 489 |
| 400 bool ApiMessageWriter::IsCObjectMarked(Dart_CObject* object) { | 490 bool ApiMessageWriter::IsCObjectMarked(Dart_CObject* object) { |
| 401 return (object->type & kDartCObjectMarkMask) != 0; | 491 return (object->type & kDartCObjectMarkMask) != 0; |
| 402 } | 492 } |
| 403 | 493 |
| 404 | 494 |
| 405 intptr_t ApiMessageWriter::GetMarkedCObjectMark(Dart_CObject* object) { | 495 intptr_t ApiMessageWriter::GetMarkedCObjectMark(Dart_CObject* object) { |
| 406 ASSERT(IsCObjectMarked(object)); | 496 ASSERT(IsCObjectMarked(object)); |
| 407 intptr_t mark_value = ((object->type & kDartCObjectMarkMask) >> 3); | 497 intptr_t mark_value = |
| 498 ((object->type & kDartCObjectMarkMask) >> kDartCObjectTypeBits); | |
| 408 // An offset was added to object id for making marking object id 0 possible. | 499 // An offset was added to object id for making marking object id 0 possible. |
| 409 return mark_value - kDartCObjectMarkOffset; | 500 return mark_value - kDartCObjectMarkOffset; |
| 410 } | 501 } |
| 411 | 502 |
| 412 | 503 |
| 413 void ApiMessageWriter::UnmarkAllCObjects(Dart_CObject* object) { | 504 void ApiMessageWriter::UnmarkAllCObjects(Dart_CObject* object) { |
| 414 if (!IsCObjectMarked(object)) return; | 505 if (!IsCObjectMarked(object)) return; |
| 415 UnmarkCObject(object); | 506 UnmarkCObject(object); |
| 416 if (object->type == Dart_CObject::kArray) { | 507 if (object->type == Dart_CObject::kArray) { |
| 417 for (int i = 0; i < object->value.as_array.length; i++) { | 508 for (int i = 0; i < object->value.as_array.length; i++) { |
| 418 Dart_CObject* element = object->value.as_array.values[i]; | 509 Dart_CObject* element = object->value.as_array.values[i]; |
| 419 UnmarkAllCObjects(element); | 510 UnmarkAllCObjects(element); |
| 420 } | 511 } |
| 421 } | 512 } |
| 422 } | 513 } |
| 423 | 514 |
| 424 | 515 |
| 516 void ApiMessageWriter::AddToForwardList(Dart_CObject* object) { | |
| 517 if (forward_id_ >= forward_list_length_) { | |
| 518 intptr_t new_size = (forward_list_length_ * sizeof(object)) * 2; | |
| 519 void* new_list = ::realloc(forward_list_, new_size); | |
| 520 ASSERT(new_list != NULL); | |
| 521 forward_list_ = reinterpret_cast<Dart_CObject**>(new_list); | |
| 522 } | |
| 523 forward_list_[forward_id_] = object; | |
| 524 forward_id_ += 1; | |
| 525 } | |
| 526 | |
| 527 | |
| 425 void ApiMessageWriter::WriteSmi(int64_t value) { | 528 void ApiMessageWriter::WriteSmi(int64_t value) { |
| 426 ASSERT(Smi::IsValid64(value)); | 529 ASSERT(Smi::IsValid64(value)); |
| 427 Write<RawObject*>(Smi::New(value)); | 530 Write<RawObject*>(Smi::New(value)); |
| 428 } | 531 } |
| 429 | 532 |
| 430 | 533 |
| 431 void ApiMessageWriter::WriteMint(Dart_CObject* object, int64_t value) { | 534 void ApiMessageWriter::WriteMint(Dart_CObject* object, int64_t value) { |
| 432 ASSERT(!Smi::IsValid64(value)); | 535 ASSERT(!Smi::IsValid64(value)); |
| 433 // Write out the serialization header value for mint object. | 536 // Write out the serialization header value for mint object. |
| 434 WriteInlinedHeader(object); | 537 WriteInlinedHeader(object); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 } | 572 } |
| 470 | 573 |
| 471 | 574 |
| 472 void ApiMessageWriter::WriteCObject(Dart_CObject* object) { | 575 void ApiMessageWriter::WriteCObject(Dart_CObject* object) { |
| 473 if (IsCObjectMarked(object)) { | 576 if (IsCObjectMarked(object)) { |
| 474 intptr_t object_id = GetMarkedCObjectMark(object); | 577 intptr_t object_id = GetMarkedCObjectMark(object); |
| 475 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); | 578 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); |
| 476 return; | 579 return; |
| 477 } | 580 } |
| 478 | 581 |
| 479 switch (object->type) { | 582 Dart_CObject::Type type = object->type; |
| 583 if (type == Dart_CObject::kArray) { | |
| 584 // Write out the serialization header value for this object. | |
| 585 WriteInlinedHeader(object); | |
| 586 // Write out the class and tags information. | |
| 587 WriteObjectHeader(ObjectStore::kArrayClass, 0); | |
| 588 WriteSmi(object->value.as_array.length); | |
| 589 // Write out the type arguments. | |
| 590 WriteIndexedObject(Object::kNullObject); | |
| 591 // Write out array elements. | |
| 592 for (int i = 0; i < object->value.as_array.length; i++) { | |
| 593 WriteCObjectRef(object->value.as_array.values[i]); | |
| 594 } | |
| 595 return; | |
| 596 } | |
| 597 return WriteCObjectInlined(object, type); | |
| 598 } | |
| 599 | |
| 600 | |
| 601 void ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) { | |
| 602 if (IsCObjectMarked(object)) { | |
| 603 intptr_t object_id = GetMarkedCObjectMark(object); | |
| 604 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); | |
| 605 return; | |
| 606 } | |
| 607 | |
| 608 Dart_CObject::Type type = object->type; | |
| 609 if (type == Dart_CObject::kArray) { | |
| 610 // Write out the serialization header value for this object. | |
| 611 WriteInlinedHeader(object); | |
| 612 // Write out the class information. | |
| 613 WriteIndexedObject(ObjectStore::kArrayClass); | |
| 614 // Write out the length information. | |
| 615 WriteSmi(object->value.as_array.length); | |
| 616 // Add object to forward list so that this object is serialized later. | |
| 617 AddToForwardList(object); | |
| 618 return; | |
| 619 } | |
| 620 return WriteCObjectInlined(object, type); | |
| 621 } | |
| 622 | |
| 623 | |
| 624 void ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) { | |
| 625 ASSERT(IsCObjectMarked(object)); | |
| 626 Dart_CObject::Type type = | |
| 627 static_cast<Dart_CObject::Type>(object->type & kDartCObjectTypeMask); | |
| 628 ASSERT(type == Dart_CObject::kArray); | |
| 629 | |
| 630 // Write out the serialization header value for this object. | |
| 631 intptr_t object_id = GetMarkedCObjectMark(object); | |
| 632 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds + object_id); | |
| 633 // Write out the class and tags information. | |
| 634 WriteObjectHeader(ObjectStore::kArrayClass, 0); | |
| 635 WriteSmi(object->value.as_array.length); | |
| 636 // Write out the type arguments. | |
| 637 WriteIndexedObject(Object::kNullObject); | |
| 638 // Write out array elements. | |
| 639 for (int i = 0; i < object->value.as_array.length; i++) { | |
| 640 WriteCObjectRef(object->value.as_array.values[i]); | |
| 641 } | |
| 642 } | |
| 643 | |
| 644 | |
| 645 void ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object, | |
| 646 Dart_CObject::Type type) { | |
| 647 switch (type) { | |
| 480 case Dart_CObject::kNull: | 648 case Dart_CObject::kNull: |
| 481 WriteIndexedObject(Object::kNullObject); | 649 WriteIndexedObject(Object::kNullObject); |
| 482 break; | 650 break; |
| 483 case Dart_CObject::kBool: | 651 case Dart_CObject::kBool: |
| 484 if (object->value.as_bool) { | 652 if (object->value.as_bool) { |
| 485 WriteIndexedObject(ObjectStore::kTrueValue); | 653 WriteIndexedObject(ObjectStore::kTrueValue); |
| 486 } else { | 654 } else { |
| 487 WriteIndexedObject(ObjectStore::kFalseValue); | 655 WriteIndexedObject(ObjectStore::kFalseValue); |
| 488 } | 656 } |
| 489 break; | 657 break; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 // Write string length, hash and content | 691 // Write string length, hash and content |
| 524 char* str = object->value.as_string; | 692 char* str = object->value.as_string; |
| 525 intptr_t len = strlen(str); | 693 intptr_t len = strlen(str); |
| 526 WriteSmi(len); | 694 WriteSmi(len); |
| 527 WriteSmi(0); // TODO(sgjesse): Hash - not written. | 695 WriteSmi(0); // TODO(sgjesse): Hash - not written. |
| 528 for (intptr_t i = 0; i < len; i++) { | 696 for (intptr_t i = 0; i < len; i++) { |
| 529 Write<uint8_t>(str[i]); | 697 Write<uint8_t>(str[i]); |
| 530 } | 698 } |
| 531 break; | 699 break; |
| 532 } | 700 } |
| 533 case Dart_CObject::kArray: { | |
| 534 // Write out the serialization header value for this object. | |
| 535 WriteInlinedHeader(object); | |
| 536 // Write out the class and tags information. | |
| 537 WriteObjectHeader(ObjectStore::kArrayClass, 0); | |
| 538 WriteSmi(object->value.as_array.length); | |
| 539 // Write out the type arguments. | |
| 540 WriteIndexedObject(Object::kNullObject); | |
| 541 // Write out array elements. | |
| 542 for (int i = 0; i < object->value.as_array.length; i++) { | |
| 543 WriteCObject(object->value.as_array.values[i]); | |
| 544 } | |
| 545 break; | |
| 546 } | |
| 547 case Dart_CObject::kUint8Array: { | 701 case Dart_CObject::kUint8Array: { |
| 548 // Write out the serialization header value for this object. | 702 // Write out the serialization header value for this object. |
| 549 WriteInlinedHeader(object); | 703 WriteInlinedHeader(object); |
| 550 // Write out the class and tags information. | 704 // Write out the class and tags information. |
| 551 WriteObjectHeader(ObjectStore::kUint8ArrayClass, 0); | 705 WriteObjectHeader(ObjectStore::kUint8ArrayClass, 0); |
| 552 uint8_t* bytes = object->value.as_byte_array.values; | 706 uint8_t* bytes = object->value.as_byte_array.values; |
| 553 intptr_t len = object->value.as_byte_array.length; | 707 intptr_t len = object->value.as_byte_array.length; |
| 554 WriteSmi(len); | 708 WriteSmi(len); |
| 555 for (intptr_t i = 0; i < len; i++) { | 709 for (intptr_t i = 0; i < len; i++) { |
| 556 Write<uint8_t>(bytes[i]); | 710 Write<uint8_t>(bytes[i]); |
| 557 } | 711 } |
| 558 break; | 712 break; |
| 559 } | 713 } |
| 560 default: | 714 default: |
| 561 UNREACHABLE(); | 715 UNREACHABLE(); |
| 562 } | 716 } |
| 563 } | 717 } |
| 564 | 718 |
| 565 | 719 |
| 566 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { | 720 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { |
| 567 WriteCObject(object); | 721 WriteCObject(object); |
| 722 // Write out all objects that were added to the forward list and have | |
| 723 // not been serialized yet. These would typically be fields of arrays. | |
|
Søren Gjesse
2012/06/08 08:12:12
Maybe extend comment here to mention that the forw
siva
2012/06/11 20:49:06
Done.
| |
| 724 for (intptr_t i = 0; i < forward_id_; i++) { | |
| 725 WriteForwardedCObject(forward_list_[i]); | |
| 726 } | |
| 568 UnmarkAllCObjects(object); | 727 UnmarkAllCObjects(object); |
| 569 FinalizeBuffer(); | 728 FinalizeBuffer(); |
| 570 } | 729 } |
| 571 | 730 |
| 572 } // namespace dart | 731 } // namespace dart |
| OLD | NEW |