| 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/snapshot_ids.h" |
| 8 #include "vm/symbols.h" | 8 #include "vm/symbols.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 // TODO(sgjesse): When the external message format is done these | |
| 13 // duplicate constants from snapshot.cc should be removed. | |
| 14 enum { | |
| 15 kInstanceId = ObjectStore::kMaxId, | |
| 16 kMaxPredefinedObjectIds, | |
| 17 }; | |
| 18 static const int kNumInitialReferences = 4; | 12 static const int kNumInitialReferences = 4; |
| 19 | 13 |
| 20 ApiMessageReader::ApiMessageReader(const uint8_t* buffer, | 14 ApiMessageReader::ApiMessageReader(const uint8_t* buffer, |
| 21 intptr_t length, | 15 intptr_t length, |
| 22 ReAlloc alloc) | 16 ReAlloc alloc) |
| 23 : BaseReader(buffer, length), | 17 : BaseReader(buffer, length), |
| 24 alloc_(alloc), | 18 alloc_(alloc), |
| 25 backward_references_(kNumInitialReferences) { | 19 backward_references_(kNumInitialReferences) { |
| 26 Init(); | 20 Init(); |
| 27 } | 21 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 174 |
| 181 | 175 |
| 182 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { | 176 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { |
| 183 // Read the class header information and lookup the class. | 177 // Read the class header information and lookup the class. |
| 184 intptr_t class_header = ReadIntptrValue(); | 178 intptr_t class_header = ReadIntptrValue(); |
| 185 intptr_t tags = ReadIntptrValue(); | 179 intptr_t tags = ReadIntptrValue(); |
| 186 USE(tags); | 180 USE(tags); |
| 187 intptr_t class_id; | 181 intptr_t class_id; |
| 188 | 182 |
| 189 // Reading of regular dart instances is not supported. | 183 // Reading of regular dart instances is not supported. |
| 190 if (SerializedHeaderData::decode(class_header) == kInstanceId) { | 184 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 191 return AllocateDartCObjectUnsupported(); | 185 return AllocateDartCObjectUnsupported(); |
| 192 } | 186 } |
| 193 | 187 |
| 194 ASSERT((class_header & kSmiTagMask) != 0); | 188 ASSERT((class_header & kSmiTagMask) != 0); |
| 195 class_id = LookupInternalClass(class_header); | 189 class_id = LookupInternalClass(class_header); |
| 196 if (class_id == ObjectStore::kArrayClass || | 190 if (class_id == kArrayCid || class_id == kImmutableArrayCid) { |
| 197 class_id == ObjectStore::kImmutableArrayClass) { | |
| 198 intptr_t len = ReadSmiValue(); | 191 intptr_t len = ReadSmiValue(); |
| 199 Dart_CObject* value = GetBackRef(object_id); | 192 Dart_CObject* value = GetBackRef(object_id); |
| 200 if (value == NULL) { | 193 if (value == NULL) { |
| 201 value = AllocateDartCObjectArray(len); | 194 value = AllocateDartCObjectArray(len); |
| 202 AddBackRef(object_id, value, kIsDeserialized); | 195 AddBackRef(object_id, value, kIsDeserialized); |
| 203 } | 196 } |
| 204 // Skip type arguments. | 197 // Skip type arguments. |
| 205 // TODO(sjesse): Remove this when message serialization format is | 198 // TODO(sjesse): Remove this when message serialization format is |
| 206 // updated (currently type_arguments is leaked). | 199 // updated (currently type_arguments is leaked). |
| 207 Dart_CObject* type_arguments = ReadObjectImpl(); | 200 Dart_CObject* type_arguments = ReadObjectImpl(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 int64_t untagged_value = value >> kSmiTagShift; | 234 int64_t untagged_value = value >> kSmiTagShift; |
| 242 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { | 235 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { |
| 243 return AllocateDartCObjectInt32(untagged_value); | 236 return AllocateDartCObjectInt32(untagged_value); |
| 244 } else { | 237 } else { |
| 245 return AllocateDartCObjectInt64(untagged_value); | 238 return AllocateDartCObjectInt64(untagged_value); |
| 246 } | 239 } |
| 247 } | 240 } |
| 248 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 241 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
| 249 if (IsVMIsolateObject(value)) { | 242 if (IsVMIsolateObject(value)) { |
| 250 intptr_t object_id = GetVMIsolateObjectId(value); | 243 intptr_t object_id = GetVMIsolateObjectId(value); |
| 251 if (object_id == Object::kNullObject) { | 244 if (object_id == kNullObject) { |
| 252 return AllocateDartCObjectNull(); | 245 return AllocateDartCObjectNull(); |
| 253 } | 246 } |
| 254 return ReadVMSymbol(object_id); | 247 return ReadVMSymbol(object_id); |
| 255 } | 248 } |
| 256 if (SerializedHeaderTag::decode(value) == kObjectId) { | 249 if (SerializedHeaderTag::decode(value) == kObjectId) { |
| 257 return ReadIndexedObject(SerializedHeaderData::decode(value)); | 250 return ReadIndexedObject(SerializedHeaderData::decode(value)); |
| 258 } | 251 } |
| 259 ASSERT(SerializedHeaderTag::decode(value) == kInlined); | 252 ASSERT(SerializedHeaderTag::decode(value) == kInlined); |
| 260 // Read the class header information and lookup the class. | 253 // Read the class header information and lookup the class. |
| 261 intptr_t class_header = ReadIntptrValue(); | 254 intptr_t class_header = ReadIntptrValue(); |
| 262 | 255 |
| 263 // Reading of regular dart instances is not supported. | 256 // Reading of regular dart instances is not supported. |
| 264 if (SerializedHeaderData::decode(class_header) == kInstanceId) { | 257 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 265 return AllocateDartCObjectUnsupported(); | 258 return AllocateDartCObjectUnsupported(); |
| 266 } | 259 } |
| 267 ASSERT((class_header & kSmiTagMask) != 0); | 260 ASSERT((class_header & kSmiTagMask) != 0); |
| 268 intptr_t object_id = SerializedHeaderData::decode(value); | 261 intptr_t object_id = SerializedHeaderData::decode(value); |
| 269 intptr_t class_id = LookupInternalClass(class_header); | 262 intptr_t class_id = LookupInternalClass(class_header); |
| 270 if (class_id == ObjectStore::kArrayClass || | 263 if (class_id == kArrayCid || class_id == kImmutableArrayCid) { |
| 271 class_id == ObjectStore::kImmutableArrayClass) { | |
| 272 ASSERT(GetBackRef(object_id) == NULL); | 264 ASSERT(GetBackRef(object_id) == NULL); |
| 273 intptr_t len = ReadSmiValue(); | 265 intptr_t len = ReadSmiValue(); |
| 274 Dart_CObject* value = AllocateDartCObjectArray(len); | 266 Dart_CObject* value = AllocateDartCObjectArray(len); |
| 275 AddBackRef(object_id, value, kIsNotDeserialized); | 267 AddBackRef(object_id, value, kIsNotDeserialized); |
| 276 return value; | 268 return value; |
| 277 } | 269 } |
| 278 intptr_t tags = ReadIntptrValue(); | 270 intptr_t tags = ReadIntptrValue(); |
| 279 USE(tags); | 271 USE(tags); |
| 280 | 272 |
| 281 return ReadInternalVMObject(class_id, object_id); | 273 return ReadInternalVMObject(class_id, object_id); |
| 282 } | 274 } |
| 283 | 275 |
| 284 | 276 |
| 285 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, | 277 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, |
| 286 intptr_t object_id) { | 278 intptr_t object_id) { |
| 287 switch (class_id) { | 279 switch (class_id) { |
| 288 case Object::kClassClass: { | 280 case kClassCid: { |
| 289 return AllocateDartCObjectUnsupported(); | 281 return AllocateDartCObjectUnsupported(); |
| 290 } | 282 } |
| 291 case Object::kTypeArgumentsClass: { | 283 case kTypeArgumentsCid: { |
| 292 // TODO(sjesse): Remove this when message serialization format is | 284 // TODO(sjesse): Remove this when message serialization format is |
| 293 // updated (currently length is leaked). | 285 // updated (currently length is leaked). |
| 294 Dart_CObject* value = &type_arguments_marker; | 286 Dart_CObject* value = &type_arguments_marker; |
| 295 AddBackRef(object_id, value, kIsDeserialized); | 287 AddBackRef(object_id, value, kIsDeserialized); |
| 296 Dart_CObject* length = ReadObjectImpl(); | 288 Dart_CObject* length = ReadObjectImpl(); |
| 297 ASSERT(length->type == Dart_CObject::kInt32); | 289 ASSERT(length->type == Dart_CObject::kInt32); |
| 298 for (int i = 0; i < length->value.as_int32; i++) { | 290 for (int i = 0; i < length->value.as_int32; i++) { |
| 299 Dart_CObject* type = ReadObjectImpl(); | 291 Dart_CObject* type = ReadObjectImpl(); |
| 300 if (type != &dynamic_type_marker) { | 292 if (type != &dynamic_type_marker) { |
| 301 return AllocateDartCObjectUnsupported(); | 293 return AllocateDartCObjectUnsupported(); |
| 302 } | 294 } |
| 303 } | 295 } |
| 304 return value; | 296 return value; |
| 305 } | 297 } |
| 306 case Object::kTypeParameterClass: { | 298 case kTypeParameterCid: { |
| 307 // TODO(sgjesse): Fix this workaround ignoring the type parameter. | 299 // TODO(sgjesse): Fix this workaround ignoring the type parameter. |
| 308 Dart_CObject* value = &dynamic_type_marker; | 300 Dart_CObject* value = &dynamic_type_marker; |
| 309 AddBackRef(object_id, value, kIsDeserialized); | 301 AddBackRef(object_id, value, kIsDeserialized); |
| 310 intptr_t index = ReadIntptrValue(); | 302 intptr_t index = ReadIntptrValue(); |
| 311 USE(index); | 303 USE(index); |
| 312 intptr_t token_index = ReadIntptrValue(); | 304 intptr_t token_index = ReadIntptrValue(); |
| 313 USE(token_index); | 305 USE(token_index); |
| 314 int8_t type_state = Read<int8_t>(); | 306 int8_t type_state = Read<int8_t>(); |
| 315 USE(type_state); | 307 USE(type_state); |
| 316 Dart_CObject* parameterized_class = ReadObjectImpl(); | 308 Dart_CObject* parameterized_class = ReadObjectImpl(); |
| 317 // The type parameter is finalized, therefore parameterized_class is null. | 309 // The type parameter is finalized, therefore parameterized_class is null. |
| 318 ASSERT(parameterized_class->type == Dart_CObject::kNull); | 310 ASSERT(parameterized_class->type == Dart_CObject::kNull); |
| 319 Dart_CObject* name = ReadObjectImpl(); | 311 Dart_CObject* name = ReadObjectImpl(); |
| 320 ASSERT(name->type == Dart_CObject::kString); | 312 ASSERT(name->type == Dart_CObject::kString); |
| 321 return value; | 313 return value; |
| 322 } | 314 } |
| 323 case ObjectStore::kMintClass: { | 315 case kMintCid: { |
| 324 int64_t value = Read<int64_t>(); | 316 int64_t value = Read<int64_t>(); |
| 325 Dart_CObject* object; | 317 Dart_CObject* object; |
| 326 if (kMinInt32 <= value && value <= kMaxInt32) { | 318 if (kMinInt32 <= value && value <= kMaxInt32) { |
| 327 object = AllocateDartCObjectInt32(value); | 319 object = AllocateDartCObjectInt32(value); |
| 328 } else { | 320 } else { |
| 329 object = AllocateDartCObjectInt64(value); | 321 object = AllocateDartCObjectInt64(value); |
| 330 } | 322 } |
| 331 AddBackRef(object_id, object, kIsDeserialized); | 323 AddBackRef(object_id, object, kIsDeserialized); |
| 332 return object; | 324 return object; |
| 333 } | 325 } |
| 334 case ObjectStore::kBigintClass: { | 326 case kBigintCid: { |
| 335 // Read in the hex string representation of the bigint. | 327 // Read in the hex string representation of the bigint. |
| 336 intptr_t len = ReadIntptrValue(); | 328 intptr_t len = ReadIntptrValue(); |
| 337 Dart_CObject* object = AllocateDartCObjectBigint(len); | 329 Dart_CObject* object = AllocateDartCObjectBigint(len); |
| 338 AddBackRef(object_id, object, kIsDeserialized); | 330 AddBackRef(object_id, object, kIsDeserialized); |
| 339 char* p = object->value.as_bigint; | 331 char* p = object->value.as_bigint; |
| 340 for (intptr_t i = 0; i < len; i++) { | 332 for (intptr_t i = 0; i < len; i++) { |
| 341 p[i] = Read<uint8_t>(); | 333 p[i] = Read<uint8_t>(); |
| 342 } | 334 } |
| 343 p[len] = '\0'; | 335 p[len] = '\0'; |
| 344 return object; | 336 return object; |
| 345 } | 337 } |
| 346 case ObjectStore::kDoubleClass: { | 338 case kDoubleCid: { |
| 347 // Read the double value for the object. | 339 // Read the double value for the object. |
| 348 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); | 340 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); |
| 349 AddBackRef(object_id, object, kIsDeserialized); | 341 AddBackRef(object_id, object, kIsDeserialized); |
| 350 return object; | 342 return object; |
| 351 } | 343 } |
| 352 case ObjectStore::kOneByteStringClass: { | 344 case kOneByteStringCid: { |
| 353 intptr_t len = ReadSmiValue(); | 345 intptr_t len = ReadSmiValue(); |
| 354 intptr_t hash = ReadSmiValue(); | 346 intptr_t hash = ReadSmiValue(); |
| 355 USE(hash); | 347 USE(hash); |
| 356 Dart_CObject* object = AllocateDartCObjectString(len); | 348 Dart_CObject* object = AllocateDartCObjectString(len); |
| 357 AddBackRef(object_id, object, kIsDeserialized); | 349 AddBackRef(object_id, object, kIsDeserialized); |
| 358 char* p = object->value.as_string; | 350 char* p = object->value.as_string; |
| 359 for (intptr_t i = 0; i < len; i++) { | 351 for (intptr_t i = 0; i < len; i++) { |
| 360 p[i] = Read<uint8_t>(); | 352 p[i] = Read<uint8_t>(); |
| 361 } | 353 } |
| 362 p[len] = '\0'; | 354 p[len] = '\0'; |
| 363 return object; | 355 return object; |
| 364 } | 356 } |
| 365 case ObjectStore::kTwoByteStringClass: | 357 case kTwoByteStringCid: |
| 366 // Two byte strings not supported. | 358 // Two byte strings not supported. |
| 367 return AllocateDartCObjectUnsupported(); | 359 return AllocateDartCObjectUnsupported(); |
| 368 case ObjectStore::kFourByteStringClass: | 360 case kFourByteStringCid: |
| 369 // Four byte strings not supported. | 361 // Four byte strings not supported. |
| 370 return AllocateDartCObjectUnsupported(); | 362 return AllocateDartCObjectUnsupported(); |
| 371 case ObjectStore::kUint8ArrayClass: { | 363 case kUint8ArrayCid: { |
| 372 intptr_t len = ReadSmiValue(); | 364 intptr_t len = ReadSmiValue(); |
| 373 Dart_CObject* object = AllocateDartCObjectUint8Array(len); | 365 Dart_CObject* object = AllocateDartCObjectUint8Array(len); |
| 374 AddBackRef(object_id, object, kIsDeserialized); | 366 AddBackRef(object_id, object, kIsDeserialized); |
| 375 if (len > 0) { | 367 if (len > 0) { |
| 376 uint8_t* p = object->value.as_byte_array.values; | 368 uint8_t* p = object->value.as_byte_array.values; |
| 377 for (intptr_t i = 0; i < len; i++) { | 369 for (intptr_t i = 0; i < len; i++) { |
| 378 p[i] = Read<uint8_t>(); | 370 p[i] = Read<uint8_t>(); |
| 379 } | 371 } |
| 380 } | 372 } |
| 381 return object; | 373 return object; |
| 382 } | 374 } |
| 383 default: | 375 default: |
| 384 // Everything else not supported. | 376 // Everything else not supported. |
| 385 return AllocateDartCObjectUnsupported(); | 377 return AllocateDartCObjectUnsupported(); |
| 386 } | 378 } |
| 387 } | 379 } |
| 388 | 380 |
| 389 | 381 |
| 390 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { | 382 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { |
| 391 if (object_id == ObjectStore::kTrueValue) { | 383 if (object_id == kTrueValue) { |
| 392 return AllocateDartCObjectBool(true); | 384 return AllocateDartCObjectBool(true); |
| 393 } | 385 } |
| 394 if (object_id == ObjectStore::kFalseValue) { | 386 if (object_id == kFalseValue) { |
| 395 return AllocateDartCObjectBool(false); | 387 return AllocateDartCObjectBool(false); |
| 396 } | 388 } |
| 397 if (object_id == ObjectStore::kDynamicType || | 389 if (object_id == kDynamicType || |
| 398 object_id == ObjectStore::kDoubleInterface || | 390 object_id == kDoubleInterface || |
| 399 object_id == ObjectStore::kIntInterface || | 391 object_id == kIntInterface || |
| 400 object_id == ObjectStore::kBoolInterface || | 392 object_id == kBoolInterface || |
| 401 object_id == ObjectStore::kStringInterface) { | 393 object_id == kStringInterface) { |
| 402 // Always return dynamic type (this is only a marker). | 394 // Always return dynamic type (this is only a marker). |
| 403 return &dynamic_type_marker; | 395 return &dynamic_type_marker; |
| 404 } | 396 } |
| 405 intptr_t index = object_id - kMaxPredefinedObjectIds; | 397 intptr_t index = object_id - kMaxPredefinedObjectIds; |
| 406 ASSERT((0 <= index) && (index < backward_references_.length())); | 398 ASSERT((0 <= index) && (index < backward_references_.length())); |
| 407 ASSERT(backward_references_[index]->reference() != NULL); | 399 ASSERT(backward_references_[index]->reference() != NULL); |
| 408 return backward_references_[index]->reference(); | 400 return backward_references_[index]->reference(); |
| 409 } | 401 } |
| 410 | 402 |
| 411 | 403 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 427 int64_t untagged_value = value >> kSmiTagShift; | 419 int64_t untagged_value = value >> kSmiTagShift; |
| 428 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { | 420 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { |
| 429 return AllocateDartCObjectInt32(untagged_value); | 421 return AllocateDartCObjectInt32(untagged_value); |
| 430 } else { | 422 } else { |
| 431 return AllocateDartCObjectInt64(untagged_value); | 423 return AllocateDartCObjectInt64(untagged_value); |
| 432 } | 424 } |
| 433 } | 425 } |
| 434 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 426 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
| 435 if (IsVMIsolateObject(value)) { | 427 if (IsVMIsolateObject(value)) { |
| 436 intptr_t object_id = GetVMIsolateObjectId(value); | 428 intptr_t object_id = GetVMIsolateObjectId(value); |
| 437 if (object_id == Object::kNullObject) { | 429 if (object_id == kNullObject) { |
| 438 return AllocateDartCObjectNull(); | 430 return AllocateDartCObjectNull(); |
| 439 } | 431 } |
| 440 return ReadVMSymbol(object_id); | 432 return ReadVMSymbol(object_id); |
| 441 } | 433 } |
| 442 if (SerializedHeaderTag::decode(value) == kObjectId) { | 434 if (SerializedHeaderTag::decode(value) == kObjectId) { |
| 443 return ReadIndexedObject(SerializedHeaderData::decode(value)); | 435 return ReadIndexedObject(SerializedHeaderData::decode(value)); |
| 444 } | 436 } |
| 445 ASSERT(SerializedHeaderTag::decode(value) == kInlined); | 437 ASSERT(SerializedHeaderTag::decode(value) == kInlined); |
| 446 return ReadInlinedObject(SerializedHeaderData::decode(value)); | 438 return ReadInlinedObject(SerializedHeaderData::decode(value)); |
| 447 } | 439 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 466 } | 458 } |
| 467 return NULL; | 459 return NULL; |
| 468 } | 460 } |
| 469 | 461 |
| 470 | 462 |
| 471 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { | 463 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { |
| 472 // Write out the serialization header value for this object. | 464 // Write out the serialization header value for this object. |
| 473 WriteInlinedObjectHeader(kMaxPredefinedObjectIds); | 465 WriteInlinedObjectHeader(kMaxPredefinedObjectIds); |
| 474 | 466 |
| 475 // Write out the class and tags information. | 467 // Write out the class and tags information. |
| 476 WriteIndexedObject(ObjectStore::kArrayClass); | 468 WriteIndexedObject(kArrayCid); |
| 477 WriteIntptrValue(0); | 469 WriteIntptrValue(0); |
| 478 | 470 |
| 479 // Write out the length field. | 471 // Write out the length field. |
| 480 Write<RawObject*>(Smi::New(field_count)); | 472 Write<RawObject*>(Smi::New(field_count)); |
| 481 | 473 |
| 482 // Write out the type arguments. | 474 // Write out the type arguments. |
| 483 WriteNullObject(); | 475 WriteNullObject(); |
| 484 | 476 |
| 485 // Write out the individual Smis. | 477 // Write out the individual Smis. |
| 486 for (int i = 0; i < field_count; i++) { | 478 for (int i = 0; i < field_count; i++) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 545 } |
| 554 | 546 |
| 555 | 547 |
| 556 void ApiMessageWriter::WriteSmi(int64_t value) { | 548 void ApiMessageWriter::WriteSmi(int64_t value) { |
| 557 ASSERT(Smi::IsValid64(value)); | 549 ASSERT(Smi::IsValid64(value)); |
| 558 Write<RawObject*>(Smi::New(value)); | 550 Write<RawObject*>(Smi::New(value)); |
| 559 } | 551 } |
| 560 | 552 |
| 561 | 553 |
| 562 void ApiMessageWriter::WriteNullObject() { | 554 void ApiMessageWriter::WriteNullObject() { |
| 563 WriteVMIsolateObject(Object::kNullObject); | 555 WriteVMIsolateObject(kNullObject); |
| 564 } | 556 } |
| 565 | 557 |
| 566 | 558 |
| 567 void ApiMessageWriter::WriteMint(Dart_CObject* object, int64_t value) { | 559 void ApiMessageWriter::WriteMint(Dart_CObject* object, int64_t value) { |
| 568 ASSERT(!Smi::IsValid64(value)); | 560 ASSERT(!Smi::IsValid64(value)); |
| 569 // Write out the serialization header value for mint object. | 561 // Write out the serialization header value for mint object. |
| 570 WriteInlinedHeader(object); | 562 WriteInlinedHeader(object); |
| 571 // Write out the class and tags information. | 563 // Write out the class and tags information. |
| 572 WriteIndexedObject(ObjectStore::kMintClass); | 564 WriteIndexedObject(kMintCid); |
| 573 WriteIntptrValue(0); | 565 WriteIntptrValue(0); |
| 574 // Write the 64-bit value. | 566 // Write the 64-bit value. |
| 575 Write<int64_t>(value); | 567 Write<int64_t>(value); |
| 576 } | 568 } |
| 577 | 569 |
| 578 | 570 |
| 579 void ApiMessageWriter::WriteInt32(Dart_CObject* object) { | 571 void ApiMessageWriter::WriteInt32(Dart_CObject* object) { |
| 580 int64_t value = object->value.as_int32; | 572 int64_t value = object->value.as_int32; |
| 581 if (Smi::IsValid64(value)) { | 573 if (Smi::IsValid64(value)) { |
| 582 WriteSmi(value); | 574 WriteSmi(value); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 611 intptr_t object_id = GetMarkedCObjectMark(object); | 603 intptr_t object_id = GetMarkedCObjectMark(object); |
| 612 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); | 604 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); |
| 613 return; | 605 return; |
| 614 } | 606 } |
| 615 | 607 |
| 616 Dart_CObject::Type type = object->type; | 608 Dart_CObject::Type type = object->type; |
| 617 if (type == Dart_CObject::kArray) { | 609 if (type == Dart_CObject::kArray) { |
| 618 // Write out the serialization header value for this object. | 610 // Write out the serialization header value for this object. |
| 619 WriteInlinedHeader(object); | 611 WriteInlinedHeader(object); |
| 620 // Write out the class and tags information. | 612 // Write out the class and tags information. |
| 621 WriteIndexedObject(ObjectStore::kArrayClass); | 613 WriteIndexedObject(kArrayCid); |
| 622 WriteIntptrValue(0); | 614 WriteIntptrValue(0); |
| 623 | 615 |
| 624 WriteSmi(object->value.as_array.length); | 616 WriteSmi(object->value.as_array.length); |
| 625 // Write out the type arguments. | 617 // Write out the type arguments. |
| 626 WriteNullObject(); | 618 WriteNullObject(); |
| 627 // Write out array elements. | 619 // Write out array elements. |
| 628 for (int i = 0; i < object->value.as_array.length; i++) { | 620 for (int i = 0; i < object->value.as_array.length; i++) { |
| 629 WriteCObjectRef(object->value.as_array.values[i]); | 621 WriteCObjectRef(object->value.as_array.values[i]); |
| 630 } | 622 } |
| 631 return; | 623 return; |
| 632 } | 624 } |
| 633 return WriteCObjectInlined(object, type); | 625 return WriteCObjectInlined(object, type); |
| 634 } | 626 } |
| 635 | 627 |
| 636 | 628 |
| 637 void ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) { | 629 void ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) { |
| 638 if (IsCObjectMarked(object)) { | 630 if (IsCObjectMarked(object)) { |
| 639 intptr_t object_id = GetMarkedCObjectMark(object); | 631 intptr_t object_id = GetMarkedCObjectMark(object); |
| 640 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); | 632 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); |
| 641 return; | 633 return; |
| 642 } | 634 } |
| 643 | 635 |
| 644 Dart_CObject::Type type = object->type; | 636 Dart_CObject::Type type = object->type; |
| 645 if (type == Dart_CObject::kArray) { | 637 if (type == Dart_CObject::kArray) { |
| 646 // Write out the serialization header value for this object. | 638 // Write out the serialization header value for this object. |
| 647 WriteInlinedHeader(object); | 639 WriteInlinedHeader(object); |
| 648 // Write out the class information. | 640 // Write out the class information. |
| 649 WriteIndexedObject(ObjectStore::kArrayClass); | 641 WriteIndexedObject(kArrayCid); |
| 650 // Write out the length information. | 642 // Write out the length information. |
| 651 WriteSmi(object->value.as_array.length); | 643 WriteSmi(object->value.as_array.length); |
| 652 // Add object to forward list so that this object is serialized later. | 644 // Add object to forward list so that this object is serialized later. |
| 653 AddToForwardList(object); | 645 AddToForwardList(object); |
| 654 return; | 646 return; |
| 655 } | 647 } |
| 656 return WriteCObjectInlined(object, type); | 648 return WriteCObjectInlined(object, type); |
| 657 } | 649 } |
| 658 | 650 |
| 659 | 651 |
| 660 void ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) { | 652 void ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) { |
| 661 ASSERT(IsCObjectMarked(object)); | 653 ASSERT(IsCObjectMarked(object)); |
| 662 Dart_CObject::Type type = | 654 Dart_CObject::Type type = |
| 663 static_cast<Dart_CObject::Type>(object->type & kDartCObjectTypeMask); | 655 static_cast<Dart_CObject::Type>(object->type & kDartCObjectTypeMask); |
| 664 ASSERT(type == Dart_CObject::kArray); | 656 ASSERT(type == Dart_CObject::kArray); |
| 665 | 657 |
| 666 // Write out the serialization header value for this object. | 658 // Write out the serialization header value for this object. |
| 667 intptr_t object_id = GetMarkedCObjectMark(object); | 659 intptr_t object_id = GetMarkedCObjectMark(object); |
| 668 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id); | 660 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id); |
| 669 // Write out the class and tags information. | 661 // Write out the class and tags information. |
| 670 WriteIndexedObject(ObjectStore::kArrayClass); | 662 WriteIndexedObject(kArrayCid); |
| 671 WriteIntptrValue(0); | 663 WriteIntptrValue(0); |
| 672 | 664 |
| 673 WriteSmi(object->value.as_array.length); | 665 WriteSmi(object->value.as_array.length); |
| 674 // Write out the type arguments. | 666 // Write out the type arguments. |
| 675 WriteNullObject(); | 667 WriteNullObject(); |
| 676 // Write out array elements. | 668 // Write out array elements. |
| 677 for (int i = 0; i < object->value.as_array.length; i++) { | 669 for (int i = 0; i < object->value.as_array.length; i++) { |
| 678 WriteCObjectRef(object->value.as_array.values[i]); | 670 WriteCObjectRef(object->value.as_array.values[i]); |
| 679 } | 671 } |
| 680 } | 672 } |
| 681 | 673 |
| 682 | 674 |
| 683 void ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object, | 675 void ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object, |
| 684 Dart_CObject::Type type) { | 676 Dart_CObject::Type type) { |
| 685 switch (type) { | 677 switch (type) { |
| 686 case Dart_CObject::kNull: | 678 case Dart_CObject::kNull: |
| 687 WriteNullObject(); | 679 WriteNullObject(); |
| 688 break; | 680 break; |
| 689 case Dart_CObject::kBool: | 681 case Dart_CObject::kBool: |
| 690 if (object->value.as_bool) { | 682 if (object->value.as_bool) { |
| 691 WriteIndexedObject(ObjectStore::kTrueValue); | 683 WriteIndexedObject(kTrueValue); |
| 692 } else { | 684 } else { |
| 693 WriteIndexedObject(ObjectStore::kFalseValue); | 685 WriteIndexedObject(kFalseValue); |
| 694 } | 686 } |
| 695 break; | 687 break; |
| 696 case Dart_CObject::kInt32: | 688 case Dart_CObject::kInt32: |
| 697 WriteInt32(object); | 689 WriteInt32(object); |
| 698 break; | 690 break; |
| 699 case Dart_CObject::kInt64: | 691 case Dart_CObject::kInt64: |
| 700 WriteInt64(object); | 692 WriteInt64(object); |
| 701 break; | 693 break; |
| 702 case Dart_CObject::kBigint: { | 694 case Dart_CObject::kBigint: { |
| 703 // Write out the serialization header value for this object. | 695 // Write out the serialization header value for this object. |
| 704 WriteInlinedHeader(object); | 696 WriteInlinedHeader(object); |
| 705 // Write out the class and tags information. | 697 // Write out the class and tags information. |
| 706 WriteIndexedObject(ObjectStore::kBigintClass); | 698 WriteIndexedObject(kBigintCid); |
| 707 WriteIntptrValue(0); | 699 WriteIntptrValue(0); |
| 708 // Write hex string length and content | 700 // Write hex string length and content |
| 709 char* hex_string = object->value.as_bigint; | 701 char* hex_string = object->value.as_bigint; |
| 710 intptr_t len = strlen(hex_string); | 702 intptr_t len = strlen(hex_string); |
| 711 WriteIntptrValue(len); | 703 WriteIntptrValue(len); |
| 712 for (intptr_t i = 0; i < len; i++) { | 704 for (intptr_t i = 0; i < len; i++) { |
| 713 Write<uint8_t>(hex_string[i]); | 705 Write<uint8_t>(hex_string[i]); |
| 714 } | 706 } |
| 715 break; | 707 break; |
| 716 } | 708 } |
| 717 case Dart_CObject::kDouble: | 709 case Dart_CObject::kDouble: |
| 718 // Write out the serialization header value for this object. | 710 // Write out the serialization header value for this object. |
| 719 WriteInlinedHeader(object); | 711 WriteInlinedHeader(object); |
| 720 // Write out the class and tags information. | 712 // Write out the class and tags information. |
| 721 WriteIndexedObject(ObjectStore::kDoubleClass); | 713 WriteIndexedObject(kDoubleCid); |
| 722 WriteIntptrValue(0); | 714 WriteIntptrValue(0); |
| 723 // Write double value. | 715 // Write double value. |
| 724 Write<double>(object->value.as_double); | 716 Write<double>(object->value.as_double); |
| 725 break; | 717 break; |
| 726 case Dart_CObject::kString: { | 718 case Dart_CObject::kString: { |
| 727 // Write out the serialization header value for this object. | 719 // Write out the serialization header value for this object. |
| 728 WriteInlinedHeader(object); | 720 WriteInlinedHeader(object); |
| 729 // Write out the class and tags information. | 721 // Write out the class and tags information. |
| 730 WriteIndexedObject(ObjectStore::kOneByteStringClass); | 722 WriteIndexedObject(kOneByteStringCid); |
| 731 WriteIntptrValue(0); | 723 WriteIntptrValue(0); |
| 732 // Write string length, hash and content | 724 // Write string length, hash and content |
| 733 char* str = object->value.as_string; | 725 char* str = object->value.as_string; |
| 734 intptr_t len = strlen(str); | 726 intptr_t len = strlen(str); |
| 735 WriteSmi(len); | 727 WriteSmi(len); |
| 736 WriteSmi(0); // TODO(sgjesse): Hash - not written. | 728 WriteSmi(0); // TODO(sgjesse): Hash - not written. |
| 737 for (intptr_t i = 0; i < len; i++) { | 729 for (intptr_t i = 0; i < len; i++) { |
| 738 Write<uint8_t>(str[i]); | 730 Write<uint8_t>(str[i]); |
| 739 } | 731 } |
| 740 break; | 732 break; |
| 741 } | 733 } |
| 742 case Dart_CObject::kUint8Array: { | 734 case Dart_CObject::kUint8Array: { |
| 743 // Write out the serialization header value for this object. | 735 // Write out the serialization header value for this object. |
| 744 WriteInlinedHeader(object); | 736 WriteInlinedHeader(object); |
| 745 // Write out the class and tags information. | 737 // Write out the class and tags information. |
| 746 WriteIndexedObject(ObjectStore::kUint8ArrayClass); | 738 WriteIndexedObject(kUint8ArrayCid); |
| 747 WriteIntptrValue(0); | 739 WriteIntptrValue(0); |
| 748 uint8_t* bytes = object->value.as_byte_array.values; | 740 uint8_t* bytes = object->value.as_byte_array.values; |
| 749 intptr_t len = object->value.as_byte_array.length; | 741 intptr_t len = object->value.as_byte_array.length; |
| 750 WriteSmi(len); | 742 WriteSmi(len); |
| 751 for (intptr_t i = 0; i < len; i++) { | 743 for (intptr_t i = 0; i < len; i++) { |
| 752 Write<uint8_t>(bytes[i]); | 744 Write<uint8_t>(bytes[i]); |
| 753 } | 745 } |
| 754 break; | 746 break; |
| 755 } | 747 } |
| 756 case Dart_CObject::kExternalUint8Array: { | 748 case Dart_CObject::kExternalUint8Array: { |
| 757 // TODO(ager): we are writing C pointers into the message in | 749 // TODO(ager): we are writing C pointers into the message in |
| 758 // order to post external arrays through ports. We need to make | 750 // order to post external arrays through ports. We need to make |
| 759 // sure that messages containing pointers can never be posted | 751 // sure that messages containing pointers can never be posted |
| 760 // to other processes. | 752 // to other processes. |
| 761 | 753 |
| 762 // Write out serialization header value for this object. | 754 // Write out serialization header value for this object. |
| 763 WriteInlinedHeader(object); | 755 WriteInlinedHeader(object); |
| 764 // Write out the class and tag information. | 756 // Write out the class and tag information. |
| 765 WriteIndexedObject(ObjectStore::kExternalUint8ArrayClass); | 757 WriteIndexedObject(kExternalUint8ArrayCid); |
| 766 WriteIntptrValue(0); | 758 WriteIntptrValue(0); |
| 767 int length = object->value.as_external_byte_array.length; | 759 int length = object->value.as_external_byte_array.length; |
| 768 uint8_t* data = object->value.as_external_byte_array.data; | 760 uint8_t* data = object->value.as_external_byte_array.data; |
| 769 void* peer = object->value.as_external_byte_array.peer; | 761 void* peer = object->value.as_external_byte_array.peer; |
| 770 Dart_PeerFinalizer callback = | 762 Dart_PeerFinalizer callback = |
| 771 object->value.as_external_byte_array.callback; | 763 object->value.as_external_byte_array.callback; |
| 772 WriteSmi(length); | 764 WriteSmi(length); |
| 773 WriteIntptrValue(reinterpret_cast<intptr_t>(data)); | 765 WriteIntptrValue(reinterpret_cast<intptr_t>(data)); |
| 774 WriteIntptrValue(reinterpret_cast<intptr_t>(peer)); | 766 WriteIntptrValue(reinterpret_cast<intptr_t>(peer)); |
| 775 WriteIntptrValue(reinterpret_cast<intptr_t>(callback)); | 767 WriteIntptrValue(reinterpret_cast<intptr_t>(callback)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 787 // not been serialized yet. These would typically be fields of arrays. | 779 // not been serialized yet. These would typically be fields of arrays. |
| 788 // NOTE: The forward list might grow as we process the list. | 780 // NOTE: The forward list might grow as we process the list. |
| 789 for (intptr_t i = 0; i < forward_id_; i++) { | 781 for (intptr_t i = 0; i < forward_id_; i++) { |
| 790 WriteForwardedCObject(forward_list_[i]); | 782 WriteForwardedCObject(forward_list_[i]); |
| 791 } | 783 } |
| 792 UnmarkAllCObjects(object); | 784 UnmarkAllCObjects(object); |
| 793 FinalizeBuffer(); | 785 FinalizeBuffer(); |
| 794 } | 786 } |
| 795 | 787 |
| 796 } // namespace dart | 788 } // namespace dart |
| OLD | NEW |