Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: runtime/vm/dart_api_message.cc

Issue 23816010: "Reverting 27298" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
6 #include "vm/dart_api_message.h" 5 #include "vm/dart_api_message.h"
7 #include "vm/object.h" 6 #include "vm/object.h"
8 #include "vm/snapshot_ids.h" 7 #include "vm/snapshot_ids.h"
9 #include "vm/symbols.h" 8 #include "vm/symbols.h"
10 #include "vm/unicode.h" 9 #include "vm/unicode.h"
11 10
12 namespace dart { 11 namespace dart {
13 12
14 static const int kNumInitialReferences = 4; 13 static const int kNumInitialReferences = 4;
15 14
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 880
882 bool ApiMessageWriter::WriteCObject(Dart_CObject* object) { 881 bool ApiMessageWriter::WriteCObject(Dart_CObject* object) {
883 if (IsCObjectMarked(object)) { 882 if (IsCObjectMarked(object)) {
884 intptr_t object_id = GetMarkedCObjectMark(object); 883 intptr_t object_id = GetMarkedCObjectMark(object);
885 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); 884 WriteIndexedObject(kMaxPredefinedObjectIds + object_id);
886 return true; 885 return true;
887 } 886 }
888 887
889 Dart_CObject_Type type = object->type; 888 Dart_CObject_Type type = object->type;
890 if (type == Dart_CObject_kArray) { 889 if (type == Dart_CObject_kArray) {
891 const intptr_t array_length = object->value.as_array.length;
892 if (array_length < 0 ||
893 array_length > Array::kMaxElements) {
894 return false;
895 }
896
897 // Write out the serialization header value for this object. 890 // Write out the serialization header value for this object.
898 WriteInlinedHeader(object); 891 WriteInlinedHeader(object);
899 // Write out the class and tags information. 892 // Write out the class and tags information.
900 WriteIndexedObject(kArrayCid); 893 WriteIndexedObject(kArrayCid);
901 WriteIntptrValue(0); 894 WriteIntptrValue(0);
902 // Write out the length information. 895
903 WriteSmi(array_length); 896 WriteSmi(object->value.as_array.length);
904 // Write out the type arguments. 897 // Write out the type arguments.
905 WriteNullObject(); 898 WriteNullObject();
906 // Write out array elements. 899 // Write out array elements.
907 for (int i = 0; i < array_length; i++) { 900 for (int i = 0; i < object->value.as_array.length; i++) {
908 bool success = WriteCObjectRef(object->value.as_array.values[i]); 901 bool success = WriteCObjectRef(object->value.as_array.values[i]);
909 if (!success) return false; 902 if (!success) return false;
910 } 903 }
911 return true; 904 return true;
912 } 905 }
913 return WriteCObjectInlined(object, type); 906 return WriteCObjectInlined(object, type);
914 } 907 }
915 908
916 909
917 bool ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) { 910 bool ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) {
918 if (IsCObjectMarked(object)) { 911 if (IsCObjectMarked(object)) {
919 intptr_t object_id = GetMarkedCObjectMark(object); 912 intptr_t object_id = GetMarkedCObjectMark(object);
920 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); 913 WriteIndexedObject(kMaxPredefinedObjectIds + object_id);
921 return true; 914 return true;
922 } 915 }
923 916
924 Dart_CObject_Type type = object->type; 917 Dart_CObject_Type type = object->type;
925 if (type == Dart_CObject_kArray) { 918 if (type == Dart_CObject_kArray) {
926 const intptr_t array_length = object->value.as_array.length;
927 if (array_length < 0 ||
928 array_length > Array::kMaxElements) {
929 return false;
930 }
931 // Write out the serialization header value for this object. 919 // Write out the serialization header value for this object.
932 WriteInlinedHeader(object); 920 WriteInlinedHeader(object);
933 // Write out the class information. 921 // Write out the class information.
934 WriteIndexedObject(kArrayCid); 922 WriteIndexedObject(kArrayCid);
935 // Write out the length information. 923 // Write out the length information.
936 WriteSmi(array_length); 924 WriteSmi(object->value.as_array.length);
937 // Add object to forward list so that this object is serialized later. 925 // Add object to forward list so that this object is serialized later.
938 AddToForwardList(object); 926 AddToForwardList(object);
939 return true; 927 return true;
940 } 928 }
941 return WriteCObjectInlined(object, type); 929 return WriteCObjectInlined(object, type);
942 } 930 }
943 931
944 932
945 bool ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) { 933 bool ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) {
946 ASSERT(IsCObjectMarked(object)); 934 ASSERT(IsCObjectMarked(object));
947 Dart_CObject_Type type = 935 Dart_CObject_Type type =
948 static_cast<Dart_CObject_Type>(object->type & kDartCObjectTypeMask); 936 static_cast<Dart_CObject_Type>(object->type & kDartCObjectTypeMask);
949 ASSERT(type == Dart_CObject_kArray); 937 ASSERT(type == Dart_CObject_kArray);
950 const intptr_t array_length = object->value.as_array.length;
951 if (array_length < 0 ||
952 array_length > Array::kMaxElements) {
953 return false;
954 }
955 938
956 // Write out the serialization header value for this object. 939 // Write out the serialization header value for this object.
957 intptr_t object_id = GetMarkedCObjectMark(object); 940 intptr_t object_id = GetMarkedCObjectMark(object);
958 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id); 941 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id);
959 // Write out the class and tags information. 942 // Write out the class and tags information.
960 WriteIndexedObject(kArrayCid); 943 WriteIndexedObject(kArrayCid);
961 WriteIntptrValue(0); 944 WriteIntptrValue(0);
962 // Write out the length information. 945
963 WriteSmi(array_length); 946 WriteSmi(object->value.as_array.length);
964 // Write out the type arguments. 947 // Write out the type arguments.
965 WriteNullObject(); 948 WriteNullObject();
966 // Write out array elements. 949 // Write out array elements.
967 for (int i = 0; i < array_length; i++) { 950 for (int i = 0; i < object->value.as_array.length; i++) {
968 bool success = WriteCObjectRef(object->value.as_array.values[i]); 951 bool success = WriteCObjectRef(object->value.as_array.values[i]);
969 if (!success) return false; 952 if (!success) return false;
970 } 953 }
971 return true; 954 return true;
972 } 955 }
973 956
974 957
975 bool ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object, 958 bool ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object,
976 Dart_CObject_Type type) { 959 Dart_CObject_Type type) {
977 switch (type) { 960 switch (type) {
978 case Dart_CObject_kNull: 961 case Dart_CObject_kNull:
979 WriteNullObject(); 962 WriteNullObject();
980 break; 963 break;
981 case Dart_CObject_kBool: 964 case Dart_CObject_kBool:
982 if (object->value.as_bool) { 965 if (object->value.as_bool) {
983 WriteVMIsolateObject(kTrueValue); 966 WriteVMIsolateObject(kTrueValue);
984 } else { 967 } else {
985 WriteVMIsolateObject(kFalseValue); 968 WriteVMIsolateObject(kFalseValue);
986 } 969 }
987 break; 970 break;
988 case Dart_CObject_kInt32: 971 case Dart_CObject_kInt32:
989 WriteInt32(object); 972 WriteInt32(object);
990 break; 973 break;
991 case Dart_CObject_kInt64: 974 case Dart_CObject_kInt64:
992 WriteInt64(object); 975 WriteInt64(object);
993 break; 976 break;
994 case Dart_CObject_kBigint: { 977 case Dart_CObject_kBigint: {
995 char* hex_string = object->value.as_bigint;
996 const intptr_t chunk_len =
997 BigintOperations::ComputeChunkLength(hex_string);
998 if (chunk_len < 0 ||
999 chunk_len > Bigint::kMaxElements) {
1000 return false;
1001 }
1002 // Write out the serialization header value for this object. 978 // Write out the serialization header value for this object.
1003 WriteInlinedHeader(object); 979 WriteInlinedHeader(object);
1004 // Write out the class and tags information. 980 // Write out the class and tags information.
1005 WriteIndexedObject(kBigintCid); 981 WriteIndexedObject(kBigintCid);
1006 WriteIntptrValue(0); 982 WriteIntptrValue(0);
1007 // Write hex string length and content 983 // Write hex string length and content
984 char* hex_string = object->value.as_bigint;
1008 intptr_t len = strlen(hex_string); 985 intptr_t len = strlen(hex_string);
1009 WriteIntptrValue(len); 986 WriteIntptrValue(len);
1010 for (intptr_t i = 0; i < len; i++) { 987 for (intptr_t i = 0; i < len; i++) {
1011 Write<uint8_t>(hex_string[i]); 988 Write<uint8_t>(hex_string[i]);
1012 } 989 }
1013 break; 990 break;
1014 } 991 }
1015 case Dart_CObject_kDouble: 992 case Dart_CObject_kDouble:
1016 // Write out the serialization header value for this object. 993 // Write out the serialization header value for this object.
1017 WriteInlinedHeader(object); 994 WriteInlinedHeader(object);
1018 // Write out the class and tags information. 995 // Write out the class and tags information.
1019 WriteIndexedObject(kDoubleCid); 996 WriteIndexedObject(kDoubleCid);
1020 WriteIntptrValue(0); 997 WriteIntptrValue(0);
1021 // Write double value. 998 // Write double value.
1022 Write<double>(object->value.as_double); 999 Write<double>(object->value.as_double);
1023 break; 1000 break;
1024 case Dart_CObject_kString: { 1001 case Dart_CObject_kString: {
1025 const uint8_t* utf8_str = 1002 const uint8_t* utf8_str =
1026 reinterpret_cast<const uint8_t*>(object->value.as_string); 1003 reinterpret_cast<const uint8_t*>(object->value.as_string);
1027 intptr_t utf8_len = strlen(object->value.as_string); 1004 intptr_t utf8_len = strlen(object->value.as_string);
1028 if (!Utf8::IsValid(utf8_str, utf8_len)) { 1005 if (!Utf8::IsValid(utf8_str, utf8_len)) {
1029 return false; 1006 return false;
1030 } 1007 }
1031 1008
1032 Utf8::Type type; 1009 Utf8::Type type;
1033 intptr_t len = Utf8::CodeUnitCount(utf8_str, utf8_len, &type); 1010 intptr_t len = Utf8::CodeUnitCount(utf8_str, utf8_len, &type);
1034 ASSERT(len > 0);
1035 if (len > String::kMaxElements) {
1036 return false;
1037 }
1038 1011
1039 // Write out the serialization header value for this object. 1012 // Write out the serialization header value for this object.
1040 WriteInlinedHeader(object); 1013 WriteInlinedHeader(object);
1041 // Write out the class and tags information. 1014 // Write out the class and tags information.
1042 WriteIndexedObject(type == Utf8::kLatin1 ? kOneByteStringCid 1015 WriteIndexedObject(type == Utf8::kLatin1 ? kOneByteStringCid
1043 : kTwoByteStringCid); 1016 : kTwoByteStringCid);
1044 WriteIntptrValue(0); 1017 WriteIntptrValue(0);
1045 // Write string length, hash and content 1018 // Write string length, hash and content
1046 WriteSmi(len); 1019 WriteSmi(len);
1047 WriteSmi(0); // TODO(sgjesse): Hash - not written. 1020 WriteSmi(0); // TODO(sgjesse): Hash - not written.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 class_id = kTypedDataInt8ArrayCid; 1052 class_id = kTypedDataInt8ArrayCid;
1080 break; 1053 break;
1081 case Dart_TypedData_kUint8: 1054 case Dart_TypedData_kUint8:
1082 class_id = kTypedDataUint8ArrayCid; 1055 class_id = kTypedDataUint8ArrayCid;
1083 break; 1056 break;
1084 default: 1057 default:
1085 class_id = kTypedDataUint8ArrayCid; 1058 class_id = kTypedDataUint8ArrayCid;
1086 UNIMPLEMENTED(); 1059 UNIMPLEMENTED();
1087 } 1060 }
1088 1061
1089 intptr_t len = object->value.as_typed_data.length;
1090 if (len < 0 ||
1091 len > TypedData::MaxElements(class_id)) {
1092 return false;
1093 }
1094
1095 WriteIndexedObject(class_id); 1062 WriteIndexedObject(class_id);
1096 WriteIntptrValue(RawObject::ClassIdTag::update(class_id, 0)); 1063 WriteIntptrValue(RawObject::ClassIdTag::update(class_id, 0));
1064 uint8_t* bytes = object->value.as_typed_data.values;
1065 intptr_t len = object->value.as_typed_data.length;
1097 WriteSmi(len); 1066 WriteSmi(len);
1098 uint8_t* bytes = object->value.as_typed_data.values;
1099 for (intptr_t i = 0; i < len; i++) { 1067 for (intptr_t i = 0; i < len; i++) {
1100 Write<uint8_t>(bytes[i]); 1068 Write<uint8_t>(bytes[i]);
1101 } 1069 }
1102 break; 1070 break;
1103 } 1071 }
1104 case Dart_CObject_kExternalTypedData: { 1072 case Dart_CObject_kExternalTypedData: {
1105 // TODO(ager): we are writing C pointers into the message in 1073 // TODO(ager): we are writing C pointers into the message in
1106 // order to post external arrays through ports. We need to make 1074 // order to post external arrays through ports. We need to make
1107 // sure that messages containing pointers can never be posted 1075 // sure that messages containing pointers can never be posted
1108 // to other processes. 1076 // to other processes.
1109 1077
1110 // Write out serialization header value for this object. 1078 // Write out serialization header value for this object.
1111 WriteInlinedHeader(object); 1079 WriteInlinedHeader(object);
1112 // Write out the class and tag information. 1080 // Write out the class and tag information.
1113 WriteIndexedObject(kExternalTypedDataUint8ArrayCid); 1081 WriteIndexedObject(kExternalTypedDataUint8ArrayCid);
1114 WriteIntptrValue(RawObject::ClassIdTag::update( 1082 WriteIntptrValue(RawObject::ClassIdTag::update(
1115 kExternalTypedDataUint8ArrayCid, 0)); 1083 kExternalTypedDataUint8ArrayCid, 0));
1116 int length = object->value.as_external_typed_data.length; 1084 int length = object->value.as_external_typed_data.length;
1117 if (length < 0 ||
1118 length > ExternalTypedData::MaxElements(
1119 kExternalTypedDataUint8ArrayCid)) {
1120 return false;
1121 }
1122 uint8_t* data = object->value.as_external_typed_data.data; 1085 uint8_t* data = object->value.as_external_typed_data.data;
1123 void* peer = object->value.as_external_typed_data.peer; 1086 void* peer = object->value.as_external_typed_data.peer;
1124 Dart_WeakPersistentHandleFinalizer callback = 1087 Dart_WeakPersistentHandleFinalizer callback =
1125 object->value.as_external_typed_data.callback; 1088 object->value.as_external_typed_data.callback;
1126 WriteSmi(length); 1089 WriteSmi(length);
1127 WriteIntptrValue(reinterpret_cast<intptr_t>(data)); 1090 WriteIntptrValue(reinterpret_cast<intptr_t>(data));
1128 WriteIntptrValue(reinterpret_cast<intptr_t>(peer)); 1091 WriteIntptrValue(reinterpret_cast<intptr_t>(peer));
1129 WriteIntptrValue(reinterpret_cast<intptr_t>(callback)); 1092 WriteIntptrValue(reinterpret_cast<intptr_t>(callback));
1130 break; 1093 break;
1131 } 1094 }
(...skipping 19 matching lines...) Expand all
1151 if (!success) { 1114 if (!success) {
1152 UnmarkAllCObjects(object); 1115 UnmarkAllCObjects(object);
1153 return false; 1116 return false;
1154 } 1117 }
1155 } 1118 }
1156 UnmarkAllCObjects(object); 1119 UnmarkAllCObjects(object);
1157 return true; 1120 return true;
1158 } 1121 }
1159 1122
1160 } // namespace dart 1123 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698