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

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

Issue 1123813002: Move symbol table from per isolate snapshot to vm isolate snapshot, this reduces the per isolate in… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 7 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 | « runtime/vm/dart_api_message.h ('k') | runtime/vm/isolate.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/dart_api_message.h" 5 #include "vm/dart_api_message.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/snapshot_ids.h" 7 #include "vm/snapshot_ids.h"
8 #include "vm/symbols.h" 8 #include "vm/symbols.h"
9 #include "vm/unicode.h" 9 #include "vm/unicode.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 static const int kNumInitialReferences = 4; 13 static const int kNumInitialReferences = 4;
14 14
15 ApiMessageReader::ApiMessageReader(const uint8_t* buffer, 15 ApiMessageReader::ApiMessageReader(const uint8_t* buffer,
16 intptr_t length, 16 intptr_t length,
17 ReAlloc alloc) 17 ReAlloc alloc,
18 bool use_vm_isolate_snapshot)
18 : BaseReader(buffer, length), 19 : BaseReader(buffer, length),
19 alloc_(alloc), 20 alloc_(alloc),
20 backward_references_(kNumInitialReferences), 21 backward_references_(kNumInitialReferences),
21 vm_symbol_references_(NULL) { 22 vm_symbol_references_(NULL),
23 max_vm_isolate_object_id_(
24 use_vm_isolate_snapshot ?
25 Object::vm_isolate_snapshot_object_table().Length() : 0) {
22 Init(); 26 Init();
23 } 27 }
24 28
25 29
26 void ApiMessageReader::Init() { 30 void ApiMessageReader::Init() {
27 // Initialize marker objects used to handle Lists. 31 // Initialize marker objects used to handle Lists.
28 // TODO(sjesse): Remove this when message serialization format is 32 // TODO(sjesse): Remove this when message serialization format is
29 // updated. 33 // updated.
30 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); 34 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker));
31 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); 35 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker));
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 value->value.as_array.length = length; 192 value->value.as_array.length = length;
189 if (length > 0) { 193 if (length > 0) {
190 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); 194 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1);
191 } else { 195 } else {
192 value->value.as_array.values = NULL; 196 value->value.as_array.values = NULL;
193 } 197 }
194 return value; 198 return value;
195 } 199 }
196 200
197 201
202 Dart_CObject* ApiMessageReader::AllocateDartCObjectVmIsolateObj(intptr_t id) {
203 return CreateDartCObjectString(VmIsolateSnapshotObject(id));
204 }
205
206
198 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectInternal( 207 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectInternal(
199 Dart_CObject_Internal::Type type) { 208 Dart_CObject_Internal::Type type) {
200 Dart_CObject_Internal* value = 209 Dart_CObject_Internal* value =
201 reinterpret_cast<Dart_CObject_Internal*>( 210 reinterpret_cast<Dart_CObject_Internal*>(
202 alloc_(NULL, 0, sizeof(Dart_CObject_Internal))); 211 alloc_(NULL, 0, sizeof(Dart_CObject_Internal)));
203 ASSERT(value != NULL); 212 ASSERT(value != NULL);
204 value->type = static_cast<Dart_CObject_Type>(type); 213 value->type = static_cast<Dart_CObject_Type>(type);
205 return value; 214 return value;
206 } 215 }
207 216
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 371 }
363 372
364 if (vm_symbol_references_ == NULL) { 373 if (vm_symbol_references_ == NULL) {
365 intptr_t size = 374 intptr_t size =
366 (sizeof(*vm_symbol_references_) * Symbols::kMaxPredefinedId); 375 (sizeof(*vm_symbol_references_) * Symbols::kMaxPredefinedId);
367 vm_symbol_references_ = 376 vm_symbol_references_ =
368 reinterpret_cast<Dart_CObject**>(alloc_(NULL, 0, size)); 377 reinterpret_cast<Dart_CObject**>(alloc_(NULL, 0, size));
369 memset(vm_symbol_references_, 0, size); 378 memset(vm_symbol_references_, 0, size);
370 } 379 }
371 380
372 RawOneByteString* str = 381 object = CreateDartCObjectString(Symbols::GetVMSymbol(object_id));
373 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id));
374 intptr_t len = Smi::Value(str->ptr()->length_);
375 object = AllocateDartCObjectString(len);
376 char* p = object->value.as_string;
377 memmove(p, str->ptr()->data(), len);
378 p[len] = '\0';
379 ASSERT(vm_symbol_references_[symbol_id] == NULL); 382 ASSERT(vm_symbol_references_[symbol_id] == NULL);
380 vm_symbol_references_[symbol_id] = object; 383 vm_symbol_references_[symbol_id] = object;
381 return object; 384 return object;
382 } 385 }
383 386
384 387
385 intptr_t ApiMessageReader::NextAvailableObjectId() const { 388 intptr_t ApiMessageReader::NextAvailableObjectId() const {
386 return backward_references_.length() + kMaxPredefinedObjectIds; 389 return backward_references_.length() +
390 kMaxPredefinedObjectIds + max_vm_isolate_object_id_;
391 }
392
393
394 Dart_CObject* ApiMessageReader::CreateDartCObjectString(RawObject* raw) {
395 ASSERT(RawObject::IsOneByteStringClassId(raw->GetClassId()));
396 RawOneByteString* raw_str = reinterpret_cast<RawOneByteString*>(raw);
397 intptr_t len = Smi::Value(raw_str->ptr()->length_);
398 Dart_CObject* object = AllocateDartCObjectString(len);
399 char* p = object->value.as_string;
400 memmove(p, raw_str->ptr()->data(), len);
401 p[len] = '\0';
402 return object;
387 } 403 }
388 404
389 405
390 Dart_CObject* ApiMessageReader::ReadObjectRef() { 406 Dart_CObject* ApiMessageReader::ReadObjectRef() {
391 int64_t value64 = Read<int64_t>(); 407 int64_t value64 = Read<int64_t>();
392 if ((value64 & kSmiTagMask) == 0) { 408 if ((value64 & kSmiTagMask) == 0) {
393 int64_t untagged_value = value64 >> kSmiTagShift; 409 int64_t untagged_value = value64 >> kSmiTagShift;
394 if ((kMinInt32 <= untagged_value) && (untagged_value <= kMaxInt32)) { 410 if ((kMinInt32 <= untagged_value) && (untagged_value <= kMaxInt32)) {
395 return AllocateDartCObjectInt32(static_cast<int32_t>(untagged_value)); 411 return AllocateDartCObjectInt32(static_cast<int32_t>(untagged_value));
396 } else { 412 } else {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { 744 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) {
729 if (object_id == kDynamicType || 745 if (object_id == kDynamicType ||
730 object_id == kDoubleType || 746 object_id == kDoubleType ||
731 object_id == kIntType || 747 object_id == kIntType ||
732 object_id == kBoolType || 748 object_id == kBoolType ||
733 object_id == kStringType) { 749 object_id == kStringType) {
734 // Always return dynamic type (this is only a marker). 750 // Always return dynamic type (this is only a marker).
735 return &dynamic_type_marker; 751 return &dynamic_type_marker;
736 } 752 }
737 intptr_t index = object_id - kMaxPredefinedObjectIds; 753 intptr_t index = object_id - kMaxPredefinedObjectIds;
754 if (index < max_vm_isolate_object_id_) {
755 return AllocateDartCObjectVmIsolateObj(index);
756 }
757 index -= max_vm_isolate_object_id_;
738 ASSERT((0 <= index) && (index < backward_references_.length())); 758 ASSERT((0 <= index) && (index < backward_references_.length()));
739 ASSERT(backward_references_[index]->reference() != NULL); 759 ASSERT(backward_references_[index]->reference() != NULL);
740 return backward_references_[index]->reference(); 760 return backward_references_[index]->reference();
741 } 761 }
742 762
743 763
744 Dart_CObject* ApiMessageReader::ReadObject() { 764 Dart_CObject* ApiMessageReader::ReadObject() {
745 Dart_CObject* value = ReadObjectImpl(); 765 Dart_CObject* value = ReadObjectImpl();
746 for (intptr_t i = 0; i < backward_references_.length(); i++) { 766 for (intptr_t i = 0; i < backward_references_.length(); i++) {
747 if (!backward_references_[i]->is_deserialized()) { 767 if (!backward_references_[i]->is_deserialized()) {
(...skipping 30 matching lines...) Expand all
778 object_id = NextAvailableObjectId(); 798 object_id = NextAvailableObjectId();
779 } 799 }
780 return ReadInlinedObject(object_id); 800 return ReadInlinedObject(object_id);
781 } 801 }
782 802
783 803
784 void ApiMessageReader::AddBackRef(intptr_t id, 804 void ApiMessageReader::AddBackRef(intptr_t id,
785 Dart_CObject* obj, 805 Dart_CObject* obj,
786 DeserializeState state) { 806 DeserializeState state) {
787 intptr_t index = (id - kMaxPredefinedObjectIds); 807 intptr_t index = (id - kMaxPredefinedObjectIds);
808 ASSERT(index >= max_vm_isolate_object_id_);
809 index -= max_vm_isolate_object_id_;
788 ASSERT(index == backward_references_.length()); 810 ASSERT(index == backward_references_.length());
789 BackRefNode* node = AllocateBackRefNode(obj, state); 811 BackRefNode* node = AllocateBackRefNode(obj, state);
790 ASSERT(node != NULL); 812 ASSERT(node != NULL);
791 backward_references_.Add(node); 813 backward_references_.Add(node);
792 } 814 }
793 815
794 816
795 Dart_CObject* ApiMessageReader::GetBackRef(intptr_t id) { 817 Dart_CObject* ApiMessageReader::GetBackRef(intptr_t id) {
796 ASSERT(id >= kMaxPredefinedObjectIds); 818 ASSERT(id >= kMaxPredefinedObjectIds);
797 intptr_t index = (id - kMaxPredefinedObjectIds); 819 intptr_t index = (id - kMaxPredefinedObjectIds);
820 ASSERT(index >= max_vm_isolate_object_id_);
821 index -= max_vm_isolate_object_id_;
798 if (index < backward_references_.length()) { 822 if (index < backward_references_.length()) {
799 return backward_references_[index]->reference(); 823 return backward_references_[index]->reference();
800 } 824 }
801 return NULL; 825 return NULL;
802 } 826 }
803 827
804 828
805 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { 829 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) {
806 // Write out the serialization header value for this object. 830 // Write out the serialization header value for this object.
807 WriteInlinedObjectHeader(kMaxPredefinedObjectIds); 831 WriteInlinedObjectHeader(kMaxPredefinedObjectIds);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 if (Smi::IsValid(value)) { 949 if (Smi::IsValid(value)) {
926 WriteSmi(value); 950 WriteSmi(value);
927 } else { 951 } else {
928 WriteMint(object, value); 952 WriteMint(object, value);
929 } 953 }
930 } 954 }
931 955
932 956
933 void ApiMessageWriter::WriteInlinedHeader(Dart_CObject* object) { 957 void ApiMessageWriter::WriteInlinedHeader(Dart_CObject* object) {
934 // Write out the serialization header value for this object. 958 // Write out the serialization header value for this object.
935 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id_); 959 WriteInlinedObjectHeader(SnapshotWriter::FirstObjectId() + object_id_);
936 // Mark object with its object id. 960 // Mark object with its object id.
937 MarkCObject(object, object_id_); 961 MarkCObject(object, object_id_);
938 // Advance object id. 962 // Advance object id.
939 object_id_++; 963 object_id_++;
940 } 964 }
941 965
942 966
943 bool ApiMessageWriter::WriteCObject(Dart_CObject* object) { 967 bool ApiMessageWriter::WriteCObject(Dart_CObject* object) {
944 if (IsCObjectMarked(object)) { 968 if (IsCObjectMarked(object)) {
945 intptr_t object_id = GetMarkedCObjectMark(object); 969 intptr_t object_id = GetMarkedCObjectMark(object);
946 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); 970 WriteIndexedObject(SnapshotWriter::FirstObjectId() + object_id);
947 return true; 971 return true;
948 } 972 }
949 973
950 Dart_CObject_Type type = object->type; 974 Dart_CObject_Type type = object->type;
951 if (type == Dart_CObject_kArray) { 975 if (type == Dart_CObject_kArray) {
952 const intptr_t array_length = object->value.as_array.length; 976 const intptr_t array_length = object->value.as_array.length;
953 if (array_length < 0 || 977 if (array_length < 0 ||
954 array_length > Array::kMaxElements) { 978 array_length > Array::kMaxElements) {
955 return false; 979 return false;
956 } 980 }
(...skipping 14 matching lines...) Expand all
971 } 995 }
972 return true; 996 return true;
973 } 997 }
974 return WriteCObjectInlined(object, type); 998 return WriteCObjectInlined(object, type);
975 } 999 }
976 1000
977 1001
978 bool ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) { 1002 bool ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) {
979 if (IsCObjectMarked(object)) { 1003 if (IsCObjectMarked(object)) {
980 intptr_t object_id = GetMarkedCObjectMark(object); 1004 intptr_t object_id = GetMarkedCObjectMark(object);
981 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); 1005 WriteIndexedObject(SnapshotWriter::FirstObjectId() + object_id);
982 return true; 1006 return true;
983 } 1007 }
984 1008
985 Dart_CObject_Type type = object->type; 1009 Dart_CObject_Type type = object->type;
986 if (type == Dart_CObject_kArray) { 1010 if (type == Dart_CObject_kArray) {
987 const intptr_t array_length = object->value.as_array.length; 1011 const intptr_t array_length = object->value.as_array.length;
988 if (array_length < 0 || 1012 if (array_length < 0 ||
989 array_length > Array::kMaxElements) { 1013 array_length > Array::kMaxElements) {
990 return false; 1014 return false;
991 } 1015 }
(...skipping 17 matching lines...) Expand all
1009 static_cast<Dart_CObject_Type>(object->type & kDartCObjectTypeMask); 1033 static_cast<Dart_CObject_Type>(object->type & kDartCObjectTypeMask);
1010 ASSERT(type == Dart_CObject_kArray); 1034 ASSERT(type == Dart_CObject_kArray);
1011 const intptr_t array_length = object->value.as_array.length; 1035 const intptr_t array_length = object->value.as_array.length;
1012 if (array_length < 0 || 1036 if (array_length < 0 ||
1013 array_length > Array::kMaxElements) { 1037 array_length > Array::kMaxElements) {
1014 return false; 1038 return false;
1015 } 1039 }
1016 1040
1017 // Write out the serialization header value for this object. 1041 // Write out the serialization header value for this object.
1018 intptr_t object_id = GetMarkedCObjectMark(object); 1042 intptr_t object_id = GetMarkedCObjectMark(object);
1019 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id); 1043 WriteInlinedObjectHeader(SnapshotWriter::FirstObjectId() + object_id);
1020 // Write out the class and tags information. 1044 // Write out the class and tags information.
1021 WriteIndexedObject(kArrayCid); 1045 WriteIndexedObject(kArrayCid);
1022 WriteTags(0); 1046 WriteTags(0);
1023 // Write out the length information. 1047 // Write out the length information.
1024 WriteSmi(array_length); 1048 WriteSmi(array_length);
1025 // Write out the type arguments. 1049 // Write out the type arguments.
1026 WriteNullObject(); 1050 WriteNullObject();
1027 // Write out array elements. 1051 // Write out array elements.
1028 for (int i = 0; i < array_length; i++) { 1052 for (int i = 0; i < array_length; i++) {
1029 bool success = WriteCObjectRef(object->value.as_array.values[i]); 1053 bool success = WriteCObjectRef(object->value.as_array.values[i]);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 if (!success) { 1247 if (!success) {
1224 UnmarkAllCObjects(object); 1248 UnmarkAllCObjects(object);
1225 return false; 1249 return false;
1226 } 1250 }
1227 } 1251 }
1228 UnmarkAllCObjects(object); 1252 UnmarkAllCObjects(object);
1229 return true; 1253 return true;
1230 } 1254 }
1231 1255
1232 } // namespace dart 1256 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698