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

Side by Side Diff: src/serialize.cc

Issue 376223002: Refactor ScriptData class for cached compile data. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 1790
1791 int Serializer::SpaceAreaSize(int space) { 1791 int Serializer::SpaceAreaSize(int space) {
1792 if (space == CODE_SPACE) { 1792 if (space == CODE_SPACE) {
1793 return isolate_->memory_allocator()->CodePageAreaSize(); 1793 return isolate_->memory_allocator()->CodePageAreaSize();
1794 } else { 1794 } else {
1795 return Page::kPageSize - Page::kObjectStartOffset; 1795 return Page::kPageSize - Page::kObjectStartOffset;
1796 } 1796 }
1797 } 1797 }
1798 1798
1799 1799
1800 void Serializer::PadByte() { sink_->Put(kNop, "Padding"); }
1801
1802
1803 void Serializer::Pad() { 1800 void Serializer::Pad() {
1804 // The non-branching GetInt will read up to 3 bytes too far, so we need 1801 // The non-branching GetInt will read up to 3 bytes too far, so we need
1805 // to pad the snapshot to make sure we don't read over the end. 1802 // to pad the snapshot to make sure we don't read over the end.
1806 for (unsigned i = 0; i < sizeof(int32_t) - 1; i++) PadByte(); 1803 for (unsigned i = 0; i < sizeof(int32_t) - 1; i++) {
1804 sink_->Put(kNop, "Padding");
1805 }
1807 } 1806 }
1808 1807
1809 1808
1810 void Serializer::InitializeCodeAddressMap() { 1809 void Serializer::InitializeCodeAddressMap() {
1811 isolate_->InitializeLoggingAndCounters(); 1810 isolate_->InitializeLoggingAndCounters();
1812 code_address_map_ = new CodeAddressMap(isolate_); 1811 code_address_map_ = new CodeAddressMap(isolate_);
1813 } 1812 }
1814 1813
1815 1814
1816 ScriptData* CodeSerializer::Serialize(Handle<SharedFunctionInfo> info) { 1815 ScriptData* CodeSerializer::Serialize(Handle<SharedFunctionInfo> info) {
1817 // Serialize code object. 1816 // Serialize code object.
1818 List<char> payload; 1817 List<byte> payload;
1819 ListSnapshotSink listsink(&payload); 1818 ListSnapshotSink list_sink(&payload);
1820 CodeSerializer ser(info->GetIsolate(), &listsink); 1819 CodeSerializer cs(info->GetIsolate(), &list_sink);
1821 DisallowHeapAllocation no_gc; 1820 DisallowHeapAllocation no_gc;
1822 Object** location = Handle<Object>::cast(info).location(); 1821 Object** location = Handle<Object>::cast(info).location();
1823 ser.VisitPointer(location); 1822 cs.VisitPointer(location);
1824 ser.Pad(); 1823 cs.Pad();
1825 1824
1826 // Allocate storage. The payload length may not be aligned. Round up. 1825 SerializedCodeData data(&payload, &cs);
1827 // TODO(yangguo) replace ScriptData with a more generic super class. 1826 return data.GetScriptData();
1828 int payload_length = payload.length();
1829 int raw_length = payload_length / sizeof(unsigned) + kHeaderSize;
1830 if (!IsAligned(payload_length, sizeof(unsigned))) raw_length++;
1831 unsigned* raw_data = i::NewArray<unsigned>(raw_length);
1832 char* payload_data = reinterpret_cast<char*>(raw_data + kHeaderSize);
1833
1834 // Write header.
1835 raw_data[kVersionHashOffset] = Version::Hash();
1836 raw_data[kPayloadLengthOffset] = payload_length;
1837 STATIC_ASSERT(NEW_SPACE == 0);
1838 for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) {
1839 raw_data[kReservationsOffset + i] = ser.CurrentAllocationAddress(i);
1840 }
1841
1842 CopyBytes(payload_data, payload.begin(), static_cast<size_t>(payload_length));
1843
1844 return new ScriptData(Vector<unsigned>(raw_data, raw_length), true);
1845 } 1827 }
1846 1828
1847 1829
1848 void CodeSerializer::SerializeObject(Object* o, HowToCode how_to_code, 1830 void CodeSerializer::SerializeObject(Object* o, HowToCode how_to_code,
1849 WhereToPoint where_to_point, int skip) { 1831 WhereToPoint where_to_point, int skip) {
1850 CHECK(o->IsHeapObject()); 1832 CHECK(o->IsHeapObject());
1851 HeapObject* heap_object = HeapObject::cast(o); 1833 HeapObject* heap_object = HeapObject::cast(o);
1852 1834
1853 // The code-caches link to context-specific code objects, which 1835 // The code-caches link to context-specific code objects, which
1854 // the startup and context serializes cannot currently handle. 1836 // the startup and context serializes cannot currently handle.
(...skipping 28 matching lines...) Expand all
1883 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); 1865 sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
1884 } 1866 }
1885 // Object has not yet been serialized. Serialize it here. 1867 // Object has not yet been serialized. Serialize it here.
1886 ObjectSerializer serializer(this, heap_object, sink_, how_to_code, 1868 ObjectSerializer serializer(this, heap_object, sink_, how_to_code,
1887 where_to_point); 1869 where_to_point);
1888 serializer.Serialize(); 1870 serializer.Serialize();
1889 } 1871 }
1890 1872
1891 1873
1892 Object* CodeSerializer::Deserialize(Isolate* isolate, ScriptData* data) { 1874 Object* CodeSerializer::Deserialize(Isolate* isolate, ScriptData* data) {
1893 const unsigned* raw_data = reinterpret_cast<const unsigned*>(data->Data()); 1875 SerializedCodeData scd(data);
1894 CHECK_EQ(Version::Hash(), raw_data[kVersionHashOffset]); 1876 SnapshotByteSource payload(scd.Payload(), scd.PayloadLength());
1895 int payload_length = raw_data[kPayloadLengthOffset];
1896 const byte* payload_data =
1897 reinterpret_cast<const byte*>(raw_data + kHeaderSize);
1898 ASSERT_LE(payload_length, data->Length() - kHeaderSize);
1899
1900 SnapshotByteSource payload(payload_data, payload_length);
1901 Deserializer deserializer(&payload); 1877 Deserializer deserializer(&payload);
1902 STATIC_ASSERT(NEW_SPACE == 0); 1878 STATIC_ASSERT(NEW_SPACE == 0);
1903 // TODO(yangguo) what happens if remaining new space is too small? 1879 // TODO(yangguo) what happens if remaining new space is too small?
1904 for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) { 1880 for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) {
1905 deserializer.set_reservation( 1881 deserializer.set_reservation(i, scd.GetReservation(i));
1906 i, raw_data[CodeSerializer::kReservationsOffset + i]);
1907 } 1882 }
1908 Object* root; 1883 Object* root;
1909 deserializer.DeserializePartial(isolate, &root); 1884 deserializer.DeserializePartial(isolate, &root);
1910 deserializer.FlushICacheForNewCodeObjects(); 1885 deserializer.FlushICacheForNewCodeObjects();
1911 ASSERT(root->IsSharedFunctionInfo()); 1886 ASSERT(root->IsSharedFunctionInfo());
1912 return root; 1887 return root;
1913 } 1888 }
1889
1890
1891 SerializedCodeData::SerializedCodeData(List<byte>* payload, CodeSerializer* cs)
1892 : owns_script_data_(true) {
1893 int data_length = payload->length() + kHeaderEntries * kIntSize;
1894 byte* data = NewArray<byte>(data_length);
1895 ASSERT(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment));
1896 CopyBytes(data + kHeaderEntries * kIntSize, payload->begin(),
1897 static_cast<size_t>(payload->length()));
1898 script_data_ = new ScriptData(data, data_length);
1899 script_data_->AcquireDataOwnership();
1900 SetHeaderValue(kVersionHashOffset, Version::Hash());
1901 STATIC_ASSERT(NEW_SPACE == 0);
1902 for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) {
1903 SetHeaderValue(kReservationsOffset + i, cs->CurrentAllocationAddress(i));
1904 }
1905 }
1906
1907
1908 bool SerializedCodeData::IsSane() {
1909 return GetHeaderValue(kVersionHashOffset) == Version::Hash() &&
1910 PayloadLength() >= SharedFunctionInfo::kSize;
1911 }
1914 } } // namespace v8::internal 1912 } } // namespace v8::internal
OLDNEW
« src/preparse-data.h ('K') | « src/serialize.h ('k') | src/snapshot-source-sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698