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

Side by Side Diff: src/serialize.cc

Issue 674883002: Tweaks to the code serializer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix large object back references Created 6 years, 2 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
« no previous file with comments | « src/serialize.h ('k') | test/cctest/test-serialize.cc » ('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 // 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 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 void Serializer::ObjectSerializer::VisitPointers(Object** start, 1670 void Serializer::ObjectSerializer::VisitPointers(Object** start,
1671 Object** end) { 1671 Object** end) {
1672 Object** current = start; 1672 Object** current = start;
1673 while (current < end) { 1673 while (current < end) {
1674 while (current < end && (*current)->IsSmi()) current++; 1674 while (current < end && (*current)->IsSmi()) current++;
1675 if (current < end) OutputRawData(reinterpret_cast<Address>(current)); 1675 if (current < end) OutputRawData(reinterpret_cast<Address>(current));
1676 1676
1677 while (current < end && !(*current)->IsSmi()) { 1677 while (current < end && !(*current)->IsSmi()) {
1678 HeapObject* current_contents = HeapObject::cast(*current); 1678 HeapObject* current_contents = HeapObject::cast(*current);
1679 int root_index = serializer_->root_index_map()->Lookup(current_contents); 1679 int root_index = serializer_->root_index_map()->Lookup(current_contents);
1680 // Repeats are not subject to the write barrier so there are only some 1680 // Repeats are not subject to the write barrier so we can only use
1681 // objects that can be used in a repeat encoding. These are the early 1681 // immortal immovable root members. They are never in new space.
1682 // ones in the root array that are never in new space.
1683 if (current != start && root_index != RootIndexMap::kInvalidRootIndex && 1682 if (current != start && root_index != RootIndexMap::kInvalidRootIndex &&
1684 root_index < kRootArrayNumberOfConstantEncodings && 1683 Heap::RootIsImmortalImmovable(root_index) &&
1685 current_contents == current[-1]) { 1684 current_contents == current[-1]) {
1686 DCHECK(!serializer_->isolate()->heap()->InNewSpace(current_contents)); 1685 DCHECK(!serializer_->isolate()->heap()->InNewSpace(current_contents));
1687 int repeat_count = 1; 1686 int repeat_count = 1;
1688 while (&current[repeat_count] < end - 1 && 1687 while (&current[repeat_count] < end - 1 &&
1689 current[repeat_count] == current_contents) { 1688 current[repeat_count] == current_contents) {
1690 repeat_count++; 1689 repeat_count++;
1691 } 1690 }
1692 current += repeat_count; 1691 current += repeat_count;
1693 bytes_processed_so_far_ += repeat_count * kPointerSize; 1692 bytes_processed_so_far_ += repeat_count * kPointerSize;
1694 if (repeat_count > kMaxRepeats) { 1693 if (repeat_count > kMaxRepeats) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 } 1900 }
1902 UNREACHABLE(); 1901 UNREACHABLE();
1903 return INVALID_SPACE; 1902 return INVALID_SPACE;
1904 } 1903 }
1905 1904
1906 1905
1907 BackReference Serializer::AllocateLargeObject(int size) { 1906 BackReference Serializer::AllocateLargeObject(int size) {
1908 // Large objects are allocated one-by-one when deserializing. We do not 1907 // Large objects are allocated one-by-one when deserializing. We do not
1909 // have to keep track of multiple chunks. 1908 // have to keep track of multiple chunks.
1910 pending_chunk_[LO_SPACE] += size; 1909 pending_chunk_[LO_SPACE] += size;
1911 return BackReference(LO_SPACE, 0, seen_large_objects_index_++); 1910 return BackReference::LargeObjectReference(seen_large_objects_index_++);
1912 } 1911 }
1913 1912
1914 1913
1915 BackReference Serializer::Allocate(AllocationSpace space, int size) { 1914 BackReference Serializer::Allocate(AllocationSpace space, int size) {
1916 CHECK(space >= 0 && space < kNumberOfPreallocatedSpaces); 1915 CHECK(space >= 0 && space < kNumberOfPreallocatedSpaces);
1917 DCHECK(size > 0 && size <= Page::kMaxRegularHeapObjectSize); 1916 DCHECK(size > 0 && size <= Page::kMaxRegularHeapObjectSize);
1918 uint32_t new_chunk_size = pending_chunk_[space] + size; 1917 uint32_t new_chunk_size = pending_chunk_[space] + size;
1919 if (new_chunk_size > static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize)) { 1918 if (new_chunk_size > static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize)) {
1920 // The new chunk size would not fit onto a single page. Complete the 1919 // The new chunk size would not fit onto a single page. Complete the
1921 // current chunk and start a new one. 1920 // current chunk and start a new one.
1922 completed_chunks_[space].Add(pending_chunk_[space]); 1921 completed_chunks_[space].Add(pending_chunk_[space]);
1923 pending_chunk_[space] = 0; 1922 pending_chunk_[space] = 0;
1924 new_chunk_size = size; 1923 new_chunk_size = size;
1925 } 1924 }
1926 uint32_t offset = pending_chunk_[space]; 1925 uint32_t offset = pending_chunk_[space];
1927 pending_chunk_[space] = new_chunk_size; 1926 pending_chunk_[space] = new_chunk_size;
1928 return BackReference(space, completed_chunks_[space].length(), offset); 1927 return BackReference::Reference(space, completed_chunks_[space].length(),
1928 offset);
1929 } 1929 }
1930 1930
1931 1931
1932 int Serializer::SpaceAreaSize(int space) { 1932 int Serializer::SpaceAreaSize(int space) {
1933 if (space == CODE_SPACE) { 1933 if (space == CODE_SPACE) {
1934 return isolate_->memory_allocator()->CodePageAreaSize(); 1934 return isolate_->memory_allocator()->CodePageAreaSize();
1935 } else { 1935 } else {
1936 return Page::kPageSize - Page::kObjectStartOffset; 1936 return Page::kPageSize - Page::kObjectStartOffset;
1937 } 1937 }
1938 } 1938 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 if (root_index != RootIndexMap::kInvalidRootIndex) { 2000 if (root_index != RootIndexMap::kInvalidRootIndex) {
2001 if (FLAG_trace_code_serializer) { 2001 if (FLAG_trace_code_serializer) {
2002 PrintF(" Encoding root: %d\n", root_index); 2002 PrintF(" Encoding root: %d\n", root_index);
2003 } 2003 }
2004 PutRoot(root_index, obj, how_to_code, where_to_point, skip); 2004 PutRoot(root_index, obj, how_to_code, where_to_point, skip);
2005 return; 2005 return;
2006 } 2006 }
2007 2007
2008 BackReference back_reference = back_reference_map_.Lookup(obj); 2008 BackReference back_reference = back_reference_map_.Lookup(obj);
2009 if (back_reference.is_valid()) { 2009 if (back_reference.is_valid()) {
2010 if (FLAG_trace_code_serializer) { 2010 if (back_reference.is_source()) {
2011 PrintF(" Encoding back reference to: "); 2011 DCHECK_EQ(source_, obj);
2012 obj->ShortPrint(); 2012 SerializeSourceObject(how_to_code, where_to_point);
2013 PrintF("\n"); 2013 } else {
2014 if (FLAG_trace_code_serializer) {
2015 PrintF(" Encoding back reference to: ");
2016 obj->ShortPrint();
2017 PrintF("\n");
2018 }
2019 SerializeBackReference(back_reference, how_to_code, where_to_point, skip);
2014 } 2020 }
2015 SerializeBackReference(back_reference, how_to_code, where_to_point, skip);
2016 return; 2021 return;
2017 } 2022 }
2018 2023
2019 if (skip != 0) { 2024 if (skip != 0) {
2020 sink_->Put(kSkip, "SkipFromSerializeObject"); 2025 sink_->Put(kSkip, "SkipFromSerializeObject");
2021 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); 2026 sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
2022 } 2027 }
2023 2028
2024 if (obj->IsCode()) { 2029 if (obj->IsCode()) {
2025 Code* code_object = Code::cast(obj); 2030 Code* code_object = Code::cast(obj);
(...skipping 23 matching lines...) Expand all
2049 SerializeBuiltin(Builtins::kCompileLazy, how_to_code, where_to_point); 2054 SerializeBuiltin(Builtins::kCompileLazy, how_to_code, where_to_point);
2050 } else { 2055 } else {
2051 code_object->MakeYoung(); 2056 code_object->MakeYoung();
2052 SerializeGeneric(code_object, how_to_code, where_to_point); 2057 SerializeGeneric(code_object, how_to_code, where_to_point);
2053 } 2058 }
2054 return; 2059 return;
2055 } 2060 }
2056 UNREACHABLE(); 2061 UNREACHABLE();
2057 } 2062 }
2058 2063
2059 if (obj == source_) {
2060 SerializeSourceObject(how_to_code, where_to_point);
2061 return;
2062 }
2063
2064 // Past this point we should not see any (context-specific) maps anymore. 2064 // Past this point we should not see any (context-specific) maps anymore.
2065 CHECK(!obj->IsMap()); 2065 CHECK(!obj->IsMap());
2066 // There should be no references to the global object embedded. 2066 // There should be no references to the global object embedded.
2067 CHECK(!obj->IsJSGlobalProxy() && !obj->IsGlobalObject()); 2067 CHECK(!obj->IsJSGlobalProxy() && !obj->IsGlobalObject());
2068 // There should be no hash table embedded. They would require rehashing. 2068 // There should be no hash table embedded. They would require rehashing.
2069 CHECK(!obj->IsHashTable()); 2069 CHECK(!obj->IsHashTable());
2070 2070
2071 SerializeGeneric(obj, how_to_code, where_to_point); 2071 SerializeGeneric(obj, how_to_code, where_to_point);
2072 } 2072 }
2073 2073
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 2324
2325 int SerializedCodeData::CheckSum(String* string) { 2325 int SerializedCodeData::CheckSum(String* string) {
2326 int checksum = Version::Hash(); 2326 int checksum = Version::Hash();
2327 #ifdef DEBUG 2327 #ifdef DEBUG
2328 uint32_t seed = static_cast<uint32_t>(checksum); 2328 uint32_t seed = static_cast<uint32_t>(checksum);
2329 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed)); 2329 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed));
2330 #endif // DEBUG 2330 #endif // DEBUG
2331 return checksum; 2331 return checksum;
2332 } 2332 }
2333 } } // namespace v8::internal 2333 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698