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

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

Issue 1808553002: Precompilation: don't include an object header for instructions in the text section. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: union Created 4 years, 8 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/native_entry.h" 5 #include "vm/native_entry.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/snapshot.h" 8 #include "vm/snapshot.h"
9 #include "vm/stub_code.h" 9 #include "vm/stub_code.h"
10 #include "vm/symbols.h" 10 #include "vm/symbols.h"
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 // Write out the class and tags information. 1332 // Write out the class and tags information.
1333 writer->WriteVMIsolateObject(kNamespaceCid); 1333 writer->WriteVMIsolateObject(kNamespaceCid);
1334 writer->WriteTags(writer->GetObjectTags(this)); 1334 writer->WriteTags(writer->GetObjectTags(this));
1335 1335
1336 // Write out all the object pointer fields. 1336 // Write out all the object pointer fields.
1337 SnapshotWriterVisitor visitor(writer, kAsReference); 1337 SnapshotWriterVisitor visitor(writer, kAsReference);
1338 visitor.VisitPointers(from(), to()); 1338 visitor.VisitPointers(from(), to());
1339 } 1339 }
1340 1340
1341 1341
1342 #if defined(DEBUG)
1343 static uword Checksum(uword entry, intptr_t size) {
1344 uword sum = 0;
1345 uword* start = reinterpret_cast<uword*>(entry);
1346 uword* end = reinterpret_cast<uword*>(entry + size);
1347 for (uword* cursor = start; cursor < end; cursor++) {
1348 sum ^= *cursor;
1349 }
1350 return sum;
1351 }
1352 #endif
1353
1354
1342 RawCode* Code::ReadFrom(SnapshotReader* reader, 1355 RawCode* Code::ReadFrom(SnapshotReader* reader,
1343 intptr_t object_id, 1356 intptr_t object_id,
1344 intptr_t tags, 1357 intptr_t tags,
1345 Snapshot::Kind kind, 1358 Snapshot::Kind kind,
1346 bool as_reference) { 1359 bool as_reference) {
1347 ASSERT(reader->snapshot_code()); 1360 ASSERT(reader->snapshot_code());
1348 ASSERT(kind == Snapshot::kFull); 1361 ASSERT(kind == Snapshot::kFull);
1349 1362
1350 Code& result = Code::ZoneHandle(reader->zone(), NEW_OBJECT_WITH_LEN(Code, 0)); 1363 Code& result = Code::ZoneHandle(reader->zone(), NEW_OBJECT_WITH_LEN(Code, 0));
1351 reader->AddBackRef(object_id, &result, kIsDeserialized); 1364 reader->AddBackRef(object_id, &result, kIsDeserialized);
1352 1365
1353 result.set_compile_timestamp(0); 1366 result.set_compile_timestamp(0);
1354 result.set_state_bits(reader->Read<int32_t>()); 1367 result.set_state_bits(reader->Read<int32_t>());
1355 result.set_lazy_deopt_pc_offset(-1); 1368 result.set_lazy_deopt_pc_offset(-1);
1356 1369
1357 // Set all the object fields. 1370 int32_t text_offset = reader->Read<int32_t>();
1358 READ_OBJECT_FIELDS(result, 1371 int32_t instructions_size = reader->Read<int32_t>();
1359 result.raw()->from(), result.raw()->to_snapshot(), 1372 uword entry_point = reader->GetInstructionsAt(text_offset);
1360 kAsReference);
1361 for (RawObject** ptr = result.raw()->to();
1362 ptr > result.raw()->to_snapshot();
1363 ptr--) {
1364 result.StorePointer(ptr, Object::null());
1365 }
1366 1373
1367 // Fix entry point. 1374 #if defined(DEBUG)
1368 uword new_entry = result.EntryPoint(); 1375 uword expected_check = reader->Read<uword>();
1369 ASSERT(Dart::vm_isolate()->heap()->CodeContains(new_entry)); 1376 uword actual_check = Checksum(entry_point, instructions_size);
1370 result.StoreNonPointer(&result.raw_ptr()->entry_point_, new_entry); 1377 ASSERT(expected_check == actual_check);
1378 #endif
1379
1380 result.StoreNonPointer(&result.raw_ptr()->entry_point_, entry_point);
1381
1382 result.StorePointer(reinterpret_cast<RawSmi*const*>(
1383 &result.raw_ptr()->instructions_),
1384 Smi::New(instructions_size));
1385
1386 (*reader->ObjectPoolHandle()) ^= reader->ReadObjectImpl(kAsReference);
Florian Schneider 2016/03/28 22:15:47 Also use PassiveObjectHandle for consistency with
rmacnak 2016/03/28 23:56:45 Done.
1387 result.StorePointer(&result.raw_ptr()->object_pool_,
1388 reader->ObjectPoolHandle()->raw());
1389
1390 (*reader->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference);
1391 result.StorePointer(&result.raw_ptr()->owner_,
1392 reader->PassiveObjectHandle()->raw());
1393
1394 (*reader->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference);
1395 result.StorePointer(reinterpret_cast<RawObject*const*>(
1396 &result.raw_ptr()->exception_handlers_),
1397 reader->PassiveObjectHandle()->raw());
1398
1399 (*reader->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference);
1400 result.StorePointer(reinterpret_cast<RawObject*const*>(
1401 &result.raw_ptr()->pc_descriptors_),
1402 reader->PassiveObjectHandle()->raw());
1403
1404 (*reader->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference);
1405 result.StorePointer(reinterpret_cast<RawObject*const*>(
1406 &result.raw_ptr()->code_source_map_),
1407 reader->PassiveObjectHandle()->raw());
1408
1409 (*reader->ArrayHandle()) ^= reader->ReadObjectImpl(kAsReference);
Florian Schneider 2016/03/28 22:15:47 PassiveObjectHandle?
rmacnak 2016/03/28 23:56:45 Done.
1410 result.StorePointer(&result.raw_ptr()->stackmaps_,
1411 reader->ArrayHandle()->raw());
1412
1413 result.StorePointer(&result.raw_ptr()->deopt_info_array_,
1414 Array::null());
1415 result.StorePointer(&result.raw_ptr()->static_calls_target_table_,
1416 Array::null());
1417 result.StorePointer(&result.raw_ptr()->var_descriptors_,
1418 LocalVarDescriptors::null());
1419 result.StorePointer(&result.raw_ptr()->inlined_metadata_,
1420 Array::null());
1421 result.StorePointer(&result.raw_ptr()->comments_,
1422 Array::null());
1423 result.StorePointer(&result.raw_ptr()->return_address_metadata_,
1424 Object::null());
1425
1426 ASSERT(result.Size() == instructions_size);
1427 ASSERT(result.EntryPoint() == entry_point);
1371 1428
1372 return result.raw(); 1429 return result.raw();
1373 } 1430 }
1374 1431
1375 1432
1376 void RawCode::WriteTo(SnapshotWriter* writer, 1433 void RawCode::WriteTo(SnapshotWriter* writer,
1377 intptr_t object_id, 1434 intptr_t object_id,
1378 Snapshot::Kind kind, 1435 Snapshot::Kind kind,
1379 bool as_reference) { 1436 bool as_reference) {
1380 ASSERT(writer->snapshot_code()); 1437 ASSERT(writer->snapshot_code());
1381 ASSERT(kind == Snapshot::kFull); 1438 ASSERT(kind == Snapshot::kFull);
1382 1439
1383 intptr_t pointer_offsets_length = 1440 intptr_t pointer_offsets_length =
1384 Code::PtrOffBits::decode(ptr()->state_bits_); 1441 Code::PtrOffBits::decode(ptr()->state_bits_);
1385 if (pointer_offsets_length != 0) { 1442 if (pointer_offsets_length != 0) {
1386 // Should only be IA32. 1443 // Should only be IA32.
1387 FATAL("Cannot serialize code with embedded pointers"); 1444 FATAL("Cannot serialize code with embedded pointers");
1388 } 1445 }
1389 1446
1390 // Write out the serialization header value for this object. 1447 // Write out the serialization header value for this object.
1391 writer->WriteInlinedObjectHeader(object_id); 1448 writer->WriteInlinedObjectHeader(object_id);
1392 1449
1393 // Write out the class and tags information. 1450 // Write out the class and tags information.
1394 writer->WriteVMIsolateObject(kCodeCid); 1451 writer->WriteVMIsolateObject(kCodeCid);
1395 writer->WriteTags(writer->GetObjectTags(this)); 1452 writer->WriteTags(writer->GetObjectTags(this));
1396 1453
1397 // Write out all the non object fields. 1454 // Write out all the non object fields.
1398 writer->Write<int32_t>(ptr()->state_bits_); 1455 writer->Write<int32_t>(ptr()->state_bits_);
1399 1456
1400 // Write out all the object pointer fields. 1457 RawInstructions* instr = ptr()->instructions_;
1401 SnapshotWriterVisitor visitor(writer, kAsReference); 1458 intptr_t size = instr->ptr()->size_;
1402 visitor.VisitPointers(from(), to_snapshot()); 1459 int32_t text_offset = writer->GetInstructionsId(instr, this);
1460 writer->Write<int32_t>(text_offset);
1461 writer->Write<int32_t>(size);
1462 #if defined(DEBUG)
1463 uword entry = ptr()->entry_point_;
1464 uword check = Checksum(entry, size);
1465 writer->Write<uword>(check);
1466 #endif
1403 1467
1404 writer->SetInstructionsCode(ptr()->instructions_, this); 1468 writer->WriteObjectImpl(ptr()->object_pool_, kAsReference);
1469 writer->WriteObjectImpl(ptr()->owner_, kAsReference);
1470 writer->WriteObjectImpl(ptr()->exception_handlers_, kAsReference);
1471 writer->WriteObjectImpl(ptr()->pc_descriptors_, kAsReference);
1472 writer->WriteObjectImpl(ptr()->code_source_map_, kAsReference);
1473 writer->WriteObjectImpl(ptr()->stackmaps_, kAsReference);
1405 } 1474 }
1406 1475
1407 1476
1408 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, 1477 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader,
1409 intptr_t object_id, 1478 intptr_t object_id,
1410 intptr_t tags, 1479 intptr_t tags,
1411 Snapshot::Kind kind, 1480 Snapshot::Kind kind,
1412 bool as_reference) { 1481 bool as_reference) {
1413 ASSERT(reader->snapshot_code()); 1482 UNREACHABLE();
1414 ASSERT(kind == Snapshot::kFull); 1483 return Instructions::null();
1415
1416 #ifdef DEBUG
1417 intptr_t full_tags = static_cast<uword>(reader->Read<intptr_t>());
1418 #else
1419 intptr_t full_tags = 0; // unused in release mode
1420 #endif
1421 intptr_t offset = reader->Read<int32_t>();
1422 Instructions& result =
1423 Instructions::ZoneHandle(reader->zone(),
1424 reader->GetInstructionsAt(offset, full_tags));
1425 reader->AddBackRef(object_id, &result, kIsDeserialized);
1426
1427 return result.raw();
1428 } 1484 }
1429 1485
1430 1486
1431 void RawInstructions::WriteTo(SnapshotWriter* writer, 1487 void RawInstructions::WriteTo(SnapshotWriter* writer,
1432 intptr_t object_id, 1488 intptr_t object_id,
1433 Snapshot::Kind kind, 1489 Snapshot::Kind kind,
1434 bool as_reference) { 1490 bool as_reference) {
1435 ASSERT(writer->snapshot_code()); 1491 UNREACHABLE();
1436 ASSERT(kind == Snapshot::kFull);
1437
1438 writer->WriteInlinedObjectHeader(object_id);
1439 writer->WriteVMIsolateObject(kInstructionsCid);
1440 writer->WriteTags(writer->GetObjectTags(this));
1441
1442 #ifdef DEBUG
1443 // Instructions will be written pre-marked and in the VM heap. Write out
1444 // the tags we expect to find when reading the snapshot for a sanity check
1445 // that our offsets/alignment didn't get out of sync.
1446 uword written_tags = writer->GetObjectTags(this);
1447 written_tags = RawObject::VMHeapObjectTag::update(true, written_tags);
1448 written_tags = RawObject::MarkBit::update(true, written_tags);
1449 writer->Write<intptr_t>(written_tags);
1450 #endif
1451
1452 writer->Write<int32_t>(writer->GetInstructionsId(this));
1453 } 1492 }
1454 1493
1455 1494
1456 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, 1495 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader,
1457 intptr_t object_id, 1496 intptr_t object_id,
1458 intptr_t tags, 1497 intptr_t tags,
1459 Snapshot::Kind kind, 1498 Snapshot::Kind kind,
1460 bool as_reference) { 1499 bool as_reference) {
1461 ASSERT(reader->snapshot_code()); 1500 ASSERT(reader->snapshot_code());
1462 ASSERT(kind == Snapshot::kFull); 1501 ASSERT(kind == Snapshot::kFull);
(...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after
3653 // We do not allow objects with native fields in an isolate message. 3692 // We do not allow objects with native fields in an isolate message.
3654 writer->SetWriteException(Exceptions::kArgument, 3693 writer->SetWriteException(Exceptions::kArgument,
3655 "Illegal argument in isolate message" 3694 "Illegal argument in isolate message"
3656 " : (object is a UserTag)"); 3695 " : (object is a UserTag)");
3657 } else { 3696 } else {
3658 UNREACHABLE(); 3697 UNREACHABLE();
3659 } 3698 }
3660 } 3699 }
3661 3700
3662 } // namespace dart 3701 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.cc ('k') | runtime/vm/snapshot.h » ('j') | runtime/vm/stack_frame.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698