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/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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 ASSERT(kHeaderSize == sizeof(Snapshot)); | 129 ASSERT(kHeaderSize == sizeof(Snapshot)); |
130 ASSERT(kLengthIndex == length_offset()); | 130 ASSERT(kLengthIndex == length_offset()); |
131 ASSERT((kSnapshotFlagIndex * sizeof(int64_t)) == kind_offset()); | 131 ASSERT((kSnapshotFlagIndex * sizeof(int64_t)) == kind_offset()); |
132 ASSERT((kHeapObjectTag & kInlined)); | 132 ASSERT((kHeapObjectTag & kInlined)); |
133 // The kWatchedBit and kMarkBit are only set during GC operations. This | 133 // The kWatchedBit and kMarkBit are only set during GC operations. This |
134 // allows the two low bits in the header to be used for snapshotting. | 134 // allows the two low bits in the header to be used for snapshotting. |
135 ASSERT(kObjectId == | 135 ASSERT(kObjectId == |
136 ((1 << RawObject::kWatchedBit) | (1 << RawObject::kMarkBit))); | 136 ((1 << RawObject::kWatchedBit) | (1 << RawObject::kMarkBit))); |
137 ASSERT((kObjectAlignmentMask & kObjectId) == kObjectId); | 137 ASSERT((kObjectAlignmentMask & kObjectId) == kObjectId); |
138 const Snapshot* snapshot = reinterpret_cast<const Snapshot*>(raw_memory); | 138 const Snapshot* snapshot = reinterpret_cast<const Snapshot*>(raw_memory); |
| 139 // If the raw length is negative or greater than what the local machine can |
| 140 // handle, then signal an error. |
| 141 if ((snapshot->length_ < 0) || (snapshot->length_ > kIntptrMax)) { |
| 142 return NULL; |
| 143 } |
139 return snapshot; | 144 return snapshot; |
140 } | 145 } |
141 | 146 |
142 | 147 |
143 RawSmi* BaseReader::ReadAsSmi() { | 148 RawSmi* BaseReader::ReadAsSmi() { |
144 intptr_t value = ReadIntptrValue(); | 149 intptr_t value = ReadIntptrValue(); |
145 ASSERT((value & kSmiTagMask) == kSmiTag); | 150 ASSERT((value & kSmiTagMask) == kSmiTag); |
146 return reinterpret_cast<RawSmi*>(value); | 151 return reinterpret_cast<RawSmi*>(value); |
147 } | 152 } |
148 | 153 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 ASSERT(!cls.IsNull()); | 224 ASSERT(!cls.IsNull()); |
220 return cls.raw(); | 225 return cls.raw(); |
221 } | 226 } |
222 | 227 |
223 | 228 |
224 RawObject* SnapshotReader::ReadObjectImpl() { | 229 RawObject* SnapshotReader::ReadObjectImpl() { |
225 int64_t value = Read<int64_t>(); | 230 int64_t value = Read<int64_t>(); |
226 if ((value & kSmiTagMask) == kSmiTag) { | 231 if ((value & kSmiTagMask) == kSmiTag) { |
227 return NewInteger(value); | 232 return NewInteger(value); |
228 } | 233 } |
229 return ReadObjectImpl(value); | 234 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
| 235 return ReadObjectImpl(static_cast<intptr_t>(value)); |
230 } | 236 } |
231 | 237 |
232 | 238 |
233 intptr_t SnapshotReader::NextAvailableObjectId() const { | 239 intptr_t SnapshotReader::NextAvailableObjectId() const { |
234 return backward_references_.length() + kMaxPredefinedObjectIds; | 240 return backward_references_.length() + kMaxPredefinedObjectIds; |
235 } | 241 } |
236 | 242 |
237 | 243 |
238 RawObject* SnapshotReader::ReadObjectImpl(intptr_t header_value) { | 244 RawObject* SnapshotReader::ReadObjectImpl(intptr_t header_value) { |
239 ASSERT((header_value <= kIntptrMax) && (header_value >= kIntptrMin)); | |
240 if (IsVMIsolateObject(header_value)) { | 245 if (IsVMIsolateObject(header_value)) { |
241 return ReadVMIsolateObject(header_value); | 246 return ReadVMIsolateObject(header_value); |
242 } else { | 247 } else { |
243 if (SerializedHeaderTag::decode(header_value) == kObjectId) { | 248 if (SerializedHeaderTag::decode(header_value) == kObjectId) { |
244 return ReadIndexedObject(SerializedHeaderData::decode(header_value)); | 249 return ReadIndexedObject(SerializedHeaderData::decode(header_value)); |
245 } | 250 } |
246 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined); | 251 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined); |
247 intptr_t object_id = SerializedHeaderData::decode(header_value); | 252 intptr_t object_id = SerializedHeaderData::decode(header_value); |
248 if (object_id == kOmittedObjectId) { | 253 if (object_id == kOmittedObjectId) { |
249 object_id = NextAvailableObjectId(); | 254 object_id = NextAvailableObjectId(); |
250 } | 255 } |
251 return ReadInlinedObject(object_id); | 256 return ReadInlinedObject(object_id); |
252 } | 257 } |
253 } | 258 } |
254 | 259 |
255 | 260 |
256 RawObject* SnapshotReader::ReadObjectRef() { | 261 RawObject* SnapshotReader::ReadObjectRef() { |
257 int64_t header_value = Read<int64_t>(); | 262 int64_t header_value = Read<int64_t>(); |
258 if ((header_value & kSmiTagMask) == kSmiTag) { | 263 if ((header_value & kSmiTagMask) == kSmiTag) { |
259 return NewInteger(header_value); | 264 return NewInteger(header_value); |
260 } | 265 } |
261 ASSERT((header_value <= kIntptrMax) && (header_value >= kIntptrMin)); | 266 ASSERT((header_value <= kIntptrMax) && (header_value >= kIntptrMin)); |
262 if (IsVMIsolateObject(header_value)) { | 267 intptr_t value = static_cast<intptr_t>(header_value); |
263 return ReadVMIsolateObject(header_value); | 268 if (IsVMIsolateObject(value)) { |
264 } else if (SerializedHeaderTag::decode(header_value) == kObjectId) { | 269 return ReadVMIsolateObject(value); |
265 return ReadIndexedObject(SerializedHeaderData::decode(header_value)); | 270 } else if (SerializedHeaderTag::decode(value) == kObjectId) { |
| 271 return ReadIndexedObject(SerializedHeaderData::decode(value)); |
266 } | 272 } |
267 ASSERT(SerializedHeaderTag::decode(header_value) == kInlined); | 273 ASSERT(SerializedHeaderTag::decode(value) == kInlined); |
268 intptr_t object_id = SerializedHeaderData::decode(header_value); | 274 intptr_t object_id = SerializedHeaderData::decode(value); |
269 if (object_id == kOmittedObjectId) { | 275 if (object_id == kOmittedObjectId) { |
270 object_id = NextAvailableObjectId(); | 276 object_id = NextAvailableObjectId(); |
271 } | 277 } |
272 ASSERT(GetBackRef(object_id) == NULL); | 278 ASSERT(GetBackRef(object_id) == NULL); |
273 | 279 |
274 // Read the class header information and lookup the class. | 280 // Read the class header information and lookup the class. |
275 intptr_t class_header = ReadIntptrValue(); | 281 intptr_t class_header = ReadIntptrValue(); |
276 | 282 |
277 // Since we are only reading an object reference, If it is an instance kind | 283 // Since we are only reading an object reference, If it is an instance kind |
278 // then we only need to figure out the class of the object and allocate an | 284 // then we only need to figure out the class of the object and allocate an |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 | 704 |
699 | 705 |
700 RawUnhandledException* SnapshotReader::NewUnhandledException() { | 706 RawUnhandledException* SnapshotReader::NewUnhandledException() { |
701 ALLOC_NEW_OBJECT(UnhandledException, Object::unhandled_exception_class()); | 707 ALLOC_NEW_OBJECT(UnhandledException, Object::unhandled_exception_class()); |
702 } | 708 } |
703 | 709 |
704 | 710 |
705 RawObject* SnapshotReader::NewInteger(int64_t value) { | 711 RawObject* SnapshotReader::NewInteger(int64_t value) { |
706 ASSERT((value & kSmiTagMask) == kSmiTag); | 712 ASSERT((value & kSmiTagMask) == kSmiTag); |
707 value = value >> kSmiTagShift; | 713 value = value >> kSmiTagShift; |
708 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { | 714 if (Smi::IsValid(value)) { |
709 return Smi::New(value); | 715 return Smi::New(static_cast<intptr_t>(value)); |
710 } | 716 } |
711 if (kind_ == Snapshot::kFull) { | 717 if (kind_ == Snapshot::kFull) { |
712 return NewMint(value); | 718 return NewMint(value); |
713 } | 719 } |
714 return Mint::NewCanonical(value); | 720 return Mint::NewCanonical(value); |
715 } | 721 } |
716 | 722 |
717 | 723 |
718 RawStacktrace* SnapshotReader::NewStacktrace() { | 724 RawStacktrace* SnapshotReader::NewStacktrace() { |
719 ALLOC_NEW_OBJECT(Stacktrace, object_store()->stacktrace_class()); | 725 ALLOC_NEW_OBJECT(Stacktrace, object_store()->stacktrace_class()); |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 NoGCScope no_gc; | 1640 NoGCScope no_gc; |
1635 WriteObject(obj.raw()); | 1641 WriteObject(obj.raw()); |
1636 UnmarkAll(); | 1642 UnmarkAll(); |
1637 } else { | 1643 } else { |
1638 ThrowException(exception_type(), exception_msg()); | 1644 ThrowException(exception_type(), exception_msg()); |
1639 } | 1645 } |
1640 } | 1646 } |
1641 | 1647 |
1642 | 1648 |
1643 } // namespace dart | 1649 } // namespace dart |
OLD | NEW |