| 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/exceptions.h" | 11 #include "vm/exceptions.h" |
| 11 #include "vm/heap.h" | 12 #include "vm/heap.h" |
| 12 #include "vm/lockers.h" | 13 #include "vm/lockers.h" |
| 13 #include "vm/longjump.h" | 14 #include "vm/longjump.h" |
| 14 #include "vm/object.h" | 15 #include "vm/object.h" |
| 15 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
| 16 #include "vm/snapshot_ids.h" | 17 #include "vm/snapshot_ids.h" |
| 17 #include "vm/symbols.h" | 18 #include "vm/symbols.h" |
| 18 #include "vm/verified_memory.h" | 19 #include "vm/verified_memory.h" |
| 19 #include "vm/version.h" | 20 #include "vm/version.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 ASSERT((class_header & kSmiTagMask) != kSmiTag); | 217 ASSERT((class_header & kSmiTagMask) != kSmiTag); |
| 217 ASSERT(!IsVMIsolateObject(class_header) || | 218 ASSERT(!IsVMIsolateObject(class_header) || |
| 218 !IsSingletonClassId(GetVMIsolateObjectId(class_header))); | 219 !IsSingletonClassId(GetVMIsolateObjectId(class_header))); |
| 219 ASSERT((SerializedHeaderTag::decode(class_header) != kObjectId) || | 220 ASSERT((SerializedHeaderTag::decode(class_header) != kObjectId) || |
| 220 !IsObjectStoreClassId(SerializedHeaderData::decode(class_header))); | 221 !IsObjectStoreClassId(SerializedHeaderData::decode(class_header))); |
| 221 Class& cls = Class::ZoneHandle(isolate(), Class::null()); | 222 Class& cls = Class::ZoneHandle(isolate(), Class::null()); |
| 222 AddBackRef(object_id, &cls, kIsDeserialized); | 223 AddBackRef(object_id, &cls, kIsDeserialized); |
| 223 // Read the library/class information and lookup the class. | 224 // Read the library/class information and lookup the class. |
| 224 str_ ^= ReadObjectImpl(class_header); | 225 str_ ^= ReadObjectImpl(class_header); |
| 225 library_ = Library::LookupLibrary(str_); | 226 library_ = Library::LookupLibrary(str_); |
| 226 ASSERT(!library_.IsNull()); | 227 if (library_.IsNull() || !library_.Loaded()) { |
| 228 SetReadException("Invalid object found in message."); |
| 229 } |
| 227 str_ ^= ReadObjectImpl(); | 230 str_ ^= ReadObjectImpl(); |
| 228 cls = library_.LookupClass(str_); | 231 cls = library_.LookupClass(str_); |
| 232 if (cls.IsNull()) { |
| 233 SetReadException("Invalid object found in message."); |
| 234 } |
| 229 cls.EnsureIsFinalized(isolate()); | 235 cls.EnsureIsFinalized(isolate()); |
| 230 ASSERT(!cls.IsNull()); | |
| 231 return cls.raw(); | 236 return cls.raw(); |
| 232 } | 237 } |
| 233 | 238 |
| 234 | 239 |
| 235 RawObject* SnapshotReader::ReadObjectImpl() { | 240 RawObject* SnapshotReader::ReadObjectImpl() { |
| 236 int64_t value = Read<int64_t>(); | 241 int64_t value = Read<int64_t>(); |
| 237 if ((value & kSmiTagMask) == kSmiTag) { | 242 if ((value & kSmiTagMask) == kSmiTag) { |
| 238 return NewInteger(value); | 243 return NewInteger(value); |
| 239 } | 244 } |
| 240 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 245 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
| 241 return ReadObjectImpl(static_cast<intptr_t>(value)); | 246 return ReadObjectImpl(static_cast<intptr_t>(value)); |
| 242 } | 247 } |
| 243 | 248 |
| 244 | 249 |
| 245 intptr_t SnapshotReader::NextAvailableObjectId() const { | 250 intptr_t SnapshotReader::NextAvailableObjectId() const { |
| 246 return backward_references_.length() + kMaxPredefinedObjectIds; | 251 return backward_references_.length() + kMaxPredefinedObjectIds; |
| 247 } | 252 } |
| 248 | 253 |
| 249 | 254 |
| 255 void SnapshotReader::SetReadException(const char* msg) { |
| 256 Isolate* isolate = Isolate::Current(); |
| 257 const String& error_str = String::Handle(isolate, String::New(msg)); |
| 258 const Array& args = Array::Handle(isolate, Array::New(1)); |
| 259 args.SetAt(0, error_str); |
| 260 Object& result = Object::Handle(isolate); |
| 261 const Library& library = Library::Handle(isolate, Library::CoreLibrary()); |
| 262 result = DartLibraryCalls::InstanceCreate(library, |
| 263 Symbols::ArgumentError(), |
| 264 Symbols::Dot(), |
| 265 args); |
| 266 const Stacktrace& stacktrace = Stacktrace::Handle(isolate); |
| 267 const UnhandledException& error = UnhandledException::Handle( |
| 268 isolate, UnhandledException::New(Instance::Cast(result), stacktrace)); |
| 269 isolate->long_jump_base()->Jump(1, error); |
| 270 } |
| 271 |
| 272 |
| 250 RawObject* SnapshotReader::ReadObjectImpl(intptr_t header_value) { | 273 RawObject* SnapshotReader::ReadObjectImpl(intptr_t header_value) { |
| 251 if (IsVMIsolateObject(header_value)) { | 274 if (IsVMIsolateObject(header_value)) { |
| 252 return ReadVMIsolateObject(header_value); | 275 return ReadVMIsolateObject(header_value); |
| 253 } else { | 276 } else { |
| 254 if (SerializedHeaderTag::decode(header_value) == kObjectId) { | 277 if (SerializedHeaderTag::decode(header_value) == kObjectId) { |
| 255 return ReadIndexedObject(SerializedHeaderData::decode(header_value)); | 278 return ReadIndexedObject(SerializedHeaderData::decode(header_value)); |
| 256 } | 279 } |
| 257 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined); | 280 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined); |
| 258 intptr_t object_id = SerializedHeaderData::decode(header_value); | 281 intptr_t object_id = SerializedHeaderData::decode(header_value); |
| 259 if (object_id == kOmittedObjectId) { | 282 if (object_id == kOmittedObjectId) { |
| (...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1794 NoGCScope no_gc; | 1817 NoGCScope no_gc; |
| 1795 WriteObject(obj.raw()); | 1818 WriteObject(obj.raw()); |
| 1796 UnmarkAll(); | 1819 UnmarkAll(); |
| 1797 } else { | 1820 } else { |
| 1798 ThrowException(exception_type(), exception_msg()); | 1821 ThrowException(exception_type(), exception_msg()); |
| 1799 } | 1822 } |
| 1800 } | 1823 } |
| 1801 | 1824 |
| 1802 | 1825 |
| 1803 } // namespace dart | 1826 } // namespace dart |
| OLD | NEW |