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

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

Issue 1290933002: Toward precompiled snapshots. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months 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
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/object.h" 5 #include "vm/object.h"
6 #include "vm/object_store.h" 6 #include "vm/object_store.h"
7 #include "vm/snapshot.h" 7 #include "vm/snapshot.h"
8 #include "vm/stub_code.h" 8 #include "vm/stub_code.h"
9 #include "vm/symbols.h" 9 #include "vm/symbols.h"
10 #include "vm/visitor.h" 10 #include "vm/visitor.h"
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 func.set_num_optional_parameters(reader->Read<int16_t>()); 686 func.set_num_optional_parameters(reader->Read<int16_t>());
687 func.set_deoptimization_counter(reader->Read<int16_t>()); 687 func.set_deoptimization_counter(reader->Read<int16_t>());
688 func.set_regexp_cid(reader->ReadClassIDValue()); 688 func.set_regexp_cid(reader->ReadClassIDValue());
689 func.set_kind_tag(reader->Read<uint32_t>()); 689 func.set_kind_tag(reader->Read<uint32_t>());
690 func.set_optimized_instruction_count(reader->Read<uint16_t>()); 690 func.set_optimized_instruction_count(reader->Read<uint16_t>());
691 func.set_optimized_call_site_count(reader->Read<uint16_t>()); 691 func.set_optimized_call_site_count(reader->Read<uint16_t>());
692 692
693 // Set all the object fields. 693 // Set all the object fields.
694 // TODO(5411462): Need to assert No GC can happen here, even though 694 // TODO(5411462): Need to assert No GC can happen here, even though
695 // allocations may happen. 695 // allocations may happen.
696 intptr_t num_flds = (func.raw()->to_snapshot() - func.raw()->from()); 696 RawObject** to = reader->snapshot_code() ? func.raw()->to()
siva 2015/08/19 19:40:03 maybe use a different name instead of 'to' say 'to
rmacnak 2015/08/19 22:33:54 Done.
697 : func.raw()->to_snapshot();
698 intptr_t num_flds = to - func.raw()->from();
Florian Schneider 2015/08/18 11:54:14 This loop setting all the fields seems to be dupli
rmacnak 2015/08/19 22:33:54 Good point, we have a helper for the write. Will p
697 intptr_t from_offset = OFFSET_OF_FROM(func); 699 intptr_t from_offset = OFFSET_OF_FROM(func);
698 for (intptr_t i = 0; i <= num_flds; i++) { 700 for (intptr_t i = 0; i <= num_flds; i++) {
699 (*reader->PassiveObjectHandle()) = 701 (*reader->PassiveObjectHandle()) =
700 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); 702 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset));
701 func.StorePointer((func.raw()->from() + i), 703 func.StorePointer((func.raw()->from() + i),
702 reader->PassiveObjectHandle()->raw()); 704 reader->PassiveObjectHandle()->raw());
703 } 705 }
704 706
705 // Initialize all fields that are not part of the snapshot. 707 if (!reader->snapshot_code()) {
706 func.ClearICDataArray(); 708 // Initialize all fields that are not part of the snapshot.
707 func.ClearCode(); 709 func.ClearICDataArray();
710 func.ClearCode();
711 }
708 return func.raw(); 712 return func.raw();
709 } 713 }
710 714
711 715
712 void RawFunction::WriteTo(SnapshotWriter* writer, 716 void RawFunction::WriteTo(SnapshotWriter* writer,
713 intptr_t object_id, 717 intptr_t object_id,
714 Snapshot::Kind kind) { 718 Snapshot::Kind kind) {
715 ASSERT(writer != NULL); 719 ASSERT(writer != NULL);
716 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); 720 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull));
717 721
(...skipping 11 matching lines...) Expand all
729 writer->Write<int16_t>(ptr()->num_fixed_parameters_); 733 writer->Write<int16_t>(ptr()->num_fixed_parameters_);
730 writer->Write<int16_t>(ptr()->num_optional_parameters_); 734 writer->Write<int16_t>(ptr()->num_optional_parameters_);
731 writer->Write<int16_t>(ptr()->deoptimization_counter_); 735 writer->Write<int16_t>(ptr()->deoptimization_counter_);
732 writer->WriteClassIDValue(ptr()->regexp_cid_); 736 writer->WriteClassIDValue(ptr()->regexp_cid_);
733 writer->Write<uint32_t>(ptr()->kind_tag_); 737 writer->Write<uint32_t>(ptr()->kind_tag_);
734 writer->Write<uint16_t>(ptr()->optimized_instruction_count_); 738 writer->Write<uint16_t>(ptr()->optimized_instruction_count_);
735 writer->Write<uint16_t>(ptr()->optimized_call_site_count_); 739 writer->Write<uint16_t>(ptr()->optimized_call_site_count_);
736 740
737 // Write out all the object pointer fields. 741 // Write out all the object pointer fields.
738 SnapshotWriterVisitor visitor(writer); 742 SnapshotWriterVisitor visitor(writer);
739 visitor.VisitPointers(from(), to_snapshot()); 743 visitor.VisitPointers(from(), writer->snapshot_code() ? to()
744 : to_snapshot());
740 } 745 }
741 746
742 747
743 RawField* Field::ReadFrom(SnapshotReader* reader, 748 RawField* Field::ReadFrom(SnapshotReader* reader,
744 intptr_t object_id, 749 intptr_t object_id,
745 intptr_t tags, 750 intptr_t tags,
746 Snapshot::Kind kind) { 751 Snapshot::Kind kind) {
747 ASSERT(reader != NULL); 752 ASSERT(reader != NULL);
748 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); 753 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull));
749 754
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 // Write out all the object pointer fields. 1183 // Write out all the object pointer fields.
1179 SnapshotWriterVisitor visitor(writer); 1184 SnapshotWriterVisitor visitor(writer);
1180 visitor.VisitPointers(from(), to()); 1185 visitor.VisitPointers(from(), to());
1181 } 1186 }
1182 1187
1183 1188
1184 RawCode* Code::ReadFrom(SnapshotReader* reader, 1189 RawCode* Code::ReadFrom(SnapshotReader* reader,
1185 intptr_t object_id, 1190 intptr_t object_id,
1186 intptr_t tags, 1191 intptr_t tags,
1187 Snapshot::Kind kind) { 1192 Snapshot::Kind kind) {
1188 UNREACHABLE(); 1193 UNREACHABLE(); // Untested.
1189 return Code::null(); 1194 ASSERT(reader->snapshot_code());
1195 ASSERT(kind == Snapshot::kFull);
1196
1197 Code& result = Code::ZoneHandle(reader->zone(), NEW_OBJECT_WITH_LEN(Code, 0));
1198 reader->AddBackRef(object_id, &result, kIsDeserialized);
1199
1200 result.set_compile_timestamp(reader->Read<int64_t>());
1201 result.set_state_bits(reader->Read<int32_t>());
1202 result.set_entry_patch_pc_offset(reader->Read<int32_t>());
1203 result.set_patch_code_pc_offset(reader->Read<int32_t>());
1204 result.set_lazy_deopt_pc_offset(reader->Read<int32_t>());
1205
1206 // Set all the object fields.
1207 // TODO(5411462): Need to assert No GC can happen here, even though
1208 // allocations may happen.
1209 intptr_t num_flds = (result.raw()->to() - result.raw()->from());
1210 for (intptr_t i = 0; i <= num_flds; i++) {
1211 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
1212 result.StorePointer((result.raw()->from() + i),
1213 reader->PassiveObjectHandle()->raw());
1214 }
1215
1216 return result.raw();
1190 } 1217 }
1191 1218
1192 1219
1193 void RawCode::WriteTo(SnapshotWriter* writer, 1220 void RawCode::WriteTo(SnapshotWriter* writer,
1194 intptr_t object_id, 1221 intptr_t object_id,
1195 Snapshot::Kind kind) { 1222 Snapshot::Kind kind) {
1196 // We have already checked for this and written a NULL object, hence we 1223 ASSERT(writer->snapshot_code());
1197 // should not reach here. 1224 ASSERT(kind == Snapshot::kFull);
1198 UNREACHABLE(); 1225
1226 // Write out the serialization header value for this object.
1227 writer->WriteInlinedObjectHeader(object_id);
1228
1229 // Write out the class and tags information.
1230 writer->WriteVMIsolateObject(kCodeCid);
1231 writer->WriteTags(writer->GetObjectTags(this));
1232
1233 // Write out all the non object fields.
1234 writer->Write<int64_t>(ptr()->compile_timestamp_);
1235 writer->Write<int32_t>(ptr()->state_bits_);
1236 writer->Write<int32_t>(ptr()->entry_patch_pc_offset_);
1237 writer->Write<int32_t>(ptr()->patch_code_pc_offset_);
1238 writer->Write<int32_t>(ptr()->lazy_deopt_pc_offset_);
1239
1240 intptr_t pointer_offsets_length =
1241 Code::PtrOffBits::decode(ptr()->state_bits_);
1242 if (pointer_offsets_length != 0) {
1243 // Should only be IA32.
1244 FATAL("Serializing embedded pointer offsets unimplemented");
1245 }
siva 2015/08/19 19:40:02 Why not do this check on top before writing anythi
rmacnak 2015/08/19 22:33:54 Moved up.
1246
1247 // Write out all the object pointer fields.
1248 SnapshotWriterVisitor visitor(writer);
1249 visitor.VisitPointers(from(), to());
1199 } 1250 }
1200 1251
1201 1252
1202 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, 1253 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader,
1203 intptr_t object_id, 1254 intptr_t object_id,
1204 intptr_t tags, 1255 intptr_t tags,
1205 Snapshot::Kind kind) { 1256 Snapshot::Kind kind) {
1206 UNREACHABLE(); 1257 UNREACHABLE(); // Untested.
1207 return Instructions::null(); 1258 ASSERT(reader->snapshot_code());
1259 ASSERT(kind == Snapshot::kFull);
1260
1261 intptr_t id = reader->Read<int32_t>();
1262 Instructions& result =
1263 Instructions::ZoneHandle(reader->zone(),
1264 reader->GetInstructionsById(id));
1265 reader->AddBackRef(object_id, &result, kIsDeserialized);
1266 return result.raw();
1208 } 1267 }
1209 1268
1210 1269
1211 void RawInstructions::WriteTo(SnapshotWriter* writer, 1270 void RawInstructions::WriteTo(SnapshotWriter* writer,
1212 intptr_t object_id, 1271 intptr_t object_id,
1213 Snapshot::Kind kind) { 1272 Snapshot::Kind kind) {
1214 UNREACHABLE(); 1273 ASSERT(writer->snapshot_code());
1274 ASSERT(kind == Snapshot::kFull);
1275
1276 {
1277 // TODO(rmacnak): Drop after calling convention change.
1278 writer->WriteInlinedObjectHeader(object_id);
1279 writer->WriteVMIsolateObject(kInstructionsCid);
1280 writer->WriteTags(writer->GetObjectTags(this));
1281 writer->WriteObjectImpl(ptr()->code_, kAsReference);
1282 writer->WriteObjectImpl(ptr()->object_pool_, kAsReference);
1283 }
siva 2015/08/19 19:40:02 Why is this scoped like this.
rmacnak 2015/08/19 22:33:54 Scoping the comment.
1284
1285 writer->Write<int32_t>(writer->GetInstructionsId(this));
1215 } 1286 }
1216 1287
1217 1288
1218 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, 1289 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader,
1219 intptr_t object_id, 1290 intptr_t object_id,
1220 intptr_t tags, 1291 intptr_t tags,
1221 Snapshot::Kind kind) { 1292 Snapshot::Kind kind) {
1222 UNREACHABLE(); 1293 UNREACHABLE(); // Untested.
1223 return ObjectPool::null(); 1294 ASSERT(reader->snapshot_code());
1295 ASSERT(kind == Snapshot::kFull);
1296
1297 intptr_t length = reader->Read<intptr_t>();
1298
1299 ObjectPool& result =
1300 ObjectPool::ZoneHandle(reader->zone(),
1301 NEW_OBJECT_WITH_LEN(ObjectPool, length));
1302 reader->AddBackRef(object_id, &result, kIsDeserialized);
1303
1304 RawTypedData* info_array = result.raw_ptr()->info_array_->ptr();
1305
1306 // Set all the object fields.
1307 // TODO(5411462): Need to assert No GC can happen here, even though
1308 // allocations may happen.
1309 for (intptr_t i = 0; i < length; i++) {
1310 ObjectPool::EntryType entry_type =
1311 static_cast<ObjectPool::EntryType>(reader->Read<uint8_t>());
1312 info_array->data()[i] = entry_type;
1313 switch (entry_type) {
1314 case ObjectPool::kTaggedObject: {
1315 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
1316 result.SetObjectAt(i, *(reader->PassiveObjectHandle()));
1317 break;
1318 }
1319 case ObjectPool::kImmediate: {
1320 intptr_t raw_value = reader->Read<intptr_t>();
1321 result.SetRawValueAt(i, raw_value);
1322 break;
1323 }
siva 2015/08/19 19:40:03 case statements seem to be not indented.
rmacnak 2015/08/19 22:33:54 Done.
1324 default:
1325 UNREACHABLE();
siva 2015/08/19 19:40:02 It is probably better to throw exceptions in these
rmacnak 2015/08/19 22:33:54 Acknowledged.
1326 }
1327 }
1328
1329 return result.raw();
1224 } 1330 }
1225 1331
1226 1332
1227 void RawObjectPool::WriteTo(SnapshotWriter* writer, 1333 void RawObjectPool::WriteTo(SnapshotWriter* writer,
1228 intptr_t object_id, 1334 intptr_t object_id,
1229 Snapshot::Kind kind) { 1335 Snapshot::Kind kind) {
1230 UNREACHABLE(); 1336 ASSERT(writer->snapshot_code());
1337 ASSERT(kind == Snapshot::kFull);
1338
1339 // Write out the serialization header value for this object.
1340 writer->WriteInlinedObjectHeader(object_id);
1341
1342 // Write out the class and tags information.
1343 writer->WriteVMIsolateObject(kObjectPoolCid);
1344 writer->WriteTags(writer->GetObjectTags(this));
1345
1346 intptr_t length = ptr()->length_;
1347 RawTypedData* info_array = ptr()->info_array_->ptr();
1348 ASSERT(info_array != TypedData::null());
1349
1350 writer->Write<intptr_t>(length);
1351 for (intptr_t i = 0; i < length; i++) {
1352 ObjectPool::EntryType entry_type =
1353 static_cast<ObjectPool::EntryType>(info_array->data()[i]);
1354 writer->Write<uint8_t>(entry_type);
1355 Entry& entry = ptr()->data()[i];
1356 switch (entry_type) {
1357 case ObjectPool::kTaggedObject:
1358 writer->WriteObjectImpl(entry.raw_obj_, kAsReference);
1359 break;
1360 case ObjectPool::kImmediate:
1361 writer->Write<intptr_t>(entry.raw_value_);
1362 break;
1363 default:
1364 UNREACHABLE();
1365 }
siva 2015/08/19 19:40:02 indentation seems to be off.
1366 }
1231 } 1367 }
1232 1368
1233 1369
1234 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader, 1370 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader,
1235 intptr_t object_id, 1371 intptr_t object_id,
1236 intptr_t tags, 1372 intptr_t tags,
1237 Snapshot::Kind kind) { 1373 Snapshot::Kind kind) {
1238 ASSERT(reader->allow_code()); 1374 UNREACHABLE(); // Untested.
1375 ASSERT(reader->snapshot_code());
1239 1376
1240 const int32_t length = reader->Read<int32_t>(); 1377 const int32_t length = reader->Read<int32_t>();
1241 PcDescriptors& result = PcDescriptors::ZoneHandle(reader->zone(), 1378 PcDescriptors& result = PcDescriptors::ZoneHandle(reader->zone(),
1242 PcDescriptors::New(length)); 1379 PcDescriptors::New(length));
siva 2015/08/19 19:40:03 Maybe in another CL you could convert these to als
1243 reader->AddBackRef(object_id, &result, kIsDeserialized); 1380 reader->AddBackRef(object_id, &result, kIsDeserialized);
1244 1381
1245 if (result.Length() > 0) { 1382 if (result.Length() > 0) {
1246 NoSafepointScope no_safepoint; 1383 NoSafepointScope no_safepoint;
1247 intptr_t len = result.Length(); 1384 intptr_t len = result.Length();
1248 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); 1385 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data());
1249 reader->ReadBytes(data, len); 1386 reader->ReadBytes(data, len);
1250 } 1387 }
1251 1388
1252 return result.raw(); 1389 return result.raw();
1253 } 1390 }
1254 1391
1255 1392
1256 void RawPcDescriptors::WriteTo(SnapshotWriter* writer, 1393 void RawPcDescriptors::WriteTo(SnapshotWriter* writer,
1257 intptr_t object_id, 1394 intptr_t object_id,
1258 Snapshot::Kind kind) { 1395 Snapshot::Kind kind) {
1259 ASSERT(writer->allow_code()); 1396 ASSERT(writer->snapshot_code());
1260 1397
1261 // Write out the serialization header value for this object. 1398 // Write out the serialization header value for this object.
1262 writer->WriteInlinedObjectHeader(object_id); 1399 writer->WriteInlinedObjectHeader(object_id);
1263 writer->WriteIndexedObject(kPcDescriptorsCid); 1400 writer->WriteIndexedObject(kPcDescriptorsCid);
1264 writer->WriteTags(writer->GetObjectTags(this)); 1401 writer->WriteTags(writer->GetObjectTags(this));
1265 writer->Write<int32_t>(ptr()->length_); 1402 writer->Write<int32_t>(ptr()->length_);
1266 if (ptr()->length_ > 0) { 1403 if (ptr()->length_ > 0) {
1267 intptr_t len = ptr()->length_; 1404 intptr_t len = ptr()->length_;
1268 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); 1405 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data());
1269 writer->WriteBytes(data, len); 1406 writer->WriteBytes(data, len);
1270 } 1407 }
1271 } 1408 }
1272 1409
1273 1410
1274 RawStackmap* Stackmap::ReadFrom(SnapshotReader* reader, 1411 RawStackmap* Stackmap::ReadFrom(SnapshotReader* reader,
1275 intptr_t object_id, 1412 intptr_t object_id,
1276 intptr_t tags, 1413 intptr_t tags,
1277 Snapshot::Kind kind) { 1414 Snapshot::Kind kind) {
1278 ASSERT(reader->allow_code()); 1415 UNREACHABLE(); // Untested.
1416 ASSERT(reader->snapshot_code());
1279 1417
1280 const int32_t length = reader->Read<int32_t>(); 1418 const int32_t length = reader->Read<int32_t>();
1281 const int32_t register_bit_count = reader->Read<int32_t>(); 1419 const int32_t register_bit_count = reader->Read<int32_t>();
1282 const uword pc_offset = reader->Read<uint32_t>(); 1420 const uword pc_offset = reader->Read<uint32_t>();
1283 1421
1284 Stackmap& result = 1422 Stackmap& result =
1285 Stackmap::ZoneHandle(reader->zone(), 1423 Stackmap::ZoneHandle(reader->zone(),
1286 Stackmap::New(length, register_bit_count, pc_offset)); 1424 Stackmap::New(length, register_bit_count, pc_offset));
1287 reader->AddBackRef(object_id, &result, kIsDeserialized); 1425 reader->AddBackRef(object_id, &result, kIsDeserialized);
1288 1426
1289 if (result.Length() > 0) { 1427 if (result.Length() > 0) {
1290 NoSafepointScope no_safepoint; 1428 NoSafepointScope no_safepoint;
1291 intptr_t len = (result.Length() + 7) / 8; 1429 intptr_t len = (result.Length() + 7) / 8;
1292 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); 1430 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data());
1293 reader->ReadBytes(data, len); 1431 reader->ReadBytes(data, len);
1294 } 1432 }
1295 1433
1296 return result.raw(); 1434 return result.raw();
1297 } 1435 }
1298 1436
1299 1437
1300 void RawStackmap::WriteTo(SnapshotWriter* writer, 1438 void RawStackmap::WriteTo(SnapshotWriter* writer,
1301 intptr_t object_id, 1439 intptr_t object_id,
1302 Snapshot::Kind kind) { 1440 Snapshot::Kind kind) {
1303 ASSERT(writer->allow_code()); 1441 ASSERT(writer->snapshot_code());
1304 1442
1305 // Write out the serialization header value for this object. 1443 // Write out the serialization header value for this object.
1306 writer->WriteInlinedObjectHeader(object_id); 1444 writer->WriteInlinedObjectHeader(object_id);
1307 writer->WriteIndexedObject(kStackmapCid); 1445 writer->WriteIndexedObject(kStackmapCid);
1308 writer->WriteTags(writer->GetObjectTags(this)); 1446 writer->WriteTags(writer->GetObjectTags(this));
1309 writer->Write<int32_t>(ptr()->length_); 1447 writer->Write<int32_t>(ptr()->length_);
1310 writer->Write<int32_t>(ptr()->register_bit_count_); 1448 writer->Write<int32_t>(ptr()->register_bit_count_);
1311 writer->Write<uint32_t>(ptr()->pc_offset_); 1449 writer->Write<uint32_t>(ptr()->pc_offset_);
1312 if (ptr()->length_ > 0) { 1450 if (ptr()->length_ > 0) {
1313 intptr_t len = (ptr()->length_ + 7) / 8; 1451 intptr_t len = (ptr()->length_ + 7) / 8;
1314 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); 1452 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data());
1315 writer->WriteBytes(data, len); 1453 writer->WriteBytes(data, len);
1316 } 1454 }
1317 } 1455 }
1318 1456
1319 1457
1320 RawLocalVarDescriptors* LocalVarDescriptors::ReadFrom(SnapshotReader* reader, 1458 RawLocalVarDescriptors* LocalVarDescriptors::ReadFrom(SnapshotReader* reader,
1321 intptr_t object_id, 1459 intptr_t object_id,
1322 intptr_t tags, 1460 intptr_t tags,
1323 Snapshot::Kind kind) { 1461 Snapshot::Kind kind) {
1324 ASSERT(reader->allow_code()); 1462 UNREACHABLE(); // Untested.
1463 ASSERT(reader->snapshot_code());
1325 1464
1326 const int32_t num_entries = reader->Read<int32_t>(); 1465 const int32_t num_entries = reader->Read<int32_t>();
1327 1466
1328 LocalVarDescriptors& result = 1467 LocalVarDescriptors& result =
1329 LocalVarDescriptors::ZoneHandle(reader->zone(), 1468 LocalVarDescriptors::ZoneHandle(reader->zone(),
1330 LocalVarDescriptors::New(num_entries)); 1469 LocalVarDescriptors::New(num_entries));
1331 reader->AddBackRef(object_id, &result, kIsDeserialized); 1470 reader->AddBackRef(object_id, &result, kIsDeserialized);
1332 1471
1333 for (intptr_t i = 0; i < num_entries; i++) { 1472 for (intptr_t i = 0; i < num_entries; i++) {
1334 (*reader->StringHandle()) ^= reader->ReadObjectImpl(kAsReference); 1473 (*reader->StringHandle()) ^= reader->ReadObjectImpl(kAsReference);
1335 result.StorePointer(result.raw()->nameAddrAt(i), 1474 result.StorePointer(result.raw()->nameAddrAt(i),
1336 reader->StringHandle()->raw()); 1475 reader->StringHandle()->raw());
1337 } 1476 }
1338 1477
1339 if (num_entries > 0) { 1478 if (num_entries > 0) {
1340 NoSafepointScope no_safepoint; 1479 NoSafepointScope no_safepoint;
1341 intptr_t len = num_entries * sizeof(RawLocalVarDescriptors::VarInfo); 1480 intptr_t len = num_entries * sizeof(RawLocalVarDescriptors::VarInfo);
1342 uint8_t* data = result.UnsafeMutableNonPointer( 1481 uint8_t* data = result.UnsafeMutableNonPointer(
1343 reinterpret_cast<const uint8_t*>(result.raw()->data())); 1482 reinterpret_cast<const uint8_t*>(result.raw()->data()));
1344 reader->ReadBytes(data, len); 1483 reader->ReadBytes(data, len);
1345 } 1484 }
1346 1485
1347 return result.raw(); 1486 return result.raw();
1348 } 1487 }
1349 1488
1350 1489
1351 void RawLocalVarDescriptors::WriteTo(SnapshotWriter* writer, 1490 void RawLocalVarDescriptors::WriteTo(SnapshotWriter* writer,
1352 intptr_t object_id, 1491 intptr_t object_id,
1353 Snapshot::Kind kind) { 1492 Snapshot::Kind kind) {
1354 ASSERT(writer->allow_code()); 1493 ASSERT(writer->snapshot_code());
1355 1494
1356 // Write out the serialization header value for this object. 1495 // Write out the serialization header value for this object.
1357 writer->WriteInlinedObjectHeader(object_id); 1496 writer->WriteInlinedObjectHeader(object_id);
1358 writer->WriteIndexedObject(kLocalVarDescriptorsCid); 1497 writer->WriteIndexedObject(kLocalVarDescriptorsCid);
1359 writer->WriteTags(writer->GetObjectTags(this)); 1498 writer->WriteTags(writer->GetObjectTags(this));
1360 writer->Write<int32_t>(ptr()->num_entries_); 1499 writer->Write<int32_t>(ptr()->num_entries_);
1361 for (intptr_t i = 0; i < ptr()->num_entries_; i++) { 1500 for (intptr_t i = 0; i < ptr()->num_entries_; i++) {
1362 writer->WriteObjectImpl(ptr()->names()[i], kAsInlinedObject); 1501 writer->WriteObjectImpl(ptr()->names()[i], kAsInlinedObject);
1363 } 1502 }
1364 if (ptr()->num_entries_ > 0) { 1503 if (ptr()->num_entries_ > 0) {
1365 intptr_t len = ptr()->num_entries_ * sizeof(VarInfo); 1504 intptr_t len = ptr()->num_entries_ * sizeof(VarInfo);
1366 uint8_t* data = reinterpret_cast<uint8_t*>(this->data()); 1505 uint8_t* data = reinterpret_cast<uint8_t*>(this->data());
1367 writer->WriteBytes(data, len); 1506 writer->WriteBytes(data, len);
1368 } 1507 }
1369 } 1508 }
1370 1509
1371 1510
1372 RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader, 1511 RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader,
1373 intptr_t object_id, 1512 intptr_t object_id,
1374 intptr_t tags, 1513 intptr_t tags,
1375 Snapshot::Kind kind) { 1514 Snapshot::Kind kind) {
1376 ASSERT(reader->allow_code()); 1515 UNREACHABLE(); // Untested.
1516 ASSERT(reader->snapshot_code());
1377 1517
1378 // handled_types_data. 1518 // handled_types_data.
1379 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject); 1519 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
1380 1520
1381 ExceptionHandlers& result = 1521 ExceptionHandlers& result =
1382 ExceptionHandlers::ZoneHandle(reader->zone(), 1522 ExceptionHandlers::ZoneHandle(reader->zone(),
1383 ExceptionHandlers::New(*reader->ArrayHandle())); 1523 ExceptionHandlers::New(*reader->ArrayHandle()));
1384 reader->AddBackRef(object_id, &result, kIsDeserialized); 1524 reader->AddBackRef(object_id, &result, kIsDeserialized);
1385 1525
1386 if (result.num_entries() > 0) { 1526 if (result.num_entries() > 0) {
1387 NoSafepointScope no_safepoint; 1527 NoSafepointScope no_safepoint;
1388 const intptr_t len = 1528 const intptr_t len =
1389 result.num_entries() * sizeof(RawExceptionHandlers::HandlerInfo); 1529 result.num_entries() * sizeof(RawExceptionHandlers::HandlerInfo);
1390 uint8_t* data = result.UnsafeMutableNonPointer( 1530 uint8_t* data = result.UnsafeMutableNonPointer(
1391 reinterpret_cast<const uint8_t*>(result.raw_ptr()->data())); 1531 reinterpret_cast<const uint8_t*>(result.raw_ptr()->data()));
1392 reader->ReadBytes(data, len); 1532 reader->ReadBytes(data, len);
1393 } 1533 }
1394 1534
1395 return result.raw(); 1535 return result.raw();
1396 } 1536 }
1397 1537
1398 1538
1399 void RawExceptionHandlers::WriteTo(SnapshotWriter* writer, 1539 void RawExceptionHandlers::WriteTo(SnapshotWriter* writer,
1400 intptr_t object_id, 1540 intptr_t object_id,
1401 Snapshot::Kind kind) { 1541 Snapshot::Kind kind) {
1402 ASSERT(writer->allow_code()); 1542 ASSERT(writer->snapshot_code());
1403 1543
1404 // Write out the serialization header value for this object. 1544 // Write out the serialization header value for this object.
1405 writer->WriteInlinedObjectHeader(object_id); 1545 writer->WriteInlinedObjectHeader(object_id);
1406 writer->WriteIndexedObject(kExceptionHandlersCid); 1546 writer->WriteIndexedObject(kExceptionHandlersCid);
1407 writer->WriteTags(writer->GetObjectTags(this)); 1547 writer->WriteTags(writer->GetObjectTags(this));
1408 writer->WriteObjectImpl(ptr()->handled_types_data_, kAsInlinedObject); 1548 writer->WriteObjectImpl(ptr()->handled_types_data_, kAsInlinedObject);
1409 1549
1410 if (ptr()->num_entries_ > 0) { 1550 if (ptr()->num_entries_ > 0) {
1411 intptr_t len = ptr()->num_entries_ * sizeof(HandlerInfo); 1551 intptr_t len = ptr()->num_entries_ * sizeof(HandlerInfo);
1412 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); 1552 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 intptr_t object_id, 1620 intptr_t object_id,
1481 Snapshot::Kind kind) { 1621 Snapshot::Kind kind) {
1482 UNREACHABLE(); 1622 UNREACHABLE();
1483 } 1623 }
1484 1624
1485 1625
1486 RawICData* ICData::ReadFrom(SnapshotReader* reader, 1626 RawICData* ICData::ReadFrom(SnapshotReader* reader,
1487 intptr_t object_id, 1627 intptr_t object_id,
1488 intptr_t tags, 1628 intptr_t tags,
1489 Snapshot::Kind kind) { 1629 Snapshot::Kind kind) {
1490 UNREACHABLE(); 1630 UNREACHABLE(); // Untested.
1491 return NULL; 1631 ASSERT(reader->snapshot_code());
1632 ASSERT(kind == Snapshot::kFull);
1633
1634 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData));
1635 reader->AddBackRef(object_id, &result, kIsDeserialized);
1636
1637 result.set_deopt_id(reader->Read<int32_t>());
1638 result.set_state_bits(reader->Read<uint32_t>());
1639
1640 // Set all the object fields.
1641 // TODO(5411462): Need to assert No GC can happen here, even though
1642 // allocations may happen.
1643 intptr_t num_flds = (result.raw()->to() - result.raw()->from());
1644 for (intptr_t i = 0; i <= num_flds; i++) {
1645 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
1646 result.StorePointer((result.raw()->from() + i),
1647 reader->PassiveObjectHandle()->raw());
1648 }
1649
1650 return result.raw();
1492 } 1651 }
1493 1652
1494 1653
1495 void RawICData::WriteTo(SnapshotWriter* writer, 1654 void RawICData::WriteTo(SnapshotWriter* writer,
1496 intptr_t object_id, 1655 intptr_t object_id,
1497 Snapshot::Kind kind) { 1656 Snapshot::Kind kind) {
1498 UNREACHABLE(); 1657 ASSERT(writer->snapshot_code());
1658 ASSERT(kind == Snapshot::kFull);
1659
1660 // Write out the serialization header value for this object.
1661 writer->WriteInlinedObjectHeader(object_id);
1662
1663 // Write out the class and tags information.
1664 writer->WriteVMIsolateObject(kICDataCid);
1665 writer->WriteTags(writer->GetObjectTags(this));
1666
1667 // Write out all the non object fields.
1668 writer->Write<int32_t>(ptr()->deopt_id_);
1669 writer->Write<uint32_t>(ptr()->state_bits_);
1670
1671 // Write out all the object pointer fields.
1672 SnapshotWriterVisitor visitor(writer);
1673 visitor.VisitPointers(from(), to());
1499 } 1674 }
1500 1675
1501 1676
1502 RawMegamorphicCache* MegamorphicCache::ReadFrom(SnapshotReader* reader, 1677 RawMegamorphicCache* MegamorphicCache::ReadFrom(SnapshotReader* reader,
1503 intptr_t object_id, 1678 intptr_t object_id,
1504 intptr_t tags, 1679 intptr_t tags,
1505 Snapshot::Kind kind) { 1680 Snapshot::Kind kind) {
1506 UNREACHABLE(); 1681 UNREACHABLE(); // Untested.
1507 return NULL; 1682 ASSERT(reader->snapshot_code());
1683 ASSERT(kind == Snapshot::kFull);
1684
1685 MegamorphicCache& result =
1686 MegamorphicCache::ZoneHandle(reader->zone(),
1687 NEW_OBJECT(MegamorphicCache));
1688 reader->AddBackRef(object_id, &result, kIsDeserialized);
1689
1690 result.set_filled_entry_count(reader->Read<int32_t>());
1691
1692 // Set all the object fields.
1693 // TODO(5411462): Need to assert No GC can happen here, even though
1694 // allocations may happen.
1695 intptr_t num_flds = (result.raw()->to() - result.raw()->from());
1696 for (intptr_t i = 0; i <= num_flds; i++) {
1697 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
1698 result.StorePointer((result.raw()->from() + i),
1699 reader->PassiveObjectHandle()->raw());
1700 }
1701
1702 return result.raw();
1508 } 1703 }
1509 1704
1510 1705
1511 void RawMegamorphicCache::WriteTo(SnapshotWriter* writer, 1706 void RawMegamorphicCache::WriteTo(SnapshotWriter* writer,
1512 intptr_t object_id, 1707 intptr_t object_id,
1513 Snapshot::Kind kind) { 1708 Snapshot::Kind kind) {
1514 UNREACHABLE(); 1709 ASSERT(writer->snapshot_code());
1710 ASSERT(kind == Snapshot::kFull);
1711
1712 // Write out the serialization header value for this object.
1713 writer->WriteInlinedObjectHeader(object_id);
1714
1715 // Write out the class and tags information.
1716 writer->WriteVMIsolateObject(kMegamorphicCacheCid);
1717 writer->WriteTags(writer->GetObjectTags(this));
1718
1719 // Write out all the non object fields.
1720 writer->Write<int32_t>(ptr()->filled_entry_count_);
1721
1722 // Write out all the object pointer fields.
1723 SnapshotWriterVisitor visitor(writer);
1724 visitor.VisitPointers(from(), to());
1515 } 1725 }
1516 1726
1517 1727
1518 RawSubtypeTestCache* SubtypeTestCache::ReadFrom(SnapshotReader* reader, 1728 RawSubtypeTestCache* SubtypeTestCache::ReadFrom(SnapshotReader* reader,
1519 intptr_t object_id, 1729 intptr_t object_id,
1520 intptr_t tags, 1730 intptr_t tags,
1521 Snapshot::Kind kind) { 1731 Snapshot::Kind kind) {
1522 UNREACHABLE(); 1732 UNREACHABLE(); // Untested.
1523 return NULL; 1733 ASSERT(reader->snapshot_code());
1734 ASSERT(kind == Snapshot::kFull);
1735
1736 SubtypeTestCache& result =
1737 SubtypeTestCache::ZoneHandle(reader->zone(),
1738 NEW_OBJECT(SubtypeTestCache));
1739 reader->AddBackRef(object_id, &result, kIsDeserialized);
1740
1741 // Set all the object fields.
1742 // TODO(5411462): Need to assert No GC can happen here, even though
1743 // allocations may happen.
1744 (*reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsReference);
1745 result.StorePointer(&result.raw_ptr()->cache_,
1746 reader->ArrayHandle()->raw());
siva 2015/08/19 19:40:02 This is being read as a reference but the write si
rmacnak 2015/08/19 22:33:54 Switched write to reference.
1747
1748 return result.raw();
1524 } 1749 }
1525 1750
1526 1751
1527 void RawSubtypeTestCache::WriteTo(SnapshotWriter* writer, 1752 void RawSubtypeTestCache::WriteTo(SnapshotWriter* writer,
1528 intptr_t object_id, 1753 intptr_t object_id,
1529 Snapshot::Kind kind) { 1754 Snapshot::Kind kind) {
1530 UNREACHABLE(); 1755 ASSERT(writer->snapshot_code());
1756 ASSERT(kind == Snapshot::kFull);
1757
1758 // Write out the serialization header value for this object.
1759 writer->WriteInlinedObjectHeader(object_id);
1760
1761 // Write out the class and tags information.
1762 writer->WriteVMIsolateObject(kSubtypeTestCacheCid);
1763 writer->WriteTags(writer->GetObjectTags(this));
1764
1765 // Write out all the object pointer fields.
1766 writer->WriteObjectImpl(ptr()->cache_, kAsInlinedObject);
1531 } 1767 }
1532 1768
1533 1769
1534 RawError* Error::ReadFrom(SnapshotReader* reader, 1770 RawError* Error::ReadFrom(SnapshotReader* reader,
1535 intptr_t object_id, 1771 intptr_t object_id,
1536 intptr_t tags, 1772 intptr_t tags,
1537 Snapshot::Kind kind) { 1773 Snapshot::Kind kind) {
1538 UNREACHABLE(); 1774 UNREACHABLE();
1539 return Error::null(); // Error is an abstract class. 1775 return Error::null(); // Error is an abstract class.
1540 } 1776 }
(...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 // We do not allow objects with native fields in an isolate message. 3245 // We do not allow objects with native fields in an isolate message.
3010 writer->SetWriteException(Exceptions::kArgument, 3246 writer->SetWriteException(Exceptions::kArgument,
3011 "Illegal argument in isolate message" 3247 "Illegal argument in isolate message"
3012 " : (object is a UserTag)"); 3248 " : (object is a UserTag)");
3013 } else { 3249 } else {
3014 UNREACHABLE(); 3250 UNREACHABLE();
3015 } 3251 }
3016 } 3252 }
3017 3253
3018 } // namespace dart 3254 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/snapshot.h » ('j') | runtime/vm/snapshot.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698