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/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 Loading... |
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->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference); |
| 1387 result.StorePointer(reinterpret_cast<RawObject*const*>( |
| 1388 &result.raw_ptr()->object_pool_), |
| 1389 reader->PassiveObjectHandle()->raw()); |
| 1390 |
| 1391 (*reader->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference); |
| 1392 result.StorePointer(&result.raw_ptr()->owner_, |
| 1393 reader->PassiveObjectHandle()->raw()); |
| 1394 |
| 1395 (*reader->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference); |
| 1396 result.StorePointer(reinterpret_cast<RawObject*const*>( |
| 1397 &result.raw_ptr()->exception_handlers_), |
| 1398 reader->PassiveObjectHandle()->raw()); |
| 1399 |
| 1400 (*reader->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference); |
| 1401 result.StorePointer(reinterpret_cast<RawObject*const*>( |
| 1402 &result.raw_ptr()->pc_descriptors_), |
| 1403 reader->PassiveObjectHandle()->raw()); |
| 1404 |
| 1405 (*reader->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference); |
| 1406 result.StorePointer(reinterpret_cast<RawObject*const*>( |
| 1407 &result.raw_ptr()->code_source_map_), |
| 1408 reader->PassiveObjectHandle()->raw()); |
| 1409 |
| 1410 (*reader->PassiveObjectHandle()) ^= reader->ReadObjectImpl(kAsReference); |
| 1411 result.StorePointer(reinterpret_cast<RawObject*const*>( |
| 1412 &result.raw_ptr()->stackmaps_), |
| 1413 reader->PassiveObjectHandle()->raw()); |
| 1414 |
| 1415 result.StorePointer(&result.raw_ptr()->deopt_info_array_, |
| 1416 Array::null()); |
| 1417 result.StorePointer(&result.raw_ptr()->static_calls_target_table_, |
| 1418 Array::null()); |
| 1419 result.StorePointer(&result.raw_ptr()->var_descriptors_, |
| 1420 LocalVarDescriptors::null()); |
| 1421 result.StorePointer(&result.raw_ptr()->inlined_metadata_, |
| 1422 Array::null()); |
| 1423 result.StorePointer(&result.raw_ptr()->comments_, |
| 1424 Array::null()); |
| 1425 result.StorePointer(&result.raw_ptr()->return_address_metadata_, |
| 1426 Object::null()); |
| 1427 |
| 1428 ASSERT(result.Size() == instructions_size); |
| 1429 ASSERT(result.EntryPoint() == entry_point); |
1371 | 1430 |
1372 return result.raw(); | 1431 return result.raw(); |
1373 } | 1432 } |
1374 | 1433 |
1375 | 1434 |
1376 void RawCode::WriteTo(SnapshotWriter* writer, | 1435 void RawCode::WriteTo(SnapshotWriter* writer, |
1377 intptr_t object_id, | 1436 intptr_t object_id, |
1378 Snapshot::Kind kind, | 1437 Snapshot::Kind kind, |
1379 bool as_reference) { | 1438 bool as_reference) { |
1380 ASSERT(writer->snapshot_code()); | 1439 ASSERT(writer->snapshot_code()); |
1381 ASSERT(kind == Snapshot::kFull); | 1440 ASSERT(kind == Snapshot::kFull); |
1382 | 1441 |
1383 intptr_t pointer_offsets_length = | 1442 intptr_t pointer_offsets_length = |
1384 Code::PtrOffBits::decode(ptr()->state_bits_); | 1443 Code::PtrOffBits::decode(ptr()->state_bits_); |
1385 if (pointer_offsets_length != 0) { | 1444 if (pointer_offsets_length != 0) { |
1386 // Should only be IA32. | 1445 // Should only be IA32. |
1387 FATAL("Cannot serialize code with embedded pointers"); | 1446 FATAL("Cannot serialize code with embedded pointers"); |
1388 } | 1447 } |
1389 | 1448 |
1390 // Write out the serialization header value for this object. | 1449 // Write out the serialization header value for this object. |
1391 writer->WriteInlinedObjectHeader(object_id); | 1450 writer->WriteInlinedObjectHeader(object_id); |
1392 | 1451 |
1393 // Write out the class and tags information. | 1452 // Write out the class and tags information. |
1394 writer->WriteVMIsolateObject(kCodeCid); | 1453 writer->WriteVMIsolateObject(kCodeCid); |
1395 writer->WriteTags(writer->GetObjectTags(this)); | 1454 writer->WriteTags(writer->GetObjectTags(this)); |
1396 | 1455 |
1397 // Write out all the non object fields. | 1456 // Write out all the non object fields. |
1398 writer->Write<int32_t>(ptr()->state_bits_); | 1457 writer->Write<int32_t>(ptr()->state_bits_); |
1399 | 1458 |
1400 // Write out all the object pointer fields. | 1459 RawInstructions* instr = ptr()->instructions_; |
1401 SnapshotWriterVisitor visitor(writer, kAsReference); | 1460 intptr_t size = instr->ptr()->size_; |
1402 visitor.VisitPointers(from(), to_snapshot()); | 1461 int32_t text_offset = writer->GetInstructionsId(instr, this); |
| 1462 writer->Write<int32_t>(text_offset); |
| 1463 writer->Write<int32_t>(size); |
| 1464 #if defined(DEBUG) |
| 1465 uword entry = ptr()->entry_point_; |
| 1466 uword check = Checksum(entry, size); |
| 1467 writer->Write<uword>(check); |
| 1468 #endif |
1403 | 1469 |
1404 writer->SetInstructionsCode(ptr()->instructions_, this); | 1470 writer->WriteObjectImpl(ptr()->object_pool_, kAsReference); |
| 1471 writer->WriteObjectImpl(ptr()->owner_, kAsReference); |
| 1472 writer->WriteObjectImpl(ptr()->exception_handlers_, kAsReference); |
| 1473 writer->WriteObjectImpl(ptr()->pc_descriptors_, kAsReference); |
| 1474 writer->WriteObjectImpl(ptr()->code_source_map_, kAsReference); |
| 1475 writer->WriteObjectImpl(ptr()->stackmaps_, kAsReference); |
1405 } | 1476 } |
1406 | 1477 |
1407 | 1478 |
1408 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, | 1479 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, |
1409 intptr_t object_id, | 1480 intptr_t object_id, |
1410 intptr_t tags, | 1481 intptr_t tags, |
1411 Snapshot::Kind kind, | 1482 Snapshot::Kind kind, |
1412 bool as_reference) { | 1483 bool as_reference) { |
1413 ASSERT(reader->snapshot_code()); | 1484 UNREACHABLE(); |
1414 ASSERT(kind == Snapshot::kFull); | 1485 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 } | 1486 } |
1429 | 1487 |
1430 | 1488 |
1431 void RawInstructions::WriteTo(SnapshotWriter* writer, | 1489 void RawInstructions::WriteTo(SnapshotWriter* writer, |
1432 intptr_t object_id, | 1490 intptr_t object_id, |
1433 Snapshot::Kind kind, | 1491 Snapshot::Kind kind, |
1434 bool as_reference) { | 1492 bool as_reference) { |
1435 ASSERT(writer->snapshot_code()); | 1493 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 } | 1494 } |
1454 | 1495 |
1455 | 1496 |
1456 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, | 1497 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, |
1457 intptr_t object_id, | 1498 intptr_t object_id, |
1458 intptr_t tags, | 1499 intptr_t tags, |
1459 Snapshot::Kind kind, | 1500 Snapshot::Kind kind, |
1460 bool as_reference) { | 1501 bool as_reference) { |
1461 ASSERT(reader->snapshot_code()); | 1502 ASSERT(reader->snapshot_code()); |
1462 ASSERT(kind == Snapshot::kFull); | 1503 ASSERT(kind == Snapshot::kFull); |
(...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3653 // We do not allow objects with native fields in an isolate message. | 3694 // We do not allow objects with native fields in an isolate message. |
3654 writer->SetWriteException(Exceptions::kArgument, | 3695 writer->SetWriteException(Exceptions::kArgument, |
3655 "Illegal argument in isolate message" | 3696 "Illegal argument in isolate message" |
3656 " : (object is a UserTag)"); | 3697 " : (object is a UserTag)"); |
3657 } else { | 3698 } else { |
3658 UNREACHABLE(); | 3699 UNREACHABLE(); |
3659 } | 3700 } |
3660 } | 3701 } |
3661 | 3702 |
3662 } // namespace dart | 3703 } // namespace dart |
OLD | NEW |