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/bigint_operations.h" | 5 #include "vm/bigint_operations.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 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 | 821 |
822 // Create the literal token object. | 822 // Create the literal token object. |
823 LiteralToken& literal_token = LiteralToken::ZoneHandle( | 823 LiteralToken& literal_token = LiteralToken::ZoneHandle( |
824 reader->isolate(), NEW_OBJECT(LiteralToken)); | 824 reader->isolate(), NEW_OBJECT(LiteralToken)); |
825 reader->AddBackRef(object_id, &literal_token, kIsDeserialized); | 825 reader->AddBackRef(object_id, &literal_token, kIsDeserialized); |
826 | 826 |
827 // Set the object tags. | 827 // Set the object tags. |
828 literal_token.set_tags(tags); | 828 literal_token.set_tags(tags); |
829 | 829 |
830 // Read the token attributes. | 830 // Read the token attributes. |
831 Token::Kind token_kind = static_cast<Token::Kind>(reader->ReadIntptrValue()); | 831 Token::Kind token_kind = static_cast<Token::Kind>(reader->Read<int32_t>()); |
832 literal_token.set_kind(token_kind); | 832 literal_token.set_kind(token_kind); |
833 *reader->StringHandle() ^= reader->ReadObjectImpl(); | 833 *reader->StringHandle() ^= reader->ReadObjectImpl(); |
834 literal_token.set_literal(*reader->StringHandle()); | 834 literal_token.set_literal(*reader->StringHandle()); |
835 *reader->ObjectHandle() = reader->ReadObjectImpl(); | 835 *reader->ObjectHandle() = reader->ReadObjectImpl(); |
836 literal_token.set_value(*reader->ObjectHandle()); | 836 literal_token.set_value(*reader->ObjectHandle()); |
837 | 837 |
838 return literal_token.raw(); | 838 return literal_token.raw(); |
839 } | 839 } |
840 | 840 |
841 | 841 |
842 void RawLiteralToken::WriteTo(SnapshotWriter* writer, | 842 void RawLiteralToken::WriteTo(SnapshotWriter* writer, |
843 intptr_t object_id, | 843 intptr_t object_id, |
844 Snapshot::Kind kind) { | 844 Snapshot::Kind kind) { |
845 ASSERT(writer != NULL); | 845 ASSERT(writer != NULL); |
846 ASSERT(kind != Snapshot::kMessage); | 846 ASSERT(kind != Snapshot::kMessage); |
847 | 847 |
848 // Write out the serialization header value for this object. | 848 // Write out the serialization header value for this object. |
849 writer->WriteInlinedObjectHeader(object_id); | 849 writer->WriteInlinedObjectHeader(object_id); |
850 | 850 |
851 // Write out the class and tags information. | 851 // Write out the class and tags information. |
852 writer->WriteVMIsolateObject(kLiteralTokenCid); | 852 writer->WriteVMIsolateObject(kLiteralTokenCid); |
853 writer->WriteTags(writer->GetObjectTags(this)); | 853 writer->WriteTags(writer->GetObjectTags(this)); |
854 | 854 |
855 // Write out the kind field. | 855 // Write out the kind field. |
856 writer->Write<intptr_t>(ptr()->kind_); | 856 writer->Write<int32_t>(ptr()->kind_); |
857 | 857 |
858 // Write out literal and value fields. | 858 // Write out literal and value fields. |
859 writer->WriteObjectImpl(ptr()->literal_); | 859 writer->WriteObjectImpl(ptr()->literal_); |
860 writer->WriteObjectImpl(ptr()->value_); | 860 writer->WriteObjectImpl(ptr()->value_); |
861 } | 861 } |
862 | 862 |
863 | 863 |
864 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, | 864 RawTokenStream* TokenStream::ReadFrom(SnapshotReader* reader, |
865 intptr_t object_id, | 865 intptr_t object_id, |
866 intptr_t tags, | 866 intptr_t tags, |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 } | 1315 } |
1316 | 1316 |
1317 | 1317 |
1318 RawContext* Context::ReadFrom(SnapshotReader* reader, | 1318 RawContext* Context::ReadFrom(SnapshotReader* reader, |
1319 intptr_t object_id, | 1319 intptr_t object_id, |
1320 intptr_t tags, | 1320 intptr_t tags, |
1321 Snapshot::Kind kind) { | 1321 Snapshot::Kind kind) { |
1322 ASSERT(reader != NULL); | 1322 ASSERT(reader != NULL); |
1323 | 1323 |
1324 // Allocate context object. | 1324 // Allocate context object. |
1325 intptr_t num_vars = reader->ReadIntptrValue(); | 1325 int32_t num_vars = reader->Read<int32_t>(); |
1326 Context& context = Context::ZoneHandle(reader->isolate(), Context::null()); | 1326 Context& context = Context::ZoneHandle(reader->isolate(), Context::null()); |
1327 if (kind == Snapshot::kFull) { | 1327 if (kind == Snapshot::kFull) { |
1328 context = reader->NewContext(num_vars); | 1328 context = reader->NewContext(num_vars); |
1329 } else { | 1329 } else { |
1330 context = Context::New(num_vars, HEAP_SPACE(kind)); | 1330 context = Context::New(num_vars, HEAP_SPACE(kind)); |
1331 } | 1331 } |
1332 reader->AddBackRef(object_id, &context, kIsDeserialized); | 1332 reader->AddBackRef(object_id, &context, kIsDeserialized); |
1333 | 1333 |
1334 // Set the object tags. | 1334 // Set the object tags. |
1335 context.set_tags(tags); | 1335 context.set_tags(tags); |
(...skipping 21 matching lines...) Expand all Loading... |
1357 ASSERT(writer != NULL); | 1357 ASSERT(writer != NULL); |
1358 | 1358 |
1359 // Write out the serialization header value for this object. | 1359 // Write out the serialization header value for this object. |
1360 writer->WriteInlinedObjectHeader(object_id); | 1360 writer->WriteInlinedObjectHeader(object_id); |
1361 | 1361 |
1362 // Write out the class and tags information. | 1362 // Write out the class and tags information. |
1363 writer->WriteVMIsolateObject(kContextCid); | 1363 writer->WriteVMIsolateObject(kContextCid); |
1364 writer->WriteTags(writer->GetObjectTags(this)); | 1364 writer->WriteTags(writer->GetObjectTags(this)); |
1365 | 1365 |
1366 // Write out num of variables in the context. | 1366 // Write out num of variables in the context. |
1367 writer->WriteIntptrValue(ptr()->num_variables_); | 1367 writer->Write<int32_t>(ptr()->num_variables_); |
1368 | 1368 |
1369 // Can't serialize the isolate pointer, we set it implicitly on read. | 1369 // Can't serialize the isolate pointer, we set it implicitly on read. |
1370 | 1370 |
1371 // Write out all the object pointer fields. | 1371 // Write out all the object pointer fields. |
1372 SnapshotWriterVisitor visitor(writer); | 1372 SnapshotWriterVisitor visitor(writer); |
1373 visitor.VisitPointers(from(), to(ptr()->num_variables_)); | 1373 visitor.VisitPointers(from(), to(ptr()->num_variables_)); |
1374 } | 1374 } |
1375 | 1375 |
1376 | 1376 |
1377 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader, | 1377 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader, |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 } | 1689 } |
1690 | 1690 |
1691 | 1691 |
1692 RawBigint* Bigint::ReadFrom(SnapshotReader* reader, | 1692 RawBigint* Bigint::ReadFrom(SnapshotReader* reader, |
1693 intptr_t object_id, | 1693 intptr_t object_id, |
1694 intptr_t tags, | 1694 intptr_t tags, |
1695 Snapshot::Kind kind) { | 1695 Snapshot::Kind kind) { |
1696 ASSERT(reader != NULL); | 1696 ASSERT(reader != NULL); |
1697 | 1697 |
1698 // Read in the HexCString representation of the bigint. | 1698 // Read in the HexCString representation of the bigint. |
1699 intptr_t len = reader->ReadIntptrValue(); | 1699 int32_t len = reader->Read<int32_t>(); |
1700 char* str = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 1700 char* str = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
1701 str[len] = '\0'; | 1701 str[len] = '\0'; |
1702 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); | 1702 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); |
1703 | 1703 |
1704 // Create a Bigint object from HexCString. | 1704 // Create a Bigint object from HexCString. |
1705 Bigint& obj = Bigint::ZoneHandle( | 1705 Bigint& obj = Bigint::ZoneHandle( |
1706 reader->isolate(), | 1706 reader->isolate(), |
1707 ((kind == Snapshot::kFull) ? reader->NewBigint(str) : | 1707 ((kind == Snapshot::kFull) ? reader->NewBigint(str) : |
1708 BigintOperations::FromHexCString(str, HEAP_SPACE(kind)))); | 1708 BigintOperations::FromHexCString(str, HEAP_SPACE(kind)))); |
1709 | 1709 |
(...skipping 26 matching lines...) Expand all Loading... |
1736 ASSERT(writer != NULL); | 1736 ASSERT(writer != NULL); |
1737 | 1737 |
1738 // Write out the serialization header value for this object. | 1738 // Write out the serialization header value for this object. |
1739 writer->WriteInlinedObjectHeader(object_id); | 1739 writer->WriteInlinedObjectHeader(object_id); |
1740 | 1740 |
1741 // Write out the class and tags information. | 1741 // Write out the class and tags information. |
1742 writer->WriteIndexedObject(kBigintCid); | 1742 writer->WriteIndexedObject(kBigintCid); |
1743 writer->WriteTags(writer->GetObjectTags(this)); | 1743 writer->WriteTags(writer->GetObjectTags(this)); |
1744 | 1744 |
1745 // Write out the bigint value as a HEXCstring. | 1745 // Write out the bigint value as a HEXCstring. |
1746 intptr_t length = ptr()->signed_length_; | 1746 int32_t length = ptr()->signed_length_; |
1747 bool is_negative = false; | 1747 bool is_negative = false; |
1748 if (length <= 0) { | 1748 if (length <= 0) { |
1749 length = -length; | 1749 length = -length; |
1750 is_negative = true; | 1750 is_negative = true; |
1751 } | 1751 } |
1752 uword data_start = reinterpret_cast<uword>(ptr()) + sizeof(RawBigint); | 1752 uword data_start = reinterpret_cast<uword>(ptr()) + sizeof(RawBigint); |
1753 const char* str = BigintOperations::ToHexCString( | 1753 const char* str = BigintOperations::ToHexCString( |
1754 length, | 1754 length, |
1755 is_negative, | 1755 is_negative, |
1756 reinterpret_cast<void*>(data_start), | 1756 reinterpret_cast<void*>(data_start), |
1757 &BigintAllocator); | 1757 &BigintAllocator); |
1758 bool neg = false; | 1758 bool neg = false; |
1759 if (*str == '-') { | 1759 if (*str == '-') { |
1760 neg = true; | 1760 neg = true; |
1761 str++; | 1761 str++; |
1762 } | 1762 } |
1763 intptr_t len = strlen(str); | 1763 intptr_t len = strlen(str); |
1764 ASSERT(len > 2 && str[0] == '0' && str[1] == 'x'); | 1764 ASSERT(len > 2 && str[0] == '0' && str[1] == 'x'); |
1765 if (neg) { | 1765 if (neg) { |
1766 writer->WriteIntptrValue(len - 1); // Include '-' in length. | 1766 writer->Write<int32_t>(len - 1); // Include '-' in length. |
1767 writer->Write<uint8_t>('-'); | 1767 writer->Write<uint8_t>('-'); |
1768 } else { | 1768 } else { |
1769 writer->WriteIntptrValue(len - 2); | 1769 writer->Write<int32_t>(len - 2); |
1770 } | 1770 } |
1771 writer->WriteBytes(reinterpret_cast<const uint8_t*>(&(str[2])), (len - 2)); | 1771 writer->WriteBytes(reinterpret_cast<const uint8_t*>(&(str[2])), (len - 2)); |
1772 } | 1772 } |
1773 | 1773 |
1774 | 1774 |
1775 RawDouble* Double::ReadFrom(SnapshotReader* reader, | 1775 RawDouble* Double::ReadFrom(SnapshotReader* reader, |
1776 intptr_t object_id, | 1776 intptr_t object_id, |
1777 intptr_t tags, | 1777 intptr_t tags, |
1778 Snapshot::Kind kind) { | 1778 Snapshot::Kind kind) { |
1779 ASSERT(reader != NULL); | 1779 ASSERT(reader != NULL); |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2667 reader->isolate(), JSRegExp::New(len, HEAP_SPACE(kind))); | 2667 reader->isolate(), JSRegExp::New(len, HEAP_SPACE(kind))); |
2668 reader->AddBackRef(object_id, ®ex, kIsDeserialized); | 2668 reader->AddBackRef(object_id, ®ex, kIsDeserialized); |
2669 | 2669 |
2670 // Set the object tags. | 2670 // Set the object tags. |
2671 regex.set_tags(tags); | 2671 regex.set_tags(tags); |
2672 | 2672 |
2673 // Read and Set all the other fields. | 2673 // Read and Set all the other fields. |
2674 regex.raw_ptr()->num_bracket_expressions_ = reader->ReadAsSmi(); | 2674 regex.raw_ptr()->num_bracket_expressions_ = reader->ReadAsSmi(); |
2675 *reader->StringHandle() ^= reader->ReadObjectImpl(); | 2675 *reader->StringHandle() ^= reader->ReadObjectImpl(); |
2676 regex.set_pattern(*reader->StringHandle()); | 2676 regex.set_pattern(*reader->StringHandle()); |
2677 regex.raw_ptr()->type_ = reader->ReadIntptrValue(); | 2677 regex.raw_ptr()->type_flags_ = reader->Read<int8_t>(); |
2678 regex.raw_ptr()->flags_ = reader->ReadIntptrValue(); | |
2679 | 2678 |
2680 // TODO(5411462): Need to implement a way of recompiling the regex. | 2679 // TODO(5411462): Need to implement a way of recompiling the regex. |
2681 | 2680 |
2682 return regex.raw(); | 2681 return regex.raw(); |
2683 } | 2682 } |
2684 | 2683 |
2685 | 2684 |
2686 void RawJSRegExp::WriteTo(SnapshotWriter* writer, | 2685 void RawJSRegExp::WriteTo(SnapshotWriter* writer, |
2687 intptr_t object_id, | 2686 intptr_t object_id, |
2688 Snapshot::Kind kind) { | 2687 Snapshot::Kind kind) { |
2689 ASSERT(writer != NULL); | 2688 ASSERT(writer != NULL); |
2690 ASSERT(kind == Snapshot::kMessage); | 2689 ASSERT(kind == Snapshot::kMessage); |
2691 | 2690 |
2692 // Write out the serialization header value for this object. | 2691 // Write out the serialization header value for this object. |
2693 writer->WriteInlinedObjectHeader(object_id); | 2692 writer->WriteInlinedObjectHeader(object_id); |
2694 | 2693 |
2695 // Write out the class and tags information. | 2694 // Write out the class and tags information. |
2696 writer->WriteIndexedObject(kJSRegExpCid); | 2695 writer->WriteIndexedObject(kJSRegExpCid); |
2697 writer->WriteTags(writer->GetObjectTags(this)); | 2696 writer->WriteTags(writer->GetObjectTags(this)); |
2698 | 2697 |
2699 // Write out the data length field. | 2698 // Write out the data length field. |
2700 writer->Write<RawObject*>(ptr()->data_length_); | 2699 writer->Write<RawObject*>(ptr()->data_length_); |
2701 | 2700 |
2702 // Write out all the other fields. | 2701 // Write out all the other fields. |
2703 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); | 2702 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); |
2704 writer->WriteObjectImpl(ptr()->pattern_); | 2703 writer->WriteObjectImpl(ptr()->pattern_); |
2705 writer->WriteIntptrValue(ptr()->type_); | 2704 writer->Write<int8_t>(ptr()->type_flags_); |
2706 writer->WriteIntptrValue(ptr()->flags_); | |
2707 | 2705 |
2708 // Do not write out the data part which is native. | 2706 // Do not write out the data part which is native. |
2709 } | 2707 } |
2710 | 2708 |
2711 | 2709 |
2712 RawWeakProperty* WeakProperty::ReadFrom(SnapshotReader* reader, | 2710 RawWeakProperty* WeakProperty::ReadFrom(SnapshotReader* reader, |
2713 intptr_t object_id, | 2711 intptr_t object_id, |
2714 intptr_t tags, | 2712 intptr_t tags, |
2715 Snapshot::Kind kind) { | 2713 Snapshot::Kind kind) { |
2716 ASSERT(reader != NULL); | 2714 ASSERT(reader != NULL); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2788 // We do not allow objects with native fields in an isolate message. | 2786 // We do not allow objects with native fields in an isolate message. |
2789 writer->SetWriteException(Exceptions::kArgument, | 2787 writer->SetWriteException(Exceptions::kArgument, |
2790 "Illegal argument in isolate message" | 2788 "Illegal argument in isolate message" |
2791 " : (object is a UserTag)"); | 2789 " : (object is a UserTag)"); |
2792 } else { | 2790 } else { |
2793 UNREACHABLE(); | 2791 UNREACHABLE(); |
2794 } | 2792 } |
2795 } | 2793 } |
2796 | 2794 |
2797 } // namespace dart | 2795 } // namespace dart |
OLD | NEW |