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

Side by Side Diff: src/serialize.cc

Issue 686103004: Break allocations in the code serializer into correct chunk sizes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 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/serialize.h ('k') | no next file » | 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 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 DCHECK_EQ(limit, current); 1251 DCHECK_EQ(limit, current);
1252 } 1252 }
1253 1253
1254 1254
1255 Serializer::Serializer(Isolate* isolate, SnapshotByteSink* sink) 1255 Serializer::Serializer(Isolate* isolate, SnapshotByteSink* sink)
1256 : isolate_(isolate), 1256 : isolate_(isolate),
1257 sink_(sink), 1257 sink_(sink),
1258 external_reference_encoder_(new ExternalReferenceEncoder(isolate)), 1258 external_reference_encoder_(new ExternalReferenceEncoder(isolate)),
1259 root_index_map_(isolate), 1259 root_index_map_(isolate),
1260 code_address_map_(NULL), 1260 code_address_map_(NULL),
1261 large_objects_total_size_(0),
1261 seen_large_objects_index_(0) { 1262 seen_large_objects_index_(0) {
1262 // The serializer is meant to be used only to generate initial heap images 1263 // The serializer is meant to be used only to generate initial heap images
1263 // from a context in which there is only one isolate. 1264 // from a context in which there is only one isolate.
1264 for (int i = 0; i < kNumberOfSpaces; i++) pending_chunk_[i] = 0; 1265 for (int i = 0; i < kNumberOfPreallocatedSpaces; i++) {
1266 pending_chunk_[i] = 0;
1267 max_chunk_size_[i] = static_cast<uint32_t>(
1268 MemoryAllocator::PageAreaSize(static_cast<AllocationSpace>(i)));
1269 }
1265 } 1270 }
1266 1271
1267 1272
1268 Serializer::~Serializer() { 1273 Serializer::~Serializer() {
1269 delete external_reference_encoder_; 1274 delete external_reference_encoder_;
1270 if (code_address_map_ != NULL) delete code_address_map_; 1275 if (code_address_map_ != NULL) delete code_address_map_;
1271 } 1276 }
1272 1277
1273 1278
1274 void StartupSerializer::SerializeStrongReferences() { 1279 void StartupSerializer::SerializeStrongReferences() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte"); 1334 sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte");
1330 } 1335 }
1331 } else { 1336 } else {
1332 SerializeObject(HeapObject::cast(*current), kPlain, kStartOfObject, 0); 1337 SerializeObject(HeapObject::cast(*current), kPlain, kStartOfObject, 0);
1333 } 1338 }
1334 } 1339 }
1335 } 1340 }
1336 1341
1337 1342
1338 void Serializer::FinalizeAllocation() { 1343 void Serializer::FinalizeAllocation() {
1339 DCHECK_EQ(0, completed_chunks_[LO_SPACE].length()); // Not yet finalized. 1344 for (int i = 0; i < kNumberOfPreallocatedSpaces; i++) {
1340 for (int i = 0; i < kNumberOfSpaces; i++) {
1341 // Complete the last pending chunk and if there are no completed chunks, 1345 // Complete the last pending chunk and if there are no completed chunks,
1342 // make sure there is at least one empty chunk. 1346 // make sure there is at least one empty chunk.
1343 if (pending_chunk_[i] > 0 || completed_chunks_[i].length() == 0) { 1347 if (pending_chunk_[i] > 0 || completed_chunks_[i].length() == 0) {
1344 completed_chunks_[i].Add(pending_chunk_[i]); 1348 completed_chunks_[i].Add(pending_chunk_[i]);
1345 pending_chunk_[i] = 0; 1349 pending_chunk_[i] = 0;
1346 } 1350 }
1347 } 1351 }
1348 } 1352 }
1349 1353
1350 1354
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 } 1903 }
1900 } 1904 }
1901 UNREACHABLE(); 1905 UNREACHABLE();
1902 return INVALID_SPACE; 1906 return INVALID_SPACE;
1903 } 1907 }
1904 1908
1905 1909
1906 BackReference Serializer::AllocateLargeObject(int size) { 1910 BackReference Serializer::AllocateLargeObject(int size) {
1907 // Large objects are allocated one-by-one when deserializing. We do not 1911 // Large objects are allocated one-by-one when deserializing. We do not
1908 // have to keep track of multiple chunks. 1912 // have to keep track of multiple chunks.
1909 pending_chunk_[LO_SPACE] += size; 1913 large_objects_total_size_ += size;
1910 return BackReference::LargeObjectReference(seen_large_objects_index_++); 1914 return BackReference::LargeObjectReference(seen_large_objects_index_++);
1911 } 1915 }
1912 1916
1913 1917
1914 BackReference Serializer::Allocate(AllocationSpace space, int size) { 1918 BackReference Serializer::Allocate(AllocationSpace space, int size) {
1915 CHECK(space >= 0 && space < kNumberOfPreallocatedSpaces); 1919 CHECK(space >= 0 && space < kNumberOfPreallocatedSpaces);
1916 DCHECK(size > 0 && size <= Page::kMaxRegularHeapObjectSize); 1920 DCHECK(size > 0 && size <= static_cast<int>(max_chunk_size(space)));
1917 uint32_t new_chunk_size = pending_chunk_[space] + size; 1921 uint32_t new_chunk_size = pending_chunk_[space] + size;
1918 if (new_chunk_size > static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize)) { 1922 if (new_chunk_size > max_chunk_size(space)) {
1919 // The new chunk size would not fit onto a single page. Complete the 1923 // The new chunk size would not fit onto a single page. Complete the
1920 // current chunk and start a new one. 1924 // current chunk and start a new one.
1921 completed_chunks_[space].Add(pending_chunk_[space]); 1925 completed_chunks_[space].Add(pending_chunk_[space]);
1922 pending_chunk_[space] = 0; 1926 pending_chunk_[space] = 0;
1923 new_chunk_size = size; 1927 new_chunk_size = size;
1924 } 1928 }
1925 uint32_t offset = pending_chunk_[space]; 1929 uint32_t offset = pending_chunk_[space];
1926 pending_chunk_[space] = new_chunk_size; 1930 pending_chunk_[space] = new_chunk_size;
1927 return BackReference::Reference(space, completed_chunks_[space].length(), 1931 return BackReference::Reference(space, completed_chunks_[space].length(),
1928 offset); 1932 offset);
1929 } 1933 }
1930 1934
1931 1935
1932 int Serializer::SpaceAreaSize(int space) {
1933 if (space == CODE_SPACE) {
1934 return isolate_->memory_allocator()->CodePageAreaSize();
1935 } else {
1936 return Page::kPageSize - Page::kObjectStartOffset;
1937 }
1938 }
1939
1940
1941 void Serializer::Pad() { 1936 void Serializer::Pad() {
1942 // The non-branching GetInt will read up to 3 bytes too far, so we need 1937 // The non-branching GetInt will read up to 3 bytes too far, so we need
1943 // to pad the snapshot to make sure we don't read over the end. 1938 // to pad the snapshot to make sure we don't read over the end.
1944 for (unsigned i = 0; i < sizeof(int32_t) - 1; i++) { 1939 for (unsigned i = 0; i < sizeof(int32_t) - 1; i++) {
1945 sink_->Put(kNop, "Padding"); 1940 sink_->Put(kNop, "Padding");
1946 } 1941 }
1947 } 1942 }
1948 1943
1949 1944
1950 void Serializer::InitializeCodeAddressMap() { 1945 void Serializer::InitializeCodeAddressMap() {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
2266 : script_data_(NULL), owns_script_data_(true) { 2261 : script_data_(NULL), owns_script_data_(true) {
2267 DisallowHeapAllocation no_gc; 2262 DisallowHeapAllocation no_gc;
2268 List<uint32_t>* stub_keys = cs->stub_keys(); 2263 List<uint32_t>* stub_keys = cs->stub_keys();
2269 2264
2270 // Gather reservation chunk sizes. 2265 // Gather reservation chunk sizes.
2271 List<uint32_t> reservations(SerializerDeserializer::kNumberOfSpaces); 2266 List<uint32_t> reservations(SerializerDeserializer::kNumberOfSpaces);
2272 STATIC_ASSERT(NEW_SPACE == 0); 2267 STATIC_ASSERT(NEW_SPACE == 0);
2273 for (int i = 0; i < SerializerDeserializer::kNumberOfSpaces; i++) { 2268 for (int i = 0; i < SerializerDeserializer::kNumberOfSpaces; i++) {
2274 Vector<const uint32_t> chunks = cs->FinalAllocationChunks(i); 2269 Vector<const uint32_t> chunks = cs->FinalAllocationChunks(i);
2275 for (int j = 0; j < chunks.length(); j++) { 2270 for (int j = 0; j < chunks.length(); j++) {
2276 DCHECK(i == LO_SPACE ||
2277 chunks[j] <=
2278 static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize));
2279 uint32_t chunk = ChunkSizeBits::encode(chunks[j]) | 2271 uint32_t chunk = ChunkSizeBits::encode(chunks[j]) |
2280 IsLastChunkBits::encode(j == chunks.length() - 1); 2272 IsLastChunkBits::encode(j == chunks.length() - 1);
2281 reservations.Add(chunk); 2273 reservations.Add(chunk);
2282 } 2274 }
2283 } 2275 }
2284 2276
2285 // Calculate sizes. 2277 // Calculate sizes.
2286 int reservation_size = reservations.length() * kInt32Size; 2278 int reservation_size = reservations.length() * kInt32Size;
2287 int num_stub_keys = stub_keys->length(); 2279 int num_stub_keys = stub_keys->length();
2288 int stub_keys_size = stub_keys->length() * kInt32Size; 2280 int stub_keys_size = stub_keys->length() * kInt32Size;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 2316
2325 int SerializedCodeData::CheckSum(String* string) { 2317 int SerializedCodeData::CheckSum(String* string) {
2326 int checksum = Version::Hash(); 2318 int checksum = Version::Hash();
2327 #ifdef DEBUG 2319 #ifdef DEBUG
2328 uint32_t seed = static_cast<uint32_t>(checksum); 2320 uint32_t seed = static_cast<uint32_t>(checksum);
2329 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed)); 2321 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed));
2330 #endif // DEBUG 2322 #endif // DEBUG
2331 return checksum; 2323 return checksum;
2332 } 2324 }
2333 } } // namespace v8::internal 2325 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698