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 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 | 1470 |
1471 | 1471 |
1472 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, | 1472 RawInstructions* Instructions::ReadFrom(SnapshotReader* reader, |
1473 intptr_t object_id, | 1473 intptr_t object_id, |
1474 intptr_t tags, | 1474 intptr_t tags, |
1475 Snapshot::Kind kind, | 1475 Snapshot::Kind kind, |
1476 bool as_reference) { | 1476 bool as_reference) { |
1477 ASSERT(reader->snapshot_code()); | 1477 ASSERT(reader->snapshot_code()); |
1478 ASSERT(kind == Snapshot::kFull); | 1478 ASSERT(kind == Snapshot::kFull); |
1479 | 1479 |
| 1480 #ifdef DEBUG |
1480 intptr_t full_tags = static_cast<uword>(reader->Read<intptr_t>()); | 1481 intptr_t full_tags = static_cast<uword>(reader->Read<intptr_t>()); |
| 1482 #else |
| 1483 intptr_t full_tags = 0; // unused in release mode |
| 1484 #endif |
1481 intptr_t offset = reader->Read<int32_t>(); | 1485 intptr_t offset = reader->Read<int32_t>(); |
1482 Instructions& result = | 1486 Instructions& result = |
1483 Instructions::ZoneHandle(reader->zone(), | 1487 Instructions::ZoneHandle(reader->zone(), |
1484 reader->GetInstructionsAt(offset, full_tags)); | 1488 reader->GetInstructionsAt(offset, full_tags)); |
1485 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1489 reader->AddBackRef(object_id, &result, kIsDeserialized); |
1486 | 1490 |
1487 return result.raw(); | 1491 return result.raw(); |
1488 } | 1492 } |
1489 | 1493 |
1490 | 1494 |
1491 void RawInstructions::WriteTo(SnapshotWriter* writer, | 1495 void RawInstructions::WriteTo(SnapshotWriter* writer, |
1492 intptr_t object_id, | 1496 intptr_t object_id, |
1493 Snapshot::Kind kind, | 1497 Snapshot::Kind kind, |
1494 bool as_reference) { | 1498 bool as_reference) { |
1495 ASSERT(writer->snapshot_code()); | 1499 ASSERT(writer->snapshot_code()); |
1496 ASSERT(kind == Snapshot::kFull); | 1500 ASSERT(kind == Snapshot::kFull); |
1497 | 1501 |
1498 writer->WriteInlinedObjectHeader(object_id); | 1502 writer->WriteInlinedObjectHeader(object_id); |
1499 writer->WriteVMIsolateObject(kInstructionsCid); | 1503 writer->WriteVMIsolateObject(kInstructionsCid); |
1500 writer->WriteTags(writer->GetObjectTags(this)); | 1504 writer->WriteTags(writer->GetObjectTags(this)); |
1501 | 1505 |
| 1506 #ifdef DEBUG |
1502 // Instructions will be written pre-marked and in the VM heap. Write out | 1507 // Instructions will be written pre-marked and in the VM heap. Write out |
1503 // the tags we expect to find when reading the snapshot for a sanity check | 1508 // the tags we expect to find when reading the snapshot for a sanity check |
1504 // that our offsets/alignment didn't get out of sync. | 1509 // that our offsets/alignment didn't get out of sync. |
1505 uword written_tags = writer->GetObjectTags(this); | 1510 uword written_tags = writer->GetObjectTags(this); |
1506 written_tags = RawObject::VMHeapObjectTag::update(true, written_tags); | 1511 written_tags = RawObject::VMHeapObjectTag::update(true, written_tags); |
1507 written_tags = RawObject::MarkBit::update(true, written_tags); | 1512 written_tags = RawObject::MarkBit::update(true, written_tags); |
1508 writer->Write<intptr_t>(written_tags); | 1513 writer->Write<intptr_t>(written_tags); |
| 1514 #endif |
1509 | 1515 |
1510 writer->Write<int32_t>(writer->GetInstructionsId(this)); | 1516 writer->Write<int32_t>(writer->GetInstructionsId(this)); |
1511 } | 1517 } |
1512 | 1518 |
1513 | 1519 |
1514 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, | 1520 RawObjectPool* ObjectPool::ReadFrom(SnapshotReader* reader, |
1515 intptr_t object_id, | 1521 intptr_t object_id, |
1516 intptr_t tags, | 1522 intptr_t tags, |
1517 Snapshot::Kind kind, | 1523 Snapshot::Kind kind, |
1518 bool as_reference) { | 1524 bool as_reference) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1636 | 1642 |
1637 | 1643 |
1638 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader, | 1644 RawPcDescriptors* PcDescriptors::ReadFrom(SnapshotReader* reader, |
1639 intptr_t object_id, | 1645 intptr_t object_id, |
1640 intptr_t tags, | 1646 intptr_t tags, |
1641 Snapshot::Kind kind, | 1647 Snapshot::Kind kind, |
1642 bool as_reference) { | 1648 bool as_reference) { |
1643 ASSERT(reader->snapshot_code()); | 1649 ASSERT(reader->snapshot_code()); |
1644 ASSERT(kind == Snapshot::kFull); | 1650 ASSERT(kind == Snapshot::kFull); |
1645 | 1651 |
1646 const int32_t length = reader->Read<int32_t>(); | 1652 intptr_t offset = reader->Read<int32_t>(); |
1647 PcDescriptors& result = | 1653 PcDescriptors& result = PcDescriptors::ZoneHandle(reader->zone()); |
1648 PcDescriptors::ZoneHandle(reader->zone(), | 1654 result ^= reader->GetObjectAt(offset); |
1649 NEW_OBJECT_WITH_LEN(PcDescriptors, length)); | |
1650 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1655 reader->AddBackRef(object_id, &result, kIsDeserialized); |
1651 | 1656 |
1652 if (result.Length() > 0) { | |
1653 NoSafepointScope no_safepoint; | |
1654 intptr_t len = result.Length(); | |
1655 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); | |
1656 reader->ReadBytes(data, len); | |
1657 } | |
1658 | |
1659 return result.raw(); | 1657 return result.raw(); |
1660 } | 1658 } |
1661 | 1659 |
1662 | 1660 |
1663 void RawPcDescriptors::WriteTo(SnapshotWriter* writer, | 1661 void RawPcDescriptors::WriteTo(SnapshotWriter* writer, |
1664 intptr_t object_id, | 1662 intptr_t object_id, |
1665 Snapshot::Kind kind, | 1663 Snapshot::Kind kind, |
1666 bool as_reference) { | 1664 bool as_reference) { |
1667 ASSERT(writer->snapshot_code()); | 1665 ASSERT(writer->snapshot_code()); |
1668 ASSERT(kind == Snapshot::kFull); | 1666 ASSERT(kind == Snapshot::kFull); |
1669 | 1667 |
1670 // Write out the serialization header value for this object. | 1668 // Write out the serialization header value for this object. |
1671 writer->WriteInlinedObjectHeader(object_id); | 1669 writer->WriteInlinedObjectHeader(object_id); |
1672 writer->WriteIndexedObject(kPcDescriptorsCid); | 1670 writer->WriteIndexedObject(kPcDescriptorsCid); |
1673 writer->WriteTags(writer->GetObjectTags(this)); | 1671 writer->WriteTags(writer->GetObjectTags(this)); |
1674 writer->Write<int32_t>(ptr()->length_); | 1672 |
1675 if (ptr()->length_ > 0) { | 1673 writer->Write<int32_t>(writer->GetObjectId(this)); |
1676 intptr_t len = ptr()->length_; | |
1677 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); | |
1678 writer->WriteBytes(data, len); | |
1679 } | |
1680 } | 1674 } |
1681 | 1675 |
1682 | 1676 |
1683 RawCodeSourceMap* CodeSourceMap::ReadFrom(SnapshotReader* reader, | 1677 RawCodeSourceMap* CodeSourceMap::ReadFrom(SnapshotReader* reader, |
1684 intptr_t object_id, | 1678 intptr_t object_id, |
1685 intptr_t tags, | 1679 intptr_t tags, |
1686 Snapshot::Kind kind, | 1680 Snapshot::Kind kind, |
1687 bool as_reference) { | 1681 bool as_reference) { |
1688 ASSERT(reader->snapshot_code()); | 1682 ASSERT(reader->snapshot_code()); |
1689 ASSERT(kind == Snapshot::kFull); | 1683 ASSERT(kind == Snapshot::kFull); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 | 1720 |
1727 | 1721 |
1728 RawStackmap* Stackmap::ReadFrom(SnapshotReader* reader, | 1722 RawStackmap* Stackmap::ReadFrom(SnapshotReader* reader, |
1729 intptr_t object_id, | 1723 intptr_t object_id, |
1730 intptr_t tags, | 1724 intptr_t tags, |
1731 Snapshot::Kind kind, | 1725 Snapshot::Kind kind, |
1732 bool as_reference) { | 1726 bool as_reference) { |
1733 ASSERT(reader->snapshot_code()); | 1727 ASSERT(reader->snapshot_code()); |
1734 ASSERT(kind == Snapshot::kFull); | 1728 ASSERT(kind == Snapshot::kFull); |
1735 | 1729 |
1736 const int32_t length = reader->Read<int32_t>(); | 1730 intptr_t offset = reader->Read<int32_t>(); |
1737 Stackmap& result = | 1731 Stackmap& result = Stackmap::ZoneHandle(reader->zone()); |
1738 Stackmap::ZoneHandle(reader->zone(), | 1732 result ^= reader->GetObjectAt(offset); |
1739 reader->NewStackmap(length)); | |
1740 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1733 reader->AddBackRef(object_id, &result, kIsDeserialized); |
1741 | 1734 |
1742 result.SetRegisterBitCount(reader->Read<int32_t>()); | |
1743 result.SetPcOffset(reader->Read<uint32_t>()); | |
1744 | |
1745 if (length > 0) { | |
1746 NoSafepointScope no_safepoint; | |
1747 intptr_t len = (result.Length() + 7) / 8; | |
1748 uint8_t* data = result.UnsafeMutableNonPointer(result.raw_ptr()->data()); | |
1749 reader->ReadBytes(data, len); | |
1750 } | |
1751 | |
1752 return result.raw(); | 1735 return result.raw(); |
1753 } | 1736 } |
1754 | 1737 |
1755 | 1738 |
1756 void RawStackmap::WriteTo(SnapshotWriter* writer, | 1739 void RawStackmap::WriteTo(SnapshotWriter* writer, |
1757 intptr_t object_id, | 1740 intptr_t object_id, |
1758 Snapshot::Kind kind, | 1741 Snapshot::Kind kind, |
1759 bool as_reference) { | 1742 bool as_reference) { |
1760 ASSERT(writer->snapshot_code()); | 1743 ASSERT(writer->snapshot_code()); |
1761 ASSERT(kind == Snapshot::kFull); | 1744 ASSERT(kind == Snapshot::kFull); |
1762 | 1745 |
1763 // Write out the serialization header value for this object. | 1746 // Write out the serialization header value for this object. |
1764 writer->WriteInlinedObjectHeader(object_id); | 1747 writer->WriteInlinedObjectHeader(object_id); |
1765 writer->WriteIndexedObject(kStackmapCid); | 1748 writer->WriteIndexedObject(kStackmapCid); |
1766 writer->WriteTags(writer->GetObjectTags(this)); | 1749 writer->WriteTags(writer->GetObjectTags(this)); |
1767 | 1750 |
1768 writer->Write<int32_t>(ptr()->length_); | 1751 writer->Write<int32_t>(writer->GetObjectId(this)); |
1769 writer->Write<int32_t>(ptr()->register_bit_count_); | |
1770 writer->Write<uint32_t>(ptr()->pc_offset_); | |
1771 if (ptr()->length_ > 0) { | |
1772 intptr_t len = (ptr()->length_ + 7) / 8; | |
1773 uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data()); | |
1774 writer->WriteBytes(data, len); | |
1775 } | |
1776 } | 1752 } |
1777 | 1753 |
1778 | 1754 |
1779 RawLocalVarDescriptors* LocalVarDescriptors::ReadFrom(SnapshotReader* reader, | 1755 RawLocalVarDescriptors* LocalVarDescriptors::ReadFrom(SnapshotReader* reader, |
1780 intptr_t object_id, | 1756 intptr_t object_id, |
1781 intptr_t tags, | 1757 intptr_t tags, |
1782 Snapshot::Kind kind, | 1758 Snapshot::Kind kind, |
1783 bool as_reference) { | 1759 bool as_reference) { |
1784 ASSERT(reader->snapshot_code()); | 1760 ASSERT(reader->snapshot_code()); |
1785 ASSERT(kind == Snapshot::kFull); | 1761 ASSERT(kind == Snapshot::kFull); |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 } | 2541 } |
2566 } | 2542 } |
2567 } | 2543 } |
2568 | 2544 |
2569 | 2545 |
2570 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 2546 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
2571 intptr_t object_id, | 2547 intptr_t object_id, |
2572 intptr_t tags, | 2548 intptr_t tags, |
2573 Snapshot::Kind kind, | 2549 Snapshot::Kind kind, |
2574 bool as_reference) { | 2550 bool as_reference) { |
| 2551 if (reader->snapshot_code()) { |
| 2552 ASSERT(kind == Snapshot::kFull); |
| 2553 intptr_t offset = reader->Read<int32_t>(); |
| 2554 String& result = String::ZoneHandle(reader->zone()); |
| 2555 result ^= reader->GetObjectAt(offset); |
| 2556 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 2557 return raw(result); |
| 2558 } |
2575 // Read the length so that we can determine instance size to allocate. | 2559 // Read the length so that we can determine instance size to allocate. |
2576 ASSERT(reader != NULL); | 2560 ASSERT(reader != NULL); |
2577 intptr_t len = reader->ReadSmiValue(); | 2561 intptr_t len = reader->ReadSmiValue(); |
2578 intptr_t hash = reader->ReadSmiValue(); | 2562 intptr_t hash = reader->ReadSmiValue(); |
2579 String& str_obj = String::ZoneHandle(reader->zone(), String::null()); | 2563 String& str_obj = String::ZoneHandle(reader->zone(), String::null()); |
2580 | 2564 |
2581 if (kind == Snapshot::kFull) { | 2565 if (kind == Snapshot::kFull) { |
2582 // We currently only expect the Dart mutator to read snapshots. | 2566 // We currently only expect the Dart mutator to read snapshots. |
2583 reader->isolate()->AssertCurrentThreadIsMutator(); | 2567 reader->isolate()->AssertCurrentThreadIsMutator(); |
2584 ASSERT(Thread::Current()->no_safepoint_scope_depth() != 0); | 2568 ASSERT(Thread::Current()->no_safepoint_scope_depth() != 0); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2672 } | 2656 } |
2673 } | 2657 } |
2674 } | 2658 } |
2675 } | 2659 } |
2676 | 2660 |
2677 | 2661 |
2678 void RawOneByteString::WriteTo(SnapshotWriter* writer, | 2662 void RawOneByteString::WriteTo(SnapshotWriter* writer, |
2679 intptr_t object_id, | 2663 intptr_t object_id, |
2680 Snapshot::Kind kind, | 2664 Snapshot::Kind kind, |
2681 bool as_reference) { | 2665 bool as_reference) { |
| 2666 if (writer->snapshot_code()) { |
| 2667 ASSERT(writer->snapshot_code()); |
| 2668 ASSERT(kind == Snapshot::kFull); |
| 2669 // Assert that hash is computed. |
| 2670 if (ptr()->hash_ == NULL) { |
| 2671 ptr()->hash_ = Smi::New(String::Hash(ptr()->data(), |
| 2672 Smi::Value(ptr()->length_))); |
| 2673 } |
| 2674 ASSERT(ptr()->hash_ != NULL); |
| 2675 // Write out the serialization header value for this object. |
| 2676 writer->WriteInlinedObjectHeader(object_id); |
| 2677 writer->WriteIndexedObject(kOneByteStringCid); |
| 2678 writer->WriteTags(writer->GetObjectTags(this)); |
| 2679 writer->Write<int32_t>(writer->GetObjectId(this)); |
| 2680 return; |
| 2681 } |
2682 StringWriteTo(writer, | 2682 StringWriteTo(writer, |
2683 object_id, | 2683 object_id, |
2684 kind, | 2684 kind, |
2685 kOneByteStringCid, | 2685 kOneByteStringCid, |
2686 writer->GetObjectTags(this), | 2686 writer->GetObjectTags(this), |
2687 ptr()->length_, | 2687 ptr()->length_, |
2688 ptr()->hash_, | 2688 ptr()->hash_, |
2689 ptr()->data()); | 2689 ptr()->data()); |
2690 } | 2690 } |
2691 | 2691 |
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3692 // 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. |
3693 writer->SetWriteException(Exceptions::kArgument, | 3693 writer->SetWriteException(Exceptions::kArgument, |
3694 "Illegal argument in isolate message" | 3694 "Illegal argument in isolate message" |
3695 " : (object is a UserTag)"); | 3695 " : (object is a UserTag)"); |
3696 } else { | 3696 } else { |
3697 UNREACHABLE(); | 3697 UNREACHABLE(); |
3698 } | 3698 } |
3699 } | 3699 } |
3700 | 3700 |
3701 } // namespace dart | 3701 } // namespace dart |
OLD | NEW |