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

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

Issue 1318803002: Toward precompiled snapshots. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 (*reader->PassiveObjectHandle()) = 700 (*reader->PassiveObjectHandle()) =
701 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset)); 701 reader->ReadObjectImpl(kAsReference, object_id, (i + from_offset));
702 func.StorePointer((func.raw()->from() + i), 702 func.StorePointer((func.raw()->from() + i),
703 reader->PassiveObjectHandle()->raw()); 703 reader->PassiveObjectHandle()->raw());
704 } 704 }
705 705
706 if (!reader->snapshot_code()) { 706 if (!reader->snapshot_code()) {
707 // Initialize all fields that are not part of the snapshot. 707 // Initialize all fields that are not part of the snapshot.
708 func.ClearICDataArray(); 708 func.ClearICDataArray();
709 func.ClearCode(); 709 func.ClearCode();
710 } else {
711 // TODO(rmacnak): Fix entry_point_.
710 } 712 }
711 return func.raw(); 713 return func.raw();
712 } 714 }
713 715
714 716
715 void RawFunction::WriteTo(SnapshotWriter* writer, 717 void RawFunction::WriteTo(SnapshotWriter* writer,
716 intptr_t object_id, 718 intptr_t object_id,
717 Snapshot::Kind kind) { 719 Snapshot::Kind kind) {
718 ASSERT(writer != NULL); 720 ASSERT(writer != NULL);
719 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull)); 721 ASSERT((kind == Snapshot::kScript) || (kind == Snapshot::kFull));
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 // Write out all the object pointer fields. 1183 // Write out all the object pointer fields.
1182 SnapshotWriterVisitor visitor(writer); 1184 SnapshotWriterVisitor visitor(writer);
1183 visitor.VisitPointers(from(), to()); 1185 visitor.VisitPointers(from(), to());
1184 } 1186 }
1185 1187
1186 1188
1187 RawCode* Code::ReadFrom(SnapshotReader* reader, 1189 RawCode* Code::ReadFrom(SnapshotReader* reader,
1188 intptr_t object_id, 1190 intptr_t object_id,
1189 intptr_t tags, 1191 intptr_t tags,
1190 Snapshot::Kind kind) { 1192 Snapshot::Kind kind) {
1191 UNREACHABLE(); // Untested.
1192 ASSERT(reader->snapshot_code()); 1193 ASSERT(reader->snapshot_code());
1193 ASSERT(kind == Snapshot::kFull); 1194 ASSERT(kind == Snapshot::kFull);
1194 1195
1195 Code& result = Code::ZoneHandle(reader->zone(), NEW_OBJECT_WITH_LEN(Code, 0)); 1196 Code& result = Code::ZoneHandle(reader->zone(), NEW_OBJECT_WITH_LEN(Code, 0));
1196 reader->AddBackRef(object_id, &result, kIsDeserialized); 1197 reader->AddBackRef(object_id, &result, kIsDeserialized);
1197 1198
1198 result.set_compile_timestamp(reader->Read<int64_t>()); 1199 result.set_compile_timestamp(reader->Read<int64_t>());
1199 result.set_state_bits(reader->Read<int32_t>()); 1200 result.set_state_bits(reader->Read<int32_t>());
1200 result.set_entry_patch_pc_offset(reader->Read<int32_t>()); 1201 result.set_entry_patch_pc_offset(reader->Read<int32_t>());
1201 result.set_patch_code_pc_offset(reader->Read<int32_t>()); 1202 result.set_patch_code_pc_offset(reader->Read<int32_t>());
1202 result.set_lazy_deopt_pc_offset(reader->Read<int32_t>()); 1203 result.set_lazy_deopt_pc_offset(reader->Read<int32_t>());
1203 1204
1204 // Set all the object fields. 1205 // Set all the object fields.
1205 // TODO(5411462): Need to assert No GC can happen here, even though 1206 // TODO(5411462): Need to assert No GC can happen here, even though
1206 // allocations may happen. 1207 // allocations may happen.
1207 intptr_t num_flds = (result.raw()->to() - result.raw()->from()); 1208 intptr_t num_flds = (result.raw()->to() - result.raw()->from());
1208 for (intptr_t i = 0; i <= num_flds; i++) { 1209 for (intptr_t i = 0; i <= num_flds; i++) {
1209 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); 1210 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
1210 result.StorePointer((result.raw()->from() + i), 1211 result.StorePointer((result.raw()->from() + i),
1211 reader->PassiveObjectHandle()->raw()); 1212 reader->PassiveObjectHandle()->raw());
1212 } 1213 }
1213 1214
1215 // TODO(rmacnak): Fix entry_point_.
1216
1214 return result.raw(); 1217 return result.raw();
1215 } 1218 }
1216 1219
1217 1220
1218 void RawCode::WriteTo(SnapshotWriter* writer, 1221 void RawCode::WriteTo(SnapshotWriter* writer,
1219 intptr_t object_id, 1222 intptr_t object_id,
1220 Snapshot::Kind kind) { 1223 Snapshot::Kind kind) {
1221 ASSERT(writer->snapshot_code()); 1224 ASSERT(writer->snapshot_code());
1222 ASSERT(kind == Snapshot::kFull); 1225 ASSERT(kind == Snapshot::kFull);
1223 1226
(...skipping 21 matching lines...) Expand all
1245 // Write out all the object pointer fields. 1248 // Write out all the object pointer fields.
1246 SnapshotWriterVisitor visitor(writer); 1249 SnapshotWriterVisitor visitor(writer);
1247 visitor.VisitPointers(from(), to()); 1250 visitor.VisitPointers(from(), to());
1248 } 1251 }
1249 1252
1250 1253
1251 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, 1254 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader,
1252 intptr_t object_id, 1255 intptr_t object_id,
1253 intptr_t tags, 1256 intptr_t tags,
1254 Snapshot::Kind kind) { 1257 Snapshot::Kind kind) {
1255 UNREACHABLE(); // Untested.
1256 ASSERT(reader->snapshot_code()); 1258 ASSERT(reader->snapshot_code());
1257 ASSERT(kind == Snapshot::kFull); 1259 ASSERT(kind == Snapshot::kFull);
1258 1260
1259 intptr_t id = reader->Read<int32_t>(); 1261 intptr_t full_tags = static_cast<uword>(reader->Read<intptr_t>());
1262 intptr_t offset = reader->Read<int32_t>();
1260 Instructions& result = 1263 Instructions& result =
1261 Instructions::ZoneHandle(reader->zone(), 1264 Instructions::ZoneHandle(reader->zone(),
1262 reader->GetInstructionsById(id)); 1265 reader->GetInstructionsAt(offset, full_tags));
1263 reader->AddBackRef(object_id, &result, kIsDeserialized); 1266 reader->AddBackRef(object_id, &result, kIsDeserialized);
1267
1268 {
1269 // TODO(rmacnak): Drop after calling convention change.
1270 Code::CheckedHandle(reader->ReadObjectImpl(kAsReference));
1271 ObjectPool::CheckedHandle(reader->ReadObjectImpl(kAsReference));
1272 }
1273
1264 return result.raw(); 1274 return result.raw();
1265 } 1275 }
1266 1276
1267 1277
1268 void RawInstructions::WriteTo(SnapshotWriter* writer, 1278 void RawInstructions::WriteTo(SnapshotWriter* writer,
1269 intptr_t object_id, 1279 intptr_t object_id,
1270 Snapshot::Kind kind) { 1280 Snapshot::Kind kind) {
1271 ASSERT(writer->snapshot_code()); 1281 ASSERT(writer->snapshot_code());
1272 ASSERT(kind == Snapshot::kFull); 1282 ASSERT(kind == Snapshot::kFull);
1273 1283
1274 { 1284 {
1275 // TODO(rmacnak): Drop after calling convention change. 1285 // TODO(rmacnak): Drop after calling convention change.
1276 writer->WriteInlinedObjectHeader(object_id); 1286 writer->WriteInlinedObjectHeader(object_id);
1277 writer->WriteVMIsolateObject(kInstructionsCid); 1287 writer->WriteVMIsolateObject(kInstructionsCid);
1278 writer->WriteTags(writer->GetObjectTags(this)); 1288 writer->WriteTags(writer->GetObjectTags(this));
1289 }
1290
1291 writer->Write<intptr_t>(writer->GetObjectTags(this)); // For sanity check.
1292
1293 // Temporarily restore the object header for writing to the text section.
1294 // TODO(asiva): Don't mutate object headers during serialization.
1295 uword object_tags = writer->GetObjectTags(this);
1296 uword snapshot_tags = ptr()->tags_;
1297 ptr()->tags_ = object_tags;
1298 writer->Write<int32_t>(writer->GetInstructionsId(this));
1299 ptr()->tags_ = snapshot_tags;
1300
1301 {
1302 // TODO(rmacnak): Drop after calling convention change.
1279 writer->WriteObjectImpl(ptr()->code_, kAsReference); 1303 writer->WriteObjectImpl(ptr()->code_, kAsReference);
1280 writer->WriteObjectImpl(ptr()->object_pool_, kAsReference); 1304 writer->WriteObjectImpl(ptr()->object_pool_, kAsReference);
1281 } 1305 }
1282
1283 writer->Write<int32_t>(writer->GetInstructionsId(this));
1284 } 1306 }
1285 1307
1286 1308
1287 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, 1309 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader,
1288 intptr_t object_id, 1310 intptr_t object_id,
1289 intptr_t tags, 1311 intptr_t tags,
1290 Snapshot::Kind kind) { 1312 Snapshot::Kind kind) {
1291 UNREACHABLE(); // Untested.
1292 ASSERT(reader->snapshot_code()); 1313 ASSERT(reader->snapshot_code());
1293 ASSERT(kind == Snapshot::kFull); 1314 ASSERT(kind == Snapshot::kFull);
1294 1315
1295 intptr_t length = reader->Read<intptr_t>(); 1316 intptr_t length = reader->Read<intptr_t>();
1296 1317
1297 ObjectPool& result = 1318 ObjectPool& result =
1298 ObjectPool::ZoneHandle(reader->zone(), 1319 ObjectPool::ZoneHandle(reader->zone(),
1299 NEW_OBJECT_WITH_LEN(ObjectPool, length)); 1320 NEW_OBJECT_WITH_LEN(ObjectPool, length));
1300 reader->AddBackRef(object_id, &result, kIsDeserialized); 1321 reader->AddBackRef(object_id, &result, kIsDeserialized);
1301 1322
1302 RawTypedData* info_array = result.raw_ptr()->info_array_->ptr(); 1323 const TypedData& info_array =
1324 TypedData::Handle(reader->NewTypedData(kTypedDataInt8ArrayCid, length));
1325 result.set_info_array(info_array);
1303 1326
1304 // Set all the object fields. 1327 NoSafepointScope no_safepoint;
1305 // TODO(5411462): Need to assert No GC can happen here, even though
1306 // allocations may happen.
1307 for (intptr_t i = 0; i < length; i++) { 1328 for (intptr_t i = 0; i < length; i++) {
1308 ObjectPool::EntryType entry_type = 1329 ObjectPool::EntryType entry_type =
1309 static_cast<ObjectPool::EntryType>(reader->Read<uint8_t>()); 1330 static_cast<ObjectPool::EntryType>(reader->Read<int8_t>());
1310 info_array->data()[i] = entry_type; 1331 *reinterpret_cast<int8_t*>(info_array.DataAddr(i)) = entry_type;
1311 switch (entry_type) { 1332 switch (entry_type) {
1312 case ObjectPool::kTaggedObject: { 1333 case ObjectPool::kTaggedObject: {
1313 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference); 1334 (*reader->PassiveObjectHandle()) = reader->ReadObjectImpl(kAsReference);
1314 result.SetObjectAt(i, *(reader->PassiveObjectHandle())); 1335 result.SetObjectAt(i, *(reader->PassiveObjectHandle()));
1315 break; 1336 break;
1316 } 1337 }
1317 case ObjectPool::kImmediate: { 1338 case ObjectPool::kImmediate: {
1318 intptr_t raw_value = reader->Read<intptr_t>(); 1339 intptr_t raw_value = reader->Read<intptr_t>();
1319 result.SetRawValueAt(i, raw_value); 1340 result.SetRawValueAt(i, raw_value);
1320 break; 1341 break;
(...skipping 27 matching lines...) Expand all
1348 writer->WriteTags(writer->GetObjectTags(this)); 1369 writer->WriteTags(writer->GetObjectTags(this));
1349 1370
1350 intptr_t length = ptr()->length_; 1371 intptr_t length = ptr()->length_;
1351 RawTypedData* info_array = ptr()->info_array_->ptr(); 1372 RawTypedData* info_array = ptr()->info_array_->ptr();
1352 ASSERT(info_array != TypedData::null()); 1373 ASSERT(info_array != TypedData::null());
1353 1374
1354 writer->Write<intptr_t>(length); 1375 writer->Write<intptr_t>(length);
1355 for (intptr_t i = 0; i < length; i++) { 1376 for (intptr_t i = 0; i < length; i++) {
1356 ObjectPool::EntryType entry_type = 1377 ObjectPool::EntryType entry_type =
1357 static_cast<ObjectPool::EntryType>(info_array->data()[i]); 1378 static_cast<ObjectPool::EntryType>(info_array->data()[i]);
1358 writer->Write<uint8_t>(entry_type); 1379 writer->Write<int8_t>(entry_type);
1359 Entry& entry = ptr()->data()[i]; 1380 Entry& entry = ptr()->data()[i];
1360 switch (entry_type) { 1381 switch (entry_type) {
1361 case ObjectPool::kTaggedObject: 1382 case ObjectPool::kTaggedObject:
1362 writer->WriteObjectImpl(entry.raw_obj_, kAsReference); 1383 writer->WriteObjectImpl(entry.raw_obj_, kAsReference);
1363 break; 1384 break;
1364 case ObjectPool::kImmediate: 1385 case ObjectPool::kImmediate:
1365 writer->Write<intptr_t>(entry.raw_value_); 1386 writer->Write<intptr_t>(entry.raw_value_);
1366 break; 1387 break;
1367 case ObjectPool::kExternalLabel: 1388 case ObjectPool::kExternalLabel:
1368 // TODO(rmacnak): Write symbolically. 1389 // TODO(rmacnak): Write symbolically.
1369 writer->Write<intptr_t>(entry.raw_value_); 1390 writer->Write<intptr_t>(entry.raw_value_);
1370 break; 1391 break;
1371 default: 1392 default:
1372 UNREACHABLE(); 1393 UNREACHABLE();
1373 } 1394 }
1374 } 1395 }
1375 } 1396 }
1376 1397
1377 1398
1378 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader, 1399 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader,
1379 intptr_t object_id, 1400 intptr_t object_id,
1380 intptr_t tags, 1401 intptr_t tags,
1381 Snapshot::Kind kind) { 1402 Snapshot::Kind kind) {
1382 UNREACHABLE(); // Untested.
1383 ASSERT(reader->snapshot_code()); 1403 ASSERT(reader->snapshot_code());
1404 ASSERT(kind == Snapshot::kFull);
1384 1405
1385 const int32_t length = reader->Read<int32_t>(); 1406 const int32_t length = reader->Read<int32_t>();
1386 PcDescriptors& result = PcDescriptors::ZoneHandle(reader->zone(), 1407 PcDescriptors& result =
1387 PcDescriptors::New(length)); 1408 PcDescriptors::ZoneHandle(reader->zone(),
1409 NEW_OBJECT_WITH_LEN(PcDescriptors, length));
1388 reader->AddBackRef(object_id, &result, kIsDeserialized); 1410 reader->AddBackRef(object_id, &result, kIsDeserialized);
1389 1411
1390 if (result.Length() > 0) { 1412 if (result.Length() > 0) {
1391 NoSafepointScope no_safepoint; 1413 NoSafepointScope no_safepoint;
1392 intptr_t len = result.Length(); 1414 intptr_t len = result.Length();
1393 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); 1415 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data());
1394 reader->ReadBytes(data, len); 1416 reader->ReadBytes(data, len);
1395 } 1417 }
1396 1418
1397 return result.raw(); 1419 return result.raw();
1398 } 1420 }
1399 1421
1400 1422
1401 void RawPcDescriptors::WriteTo(SnapshotWriter* writer, 1423 void RawPcDescriptors::WriteTo(SnapshotWriter* writer,
1402 intptr_t object_id, 1424 intptr_t object_id,
1403 Snapshot::Kind kind) { 1425 Snapshot::Kind kind) {
1404 ASSERT(writer->snapshot_code()); 1426 ASSERT(writer->snapshot_code());
1427 ASSERT(kind == Snapshot::kFull);
1405 1428
1406 // Write out the serialization header value for this object. 1429 // Write out the serialization header value for this object.
1407 writer->WriteInlinedObjectHeader(object_id); 1430 writer->WriteInlinedObjectHeader(object_id);
1408 writer->WriteIndexedObject(kPcDescriptorsCid); 1431 writer->WriteIndexedObject(kPcDescriptorsCid);
1409 writer->WriteTags(writer->GetObjectTags(this)); 1432 writer->WriteTags(writer->GetObjectTags(this));
1410 writer->Write<int32_t>(ptr()->length_); 1433 writer->Write<int32_t>(ptr()->length_);
1411 if (ptr()->length_ > 0) { 1434 if (ptr()->length_ > 0) {
1412 intptr_t len = ptr()->length_; 1435 intptr_t len = ptr()->length_;
1413 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); 1436 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data());
1414 writer->WriteBytes(data, len); 1437 writer->WriteBytes(data, len);
1415 } 1438 }
1416 } 1439 }
1417 1440
1418 1441
1419 RawStackmap* Stackmap::ReadFrom(SnapshotReader* reader, 1442 RawStackmap* Stackmap::ReadFrom(SnapshotReader* reader,
1420 intptr_t object_id, 1443 intptr_t object_id,
1421 intptr_t tags, 1444 intptr_t tags,
1422 Snapshot::Kind kind) { 1445 Snapshot::Kind kind) {
1423 UNREACHABLE(); // Untested.
1424 ASSERT(reader->snapshot_code()); 1446 ASSERT(reader->snapshot_code());
1447 ASSERT(kind == Snapshot::kFull);
1425 1448
1426 const int32_t length = reader->Read<int32_t>(); 1449 const int32_t length = reader->Read<int32_t>();
1427 const int32_t register_bit_count = reader->Read<int32_t>();
1428 const uword pc_offset = reader->Read<uint32_t>();
1429
1430 Stackmap& result = 1450 Stackmap& result =
1431 Stackmap::ZoneHandle(reader->zone(), 1451 Stackmap::ZoneHandle(reader->zone(),
1432 Stackmap::New(length, register_bit_count, pc_offset)); 1452 reader->NewStackmap(length));
1433 reader->AddBackRef(object_id, &result, kIsDeserialized); 1453 reader->AddBackRef(object_id, &result, kIsDeserialized);
1434 1454
1435 if (result.Length() > 0) { 1455 result.SetRegisterBitCount(reader->Read<int32_t>());
1456 result.SetPcOffset(reader->Read<uint32_t>());
1457
1458 if (length > 0) {
1436 NoSafepointScope no_safepoint; 1459 NoSafepointScope no_safepoint;
1437 intptr_t len = (result.Length() + 7) / 8; 1460 intptr_t len = (result.Length() + 7) / 8;
1438 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); 1461 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data());
1439 reader->ReadBytes(data, len); 1462 reader->ReadBytes(data, len);
1440 } 1463 }
1441 1464
1442 return result.raw(); 1465 return result.raw();
1443 } 1466 }
1444 1467
1445 1468
1446 void RawStackmap::WriteTo(SnapshotWriter* writer, 1469 void RawStackmap::WriteTo(SnapshotWriter* writer,
1447 intptr_t object_id, 1470 intptr_t object_id,
1448 Snapshot::Kind kind) { 1471 Snapshot::Kind kind) {
1449 ASSERT(writer->snapshot_code()); 1472 ASSERT(writer->snapshot_code());
1473 ASSERT(kind == Snapshot::kFull);
1450 1474
1451 // Write out the serialization header value for this object. 1475 // Write out the serialization header value for this object.
1452 writer->WriteInlinedObjectHeader(object_id); 1476 writer->WriteInlinedObjectHeader(object_id);
1453 writer->WriteIndexedObject(kStackmapCid); 1477 writer->WriteIndexedObject(kStackmapCid);
1454 writer->WriteTags(writer->GetObjectTags(this)); 1478 writer->WriteTags(writer->GetObjectTags(this));
1479
1455 writer->Write<int32_t>(ptr()->length_); 1480 writer->Write<int32_t>(ptr()->length_);
1456 writer->Write<int32_t>(ptr()->register_bit_count_); 1481 writer->Write<int32_t>(ptr()->register_bit_count_);
1457 writer->Write<uint32_t>(ptr()->pc_offset_); 1482 writer->Write<uint32_t>(ptr()->pc_offset_);
1458 if (ptr()->length_ > 0) { 1483 if (ptr()->length_ > 0) {
1459 intptr_t len = (ptr()->length_ + 7) / 8; 1484 intptr_t len = (ptr()->length_ + 7) / 8;
1460 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); 1485 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data());
1461 writer->WriteBytes(data, len); 1486 writer->WriteBytes(data, len);
1462 } 1487 }
1463 } 1488 }
1464 1489
1465 1490
1466 RawLocalVarDescriptors* LocalVarDescriptors::ReadFrom(SnapshotReader* reader, 1491 RawLocalVarDescriptors* LocalVarDescriptors::ReadFrom(SnapshotReader* reader,
1467 intptr_t object_id, 1492 intptr_t object_id,
1468 intptr_t tags, 1493 intptr_t tags,
1469 Snapshot::Kind kind) { 1494 Snapshot::Kind kind) {
1470 UNREACHABLE(); // Untested.
1471 ASSERT(reader->snapshot_code()); 1495 ASSERT(reader->snapshot_code());
1496 ASSERT(kind == Snapshot::kFull);
1472 1497
1473 const int32_t num_entries = reader->Read<int32_t>(); 1498 const int32_t num_entries = reader->Read<int32_t>();
1474 1499
1475 LocalVarDescriptors& result = 1500 LocalVarDescriptors& result =
1476 LocalVarDescriptors::ZoneHandle(reader->zone(), 1501 LocalVarDescriptors::ZoneHandle(reader->zone(),
1477 LocalVarDescriptors::New(num_entries)); 1502 NEW_OBJECT_WITH_LEN(LocalVarDescriptors,
1503 num_entries));
1478 reader->AddBackRef(object_id, &result, kIsDeserialized); 1504 reader->AddBackRef(object_id, &result, kIsDeserialized);
1479 1505
1480 for (intptr_t i = 0; i < num_entries; i++) { 1506 for (intptr_t i = 0; i < num_entries; i++) {
1481 (*reader->StringHandle()) ^= reader->ReadObjectImpl(kAsReference); 1507 (*reader->StringHandle()) ^= reader->ReadObjectImpl(kAsReference);
1482 result.StorePointer(result.raw()->nameAddrAt(i), 1508 result.StorePointer(result.raw()->nameAddrAt(i),
1483 reader->StringHandle()->raw()); 1509 reader->StringHandle()->raw());
1484 } 1510 }
1485 1511
1486 if (num_entries > 0) { 1512 if (num_entries > 0) {
1487 NoSafepointScope no_safepoint; 1513 NoSafepointScope no_safepoint;
1488 intptr_t len = num_entries * sizeof(RawLocalVarDescriptors::VarInfo); 1514 intptr_t len = num_entries * sizeof(RawLocalVarDescriptors::VarInfo);
1489 uint8_t* data = result.UnsafeMutableNonPointer( 1515 uint8_t* data = result.UnsafeMutableNonPointer(
1490 reinterpret_cast<const uint8_t*>(result.raw()->data())); 1516 reinterpret_cast<const uint8_t*>(result.raw()->data()));
1491 reader->ReadBytes(data, len); 1517 reader->ReadBytes(data, len);
1492 } 1518 }
1493 1519
1494 return result.raw(); 1520 return result.raw();
1495 } 1521 }
1496 1522
1497 1523
1498 void RawLocalVarDescriptors::WriteTo(SnapshotWriter* writer, 1524 void RawLocalVarDescriptors::WriteTo(SnapshotWriter* writer,
1499 intptr_t object_id, 1525 intptr_t object_id,
1500 Snapshot::Kind kind) { 1526 Snapshot::Kind kind) {
1501 ASSERT(writer->snapshot_code()); 1527 ASSERT(writer->snapshot_code());
1528 ASSERT(kind == Snapshot::kFull);
1502 1529
1503 // Write out the serialization header value for this object. 1530 // Write out the serialization header value for this object.
1504 writer->WriteInlinedObjectHeader(object_id); 1531 writer->WriteInlinedObjectHeader(object_id);
1505 writer->WriteIndexedObject(kLocalVarDescriptorsCid); 1532 writer->WriteIndexedObject(kLocalVarDescriptorsCid);
1506 writer->WriteTags(writer->GetObjectTags(this)); 1533 writer->WriteTags(writer->GetObjectTags(this));
1507 writer->Write<int32_t>(ptr()->num_entries_); 1534 writer->Write<int32_t>(ptr()->num_entries_);
1508 for (intptr_t i = 0; i < ptr()->num_entries_; i++) { 1535 for (intptr_t i = 0; i < ptr()->num_entries_; i++) {
1509 writer->WriteObjectImpl(ptr()->names()[i], kAsInlinedObject); 1536 writer->WriteObjectImpl(ptr()->names()[i], kAsInlinedObject);
1510 } 1537 }
1511 if (ptr()->num_entries_ > 0) { 1538 if (ptr()->num_entries_ > 0) {
1512 intptr_t len = ptr()->num_entries_ * sizeof(VarInfo); 1539 intptr_t len = ptr()->num_entries_ * sizeof(VarInfo);
1513 uint8_t* data = reinterpret_cast<uint8_t*>(this->data()); 1540 uint8_t* data = reinterpret_cast<uint8_t*>(this->data());
1514 writer->WriteBytes(data, len); 1541 writer->WriteBytes(data, len);
1515 } 1542 }
1516 } 1543 }
1517 1544
1518 1545
1519 RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader, 1546 RawExceptionHandlers* ExceptionHandlers::ReadFrom(SnapshotReader* reader,
1520 intptr_t object_id, 1547 intptr_t object_id,
1521 intptr_t tags, 1548 intptr_t tags,
1522 Snapshot::Kind kind) { 1549 Snapshot::Kind kind) {
1523 UNREACHABLE(); // Untested.
1524 ASSERT(reader->snapshot_code()); 1550 ASSERT(reader->snapshot_code());
1551 ASSERT(kind == Snapshot::kFull);
1525 1552
1526 // handled_types_data. 1553 const int32_t num_entries = reader->Read<int32_t>();
1527 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
1528
1529 ExceptionHandlers& result = 1554 ExceptionHandlers& result =
1530 ExceptionHandlers::ZoneHandle(reader->zone(), 1555 ExceptionHandlers::ZoneHandle(reader->zone(),
1531 ExceptionHandlers::New(*reader->ArrayHandle())); 1556 NEW_OBJECT_WITH_LEN(ExceptionHandlers,
1557 num_entries));
1532 reader->AddBackRef(object_id, &result, kIsDeserialized); 1558 reader->AddBackRef(object_id, &result, kIsDeserialized);
1533 1559
1534 if (result.num_entries() > 0) { 1560 if (result.num_entries() > 0) {
1535 NoSafepointScope no_safepoint; 1561 NoSafepointScope no_safepoint;
1536 const intptr_t len = 1562 const intptr_t len =
1537 result.num_entries() * sizeof(RawExceptionHandlers::HandlerInfo); 1563 result.num_entries() * sizeof(RawExceptionHandlers::HandlerInfo);
1538 uint8_t* data = result.UnsafeMutableNonPointer( 1564 uint8_t* data = result.UnsafeMutableNonPointer(
1539 reinterpret_cast<const uint8_t*>(result.raw_ptr()->data())); 1565 reinterpret_cast<const uint8_t*>(result.raw_ptr()->data()));
1540 reader->ReadBytes(data, len); 1566 reader->ReadBytes(data, len);
1541 } 1567 }
1542 1568
1569 *(reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsInlinedObject);
1570 result.StorePointer(&result.raw_ptr()->handled_types_data_,
1571 reader->ArrayHandle()->raw());
1572
1543 return result.raw(); 1573 return result.raw();
1544 } 1574 }
1545 1575
1546 1576
1547 void RawExceptionHandlers::WriteTo(SnapshotWriter* writer, 1577 void RawExceptionHandlers::WriteTo(SnapshotWriter* writer,
1548 intptr_t object_id, 1578 intptr_t object_id,
1549 Snapshot::Kind kind) { 1579 Snapshot::Kind kind) {
1550 ASSERT(writer->snapshot_code()); 1580 ASSERT(writer->snapshot_code());
1581 ASSERT(kind == Snapshot::kFull);
1551 1582
1552 // Write out the serialization header value for this object. 1583 // Write out the serialization header value for this object.
1553 writer->WriteInlinedObjectHeader(object_id); 1584 writer->WriteInlinedObjectHeader(object_id);
1554 writer->WriteIndexedObject(kExceptionHandlersCid); 1585 writer->WriteIndexedObject(kExceptionHandlersCid);
1555 writer->WriteTags(writer->GetObjectTags(this)); 1586 writer->WriteTags(writer->GetObjectTags(this));
1556 writer->WriteObjectImpl(ptr()->handled_types_data_, kAsInlinedObject); 1587 writer->Write<int32_t>(ptr()->num_entries_);
1557 1588
1558 if (ptr()->num_entries_ > 0) { 1589 if (ptr()->num_entries_ > 0) {
1559 intptr_t len = ptr()->num_entries_ * sizeof(HandlerInfo); 1590 intptr_t len = ptr()->num_entries_ * sizeof(HandlerInfo);
1560 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); 1591 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data());
1561 writer->WriteBytes(data, len); 1592 writer->WriteBytes(data, len);
1562 } 1593 }
1594
1595 writer->WriteObjectImpl(ptr()->handled_types_data_, kAsInlinedObject);
1563 } 1596 }
1564 1597
1565 1598
1566 RawContext* Context::ReadFrom(SnapshotReader* reader, 1599 RawContext* Context::ReadFrom(SnapshotReader* reader,
1567 intptr_t object_id, 1600 intptr_t object_id,
1568 intptr_t tags, 1601 intptr_t tags,
1569 Snapshot::Kind kind) { 1602 Snapshot::Kind kind) {
1570 ASSERT(reader != NULL); 1603 ASSERT(reader != NULL);
1571 1604
1572 // Allocate context object. 1605 // Allocate context object.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 intptr_t object_id, 1661 intptr_t object_id,
1629 Snapshot::Kind kind) { 1662 Snapshot::Kind kind) {
1630 UNREACHABLE(); 1663 UNREACHABLE();
1631 } 1664 }
1632 1665
1633 1666
1634 RawICData* ICData::ReadFrom(SnapshotReader* reader, 1667 RawICData* ICData::ReadFrom(SnapshotReader* reader,
1635 intptr_t object_id, 1668 intptr_t object_id,
1636 intptr_t tags, 1669 intptr_t tags,
1637 Snapshot::Kind kind) { 1670 Snapshot::Kind kind) {
1638 UNREACHABLE(); // Untested.
1639 ASSERT(reader->snapshot_code()); 1671 ASSERT(reader->snapshot_code());
1640 ASSERT(kind == Snapshot::kFull); 1672 ASSERT(kind == Snapshot::kFull);
1641 1673
1642 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData)); 1674 ICData& result = ICData::ZoneHandle(reader->zone(), NEW_OBJECT(ICData));
1643 reader->AddBackRef(object_id, &result, kIsDeserialized); 1675 reader->AddBackRef(object_id, &result, kIsDeserialized);
1644 1676
1645 result.set_deopt_id(reader->Read<int32_t>()); 1677 result.set_deopt_id(reader->Read<int32_t>());
1646 result.set_state_bits(reader->Read<uint32_t>()); 1678 result.set_state_bits(reader->Read<uint32_t>());
1647 1679
1648 // Set all the object fields. 1680 // Set all the object fields.
(...skipping 30 matching lines...) Expand all
1679 // Write out all the object pointer fields. 1711 // Write out all the object pointer fields.
1680 SnapshotWriterVisitor visitor(writer); 1712 SnapshotWriterVisitor visitor(writer);
1681 visitor.VisitPointers(from(), to()); 1713 visitor.VisitPointers(from(), to());
1682 } 1714 }
1683 1715
1684 1716
1685 RawMegamorphicCache* MegamorphicCache::ReadFrom(SnapshotReader* reader, 1717 RawMegamorphicCache* MegamorphicCache::ReadFrom(SnapshotReader* reader,
1686 intptr_t object_id, 1718 intptr_t object_id,
1687 intptr_t tags, 1719 intptr_t tags,
1688 Snapshot::Kind kind) { 1720 Snapshot::Kind kind) {
1689 UNREACHABLE(); // Untested.
1690 ASSERT(reader->snapshot_code()); 1721 ASSERT(reader->snapshot_code());
1691 ASSERT(kind == Snapshot::kFull); 1722 ASSERT(kind == Snapshot::kFull);
1692 1723
1693 MegamorphicCache& result = 1724 MegamorphicCache& result =
1694 MegamorphicCache::ZoneHandle(reader->zone(), 1725 MegamorphicCache::ZoneHandle(reader->zone(),
1695 NEW_OBJECT(MegamorphicCache)); 1726 NEW_OBJECT(MegamorphicCache));
1696 reader->AddBackRef(object_id, &result, kIsDeserialized); 1727 reader->AddBackRef(object_id, &result, kIsDeserialized);
1697 1728
1698 result.set_filled_entry_count(reader->Read<int32_t>()); 1729 result.set_filled_entry_count(reader->Read<int32_t>());
1699 1730
(...skipping 30 matching lines...) Expand all
1730 // Write out all the object pointer fields. 1761 // Write out all the object pointer fields.
1731 SnapshotWriterVisitor visitor(writer); 1762 SnapshotWriterVisitor visitor(writer);
1732 visitor.VisitPointers(from(), to()); 1763 visitor.VisitPointers(from(), to());
1733 } 1764 }
1734 1765
1735 1766
1736 RawSubtypeTestCache* SubtypeTestCache::ReadFrom(SnapshotReader* reader, 1767 RawSubtypeTestCache* SubtypeTestCache::ReadFrom(SnapshotReader* reader,
1737 intptr_t object_id, 1768 intptr_t object_id,
1738 intptr_t tags, 1769 intptr_t tags,
1739 Snapshot::Kind kind) { 1770 Snapshot::Kind kind) {
1740 UNREACHABLE(); // Untested.
1741 ASSERT(reader->snapshot_code()); 1771 ASSERT(reader->snapshot_code());
1742 ASSERT(kind == Snapshot::kFull); 1772 ASSERT(kind == Snapshot::kFull);
1743 1773
1744 SubtypeTestCache& result = 1774 SubtypeTestCache& result =
1745 SubtypeTestCache::ZoneHandle(reader->zone(), 1775 SubtypeTestCache::ZoneHandle(reader->zone(),
1746 NEW_OBJECT(SubtypeTestCache)); 1776 NEW_OBJECT(SubtypeTestCache));
1747 reader->AddBackRef(object_id, &result, kIsDeserialized); 1777 reader->AddBackRef(object_id, &result, kIsDeserialized);
1748 1778
1749 // Set all the object fields. 1779 // Set all the object fields.
1750 // TODO(5411462): Need to assert No GC can happen here, even though 1780 // TODO(5411462): Need to assert No GC can happen here, even though
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
2532 2562
2533 2563
2534 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader, 2564 RawLinkedHashMap* LinkedHashMap::ReadFrom(SnapshotReader* reader,
2535 intptr_t object_id, 2565 intptr_t object_id,
2536 intptr_t tags, 2566 intptr_t tags,
2537 Snapshot::Kind kind) { 2567 Snapshot::Kind kind) {
2538 ASSERT(reader != NULL); 2568 ASSERT(reader != NULL);
2539 2569
2540 LinkedHashMap& map = LinkedHashMap::ZoneHandle( 2570 LinkedHashMap& map = LinkedHashMap::ZoneHandle(
2541 reader->zone(), LinkedHashMap::null()); 2571 reader->zone(), LinkedHashMap::null());
2542 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { 2572 if ((kind == Snapshot::kFull && !reader->snapshot_code()) ||
2573 kind == Snapshot::kScript) {
2543 // The immutable maps that seed map literals are not yet VM-internal, so 2574 // The immutable maps that seed map literals are not yet VM-internal, so
2544 // we don't reach this. 2575 // we don't reach this.
2545 UNREACHABLE(); 2576 UNREACHABLE();
2546 } else { 2577 } else {
2547 // Since the map might contain itself as a key or value, allocate first. 2578 // Since the map might contain itself as a key or value, allocate first.
2548 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind)); 2579 if (kind == Snapshot::kFull) {
2580 map = reader->NewLinkedHashMap();
2581 } else {
2582 map = LinkedHashMap::NewUninitialized(HEAP_SPACE(kind));
2583 }
2549 } 2584 }
2550 reader->AddBackRef(object_id, &map, kIsDeserialized); 2585 reader->AddBackRef(object_id, &map, kIsDeserialized);
2551 2586
2552 // Read the type arguments. 2587 // Read the type arguments.
2553 const intptr_t typeargs_offset = 2588 const intptr_t typeargs_offset =
2554 GrowableObjectArray::type_arguments_offset() / kWordSize; 2589 GrowableObjectArray::type_arguments_offset() / kWordSize;
2555 *reader->TypeArgumentsHandle() ^= 2590 *reader->TypeArgumentsHandle() ^=
2556 reader->ReadObjectImpl(kAsInlinedObject, object_id, typeargs_offset); 2591 reader->ReadObjectImpl(kAsInlinedObject, object_id, typeargs_offset);
2557 map.SetTypeArguments(*reader->TypeArgumentsHandle()); 2592 map.SetTypeArguments(*reader->TypeArgumentsHandle());
2558 2593
2559 // Read the number of key/value pairs. 2594 // Read the number of key/value pairs.
2560 intptr_t len = reader->ReadSmiValue(); 2595 intptr_t len = reader->ReadSmiValue();
2561 intptr_t used_data = (len << 1); 2596 intptr_t used_data = (len << 1);
2562 map.SetUsedData(used_data); 2597 map.SetUsedData(used_data);
2563 2598
2564 // Allocate the data array. 2599 // Allocate the data array.
2565 intptr_t data_size = Utils::Maximum( 2600 intptr_t data_size = Utils::Maximum(
2566 Utils::RoundUpToPowerOfTwo(used_data), 2601 Utils::RoundUpToPowerOfTwo(used_data),
2567 static_cast<uintptr_t>(LinkedHashMap::kInitialIndexSize)); 2602 static_cast<uintptr_t>(LinkedHashMap::kInitialIndexSize));
2568 Array& data = Array::ZoneHandle(reader->zone(), 2603 Array& data = Array::ZoneHandle(reader->zone(),
2569 Array::New(data_size, HEAP_SPACE(kind))); 2604 NEW_OBJECT_WITH_LEN_SPACE(Array,
2605 data_size,
2606 kind));
2570 map.SetData(data); 2607 map.SetData(data);
2571 map.SetDeletedKeys(0); 2608 map.SetDeletedKeys(0);
2572 2609
2573 // The index and hashMask is regenerated by the maps themselves on demand. 2610 // The index and hashMask is regenerated by the maps themselves on demand.
2574 // Thus, the index will probably be allocated in new space (unless it's huge). 2611 // Thus, the index will probably be allocated in new space (unless it's huge).
2575 // TODO(koda): Eagerly rehash here when no keys have user-defined '==', and 2612 // TODO(koda): Eagerly rehash here when no keys have user-defined '==', and
2576 // in particular, if/when (const) maps are needed in the VM isolate snapshot. 2613 // in particular, if/when (const) maps are needed in the VM isolate snapshot.
2577 ASSERT(reader->isolate() != Dart::vm_isolate()); 2614 ASSERT(reader->isolate() != Dart::vm_isolate());
2578 map.SetHashMask(0); // Prefer sentinel 0 over null for better type feedback. 2615 map.SetHashMask(0); // Prefer sentinel 0 over null for better type feedback.
2579 2616
2580 // Read the keys and values. 2617 // Read the keys and values.
2581 bool as_reference = RawObject::IsCanonical(tags) ? false : true; 2618 bool as_reference = RawObject::IsCanonical(tags) ? false : true;
2582 for (intptr_t i = 0; i < used_data; i++) { 2619 for (intptr_t i = 0; i < used_data; i++) {
2583 *reader->PassiveObjectHandle() = reader->ReadObjectImpl(as_reference); 2620 *reader->PassiveObjectHandle() = reader->ReadObjectImpl(as_reference);
2584 data.SetAt(i, *reader->PassiveObjectHandle()); 2621 data.SetAt(i, *reader->PassiveObjectHandle());
2585 } 2622 }
2586 return map.raw(); 2623 return map.raw();
2587 } 2624 }
2588 2625
2589 2626
2590 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer, 2627 void RawLinkedHashMap::WriteTo(SnapshotWriter* writer,
2591 intptr_t object_id, 2628 intptr_t object_id,
2592 Snapshot::Kind kind) { 2629 Snapshot::Kind kind) {
2593 if (kind == Snapshot::kFull || kind == Snapshot::kScript) { 2630 if ((kind == Snapshot::kFull && !writer->snapshot_code()) ||
2631 kind == Snapshot::kScript) {
2594 // The immutable maps that seed map literals are not yet VM-internal, so 2632 // The immutable maps that seed map literals are not yet VM-internal, so
2595 // we don't reach this. 2633 // we don't reach this.
2596 UNREACHABLE();
2597 } 2634 }
2598 ASSERT(writer != NULL); 2635 ASSERT(writer != NULL);
2599 2636
2600 // Write out the serialization header value for this object. 2637 // Write out the serialization header value for this object.
2601 writer->WriteInlinedObjectHeader(object_id); 2638 writer->WriteInlinedObjectHeader(object_id);
2602 2639
2603 // Write out the class and tags information. 2640 // Write out the class and tags information.
2604 writer->WriteIndexedObject(kLinkedHashMapCid); 2641 writer->WriteIndexedObject(kLinkedHashMapCid);
2605 const uword tags = writer->GetObjectTags(this); 2642 const uword tags = writer->GetObjectTags(this);
2606 writer->WriteTags(tags); 2643 writer->WriteTags(tags);
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
3032 } else { 3069 } else {
3033 UNREACHABLE(); 3070 UNREACHABLE();
3034 } 3071 }
3035 } 3072 }
3036 3073
3037 3074
3038 RawSendPort* SendPort::ReadFrom(SnapshotReader* reader, 3075 RawSendPort* SendPort::ReadFrom(SnapshotReader* reader,
3039 intptr_t object_id, 3076 intptr_t object_id,
3040 intptr_t tags, 3077 intptr_t tags,
3041 Snapshot::Kind kind) { 3078 Snapshot::Kind kind) {
3079 ASSERT(kind == Snapshot::kMessage || reader->snapshot_code());
3080
3042 uint64_t id = reader->Read<uint64_t>(); 3081 uint64_t id = reader->Read<uint64_t>();
3043 uint64_t origin_id = reader->Read<uint64_t>(); 3082 uint64_t origin_id = reader->Read<uint64_t>();
3044 3083
3045 SendPort& result = SendPort::ZoneHandle(reader->zone(), 3084 SendPort& result = SendPort::ZoneHandle(reader->zone());
3046 SendPort::New(id, origin_id)); 3085 if (reader->snapshot_code()) {
3086 // TODO(rmacnak): Reset fields in precompiled snapshots and assert
3087 // this is unreachable.
3088 } else {
3089 result = SendPort::New(id, origin_id);
3090 }
3047 reader->AddBackRef(object_id, &result, kIsDeserialized); 3091 reader->AddBackRef(object_id, &result, kIsDeserialized);
3048 return result.raw(); 3092 return result.raw();
3049 } 3093 }
3050 3094
3051 3095
3052 void RawSendPort::WriteTo(SnapshotWriter* writer, 3096 void RawSendPort::WriteTo(SnapshotWriter* writer,
3053 intptr_t object_id, 3097 intptr_t object_id,
3054 Snapshot::Kind kind) { 3098 Snapshot::Kind kind) {
3055 // Write out the serialization header value for this object. 3099 // Write out the serialization header value for this object.
3056 writer->WriteInlinedObjectHeader(object_id); 3100 writer->WriteInlinedObjectHeader(object_id);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
3253 // We do not allow objects with native fields in an isolate message. 3297 // We do not allow objects with native fields in an isolate message.
3254 writer->SetWriteException(Exceptions::kArgument, 3298 writer->SetWriteException(Exceptions::kArgument,
3255 "Illegal argument in isolate message" 3299 "Illegal argument in isolate message"
3256 " : (object is a UserTag)"); 3300 " : (object is a UserTag)");
3257 } else { 3301 } else {
3258 UNREACHABLE(); 3302 UNREACHABLE();
3259 } 3303 }
3260 } 3304 }
3261 3305
3262 } // namespace dart 3306 } // namespace dart
OLDNEW
« runtime/bin/main.cc ('K') | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698