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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 } | 772 } |
773 if (object_id == kVoidType) { | 773 if (object_id == kVoidType) { |
774 return Object::void_type(); | 774 return Object::void_type(); |
775 } | 775 } |
776 if (object_id == kTrueValue) { | 776 if (object_id == kTrueValue) { |
777 return Bool::True().raw(); | 777 return Bool::True().raw(); |
778 } | 778 } |
779 if (object_id == kFalseValue) { | 779 if (object_id == kFalseValue) { |
780 return Bool::False().raw(); | 780 return Bool::False().raw(); |
781 } | 781 } |
| 782 if (object_id == kDoubleObject) { |
| 783 ASSERT(kind_ == Snapshot::kMessage); |
| 784 return Double::New(ReadDouble()); |
| 785 } |
782 intptr_t class_id = ClassIdFromObjectId(object_id); | 786 intptr_t class_id = ClassIdFromObjectId(object_id); |
783 if (IsSingletonClassId(class_id)) { | 787 if (IsSingletonClassId(class_id)) { |
784 return isolate()->class_table()->At(class_id); // get singleton class. | 788 return isolate()->class_table()->At(class_id); // get singleton class. |
785 } else { | 789 } else { |
786 ASSERT(Symbols::IsVMSymbolId(object_id)); | 790 ASSERT(Symbols::IsVMSymbolId(object_id)); |
787 return Symbols::GetVMSymbol(object_id); // return VM symbol. | 791 return Symbols::GetVMSymbol(object_id); // return VM symbol. |
788 } | 792 } |
789 UNREACHABLE(); | 793 UNREACHABLE(); |
790 return Object::null(); | 794 return Object::null(); |
791 } | 795 } |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 // - Object that has already been written: (negative id in stream | 0x3) | 1205 // - Object that has already been written: (negative id in stream | 0x3) |
1202 | 1206 |
1203 NoGCScope no_gc; | 1207 NoGCScope no_gc; |
1204 | 1208 |
1205 // First check if it is a Smi (i.e not a heap object). | 1209 // First check if it is a Smi (i.e not a heap object). |
1206 if (!rawobj->IsHeapObject()) { | 1210 if (!rawobj->IsHeapObject()) { |
1207 Write<int64_t>(reinterpret_cast<intptr_t>(rawobj)); | 1211 Write<int64_t>(reinterpret_cast<intptr_t>(rawobj)); |
1208 return true; | 1212 return true; |
1209 } | 1213 } |
1210 | 1214 |
| 1215 intptr_t cid = rawobj->GetClassId(); |
| 1216 |
| 1217 if ((kind_ == Snapshot::kMessage) && (cid == kDoubleCid)) { |
| 1218 WriteVMIsolateObject(kDoubleObject); |
| 1219 RawDouble* rd = reinterpret_cast<RawDouble*>(rawobj); |
| 1220 WriteDouble(rd->ptr()->value_); |
| 1221 return true; |
| 1222 } |
| 1223 |
1211 // Check if object has already been serialized, in that case just write | 1224 // Check if object has already been serialized, in that case just write |
1212 // the object id out. | 1225 // the object id out. |
1213 uword tags = rawobj->ptr()->tags_; | 1226 uword tags = rawobj->ptr()->tags_; |
1214 if (SerializedHeaderTag::decode(tags) == kObjectId) { | 1227 if (SerializedHeaderTag::decode(tags) == kObjectId) { |
1215 intptr_t id = SerializedHeaderData::decode(tags); | 1228 intptr_t id = SerializedHeaderData::decode(tags); |
1216 WriteIndexedObject(id); | 1229 WriteIndexedObject(id); |
1217 return true; | 1230 return true; |
1218 } | 1231 } |
1219 | 1232 |
1220 // Now check if it is an object from the VM isolate (NOTE: premarked objects | 1233 // Now check if it is an object from the VM isolate (NOTE: premarked objects |
1221 // are considered to be objects in the VM isolate). These objects are shared | 1234 // are considered to be objects in the VM isolate). These objects are shared |
1222 // by all isolates. | 1235 // by all isolates. |
1223 if (rawobj->IsVMHeapObject()) { | 1236 if (rawobj->IsVMHeapObject()) { |
1224 HandleVMIsolateObject(rawobj); | 1237 HandleVMIsolateObject(rawobj); |
1225 return true; | 1238 return true; |
1226 } | 1239 } |
1227 | 1240 |
1228 // Check if the object is a Mint and could potentially be a Smi | 1241 // Check if the object is a Mint and could potentially be a Smi |
1229 // on other architectures (64 bit), if so write it out as int64_t value. | 1242 // on other architectures (64 bit), if so write it out as int64_t value. |
1230 if (rawobj->GetClassId() == kMintCid) { | 1243 if (cid == kMintCid) { |
1231 int64_t value = reinterpret_cast<RawMint*>(rawobj)->ptr()->value_; | 1244 int64_t value = reinterpret_cast<RawMint*>(rawobj)->ptr()->value_; |
1232 const intptr_t kSmi64Bits = 62; | 1245 const intptr_t kSmi64Bits = 62; |
1233 const int64_t kSmi64Max = (static_cast<int64_t>(1) << kSmi64Bits) - 1; | 1246 const int64_t kSmi64Max = (static_cast<int64_t>(1) << kSmi64Bits) - 1; |
1234 const int64_t kSmi64Min = -(static_cast<int64_t>(1) << kSmi64Bits); | 1247 const int64_t kSmi64Min = -(static_cast<int64_t>(1) << kSmi64Bits); |
1235 if (value <= kSmi64Max && value >= kSmi64Min) { | 1248 if (value <= kSmi64Max && value >= kSmi64Min) { |
1236 Write<int64_t>((value << kSmiTagShift) | kSmiTag); | 1249 Write<int64_t>((value << kSmiTagShift) | kSmiTag); |
1237 return true; | 1250 return true; |
1238 } | 1251 } |
1239 } | 1252 } |
1240 | 1253 |
1241 // Check if it is a code object in that case just write a Null object | 1254 // Check if it is a code object in that case just write a Null object |
1242 // as we do not want code objects in the snapshot. | 1255 // as we do not want code objects in the snapshot. |
1243 if (rawobj->GetClassId() == kCodeCid) { | 1256 if (cid == kCodeCid) { |
1244 WriteVMIsolateObject(kNullObject); | 1257 WriteVMIsolateObject(kNullObject); |
1245 return true; | 1258 return true; |
1246 } | 1259 } |
1247 | 1260 |
1248 // Check if classes are not being serialized and it is preinitialized type | 1261 // Check if classes are not being serialized and it is preinitialized type |
1249 // or a predefined internal VM class in the object store. | 1262 // or a predefined internal VM class in the object store. |
1250 if (kind_ != Snapshot::kFull) { | 1263 if (kind_ != Snapshot::kFull) { |
1251 // Check if it is an internal VM class which is in the object store. | 1264 // Check if it is an internal VM class which is in the object store. |
1252 if (rawobj->GetClassId() == kClassCid) { | 1265 if (cid == kClassCid) { |
1253 RawClass* raw_class = reinterpret_cast<RawClass*>(rawobj); | 1266 RawClass* raw_class = reinterpret_cast<RawClass*>(rawobj); |
1254 intptr_t class_id = raw_class->ptr()->id_; | 1267 intptr_t class_id = raw_class->ptr()->id_; |
1255 if (IsObjectStoreClassId(class_id)) { | 1268 if (IsObjectStoreClassId(class_id)) { |
1256 intptr_t object_id = ObjectIdFromClassId(class_id); | 1269 intptr_t object_id = ObjectIdFromClassId(class_id); |
1257 WriteIndexedObject(object_id); | 1270 WriteIndexedObject(object_id); |
1258 return true; | 1271 return true; |
1259 } | 1272 } |
1260 } | 1273 } |
1261 | 1274 |
1262 // Now check it is a preinitialized type object. | 1275 // Now check it is a preinitialized type object. |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 NoGCScope no_gc; | 1573 NoGCScope no_gc; |
1561 WriteObject(obj.raw()); | 1574 WriteObject(obj.raw()); |
1562 UnmarkAll(); | 1575 UnmarkAll(); |
1563 } else { | 1576 } else { |
1564 ThrowException(exception_type(), exception_msg()); | 1577 ThrowException(exception_type(), exception_msg()); |
1565 } | 1578 } |
1566 } | 1579 } |
1567 | 1580 |
1568 | 1581 |
1569 } // namespace dart | 1582 } // namespace dart |
OLD | NEW |