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

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

Issue 12544015: Implement 'dart:typeddata' directly in the VM instead of using 'dart:scalarlist' (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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/raw_object_snapshot.cc ('k') | tests/standalone/typed_array_test.dart » ('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/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 15 matching lines...) Expand all
26 // Check if this is a singleton object class which is shared by all isolates. 26 // Check if this is a singleton object class which is shared by all isolates.
27 return ((class_id >= kClassCid && class_id <= kUnwindErrorCid) || 27 return ((class_id >= kClassCid && class_id <= kUnwindErrorCid) ||
28 (class_id >= kNullCid && class_id <= kVoidCid)); 28 (class_id >= kNullCid && class_id <= kVoidCid));
29 } 29 }
30 30
31 31
32 static bool IsObjectStoreClassId(intptr_t class_id) { 32 static bool IsObjectStoreClassId(intptr_t class_id) {
33 // Check if this is a class which is stored in the object store. 33 // Check if this is a class which is stored in the object store.
34 return (class_id == kObjectCid || 34 return (class_id == kObjectCid ||
35 (class_id >= kInstanceCid && class_id <= kWeakPropertyCid) || 35 (class_id >= kInstanceCid && class_id <= kWeakPropertyCid) ||
36 RawObject::IsStringClassId(class_id)); 36 RawObject::IsStringClassId(class_id) ||
37 RawObject::IsTypedDataClassId(class_id) ||
38 RawObject::IsExternalTypedDataClassId(class_id));
37 } 39 }
38 40
39 41
40 static bool IsObjectStoreTypeId(intptr_t index) { 42 static bool IsObjectStoreTypeId(intptr_t index) {
41 // Check if this is a type which is stored in the object store. 43 // Check if this is a type which is stored in the object store.
42 return (index >= kObjectType && index <= kArrayType); 44 return (index >= kObjectType && index <= kArrayType);
43 } 45 }
44 46
45 47
46 static intptr_t ClassIdFromObjectId(intptr_t object_id) { 48 static intptr_t ClassIdFromObjectId(intptr_t object_id) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // For all other internal VM classes we read the object inline. 307 // For all other internal VM classes we read the object inline.
306 intptr_t tags = ReadIntptrValue(); 308 intptr_t tags = ReadIntptrValue();
307 switch (class_id) { 309 switch (class_id) {
308 #define SNAPSHOT_READ(clazz) \ 310 #define SNAPSHOT_READ(clazz) \
309 case clazz::kClassId: { \ 311 case clazz::kClassId: { \
310 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ 312 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \
311 break; \ 313 break; \
312 } 314 }
313 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) 315 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ)
314 #undef SNAPSHOT_READ 316 #undef SNAPSHOT_READ
317 #define SNAPSHOT_READ(clazz) \
318 case kTypedData##clazz##Cid: { \
319 obj_ = TypedData::ReadFrom(this, object_id, tags, kind_); \
320 break; \
321 }
322 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ)
323 #undef SNAPSHOT_READ
315 default: UNREACHABLE(); break; 324 default: UNREACHABLE(); break;
316 } 325 }
317 if (kind_ == Snapshot::kFull) { 326 if (kind_ == Snapshot::kFull) {
318 obj_.SetCreatedFromSnapshot(); 327 obj_.SetCreatedFromSnapshot();
319 } 328 }
320 return obj_.raw(); 329 return obj_.raw();
321 } 330 }
322 331
323 332
324 void SnapshotReader::AddBackRef(intptr_t id, 333 void SnapshotReader::AddBackRef(intptr_t id,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 obj->ptr()->num_variables_ = num_variables; 450 obj->ptr()->num_variables_ = num_variables;
442 return obj; 451 return obj;
443 } 452 }
444 453
445 454
446 RawClass* SnapshotReader::NewClass(intptr_t class_id) { 455 RawClass* SnapshotReader::NewClass(intptr_t class_id) {
447 ASSERT(kind_ == Snapshot::kFull); 456 ASSERT(kind_ == Snapshot::kFull);
448 ASSERT(isolate()->no_gc_scope_depth() != 0); 457 ASSERT(isolate()->no_gc_scope_depth() != 0);
449 if (class_id < kNumPredefinedCids) { 458 if (class_id < kNumPredefinedCids) {
450 ASSERT((class_id >= kInstanceCid) && 459 ASSERT((class_id >= kInstanceCid) &&
451 (class_id <= kExternalTwoByteStringCid)); 460 (class_id <= kExternalTypedDataFloat64ArrayCid));
452 return isolate()->class_table()->At(class_id); 461 return isolate()->class_table()->At(class_id);
453 } 462 }
454 cls_ = Object::class_class(); 463 cls_ = Object::class_class();
455 RawClass* obj = reinterpret_cast<RawClass*>( 464 RawClass* obj = reinterpret_cast<RawClass*>(
456 AllocateUninitialized(cls_, Class::InstanceSize())); 465 AllocateUninitialized(cls_, Class::InstanceSize()));
457 Instance fake; 466 Instance fake;
458 obj->ptr()->handle_vtable_ = fake.vtable(); 467 obj->ptr()->handle_vtable_ = fake.vtable();
459 cls_ = obj; 468 cls_ = obj;
460 cls_.set_id(kIllegalCid); 469 cls_.set_id(kIllegalCid);
461 isolate()->class_table()->Register(cls_); 470 isolate()->class_table()->Register(cls_);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 cls_ = LookupInternalClass(class_header); 786 cls_ = LookupInternalClass(class_header);
778 ASSERT(!cls_.IsNull()); 787 ASSERT(!cls_.IsNull());
779 switch (cls_.id()) { 788 switch (cls_.id()) {
780 #define SNAPSHOT_READ(clazz) \ 789 #define SNAPSHOT_READ(clazz) \
781 case clazz::kClassId: { \ 790 case clazz::kClassId: { \
782 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ 791 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \
783 break; \ 792 break; \
784 } 793 }
785 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) 794 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ)
786 #undef SNAPSHOT_READ 795 #undef SNAPSHOT_READ
796 #define SNAPSHOT_READ(clazz) \
797 case kTypedData##clazz##Cid: { \
798 obj_ = TypedData::ReadFrom(this, object_id, tags, kind_); \
799 break; \
800 }
801 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ)
802 #undef SNAPSHOT_READ
787 default: UNREACHABLE(); break; 803 default: UNREACHABLE(); break;
788 } 804 }
789 if (kind_ == Snapshot::kFull) { 805 if (kind_ == Snapshot::kFull) {
790 obj_.SetCreatedFromSnapshot(); 806 obj_.SetCreatedFromSnapshot();
791 } 807 }
792 return obj_.raw(); 808 return obj_.raw();
793 } 809 }
794 810
795 811
796 void SnapshotReader::ArrayReadFrom(const Array& result, 812 void SnapshotReader::ArrayReadFrom(const Array& result,
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 switch (class_id) { 986 switch (class_id) {
971 #define SNAPSHOT_WRITE(clazz) \ 987 #define SNAPSHOT_WRITE(clazz) \
972 case clazz::kClassId: { \ 988 case clazz::kClassId: { \
973 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \ 989 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \
974 raw_obj->WriteTo(this, object_id, kind_); \ 990 raw_obj->WriteTo(this, object_id, kind_); \
975 return; \ 991 return; \
976 } \ 992 } \
977 993
978 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE) 994 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE)
979 #undef SNAPSHOT_WRITE 995 #undef SNAPSHOT_WRITE
996 #define SNAPSHOT_WRITE(clazz) \
997 case kTypedData##clazz##Cid: { \
998 RawTypedData* raw_obj = reinterpret_cast<RawTypedData*>(raw); \
999 raw_obj->WriteTo(this, object_id, kind_); \
1000 return; \
1001 } \
1002 case kExternalTypedData##clazz##Cid: { \
1003 RawExternalTypedData* raw_obj = \
1004 reinterpret_cast<RawExternalTypedData*>(raw); \
1005 raw_obj->WriteTo(this, object_id, kind_); \
1006 return; \
1007 } \
1008
1009 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE)
1010 #undef SNAPSHOT_WRITE
980 default: break; 1011 default: break;
981 } 1012 }
982 UNREACHABLE(); 1013 UNREACHABLE();
983 } 1014 }
984 1015
985 1016
986 void FullSnapshotWriter::WriteFullSnapshot() { 1017 void FullSnapshotWriter::WriteFullSnapshot() {
987 Isolate* isolate = Isolate::Current(); 1018 Isolate* isolate = Isolate::Current();
988 ASSERT(isolate != NULL); 1019 ASSERT(isolate != NULL);
989 ObjectStore* object_store = isolate->object_store(); 1020 ObjectStore* object_store = isolate->object_store();
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 switch (class_id) { 1231 switch (class_id) {
1201 #define SNAPSHOT_WRITE(clazz) \ 1232 #define SNAPSHOT_WRITE(clazz) \
1202 case clazz::kClassId: { \ 1233 case clazz::kClassId: { \
1203 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \ 1234 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \
1204 raw_obj->WriteTo(this, object_id, kind_); \ 1235 raw_obj->WriteTo(this, object_id, kind_); \
1205 return; \ 1236 return; \
1206 } \ 1237 } \
1207 1238
1208 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE) 1239 CLASS_LIST_NO_OBJECT(SNAPSHOT_WRITE)
1209 #undef SNAPSHOT_WRITE 1240 #undef SNAPSHOT_WRITE
1241 #define SNAPSHOT_WRITE(clazz) \
1242 case kTypedData##clazz##Cid: { \
1243 RawTypedData* raw_obj = reinterpret_cast<RawTypedData*>(raw); \
1244 raw_obj->WriteTo(this, object_id, kind_); \
1245 return; \
1246 } \
1247 case kExternalTypedData##clazz##Cid: { \
1248 RawExternalTypedData* raw_obj = \
1249 reinterpret_cast<RawExternalTypedData*>(raw); \
1250 raw_obj->WriteTo(this, object_id, kind_); \
1251 return; \
1252 } \
1253
1254 CLASS_LIST_TYPED_DATA(SNAPSHOT_WRITE)
1255 #undef SNAPSHOT_WRITE
1210 default: break; 1256 default: break;
1211 } 1257 }
1212 UNREACHABLE(); 1258 UNREACHABLE();
1213 } 1259 }
1214 1260
1215 1261
1216 void SnapshotWriter::WriteForwardedObjects() { 1262 void SnapshotWriter::WriteForwardedObjects() {
1217 // Write out all objects that were added to the forward list and have 1263 // Write out all objects that were added to the forward list and have
1218 // not been serialized yet. These would typically be fields of instance 1264 // not been serialized yet. These would typically be fields of instance
1219 // objects, arrays or immutable arrays (this is done in order to avoid 1265 // objects, arrays or immutable arrays (this is done in order to avoid
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 UnmarkAll(); 1401 UnmarkAll();
1356 isolate->set_long_jump_base(base); 1402 isolate->set_long_jump_base(base);
1357 } else { 1403 } else {
1358 isolate->set_long_jump_base(base); 1404 isolate->set_long_jump_base(base);
1359 ThrowException(exception_type(), exception_msg()); 1405 ThrowException(exception_type(), exception_msg());
1360 } 1406 }
1361 } 1407 }
1362 1408
1363 1409
1364 } // namespace dart 1410 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object_snapshot.cc ('k') | tests/standalone/typed_array_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698