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

Side by Side Diff: src/serialize.cc

Issue 757813003: Serializer: use opcode to signal new chunk. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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
« 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 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 } 853 }
854 #endif 854 #endif
855 } 855 }
856 856
857 857
858 // We know the space requirements before deserialization and can 858 // We know the space requirements before deserialization and can
859 // pre-allocate that reserved space. During deserialization, all we need 859 // pre-allocate that reserved space. During deserialization, all we need
860 // to do is to bump up the pointer for each space in the reserved 860 // to do is to bump up the pointer for each space in the reserved
861 // space. This is also used for fixing back references. 861 // space. This is also used for fixing back references.
862 // We may have to split up the pre-allocation into several chunks 862 // We may have to split up the pre-allocation into several chunks
863 // because it would not fit onto a single page, we have to keep track 863 // because it would not fit onto a single page. We do not have to keep
864 // of when to move to the next chunk. 864 // track of when to move to the next chunk. An opcode will signal this.
865 // Since multiple large objects cannot be folded into one large object 865 // Since multiple large objects cannot be folded into one large object
866 // space allocation, we have to do an actual allocation when deserializing 866 // space allocation, we have to do an actual allocation when deserializing
867 // each large object. Instead of tracking offset for back references, we 867 // each large object. Instead of tracking offset for back references, we
868 // reference large objects by index. 868 // reference large objects by index.
869 Address Deserializer::Allocate(int space_index, int size) { 869 Address Deserializer::Allocate(int space_index, int size) {
870 if (space_index == LO_SPACE) { 870 if (space_index == LO_SPACE) {
871 AlwaysAllocateScope scope(isolate_); 871 AlwaysAllocateScope scope(isolate_);
872 LargeObjectSpace* lo_space = isolate_->heap()->lo_space(); 872 LargeObjectSpace* lo_space = isolate_->heap()->lo_space();
873 Executability exec = static_cast<Executability>(source_->Get()); 873 Executability exec = static_cast<Executability>(source_->Get());
874 AllocationResult result = lo_space->AllocateRaw(size, exec); 874 AllocationResult result = lo_space->AllocateRaw(size, exec);
875 HeapObject* obj = HeapObject::cast(result.ToObjectChecked()); 875 HeapObject* obj = HeapObject::cast(result.ToObjectChecked());
876 deserialized_large_objects_.Add(obj); 876 deserialized_large_objects_.Add(obj);
877 return obj->address(); 877 return obj->address();
878 } else { 878 } else {
879 DCHECK(space_index < kNumberOfPreallocatedSpaces); 879 DCHECK(space_index < kNumberOfPreallocatedSpaces);
880 Address address = high_water_[space_index]; 880 Address address = high_water_[space_index];
881 DCHECK_NE(NULL, address); 881 DCHECK_NE(NULL, address);
882 high_water_[space_index] += size;
883 #ifdef DEBUG
884 // Assert that the current reserved chunk is still big enough.
882 const Heap::Reservation& reservation = reservations_[space_index]; 885 const Heap::Reservation& reservation = reservations_[space_index];
883 int chunk_index = current_chunk_[space_index]; 886 int chunk_index = current_chunk_[space_index];
884 if (address + size > reservation[chunk_index].end) { 887 CHECK_LE(high_water_[space_index], reservation[chunk_index].end);
885 // The last chunk size matches exactly the already deserialized data. 888 #endif
886 DCHECK_EQ(address, reservation[chunk_index].end);
887 // Move to next reserved chunk.
888 chunk_index = ++current_chunk_[space_index];
889 DCHECK_LT(chunk_index, reservation.length());
890 // Prepare for next allocation in the next chunk.
891 address = reservation[chunk_index].start;
892 } else {
893 high_water_[space_index] = address + size;
894 }
895 high_water_[space_index] = address + size;
896 return address; 889 return address;
897 } 890 }
898 } 891 }
899 892
900 893
901 void Deserializer::ReadData(Object** current, Object** limit, int source_space, 894 void Deserializer::ReadData(Object** current, Object** limit, int source_space,
902 Address current_object_address) { 895 Address current_object_address) {
903 Isolate* const isolate = isolate_; 896 Isolate* const isolate = isolate_;
904 // Write barrier support costs around 1% in startup time. In fact there 897 // Write barrier support costs around 1% in startup time. In fact there
905 // are no new space objects in current boot snapshots, so it's not needed, 898 // are no new space objects in current boot snapshots, so it's not needed,
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 int index = source_->Get(); 1240 int index = source_->Get();
1248 Vector<const char> source_vector = Natives::GetRawScriptSource(index); 1241 Vector<const char> source_vector = Natives::GetRawScriptSource(index);
1249 NativesExternalStringResource* resource = 1242 NativesExternalStringResource* resource =
1250 new NativesExternalStringResource(isolate->bootstrapper(), 1243 new NativesExternalStringResource(isolate->bootstrapper(),
1251 source_vector.start(), 1244 source_vector.start(),
1252 source_vector.length()); 1245 source_vector.length());
1253 *current++ = reinterpret_cast<Object*>(resource); 1246 *current++ = reinterpret_cast<Object*>(resource);
1254 break; 1247 break;
1255 } 1248 }
1256 1249
1250 case kNextChunk: {
1251 int space = source_->Get();
1252 DCHECK(space < kNumberOfPreallocatedSpaces);
1253 int chunk_index = current_chunk_[space];
1254 const Heap::Reservation& reservation = reservations_[space];
1255 // Make sure the current chunk is indeed exhausted.
1256 CHECK_EQ(reservation[chunk_index].end, high_water_[space]);
1257 // Move to next reserved chunk.
1258 chunk_index = ++current_chunk_[space];
1259 DCHECK_LT(chunk_index, reservation.length());
1260 high_water_[space] = reservation[chunk_index].start;
1261 break;
1262 }
1263
1257 case kSynchronize: { 1264 case kSynchronize: {
1258 // If we get here then that indicates that you have a mismatch between 1265 // If we get here then that indicates that you have a mismatch between
1259 // the number of GC roots when serializing and deserializing. 1266 // the number of GC roots when serializing and deserializing.
1260 UNREACHABLE(); 1267 UNREACHABLE();
1261 } 1268 }
1262 1269
1263 default: 1270 default:
1264 UNREACHABLE(); 1271 UNREACHABLE();
1265 } 1272 }
1266 } 1273 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); 1565 sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
1559 } 1566 }
1560 // Object has not yet been serialized. Serialize it here. 1567 // Object has not yet been serialized. Serialize it here.
1561 ObjectSerializer serializer(this, obj, sink_, how_to_code, where_to_point); 1568 ObjectSerializer serializer(this, obj, sink_, how_to_code, where_to_point);
1562 serializer.Serialize(); 1569 serializer.Serialize();
1563 } 1570 }
1564 1571
1565 1572
1566 void Serializer::ObjectSerializer::SerializePrologue(AllocationSpace space, 1573 void Serializer::ObjectSerializer::SerializePrologue(AllocationSpace space,
1567 int size, Map* map) { 1574 int size, Map* map) {
1568 int reserved_size = size;
1569
1570 sink_->Put(kNewObject + reference_representation_ + space,
1571 "ObjectSerialization");
1572 // Objects on the large object space are always double-aligned.
1573 if (space != LO_SPACE && object_->NeedsToEnsureDoubleAlignment()) {
1574 sink_->PutInt(kDoubleAlignmentSentinel, "double align next object");
1575 // Add wriggle room for double alignment padding.
1576 reserved_size += kPointerSize;
1577 }
1578 int encoded_size = size >> kObjectAlignmentBits;
1579 DCHECK_NE(kDoubleAlignmentSentinel, encoded_size);
1580 sink_->PutInt(encoded_size, "Size in words");
1581
1582 if (serializer_->code_address_map_) { 1575 if (serializer_->code_address_map_) {
1583 const char* code_name = 1576 const char* code_name =
1584 serializer_->code_address_map_->Lookup(object_->address()); 1577 serializer_->code_address_map_->Lookup(object_->address());
1585 LOG(serializer_->isolate_, 1578 LOG(serializer_->isolate_,
1586 CodeNameEvent(object_->address(), sink_->Position(), code_name)); 1579 CodeNameEvent(object_->address(), sink_->Position(), code_name));
1587 LOG(serializer_->isolate_, 1580 LOG(serializer_->isolate_,
1588 SnapshotPositionEvent(object_->address(), sink_->Position())); 1581 SnapshotPositionEvent(object_->address(), sink_->Position()));
1589 } 1582 }
1590 1583
1591 // Mark this object as already serialized.
1592 BackReference back_reference; 1584 BackReference back_reference;
1593 if (space == LO_SPACE) { 1585 if (space == LO_SPACE) {
1586 sink_->Put(kNewObject + reference_representation_ + space,
1587 "new large object");
1588 sink_->PutInt(size >> kObjectAlignmentBits, "Size in words");
1594 if (object_->IsCode()) { 1589 if (object_->IsCode()) {
1595 sink_->Put(EXECUTABLE, "executable large object"); 1590 sink_->Put(EXECUTABLE, "executable large object");
1596 } else { 1591 } else {
1597 sink_->Put(NOT_EXECUTABLE, "not executable large object"); 1592 sink_->Put(NOT_EXECUTABLE, "not executable large object");
1598 } 1593 }
1599 back_reference = serializer_->AllocateLargeObject(size); 1594 back_reference = serializer_->AllocateLargeObject(size);
1600 } else { 1595 } else {
1601 back_reference = serializer_->Allocate(space, reserved_size); 1596 if (object_->NeedsToEnsureDoubleAlignment()) {
1597 // Add wriggle room for double alignment padding.
1598 back_reference = serializer_->Allocate(space, size + kPointerSize);
1599 sink_->PutInt(kDoubleAlignmentSentinel, "double align");
1600 } else {
1601 back_reference = serializer_->Allocate(space, size);
1602 }
1603 sink_->Put(kNewObject + reference_representation_ + space, "new object");
1604 int encoded_size = size >> kObjectAlignmentBits;
1605 DCHECK_NE(kDoubleAlignmentSentinel, encoded_size);
1606 sink_->PutInt(encoded_size, "Size in words");
1602 } 1607 }
1608
1609 // Mark this object as already serialized.
1603 serializer_->back_reference_map()->Add(object_, back_reference); 1610 serializer_->back_reference_map()->Add(object_, back_reference);
1604 1611
1605 // Serialize the map (first word of the object). 1612 // Serialize the map (first word of the object).
1606 serializer_->SerializeObject(map, kPlain, kStartOfObject, 0); 1613 serializer_->SerializeObject(map, kPlain, kStartOfObject, 0);
1607 } 1614 }
1608 1615
1609 1616
1610 void Serializer::ObjectSerializer::SerializeExternalString() { 1617 void Serializer::ObjectSerializer::SerializeExternalString() {
1611 // Instead of serializing this as an external string, we serialize 1618 // Instead of serializing this as an external string, we serialize
1612 // an imaginary sequential string with the same content. 1619 // an imaginary sequential string with the same content.
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 } 1950 }
1944 1951
1945 1952
1946 BackReference Serializer::Allocate(AllocationSpace space, int size) { 1953 BackReference Serializer::Allocate(AllocationSpace space, int size) {
1947 DCHECK(space >= 0 && space < kNumberOfPreallocatedSpaces); 1954 DCHECK(space >= 0 && space < kNumberOfPreallocatedSpaces);
1948 DCHECK(size > 0 && size <= static_cast<int>(max_chunk_size(space))); 1955 DCHECK(size > 0 && size <= static_cast<int>(max_chunk_size(space)));
1949 uint32_t new_chunk_size = pending_chunk_[space] + size; 1956 uint32_t new_chunk_size = pending_chunk_[space] + size;
1950 if (new_chunk_size > max_chunk_size(space)) { 1957 if (new_chunk_size > max_chunk_size(space)) {
1951 // The new chunk size would not fit onto a single page. Complete the 1958 // The new chunk size would not fit onto a single page. Complete the
1952 // current chunk and start a new one. 1959 // current chunk and start a new one.
1960 sink_->Put(kNextChunk, "move to next chunk");
1961 sink_->Put(space, "space of next chunk");
1953 completed_chunks_[space].Add(pending_chunk_[space]); 1962 completed_chunks_[space].Add(pending_chunk_[space]);
1954 pending_chunk_[space] = 0; 1963 pending_chunk_[space] = 0;
1955 new_chunk_size = size; 1964 new_chunk_size = size;
1956 } 1965 }
1957 uint32_t offset = pending_chunk_[space]; 1966 uint32_t offset = pending_chunk_[space];
1958 pending_chunk_[space] = new_chunk_size; 1967 pending_chunk_[space] = new_chunk_size;
1959 return BackReference::Reference(space, completed_chunks_[space].length(), 1968 return BackReference::Reference(space, completed_chunks_[space].length(),
1960 offset); 1969 offset);
1961 } 1970 }
1962 1971
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
2347 bool SerializedCodeData::IsSane(String* source) { 2356 bool SerializedCodeData::IsSane(String* source) {
2348 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) && 2357 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) &&
2349 PayloadLength() >= SharedFunctionInfo::kSize; 2358 PayloadLength() >= SharedFunctionInfo::kSize;
2350 } 2359 }
2351 2360
2352 2361
2353 int SerializedCodeData::CheckSum(String* string) { 2362 int SerializedCodeData::CheckSum(String* string) {
2354 return Version::Hash() ^ string->length(); 2363 return Version::Hash() ^ string->length();
2355 } 2364 }
2356 } } // namespace v8::internal 2365 } } // 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