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

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

Issue 672183002: Simplify SnapshotReader::LookupInternalClass. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 1 month 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/snapshot.h ('k') | no next file » | 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/bootstrap.h" 8 #include "vm/bootstrap.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 intptr_t instance_size = cls_.instance_size(); 297 intptr_t instance_size = cls_.instance_size();
298 ASSERT(instance_size > 0); 298 ASSERT(instance_size > 0);
299 if (kind_ == Snapshot::kFull) { 299 if (kind_ == Snapshot::kFull) {
300 result ^= AllocateUninitialized(cls_.id(), instance_size); 300 result ^= AllocateUninitialized(cls_.id(), instance_size);
301 } else { 301 } else {
302 result ^= Object::Allocate(cls_.id(), instance_size, HEAP_SPACE(kind_)); 302 result ^= Object::Allocate(cls_.id(), instance_size, HEAP_SPACE(kind_));
303 } 303 }
304 return result.raw(); 304 return result.raw();
305 } 305 }
306 ASSERT((class_header & kSmiTagMask) != kSmiTag); 306 ASSERT((class_header & kSmiTagMask) != kSmiTag);
307 cls_ = LookupInternalClass(class_header);
308 ASSERT(!cls_.IsNull());
309 307
310 // Similarly Array and ImmutableArray objects are also similarly only 308 // Similarly Array and ImmutableArray objects are also similarly only
311 // allocated here, the individual array elements are read later. 309 // allocated here, the individual array elements are read later.
312 intptr_t class_id = cls_.id(); 310 intptr_t class_id = LookupInternalClass(class_header);
313 if (class_id == kArrayCid) { 311 if (class_id == kArrayCid) {
314 // Read the length and allocate an object based on the len. 312 // Read the length and allocate an object based on the len.
315 intptr_t len = ReadSmiValue(); 313 intptr_t len = ReadSmiValue();
316 Array& array = Array::ZoneHandle( 314 Array& array = Array::ZoneHandle(
317 isolate(), 315 isolate(),
318 ((kind_ == Snapshot::kFull) ? 316 ((kind_ == Snapshot::kFull) ?
319 NewArray(len) : Array::New(len, HEAP_SPACE(kind_)))); 317 NewArray(len) : Array::New(len, HEAP_SPACE(kind_))));
320 AddBackRef(object_id, &array, kIsNotDeserialized); 318 AddBackRef(object_id, &array, kIsNotDeserialized);
321 319
322 return array.raw(); 320 return array.raw();
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 } 797 }
800 return Mint::NewCanonical(value); 798 return Mint::NewCanonical(value);
801 } 799 }
802 800
803 801
804 RawStacktrace* SnapshotReader::NewStacktrace() { 802 RawStacktrace* SnapshotReader::NewStacktrace() {
805 ALLOC_NEW_OBJECT(Stacktrace); 803 ALLOC_NEW_OBJECT(Stacktrace);
806 } 804 }
807 805
808 806
809 RawClass* SnapshotReader::LookupInternalClass(intptr_t class_header) { 807 intptr_t SnapshotReader::LookupInternalClass(intptr_t class_header) {
810 // If the header is an object Id, lookup singleton VM classes or classes 808 // If the header is an object Id, lookup singleton VM classes or classes
811 // stored in the object store. 809 // stored in the object store.
812 if (IsVMIsolateObject(class_header)) { 810 if (IsVMIsolateObject(class_header)) {
813 intptr_t class_id = GetVMIsolateObjectId(class_header); 811 intptr_t class_id = GetVMIsolateObjectId(class_header);
814 if (IsSingletonClassId(class_id)) { 812 ASSERT(IsSingletonClassId(class_id));
815 return isolate()->class_table()->At(class_id); // get singleton class. 813 return class_id;
816 }
817 } else if (SerializedHeaderTag::decode(class_header) == kObjectId) {
818 intptr_t class_id = SerializedHeaderData::decode(class_header);
819 if (IsObjectStoreClassId(class_id)) {
820 return isolate()->class_table()->At(class_id); // get singleton class.
821 }
822 } 814 }
823 return Class::null(); 815 ASSERT(SerializedHeaderTag::decode(class_header) == kObjectId);
816 intptr_t class_id = SerializedHeaderData::decode(class_header);
817 ASSERT(IsObjectStoreClassId(class_id));
818 return class_id;
824 } 819 }
825 820
826 821
827 RawObject* SnapshotReader::AllocateUninitialized(intptr_t class_id, 822 RawObject* SnapshotReader::AllocateUninitialized(intptr_t class_id,
828 intptr_t size) { 823 intptr_t size) {
829 ASSERT(isolate()->no_gc_scope_depth() != 0); 824 ASSERT(isolate()->no_gc_scope_depth() != 0);
830 ASSERT(Utils::IsAligned(size, kObjectAlignment)); 825 ASSERT(Utils::IsAligned(size, kObjectAlignment));
831 826
832 uword address = 827 uword address =
833 old_space()->TryAllocateDataBumpLocked(size, PageSpace::kForceGrowth); 828 old_space()->TryAllocateDataBumpLocked(size, PageSpace::kForceGrowth);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 offset += kWordSize; 979 offset += kWordSize;
985 } 980 }
986 result->SetCreatedFromSnapshot(); 981 result->SetCreatedFromSnapshot();
987 } else if (result->IsCanonical()) { 982 } else if (result->IsCanonical()) {
988 *result = result->CheckAndCanonicalize(NULL); 983 *result = result->CheckAndCanonicalize(NULL);
989 ASSERT(!result->IsNull()); 984 ASSERT(!result->IsNull());
990 } 985 }
991 return result->raw(); 986 return result->raw();
992 } 987 }
993 ASSERT((class_header & kSmiTagMask) != kSmiTag); 988 ASSERT((class_header & kSmiTagMask) != kSmiTag);
994 cls_ = LookupInternalClass(class_header); 989 intptr_t class_id = LookupInternalClass(class_header);
995 ASSERT(!cls_.IsNull()); 990 switch (class_id) {
996 switch (cls_.id()) {
997 #define SNAPSHOT_READ(clazz) \ 991 #define SNAPSHOT_READ(clazz) \
998 case clazz::kClassId: { \ 992 case clazz::kClassId: { \
999 pobj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ 993 pobj_ = clazz::ReadFrom(this, object_id, tags, kind_); \
1000 break; \ 994 break; \
1001 } 995 }
1002 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) 996 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ)
1003 #undef SNAPSHOT_READ 997 #undef SNAPSHOT_READ
1004 #define SNAPSHOT_READ(clazz) \ 998 #define SNAPSHOT_READ(clazz) \
1005 case kTypedData##clazz##Cid: \ 999 case kTypedData##clazz##Cid: \
1006 1000
1007 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) { 1001 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) {
1008 tags = RawObject::ClassIdTag::update(cls_.id(), tags); 1002 tags = RawObject::ClassIdTag::update(class_id, tags);
1009 pobj_ = TypedData::ReadFrom(this, object_id, tags, kind_); 1003 pobj_ = TypedData::ReadFrom(this, object_id, tags, kind_);
1010 break; 1004 break;
1011 } 1005 }
1012 #undef SNAPSHOT_READ 1006 #undef SNAPSHOT_READ
1013 #define SNAPSHOT_READ(clazz) \ 1007 #define SNAPSHOT_READ(clazz) \
1014 case kExternalTypedData##clazz##Cid: \ 1008 case kExternalTypedData##clazz##Cid: \
1015 1009
1016 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) { 1010 CLASS_LIST_TYPED_DATA(SNAPSHOT_READ) {
1017 tags = RawObject::ClassIdTag::update(cls_.id(), tags); 1011 tags = RawObject::ClassIdTag::update(class_id, tags);
1018 pobj_ = ExternalTypedData::ReadFrom(this, object_id, tags, kind_); 1012 pobj_ = ExternalTypedData::ReadFrom(this, object_id, tags, kind_);
1019 break; 1013 break;
1020 } 1014 }
1021 #undef SNAPSHOT_READ 1015 #undef SNAPSHOT_READ
1022 default: UNREACHABLE(); break; 1016 default: UNREACHABLE(); break;
1023 } 1017 }
1024 if (kind_ == Snapshot::kFull) { 1018 if (kind_ == Snapshot::kFull) {
1025 pobj_.SetCreatedFromSnapshot(); 1019 pobj_.SetCreatedFromSnapshot();
1026 } 1020 }
1027 return pobj_.raw(); 1021 return pobj_.raw();
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 NoGCScope no_gc; 1759 NoGCScope no_gc;
1766 WriteObject(obj.raw()); 1760 WriteObject(obj.raw());
1767 UnmarkAll(); 1761 UnmarkAll();
1768 } else { 1762 } else {
1769 ThrowException(exception_type(), exception_msg()); 1763 ThrowException(exception_type(), exception_msg());
1770 } 1764 }
1771 } 1765 }
1772 1766
1773 1767
1774 } // namespace dart 1768 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698