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

Side by Side Diff: src/serialize.cc

Issue 71163006: Merge bleeding_edge r17376:17693. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Fix all.gyp Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/scopes.cc ('k') | src/spaces.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 Add(stub_cache->map_reference(StubCache::kSecondary).address(), 290 Add(stub_cache->map_reference(StubCache::kSecondary).address(),
291 STUB_CACHE_TABLE, 291 STUB_CACHE_TABLE,
292 6, 292 6,
293 "StubCache::secondary_->map"); 293 "StubCache::secondary_->map");
294 294
295 // Runtime entries 295 // Runtime entries
296 Add(ExternalReference::perform_gc_function(isolate).address(), 296 Add(ExternalReference::perform_gc_function(isolate).address(),
297 RUNTIME_ENTRY, 297 RUNTIME_ENTRY,
298 1, 298 1,
299 "Runtime::PerformGC"); 299 "Runtime::PerformGC");
300 Add(ExternalReference::fill_heap_number_with_random_function(
301 isolate).address(),
302 RUNTIME_ENTRY,
303 2,
304 "V8::FillHeapNumberWithRandom");
305 Add(ExternalReference::random_uint32_function(isolate).address(), 300 Add(ExternalReference::random_uint32_function(isolate).address(),
306 RUNTIME_ENTRY, 301 RUNTIME_ENTRY,
307 3, 302 3,
308 "V8::Random"); 303 "V8::Random");
309 Add(ExternalReference::delete_handle_scope_extensions(isolate).address(), 304 Add(ExternalReference::delete_handle_scope_extensions(isolate).address(),
310 RUNTIME_ENTRY, 305 RUNTIME_ENTRY,
311 4, 306 4,
312 "HandleScope::DeleteExtensions"); 307 "HandleScope::DeleteExtensions");
313 Add(ExternalReference:: 308 Add(ExternalReference::
314 incremental_marking_record_write_function(isolate).address(), 309 incremental_marking_record_write_function(isolate).address(),
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 "Runtime::AllocateInOldDataSpace"); 561 "Runtime::AllocateInOldDataSpace");
567 Add(ExternalReference::new_space_high_promotion_mode_active_address(isolate). 562 Add(ExternalReference::new_space_high_promotion_mode_active_address(isolate).
568 address(), 563 address(),
569 UNCLASSIFIED, 564 UNCLASSIFIED,
570 60, 565 60,
571 "Heap::NewSpaceAllocationLimitAddress"); 566 "Heap::NewSpaceAllocationLimitAddress");
572 Add(ExternalReference::allocation_sites_list_address(isolate).address(), 567 Add(ExternalReference::allocation_sites_list_address(isolate).address(),
573 UNCLASSIFIED, 568 UNCLASSIFIED,
574 61, 569 61,
575 "Heap::allocation_sites_list_address()"); 570 "Heap::allocation_sites_list_address()");
576 Add(ExternalReference::record_object_allocation_function(isolate).address(), 571 Add(ExternalReference::address_of_uint32_bias().address(),
577 UNCLASSIFIED, 572 UNCLASSIFIED,
578 62, 573 62,
579 "HeapProfiler::RecordObjectAllocationFromMasm");
580 Add(ExternalReference::address_of_uint32_bias().address(),
581 UNCLASSIFIED,
582 63,
583 "uint32_bias"); 574 "uint32_bias");
584 Add(ExternalReference::get_mark_code_as_executed_function(isolate).address(), 575 Add(ExternalReference::get_mark_code_as_executed_function(isolate).address(),
585 UNCLASSIFIED, 576 UNCLASSIFIED,
586 64, 577 63,
587 "Code::MarkCodeAsExecuted"); 578 "Code::MarkCodeAsExecuted");
588 579
589 // Add a small set of deopt entry addresses to encoder without generating the 580 // Add a small set of deopt entry addresses to encoder without generating the
590 // deopt table code, which isn't possible at deserialization time. 581 // deopt table code, which isn't possible at deserialization time.
591 HandleScope scope(isolate); 582 HandleScope scope(isolate);
592 for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) { 583 for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) {
593 Address address = Deoptimizer::GetDeoptimizationEntry( 584 Address address = Deoptimizer::GetDeoptimizationEntry(
594 isolate, 585 isolate,
595 entry, 586 entry,
596 Deoptimizer::LAZY, 587 Deoptimizer::LAZY,
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 current_contents, kPlain, kStartOfObject, 0); 1652 current_contents, kPlain, kStartOfObject, 0);
1662 bytes_processed_so_far_ += kPointerSize; 1653 bytes_processed_so_far_ += kPointerSize;
1663 current++; 1654 current++;
1664 } 1655 }
1665 } 1656 }
1666 } 1657 }
1667 } 1658 }
1668 1659
1669 1660
1670 void Serializer::ObjectSerializer::VisitEmbeddedPointer(RelocInfo* rinfo) { 1661 void Serializer::ObjectSerializer::VisitEmbeddedPointer(RelocInfo* rinfo) {
1671 Object** current = rinfo->target_object_address();
1672
1673 int skip = OutputRawData(rinfo->target_address_address(), 1662 int skip = OutputRawData(rinfo->target_address_address(),
1674 kCanReturnSkipInsteadOfSkipping); 1663 kCanReturnSkipInsteadOfSkipping);
1675 HowToCode representation = rinfo->IsCodedSpecially() ? kFromCode : kPlain; 1664 HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
1676 serializer_->SerializeObject(*current, representation, kStartOfObject, skip); 1665 Object* object = rinfo->target_object();
1666 serializer_->SerializeObject(object, how_to_code, kStartOfObject, skip);
1677 bytes_processed_so_far_ += rinfo->target_address_size(); 1667 bytes_processed_so_far_ += rinfo->target_address_size();
1678 } 1668 }
1679 1669
1680 1670
1681 void Serializer::ObjectSerializer::VisitExternalReference(Address* p) { 1671 void Serializer::ObjectSerializer::VisitExternalReference(Address* p) {
1682 Address references_start = reinterpret_cast<Address>(p); 1672 int skip = OutputRawData(reinterpret_cast<Address>(p),
1683 int skip = OutputRawData(references_start, kCanReturnSkipInsteadOfSkipping); 1673 kCanReturnSkipInsteadOfSkipping);
1684
1685 sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef"); 1674 sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef");
1686 sink_->PutInt(skip, "SkipB4ExternalRef"); 1675 sink_->PutInt(skip, "SkipB4ExternalRef");
1687 int reference_id = serializer_->EncodeExternalReference(*p); 1676 Address target = *p;
1688 sink_->PutInt(reference_id, "reference id"); 1677 sink_->PutInt(serializer_->EncodeExternalReference(target), "reference id");
1689 bytes_processed_so_far_ += kPointerSize; 1678 bytes_processed_so_far_ += kPointerSize;
1690 } 1679 }
1691 1680
1692 1681
1693 void Serializer::ObjectSerializer::VisitExternalReference(RelocInfo* rinfo) { 1682 void Serializer::ObjectSerializer::VisitExternalReference(RelocInfo* rinfo) {
1694 Address references_start = rinfo->target_address_address(); 1683 int skip = OutputRawData(rinfo->target_address_address(),
1695 int skip = OutputRawData(references_start, kCanReturnSkipInsteadOfSkipping); 1684 kCanReturnSkipInsteadOfSkipping);
1696 1685 HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
1697 Address* current = rinfo->target_reference_address(); 1686 sink_->Put(kExternalReference + how_to_code + kStartOfObject, "ExternalRef");
1698 int representation = rinfo->IsCodedSpecially() ?
1699 kFromCode + kStartOfObject : kPlain + kStartOfObject;
1700 sink_->Put(kExternalReference + representation, "ExternalRef");
1701 sink_->PutInt(skip, "SkipB4ExternalRef"); 1687 sink_->PutInt(skip, "SkipB4ExternalRef");
1702 int reference_id = serializer_->EncodeExternalReference(*current); 1688 Address target = rinfo->target_reference();
1703 sink_->PutInt(reference_id, "reference id"); 1689 sink_->PutInt(serializer_->EncodeExternalReference(target), "reference id");
1704 bytes_processed_so_far_ += rinfo->target_address_size(); 1690 bytes_processed_so_far_ += rinfo->target_address_size();
1705 } 1691 }
1706 1692
1707 1693
1708 void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) { 1694 void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) {
1709 Address target_start = rinfo->target_address_address(); 1695 int skip = OutputRawData(rinfo->target_address_address(),
1710 int skip = OutputRawData(target_start, kCanReturnSkipInsteadOfSkipping); 1696 kCanReturnSkipInsteadOfSkipping);
1697 HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
1698 sink_->Put(kExternalReference + how_to_code + kStartOfObject, "ExternalRef");
1699 sink_->PutInt(skip, "SkipB4ExternalRef");
1711 Address target = rinfo->target_address(); 1700 Address target = rinfo->target_address();
1712 uint32_t encoding = serializer_->EncodeExternalReference(target); 1701 sink_->PutInt(serializer_->EncodeExternalReference(target), "reference id");
1713 CHECK(target == NULL ? encoding == 0 : encoding != 0);
1714 int representation;
1715 // Can't use a ternary operator because of gcc.
1716 if (rinfo->IsCodedSpecially()) {
1717 representation = kStartOfObject + kFromCode;
1718 } else {
1719 representation = kStartOfObject + kPlain;
1720 }
1721 sink_->Put(kExternalReference + representation, "ExternalReference");
1722 sink_->PutInt(skip, "SkipB4ExternalRef");
1723 sink_->PutInt(encoding, "reference id");
1724 bytes_processed_so_far_ += rinfo->target_address_size(); 1702 bytes_processed_so_far_ += rinfo->target_address_size();
1725 } 1703 }
1726 1704
1727 1705
1728 void Serializer::ObjectSerializer::VisitCodeTarget(RelocInfo* rinfo) { 1706 void Serializer::ObjectSerializer::VisitCodeTarget(RelocInfo* rinfo) {
1729 CHECK(RelocInfo::IsCodeTarget(rinfo->rmode())); 1707 int skip = OutputRawData(rinfo->target_address_address(),
1730 Address target_start = rinfo->target_address_address(); 1708 kCanReturnSkipInsteadOfSkipping);
1731 int skip = OutputRawData(target_start, kCanReturnSkipInsteadOfSkipping); 1709 Code* object = Code::GetCodeFromTargetAddress(rinfo->target_address());
1732 Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address()); 1710 serializer_->SerializeObject(object, kFromCode, kInnerPointer, skip);
1733 serializer_->SerializeObject(target, kFromCode, kInnerPointer, skip);
1734 bytes_processed_so_far_ += rinfo->target_address_size(); 1711 bytes_processed_so_far_ += rinfo->target_address_size();
1735 } 1712 }
1736 1713
1737 1714
1738 void Serializer::ObjectSerializer::VisitCodeEntry(Address entry_address) { 1715 void Serializer::ObjectSerializer::VisitCodeEntry(Address entry_address) {
1739 Code* target = Code::cast(Code::GetObjectFromEntryAddress(entry_address));
1740 int skip = OutputRawData(entry_address, kCanReturnSkipInsteadOfSkipping); 1716 int skip = OutputRawData(entry_address, kCanReturnSkipInsteadOfSkipping);
1741 serializer_->SerializeObject(target, kPlain, kInnerPointer, skip); 1717 Code* object = Code::cast(Code::GetObjectFromEntryAddress(entry_address));
1718 serializer_->SerializeObject(object, kPlain, kInnerPointer, skip);
1742 bytes_processed_so_far_ += kPointerSize; 1719 bytes_processed_so_far_ += kPointerSize;
1743 } 1720 }
1744 1721
1745 1722
1746 void Serializer::ObjectSerializer::VisitCell(RelocInfo* rinfo) { 1723 void Serializer::ObjectSerializer::VisitCell(RelocInfo* rinfo) {
1747 ASSERT(rinfo->rmode() == RelocInfo::CELL);
1748 Cell* cell = Cell::cast(rinfo->target_cell());
1749 int skip = OutputRawData(rinfo->pc(), kCanReturnSkipInsteadOfSkipping); 1724 int skip = OutputRawData(rinfo->pc(), kCanReturnSkipInsteadOfSkipping);
1750 serializer_->SerializeObject(cell, kPlain, kInnerPointer, skip); 1725 Cell* object = Cell::cast(rinfo->target_cell());
1726 serializer_->SerializeObject(object, kPlain, kInnerPointer, skip);
1751 } 1727 }
1752 1728
1753 1729
1754 void Serializer::ObjectSerializer::VisitExternalAsciiString( 1730 void Serializer::ObjectSerializer::VisitExternalAsciiString(
1755 v8::String::ExternalAsciiStringResource** resource_pointer) { 1731 v8::String::ExternalAsciiStringResource** resource_pointer) {
1756 Address references_start = reinterpret_cast<Address>(resource_pointer); 1732 Address references_start = reinterpret_cast<Address>(resource_pointer);
1757 OutputRawData(references_start); 1733 OutputRawData(references_start);
1758 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { 1734 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
1759 Object* source = 1735 Object* source =
1760 serializer_->isolate()->heap()->natives_source_cache()->get(i); 1736 serializer_->isolate()->heap()->natives_source_cache()->get(i);
1761 if (!source->IsUndefined()) { 1737 if (!source->IsUndefined()) {
1762 ExternalAsciiString* string = ExternalAsciiString::cast(source); 1738 ExternalAsciiString* string = ExternalAsciiString::cast(source);
1763 typedef v8::String::ExternalAsciiStringResource Resource; 1739 typedef v8::String::ExternalAsciiStringResource Resource;
1764 const Resource* resource = string->resource(); 1740 const Resource* resource = string->resource();
1765 if (resource == *resource_pointer) { 1741 if (resource == *resource_pointer) {
1766 sink_->Put(kNativesStringResource, "NativesStringResource"); 1742 sink_->Put(kNativesStringResource, "NativesStringResource");
1767 sink_->PutSection(i, "NativesStringResourceEnd"); 1743 sink_->PutSection(i, "NativesStringResourceEnd");
1768 bytes_processed_so_far_ += sizeof(resource); 1744 bytes_processed_so_far_ += sizeof(resource);
1769 return; 1745 return;
1770 } 1746 }
1771 } 1747 }
1772 } 1748 }
1773 // One of the strings in the natives cache should match the resource. We 1749 // One of the strings in the natives cache should match the resource. We
1774 // can't serialize any other kinds of external strings. 1750 // can't serialize any other kinds of external strings.
1775 UNREACHABLE(); 1751 UNREACHABLE();
1776 } 1752 }
1777 1753
1778 1754
1755 static Code* CloneCodeObject(HeapObject* code) {
1756 Address copy = new byte[code->Size()];
1757 OS::MemCopy(copy, code->address(), code->Size());
1758 return Code::cast(HeapObject::FromAddress(copy));
1759 }
1760
1761
1762 static void WipeOutRelocations(Code* code) {
1763 int mode_mask =
1764 RelocInfo::kCodeTargetMask |
1765 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
1766 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
1767 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY);
1768 for (RelocIterator it(code, mode_mask); !it.done(); it.next()) {
1769 it.rinfo()->WipeOut();
1770 }
1771 }
1772
1773
1779 int Serializer::ObjectSerializer::OutputRawData( 1774 int Serializer::ObjectSerializer::OutputRawData(
1780 Address up_to, Serializer::ObjectSerializer::ReturnSkip return_skip) { 1775 Address up_to, Serializer::ObjectSerializer::ReturnSkip return_skip) {
1781 Address object_start = object_->address(); 1776 Address object_start = object_->address();
1782 Address base = object_start + bytes_processed_so_far_; 1777 int base = bytes_processed_so_far_;
1783 int up_to_offset = static_cast<int>(up_to - object_start); 1778 int up_to_offset = static_cast<int>(up_to - object_start);
1784 int to_skip = up_to_offset - bytes_processed_so_far_; 1779 int to_skip = up_to_offset - bytes_processed_so_far_;
1785 int bytes_to_output = to_skip; 1780 int bytes_to_output = to_skip;
1786 bytes_processed_so_far_ += to_skip; 1781 bytes_processed_so_far_ += to_skip;
1787 // This assert will fail if the reloc info gives us the target_address_address 1782 // This assert will fail if the reloc info gives us the target_address_address
1788 // locations in a non-ascending order. Luckily that doesn't happen. 1783 // locations in a non-ascending order. Luckily that doesn't happen.
1789 ASSERT(to_skip >= 0); 1784 ASSERT(to_skip >= 0);
1790 bool outputting_code = false; 1785 bool outputting_code = false;
1791 if (to_skip != 0 && code_object_ && !code_has_been_output_) { 1786 if (to_skip != 0 && code_object_ && !code_has_been_output_) {
1792 // Output the code all at once and fix later. 1787 // Output the code all at once and fix later.
1793 bytes_to_output = object_->Size() + to_skip - bytes_processed_so_far_; 1788 bytes_to_output = object_->Size() + to_skip - bytes_processed_so_far_;
1794 outputting_code = true; 1789 outputting_code = true;
1795 code_has_been_output_ = true; 1790 code_has_been_output_ = true;
1796 } 1791 }
1797 if (bytes_to_output != 0 && 1792 if (bytes_to_output != 0 &&
1798 (!code_object_ || outputting_code)) { 1793 (!code_object_ || outputting_code)) {
1799 #define RAW_CASE(index) \ 1794 #define RAW_CASE(index) \
1800 if (!outputting_code && bytes_to_output == index * kPointerSize && \ 1795 if (!outputting_code && bytes_to_output == index * kPointerSize && \
1801 index * kPointerSize == to_skip) { \ 1796 index * kPointerSize == to_skip) { \
1802 sink_->PutSection(kRawData + index, "RawDataFixed"); \ 1797 sink_->PutSection(kRawData + index, "RawDataFixed"); \
1803 to_skip = 0; /* This insn already skips. */ \ 1798 to_skip = 0; /* This insn already skips. */ \
1804 } else /* NOLINT */ 1799 } else /* NOLINT */
1805 COMMON_RAW_LENGTHS(RAW_CASE) 1800 COMMON_RAW_LENGTHS(RAW_CASE)
1806 #undef RAW_CASE 1801 #undef RAW_CASE
1807 { /* NOLINT */ 1802 { /* NOLINT */
1808 // We always end up here if we are outputting the code of a code object. 1803 // We always end up here if we are outputting the code of a code object.
1809 sink_->Put(kRawData, "RawData"); 1804 sink_->Put(kRawData, "RawData");
1810 sink_->PutInt(bytes_to_output, "length"); 1805 sink_->PutInt(bytes_to_output, "length");
1811 } 1806 }
1807
1808 // To make snapshots reproducible, we need to wipe out all pointers in code.
1809 if (code_object_) {
1810 Code* code = CloneCodeObject(object_);
1811 WipeOutRelocations(code);
1812 // We need to wipe out the header fields *after* wiping out the
1813 // relocations, because some of these fields are needed for the latter.
1814 code->WipeOutHeader();
1815 object_start = code->address();
1816 }
1817
1818 const char* description = code_object_ ? "Code" : "Byte";
1812 for (int i = 0; i < bytes_to_output; i++) { 1819 for (int i = 0; i < bytes_to_output; i++) {
1813 unsigned int data = base[i]; 1820 sink_->PutSection(object_start[base + i], description);
1814 sink_->PutSection(data, "Byte");
1815 } 1821 }
1822 if (code_object_) delete[] object_start;
1816 } 1823 }
1817 if (to_skip != 0 && return_skip == kIgnoringReturn) { 1824 if (to_skip != 0 && return_skip == kIgnoringReturn) {
1818 sink_->Put(kSkip, "Skip"); 1825 sink_->Put(kSkip, "Skip");
1819 sink_->PutInt(to_skip, "SkipDistance"); 1826 sink_->PutInt(to_skip, "SkipDistance");
1820 to_skip = 0; 1827 to_skip = 0;
1821 } 1828 }
1822 return to_skip; 1829 return to_skip;
1823 } 1830 }
1824 1831
1825 1832
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 1871
1865 bool SnapshotByteSource::AtEOF() { 1872 bool SnapshotByteSource::AtEOF() {
1866 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; 1873 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
1867 for (int x = position_; x < length_; x++) { 1874 for (int x = position_; x < length_; x++) {
1868 if (data_[x] != SerializerDeserializer::nop()) return false; 1875 if (data_[x] != SerializerDeserializer::nop()) return false;
1869 } 1876 }
1870 return true; 1877 return true;
1871 } 1878 }
1872 1879
1873 } } // namespace v8::internal 1880 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.cc ('k') | src/spaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698