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/bigint_operations.h" | 5 #include "vm/bigint_operations.h" |
6 #include "vm/dart_api_message.h" | 6 #include "vm/dart_api_message.h" |
7 #include "vm/object.h" | 7 #include "vm/object.h" |
8 #include "vm/snapshot_ids.h" | 8 #include "vm/snapshot_ids.h" |
9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
10 #include "vm/unicode.h" | 10 #include "vm/unicode.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 251 } |
252 i++; | 252 i++; |
253 } | 253 } |
254 return Dart_TypedData_kInvalid; | 254 return Dart_TypedData_kInvalid; |
255 } | 255 } |
256 | 256 |
257 | 257 |
258 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { | 258 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { |
259 // Read the class header information and lookup the class. | 259 // Read the class header information and lookup the class. |
260 intptr_t class_header = ReadIntptrValue(); | 260 intptr_t class_header = ReadIntptrValue(); |
261 intptr_t tags = ReadIntptrValue(); | 261 intptr_t tags = ReadTags(); |
262 USE(tags); | 262 USE(tags); |
263 intptr_t class_id; | 263 intptr_t class_id; |
264 | 264 |
265 // There is limited support for reading regular dart instances. Only | 265 // There is limited support for reading regular dart instances. Only |
266 // typed data views are currently handled. | 266 // typed data views are currently handled. |
267 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 267 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
268 Dart_CObject_Internal* object = | 268 Dart_CObject_Internal* object = |
269 reinterpret_cast<Dart_CObject_Internal*>(GetBackRef(object_id)); | 269 reinterpret_cast<Dart_CObject_Internal*>(GetBackRef(object_id)); |
270 if (object == NULL) { | 270 if (object == NULL) { |
271 object = | 271 object = |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 intptr_t object_id = SerializedHeaderData::decode(value); | 419 intptr_t object_id = SerializedHeaderData::decode(value); |
420 intptr_t class_id = LookupInternalClass(class_header); | 420 intptr_t class_id = LookupInternalClass(class_header); |
421 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { | 421 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { |
422 ASSERT(GetBackRef(object_id) == NULL); | 422 ASSERT(GetBackRef(object_id) == NULL); |
423 intptr_t len = ReadSmiValue(); | 423 intptr_t len = ReadSmiValue(); |
424 Dart_CObject* value = AllocateDartCObjectArray(len); | 424 Dart_CObject* value = AllocateDartCObjectArray(len); |
425 AddBackRef(object_id, value, kIsNotDeserialized); | 425 AddBackRef(object_id, value, kIsNotDeserialized); |
426 return value; | 426 return value; |
427 } | 427 } |
428 | 428 |
429 intptr_t tags = ReadIntptrValue(); | 429 intptr_t tags = ReadTags(); |
430 USE(tags); | 430 USE(tags); |
431 | 431 |
432 return ReadInternalVMObject(class_id, object_id); | 432 return ReadInternalVMObject(class_id, object_id); |
433 } | 433 } |
434 | 434 |
435 | 435 |
436 Dart_CObject* ApiMessageReader::ReadVMIsolateObject(intptr_t value) { | 436 Dart_CObject* ApiMessageReader::ReadVMIsolateObject(intptr_t value) { |
437 intptr_t object_id = GetVMIsolateObjectId(value); | 437 intptr_t object_id = GetVMIsolateObjectId(value); |
438 if (object_id == kNullObject) { | 438 if (object_id == kNullObject) { |
439 return AllocateDartCObjectNull(); | 439 return AllocateDartCObjectNull(); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 return NULL; | 775 return NULL; |
776 } | 776 } |
777 | 777 |
778 | 778 |
779 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { | 779 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { |
780 // Write out the serialization header value for this object. | 780 // Write out the serialization header value for this object. |
781 WriteInlinedObjectHeader(kMaxPredefinedObjectIds); | 781 WriteInlinedObjectHeader(kMaxPredefinedObjectIds); |
782 | 782 |
783 // Write out the class and tags information. | 783 // Write out the class and tags information. |
784 WriteIndexedObject(kArrayCid); | 784 WriteIndexedObject(kArrayCid); |
785 WriteIntptrValue(0); | 785 WriteTags(0); |
786 | 786 |
787 // Write out the length field. | 787 // Write out the length field. |
788 Write<RawObject*>(Smi::New(field_count)); | 788 Write<RawObject*>(Smi::New(field_count)); |
789 | 789 |
790 // Write out the type arguments. | 790 // Write out the type arguments. |
791 WriteNullObject(); | 791 WriteNullObject(); |
792 | 792 |
793 // Write out the individual Smis. | 793 // Write out the individual Smis. |
794 for (int i = 0; i < field_count; i++) { | 794 for (int i = 0; i < field_count; i++) { |
795 Write<RawObject*>(Integer::New(data[i])); | 795 Write<RawObject*>(Integer::New(data[i])); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 WriteVMIsolateObject(kNullObject); | 871 WriteVMIsolateObject(kNullObject); |
872 } | 872 } |
873 | 873 |
874 | 874 |
875 void ApiMessageWriter::WriteMint(Dart_CObject* object, int64_t value) { | 875 void ApiMessageWriter::WriteMint(Dart_CObject* object, int64_t value) { |
876 ASSERT(!Smi::IsValid64(value)); | 876 ASSERT(!Smi::IsValid64(value)); |
877 // Write out the serialization header value for mint object. | 877 // Write out the serialization header value for mint object. |
878 WriteInlinedHeader(object); | 878 WriteInlinedHeader(object); |
879 // Write out the class and tags information. | 879 // Write out the class and tags information. |
880 WriteIndexedObject(kMintCid); | 880 WriteIndexedObject(kMintCid); |
881 WriteIntptrValue(0); | 881 WriteTags(0); |
882 // Write the 64-bit value. | 882 // Write the 64-bit value. |
883 Write<int64_t>(value); | 883 Write<int64_t>(value); |
884 } | 884 } |
885 | 885 |
886 | 886 |
887 void ApiMessageWriter::WriteInt32(Dart_CObject* object) { | 887 void ApiMessageWriter::WriteInt32(Dart_CObject* object) { |
888 int64_t value = object->value.as_int32; | 888 int64_t value = object->value.as_int32; |
889 if (Smi::IsValid64(value)) { | 889 if (Smi::IsValid64(value)) { |
890 WriteSmi(value); | 890 WriteSmi(value); |
891 } else { | 891 } else { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 const intptr_t array_length = object->value.as_array.length; | 926 const intptr_t array_length = object->value.as_array.length; |
927 if (array_length < 0 || | 927 if (array_length < 0 || |
928 array_length > Array::kMaxElements) { | 928 array_length > Array::kMaxElements) { |
929 return false; | 929 return false; |
930 } | 930 } |
931 | 931 |
932 // Write out the serialization header value for this object. | 932 // Write out the serialization header value for this object. |
933 WriteInlinedHeader(object); | 933 WriteInlinedHeader(object); |
934 // Write out the class and tags information. | 934 // Write out the class and tags information. |
935 WriteIndexedObject(kArrayCid); | 935 WriteIndexedObject(kArrayCid); |
936 WriteIntptrValue(0); | 936 WriteTags(0); |
937 // Write out the length information. | 937 // Write out the length information. |
938 WriteSmi(array_length); | 938 WriteSmi(array_length); |
939 // Write out the type arguments. | 939 // Write out the type arguments. |
940 WriteNullObject(); | 940 WriteNullObject(); |
941 // Write out array elements. | 941 // Write out array elements. |
942 for (int i = 0; i < array_length; i++) { | 942 for (int i = 0; i < array_length; i++) { |
943 bool success = WriteCObjectRef(object->value.as_array.values[i]); | 943 bool success = WriteCObjectRef(object->value.as_array.values[i]); |
944 if (!success) return false; | 944 if (!success) return false; |
945 } | 945 } |
946 return true; | 946 return true; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 if (array_length < 0 || | 986 if (array_length < 0 || |
987 array_length > Array::kMaxElements) { | 987 array_length > Array::kMaxElements) { |
988 return false; | 988 return false; |
989 } | 989 } |
990 | 990 |
991 // Write out the serialization header value for this object. | 991 // Write out the serialization header value for this object. |
992 intptr_t object_id = GetMarkedCObjectMark(object); | 992 intptr_t object_id = GetMarkedCObjectMark(object); |
993 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id); | 993 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id); |
994 // Write out the class and tags information. | 994 // Write out the class and tags information. |
995 WriteIndexedObject(kArrayCid); | 995 WriteIndexedObject(kArrayCid); |
996 WriteIntptrValue(0); | 996 WriteTags(0); |
997 // Write out the length information. | 997 // Write out the length information. |
998 WriteSmi(array_length); | 998 WriteSmi(array_length); |
999 // Write out the type arguments. | 999 // Write out the type arguments. |
1000 WriteNullObject(); | 1000 WriteNullObject(); |
1001 // Write out array elements. | 1001 // Write out array elements. |
1002 for (int i = 0; i < array_length; i++) { | 1002 for (int i = 0; i < array_length; i++) { |
1003 bool success = WriteCObjectRef(object->value.as_array.values[i]); | 1003 bool success = WriteCObjectRef(object->value.as_array.values[i]); |
1004 if (!success) return false; | 1004 if (!success) return false; |
1005 } | 1005 } |
1006 return true; | 1006 return true; |
(...skipping 24 matching lines...) Expand all Loading... |
1031 const intptr_t chunk_len = | 1031 const intptr_t chunk_len = |
1032 BigintOperations::ComputeChunkLength(hex_string); | 1032 BigintOperations::ComputeChunkLength(hex_string); |
1033 if (chunk_len < 0 || | 1033 if (chunk_len < 0 || |
1034 chunk_len > Bigint::kMaxElements) { | 1034 chunk_len > Bigint::kMaxElements) { |
1035 return false; | 1035 return false; |
1036 } | 1036 } |
1037 // Write out the serialization header value for this object. | 1037 // Write out the serialization header value for this object. |
1038 WriteInlinedHeader(object); | 1038 WriteInlinedHeader(object); |
1039 // Write out the class and tags information. | 1039 // Write out the class and tags information. |
1040 WriteIndexedObject(kBigintCid); | 1040 WriteIndexedObject(kBigintCid); |
1041 WriteIntptrValue(0); | 1041 WriteTags(0); |
1042 // Write hex string length and content | 1042 // Write hex string length and content |
1043 intptr_t len = strlen(hex_string); | 1043 intptr_t len = strlen(hex_string); |
1044 WriteIntptrValue(len); | 1044 WriteIntptrValue(len); |
1045 for (intptr_t i = 0; i < len; i++) { | 1045 for (intptr_t i = 0; i < len; i++) { |
1046 Write<uint8_t>(hex_string[i]); | 1046 Write<uint8_t>(hex_string[i]); |
1047 } | 1047 } |
1048 break; | 1048 break; |
1049 } | 1049 } |
1050 case Dart_CObject_kDouble: | 1050 case Dart_CObject_kDouble: |
1051 WriteVMIsolateObject(kDoubleObject); | 1051 WriteVMIsolateObject(kDoubleObject); |
(...skipping 12 matching lines...) Expand all Loading... |
1064 ASSERT(len > 0); | 1064 ASSERT(len > 0); |
1065 if (len > String::kMaxElements) { | 1065 if (len > String::kMaxElements) { |
1066 return false; | 1066 return false; |
1067 } | 1067 } |
1068 | 1068 |
1069 // Write out the serialization header value for this object. | 1069 // Write out the serialization header value for this object. |
1070 WriteInlinedHeader(object); | 1070 WriteInlinedHeader(object); |
1071 // Write out the class and tags information. | 1071 // Write out the class and tags information. |
1072 WriteIndexedObject(type == Utf8::kLatin1 ? kOneByteStringCid | 1072 WriteIndexedObject(type == Utf8::kLatin1 ? kOneByteStringCid |
1073 : kTwoByteStringCid); | 1073 : kTwoByteStringCid); |
1074 WriteIntptrValue(0); | 1074 WriteTags(0); |
1075 // Write string length, hash and content | 1075 // Write string length, hash and content |
1076 WriteSmi(len); | 1076 WriteSmi(len); |
1077 WriteSmi(0); // TODO(sgjesse): Hash - not written. | 1077 WriteSmi(0); // TODO(sgjesse): Hash - not written. |
1078 if (type == Utf8::kLatin1) { | 1078 if (type == Utf8::kLatin1) { |
1079 uint8_t* latin1_str = | 1079 uint8_t* latin1_str = |
1080 reinterpret_cast<uint8_t*>(::malloc(len * sizeof(uint8_t))); | 1080 reinterpret_cast<uint8_t*>(::malloc(len * sizeof(uint8_t))); |
1081 bool success = Utf8::DecodeToLatin1(utf8_str, | 1081 bool success = Utf8::DecodeToLatin1(utf8_str, |
1082 utf8_len, | 1082 utf8_len, |
1083 latin1_str, | 1083 latin1_str, |
1084 len); | 1084 len); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 UNIMPLEMENTED(); | 1116 UNIMPLEMENTED(); |
1117 } | 1117 } |
1118 | 1118 |
1119 intptr_t len = object->value.as_typed_data.length; | 1119 intptr_t len = object->value.as_typed_data.length; |
1120 if (len < 0 || | 1120 if (len < 0 || |
1121 len > TypedData::MaxElements(class_id)) { | 1121 len > TypedData::MaxElements(class_id)) { |
1122 return false; | 1122 return false; |
1123 } | 1123 } |
1124 | 1124 |
1125 WriteIndexedObject(class_id); | 1125 WriteIndexedObject(class_id); |
1126 WriteIntptrValue(RawObject::ClassIdTag::update(class_id, 0)); | 1126 WriteTags(RawObject::ClassIdTag::update(class_id, 0)); |
1127 WriteSmi(len); | 1127 WriteSmi(len); |
1128 uint8_t* bytes = object->value.as_typed_data.values; | 1128 uint8_t* bytes = object->value.as_typed_data.values; |
1129 for (intptr_t i = 0; i < len; i++) { | 1129 for (intptr_t i = 0; i < len; i++) { |
1130 Write<uint8_t>(bytes[i]); | 1130 Write<uint8_t>(bytes[i]); |
1131 } | 1131 } |
1132 break; | 1132 break; |
1133 } | 1133 } |
1134 case Dart_CObject_kExternalTypedData: { | 1134 case Dart_CObject_kExternalTypedData: { |
1135 // TODO(ager): we are writing C pointers into the message in | 1135 // TODO(ager): we are writing C pointers into the message in |
1136 // order to post external arrays through ports. We need to make | 1136 // order to post external arrays through ports. We need to make |
1137 // sure that messages containing pointers can never be posted | 1137 // sure that messages containing pointers can never be posted |
1138 // to other processes. | 1138 // to other processes. |
1139 | 1139 |
1140 // Write out serialization header value for this object. | 1140 // Write out serialization header value for this object. |
1141 WriteInlinedHeader(object); | 1141 WriteInlinedHeader(object); |
1142 // Write out the class and tag information. | 1142 // Write out the class and tag information. |
1143 WriteIndexedObject(kExternalTypedDataUint8ArrayCid); | 1143 WriteIndexedObject(kExternalTypedDataUint8ArrayCid); |
1144 WriteIntptrValue(RawObject::ClassIdTag::update( | 1144 WriteTags(RawObject::ClassIdTag::update( |
1145 kExternalTypedDataUint8ArrayCid, 0)); | 1145 kExternalTypedDataUint8ArrayCid, 0)); |
1146 intptr_t length = object->value.as_external_typed_data.length; | 1146 intptr_t length = object->value.as_external_typed_data.length; |
1147 if (length < 0 || | 1147 if (length < 0 || |
1148 length > ExternalTypedData::MaxElements( | 1148 length > ExternalTypedData::MaxElements( |
1149 kExternalTypedDataUint8ArrayCid)) { | 1149 kExternalTypedDataUint8ArrayCid)) { |
1150 return false; | 1150 return false; |
1151 } | 1151 } |
1152 uint8_t* data = object->value.as_external_typed_data.data; | 1152 uint8_t* data = object->value.as_external_typed_data.data; |
1153 void* peer = object->value.as_external_typed_data.peer; | 1153 void* peer = object->value.as_external_typed_data.peer; |
1154 Dart_WeakPersistentHandleFinalizer callback = | 1154 Dart_WeakPersistentHandleFinalizer callback = |
(...skipping 26 matching lines...) Expand all Loading... |
1181 if (!success) { | 1181 if (!success) { |
1182 UnmarkAllCObjects(object); | 1182 UnmarkAllCObjects(object); |
1183 return false; | 1183 return false; |
1184 } | 1184 } |
1185 } | 1185 } |
1186 UnmarkAllCObjects(object); | 1186 UnmarkAllCObjects(object); |
1187 return true; | 1187 return true; |
1188 } | 1188 } |
1189 | 1189 |
1190 } // namespace dart | 1190 } // namespace dart |
OLD | NEW |