| 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/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/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 | 158 |
| 159 intptr_t BaseReader::ReadSmiValue() { | 159 intptr_t BaseReader::ReadSmiValue() { |
| 160 return Smi::Value(ReadAsSmi()); | 160 return Smi::Value(ReadAsSmi()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 | 163 |
| 164 SnapshotReader::SnapshotReader(const uint8_t* buffer, | 164 SnapshotReader::SnapshotReader(const uint8_t* buffer, |
| 165 intptr_t size, | 165 intptr_t size, |
| 166 Snapshot::Kind kind, | 166 Snapshot::Kind kind, |
| 167 Isolate* isolate) | 167 Isolate* isolate, |
| 168 Zone* zone) |
| 168 : BaseReader(buffer, size), | 169 : BaseReader(buffer, size), |
| 169 kind_(kind), | 170 kind_(kind), |
| 170 isolate_(isolate), | 171 isolate_(isolate), |
| 172 zone_(zone), |
| 171 heap_(isolate->heap()), | 173 heap_(isolate->heap()), |
| 172 old_space_(isolate->heap()->old_space()), | 174 old_space_(isolate->heap()->old_space()), |
| 173 cls_(Class::Handle(isolate)), | 175 cls_(Class::Handle(isolate)), |
| 174 obj_(Object::Handle(isolate)), | 176 obj_(Object::Handle(isolate)), |
| 175 pobj_(PassiveObject::Handle(isolate)), | 177 pobj_(PassiveObject::Handle(isolate)), |
| 176 array_(Array::Handle(isolate)), | 178 array_(Array::Handle(isolate)), |
| 177 field_(Field::Handle(isolate)), | 179 field_(Field::Handle(isolate)), |
| 178 str_(String::Handle(isolate)), | 180 str_(String::Handle(isolate)), |
| 179 library_(Library::Handle(isolate)), | 181 library_(Library::Handle(isolate)), |
| 180 type_(AbstractType::Handle(isolate)), | 182 type_(AbstractType::Handle(isolate)), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 214 |
| 213 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { | 215 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { |
| 214 ASSERT(kind_ != Snapshot::kFull); | 216 ASSERT(kind_ != Snapshot::kFull); |
| 215 // Read the class header information and lookup the class. | 217 // Read the class header information and lookup the class. |
| 216 intptr_t class_header = Read<int32_t>(); | 218 intptr_t class_header = Read<int32_t>(); |
| 217 ASSERT((class_header & kSmiTagMask) != kSmiTag); | 219 ASSERT((class_header & kSmiTagMask) != kSmiTag); |
| 218 ASSERT(!IsVMIsolateObject(class_header) || | 220 ASSERT(!IsVMIsolateObject(class_header) || |
| 219 !IsSingletonClassId(GetVMIsolateObjectId(class_header))); | 221 !IsSingletonClassId(GetVMIsolateObjectId(class_header))); |
| 220 ASSERT((SerializedHeaderTag::decode(class_header) != kObjectId) || | 222 ASSERT((SerializedHeaderTag::decode(class_header) != kObjectId) || |
| 221 !IsObjectStoreClassId(SerializedHeaderData::decode(class_header))); | 223 !IsObjectStoreClassId(SerializedHeaderData::decode(class_header))); |
| 222 Class& cls = Class::ZoneHandle(isolate(), Class::null()); | 224 Class& cls = Class::ZoneHandle(zone(), Class::null()); |
| 223 AddBackRef(object_id, &cls, kIsDeserialized); | 225 AddBackRef(object_id, &cls, kIsDeserialized); |
| 224 // Read the library/class information and lookup the class. | 226 // Read the library/class information and lookup the class. |
| 225 str_ ^= ReadObjectImpl(class_header); | 227 str_ ^= ReadObjectImpl(class_header); |
| 226 library_ = Library::LookupLibrary(str_); | 228 library_ = Library::LookupLibrary(str_); |
| 227 if (library_.IsNull() || !library_.Loaded()) { | 229 if (library_.IsNull() || !library_.Loaded()) { |
| 228 SetReadException("Invalid object found in message."); | 230 SetReadException("Invalid object found in message."); |
| 229 } | 231 } |
| 230 str_ ^= ReadObjectImpl(); | 232 str_ ^= ReadObjectImpl(); |
| 231 cls = library_.LookupClass(str_); | 233 cls = library_.LookupClass(str_); |
| 232 if (cls.IsNull()) { | 234 if (cls.IsNull()) { |
| 233 SetReadException("Invalid object found in message."); | 235 SetReadException("Invalid object found in message."); |
| 234 } | 236 } |
| 235 cls.EnsureIsFinalized(isolate()); | 237 cls.EnsureIsFinalized(isolate()); |
| 236 return cls.raw(); | 238 return cls.raw(); |
| 237 } | 239 } |
| 238 | 240 |
| 239 | 241 |
| 240 RawObject* SnapshotReader::ReadStaticImplicitClosure(intptr_t object_id, | 242 RawObject* SnapshotReader::ReadStaticImplicitClosure(intptr_t object_id, |
| 241 intptr_t class_header) { | 243 intptr_t class_header) { |
| 242 ASSERT(kind_ == Snapshot::kMessage); | 244 ASSERT(kind_ == Snapshot::kMessage); |
| 243 | 245 |
| 244 // First create a function object and associate it with the specified | 246 // First create a function object and associate it with the specified |
| 245 // 'object_id'. | 247 // 'object_id'. |
| 246 Function& func = Function::Handle(isolate(), Function::null()); | 248 Function& func = Function::Handle(isolate(), Function::null()); |
| 247 Instance& obj = Instance::ZoneHandle(isolate(), Instance::null()); | 249 Instance& obj = Instance::ZoneHandle(zone(), Instance::null()); |
| 248 AddBackRef(object_id, &obj, kIsDeserialized); | 250 AddBackRef(object_id, &obj, kIsDeserialized); |
| 249 | 251 |
| 250 // Read the library/class/function information and lookup the function. | 252 // Read the library/class/function information and lookup the function. |
| 251 str_ ^= ReadObjectImpl(); | 253 str_ ^= ReadObjectImpl(); |
| 252 library_ = Library::LookupLibrary(str_); | 254 library_ = Library::LookupLibrary(str_); |
| 253 if (library_.IsNull() || !library_.Loaded()) { | 255 if (library_.IsNull() || !library_.Loaded()) { |
| 254 SetReadException("Invalid Library object found in message."); | 256 SetReadException("Invalid Library object found in message."); |
| 255 } | 257 } |
| 256 str_ ^= ReadObjectImpl(); | 258 str_ ^= ReadObjectImpl(); |
| 257 if (str_.Equals(Symbols::TopLevel())) { | 259 if (str_.Equals(Symbols::TopLevel())) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 ASSERT(GetBackRef(object_id) == NULL); | 351 ASSERT(GetBackRef(object_id) == NULL); |
| 350 | 352 |
| 351 // Read the class header information and lookup the class. | 353 // Read the class header information and lookup the class. |
| 352 intptr_t class_header = Read<int32_t>(); | 354 intptr_t class_header = Read<int32_t>(); |
| 353 | 355 |
| 354 // Since we are only reading an object reference, If it is an instance kind | 356 // Since we are only reading an object reference, If it is an instance kind |
| 355 // then we only need to figure out the class of the object and allocate an | 357 // then we only need to figure out the class of the object and allocate an |
| 356 // instance of it. The individual fields will be read later. | 358 // instance of it. The individual fields will be read later. |
| 357 intptr_t header_id = SerializedHeaderData::decode(class_header); | 359 intptr_t header_id = SerializedHeaderData::decode(class_header); |
| 358 if (header_id == kInstanceObjectId) { | 360 if (header_id == kInstanceObjectId) { |
| 359 Instance& result = Instance::ZoneHandle(isolate(), Instance::null()); | 361 Instance& result = Instance::ZoneHandle(zone(), Instance::null()); |
| 360 AddBackRef(object_id, &result, kIsNotDeserialized); | 362 AddBackRef(object_id, &result, kIsNotDeserialized); |
| 361 | 363 |
| 362 cls_ ^= ReadObjectImpl(); // Read class information. | 364 cls_ ^= ReadObjectImpl(); // Read class information. |
| 363 ASSERT(!cls_.IsNull()); | 365 ASSERT(!cls_.IsNull()); |
| 364 intptr_t instance_size = cls_.instance_size(); | 366 intptr_t instance_size = cls_.instance_size(); |
| 365 ASSERT(instance_size > 0); | 367 ASSERT(instance_size > 0); |
| 366 if (kind_ == Snapshot::kFull) { | 368 if (kind_ == Snapshot::kFull) { |
| 367 result ^= AllocateUninitialized(cls_.id(), instance_size); | 369 result ^= AllocateUninitialized(cls_.id(), instance_size); |
| 368 } else { | 370 } else { |
| 369 result ^= Object::Allocate(cls_.id(), instance_size, HEAP_SPACE(kind_)); | 371 result ^= Object::Allocate(cls_.id(), instance_size, HEAP_SPACE(kind_)); |
| 370 } | 372 } |
| 371 return result.raw(); | 373 return result.raw(); |
| 372 } else if (header_id == kStaticImplicitClosureObjectId) { | 374 } else if (header_id == kStaticImplicitClosureObjectId) { |
| 373 // We skip the tags that have been written as the implicit static | 375 // We skip the tags that have been written as the implicit static |
| 374 // closure is going to be created in this isolate or the canonical | 376 // closure is going to be created in this isolate or the canonical |
| 375 // version already created in the isolate will be used. | 377 // version already created in the isolate will be used. |
| 376 ReadTags(); | 378 ReadTags(); |
| 377 return ReadStaticImplicitClosure(object_id, class_header); | 379 return ReadStaticImplicitClosure(object_id, class_header); |
| 378 } | 380 } |
| 379 ASSERT((class_header & kSmiTagMask) != kSmiTag); | 381 ASSERT((class_header & kSmiTagMask) != kSmiTag); |
| 380 | 382 |
| 381 // Similarly Array and ImmutableArray objects are also similarly only | 383 // Similarly Array and ImmutableArray objects are also similarly only |
| 382 // allocated here, the individual array elements are read later. | 384 // allocated here, the individual array elements are read later. |
| 383 intptr_t class_id = LookupInternalClass(class_header); | 385 intptr_t class_id = LookupInternalClass(class_header); |
| 384 if (class_id == kArrayCid) { | 386 if (class_id == kArrayCid) { |
| 385 // Read the length and allocate an object based on the len. | 387 // Read the length and allocate an object based on the len. |
| 386 intptr_t len = ReadSmiValue(); | 388 intptr_t len = ReadSmiValue(); |
| 387 Array& array = Array::ZoneHandle( | 389 Array& array = Array::ZoneHandle( |
| 388 isolate(), | 390 zone(), |
| 389 ((kind_ == Snapshot::kFull) ? | 391 ((kind_ == Snapshot::kFull) ? |
| 390 NewArray(len) : Array::New(len, HEAP_SPACE(kind_)))); | 392 NewArray(len) : Array::New(len, HEAP_SPACE(kind_)))); |
| 391 AddBackRef(object_id, &array, kIsNotDeserialized); | 393 AddBackRef(object_id, &array, kIsNotDeserialized); |
| 392 | 394 |
| 393 return array.raw(); | 395 return array.raw(); |
| 394 } | 396 } |
| 395 if (class_id == kImmutableArrayCid) { | 397 if (class_id == kImmutableArrayCid) { |
| 396 // Read the length and allocate an object based on the len. | 398 // Read the length and allocate an object based on the len. |
| 397 intptr_t len = ReadSmiValue(); | 399 intptr_t len = ReadSmiValue(); |
| 398 Array& array = Array::ZoneHandle( | 400 Array& array = Array::ZoneHandle( |
| 399 isolate(), | 401 zone(), |
| 400 (kind_ == Snapshot::kFull) ? | 402 (kind_ == Snapshot::kFull) ? |
| 401 NewImmutableArray(len) : ImmutableArray::New(len, HEAP_SPACE(kind_))); | 403 NewImmutableArray(len) : ImmutableArray::New(len, HEAP_SPACE(kind_))); |
| 402 AddBackRef(object_id, &array, kIsNotDeserialized); | 404 AddBackRef(object_id, &array, kIsNotDeserialized); |
| 403 | 405 |
| 404 return array.raw(); | 406 return array.raw(); |
| 405 } | 407 } |
| 406 | 408 |
| 407 // For all other internal VM classes we read the object inline. | 409 // For all other internal VM classes we read the object inline. |
| 408 intptr_t tags = ReadTags(); | 410 intptr_t tags = ReadTags(); |
| 409 switch (class_id) { | 411 switch (class_id) { |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { | 987 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { |
| 986 // Read the class header information and lookup the class. | 988 // Read the class header information and lookup the class. |
| 987 intptr_t class_header = Read<int32_t>(); | 989 intptr_t class_header = Read<int32_t>(); |
| 988 intptr_t tags = ReadTags(); | 990 intptr_t tags = ReadTags(); |
| 989 intptr_t header_id = SerializedHeaderData::decode(class_header); | 991 intptr_t header_id = SerializedHeaderData::decode(class_header); |
| 990 if (header_id == kInstanceObjectId) { | 992 if (header_id == kInstanceObjectId) { |
| 991 // Object is regular dart instance. | 993 // Object is regular dart instance. |
| 992 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); | 994 Instance* result = reinterpret_cast<Instance*>(GetBackRef(object_id)); |
| 993 intptr_t instance_size = 0; | 995 intptr_t instance_size = 0; |
| 994 if (result == NULL) { | 996 if (result == NULL) { |
| 995 result = &(Instance::ZoneHandle(isolate(), Instance::null())); | 997 result = &(Instance::ZoneHandle(zone(), Instance::null())); |
| 996 AddBackRef(object_id, result, kIsDeserialized); | 998 AddBackRef(object_id, result, kIsDeserialized); |
| 997 cls_ ^= ReadObjectImpl(); | 999 cls_ ^= ReadObjectImpl(); |
| 998 ASSERT(!cls_.IsNull()); | 1000 ASSERT(!cls_.IsNull()); |
| 999 instance_size = cls_.instance_size(); | 1001 instance_size = cls_.instance_size(); |
| 1000 ASSERT(instance_size > 0); | 1002 ASSERT(instance_size > 0); |
| 1001 // Allocate the instance and read in all the fields for the object. | 1003 // Allocate the instance and read in all the fields for the object. |
| 1002 if (kind_ == Snapshot::kFull) { | 1004 if (kind_ == Snapshot::kFull) { |
| 1003 *result ^= AllocateUninitialized(cls_.id(), instance_size); | 1005 *result ^= AllocateUninitialized(cls_.id(), instance_size); |
| 1004 } else { | 1006 } else { |
| 1005 *result ^= Object::Allocate(cls_.id(), | 1007 *result ^= Object::Allocate(cls_.id(), |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1950 NoGCScope no_gc; | 1952 NoGCScope no_gc; |
| 1951 WriteObject(obj.raw()); | 1953 WriteObject(obj.raw()); |
| 1952 UnmarkAll(); | 1954 UnmarkAll(); |
| 1953 } else { | 1955 } else { |
| 1954 ThrowException(exception_type(), exception_msg()); | 1956 ThrowException(exception_type(), exception_msg()); |
| 1955 } | 1957 } |
| 1956 } | 1958 } |
| 1957 | 1959 |
| 1958 | 1960 |
| 1959 } // namespace dart | 1961 } // namespace dart |
| OLD | NEW |