| OLD | NEW |
| 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 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 800 } |
| 801 return obj; | 801 return obj; |
| 802 } | 802 } |
| 803 | 803 |
| 804 | 804 |
| 805 // This routine writes the new object into the pointer provided and then | 805 // This routine writes the new object into the pointer provided and then |
| 806 // returns true if the new object was in young space and false otherwise. | 806 // returns true if the new object was in young space and false otherwise. |
| 807 // The reason for this strange interface is that otherwise the object is | 807 // The reason for this strange interface is that otherwise the object is |
| 808 // written very late, which means the FreeSpace map is not set up by the | 808 // written very late, which means the FreeSpace map is not set up by the |
| 809 // time we need to use it to mark the space at the end of a page free. | 809 // time we need to use it to mark the space at the end of a page free. |
| 810 void Deserializer::ReadObject(int space_number, | 810 void Deserializer::ReadObject(int space_number, Object** write_back) { |
| 811 Object** write_back) { | 811 Address address; |
| 812 int size = source_->GetInt() << kObjectAlignmentBits; | 812 HeapObject* obj; |
| 813 Address address = Allocate(space_number, size); | 813 int next_int = source_->GetInt(); |
| 814 HeapObject* obj = HeapObject::FromAddress(address); | 814 |
| 815 bool double_align = false; |
| 816 #ifndef V8_HOST_ARCH_64_BIT |
| 817 double_align = next_int == kDoubleAlignmentSentinel; |
| 818 if (double_align) next_int = source_->GetInt(); |
| 819 #endif |
| 820 |
| 821 DCHECK_NE(kDoubleAlignmentSentinel, next_int); |
| 822 int size = next_int << kObjectAlignmentBits; |
| 823 int reserved_size = size + (double_align ? kPointerSize : 0); |
| 824 address = Allocate(space_number, reserved_size); |
| 825 obj = HeapObject::FromAddress(address); |
| 826 if (double_align) { |
| 827 obj = isolate_->heap()->DoubleAlignForDeserialization(obj, reserved_size); |
| 828 address = obj->address(); |
| 829 } |
| 830 |
| 815 isolate_->heap()->OnAllocationEvent(obj, size); | 831 isolate_->heap()->OnAllocationEvent(obj, size); |
| 816 Object** current = reinterpret_cast<Object**>(address); | 832 Object** current = reinterpret_cast<Object**>(address); |
| 817 Object** limit = current + (size >> kPointerSizeLog2); | 833 Object** limit = current + (size >> kPointerSizeLog2); |
| 818 if (FLAG_log_snapshot_positions) { | 834 if (FLAG_log_snapshot_positions) { |
| 819 LOG(isolate_, SnapshotPositionEvent(address, source_->position())); | 835 LOG(isolate_, SnapshotPositionEvent(address, source_->position())); |
| 820 } | 836 } |
| 821 ReadData(current, limit, space_number, address); | 837 ReadData(current, limit, space_number, address); |
| 822 | 838 |
| 823 // TODO(mvstanton): consider treating the heap()->allocation_sites_list() | 839 // TODO(mvstanton): consider treating the heap()->allocation_sites_list() |
| 824 // as a (weak) root. If this root is relocated correctly, | 840 // as a (weak) root. If this root is relocated correctly, |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); | 1558 sink_->PutInt(skip, "SkipDistanceFromSerializeObject"); |
| 1543 } | 1559 } |
| 1544 // Object has not yet been serialized. Serialize it here. | 1560 // Object has not yet been serialized. Serialize it here. |
| 1545 ObjectSerializer serializer(this, obj, sink_, how_to_code, where_to_point); | 1561 ObjectSerializer serializer(this, obj, sink_, how_to_code, where_to_point); |
| 1546 serializer.Serialize(); | 1562 serializer.Serialize(); |
| 1547 } | 1563 } |
| 1548 | 1564 |
| 1549 | 1565 |
| 1550 void Serializer::ObjectSerializer::SerializePrologue(AllocationSpace space, | 1566 void Serializer::ObjectSerializer::SerializePrologue(AllocationSpace space, |
| 1551 int size, Map* map) { | 1567 int size, Map* map) { |
| 1568 int reserved_size = size; |
| 1569 |
| 1552 sink_->Put(kNewObject + reference_representation_ + space, | 1570 sink_->Put(kNewObject + reference_representation_ + space, |
| 1553 "ObjectSerialization"); | 1571 "ObjectSerialization"); |
| 1554 sink_->PutInt(size >> kObjectAlignmentBits, "Size in words"); | 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"); |
| 1555 | 1581 |
| 1556 if (serializer_->code_address_map_) { | 1582 if (serializer_->code_address_map_) { |
| 1557 const char* code_name = | 1583 const char* code_name = |
| 1558 serializer_->code_address_map_->Lookup(object_->address()); | 1584 serializer_->code_address_map_->Lookup(object_->address()); |
| 1559 LOG(serializer_->isolate_, | 1585 LOG(serializer_->isolate_, |
| 1560 CodeNameEvent(object_->address(), sink_->Position(), code_name)); | 1586 CodeNameEvent(object_->address(), sink_->Position(), code_name)); |
| 1561 LOG(serializer_->isolate_, | 1587 LOG(serializer_->isolate_, |
| 1562 SnapshotPositionEvent(object_->address(), sink_->Position())); | 1588 SnapshotPositionEvent(object_->address(), sink_->Position())); |
| 1563 } | 1589 } |
| 1564 | 1590 |
| 1565 // Mark this object as already serialized. | 1591 // Mark this object as already serialized. |
| 1566 BackReference back_reference; | 1592 BackReference back_reference; |
| 1567 if (space == LO_SPACE) { | 1593 if (space == LO_SPACE) { |
| 1568 if (object_->IsCode()) { | 1594 if (object_->IsCode()) { |
| 1569 sink_->Put(EXECUTABLE, "executable large object"); | 1595 sink_->Put(EXECUTABLE, "executable large object"); |
| 1570 } else { | 1596 } else { |
| 1571 sink_->Put(NOT_EXECUTABLE, "not executable large object"); | 1597 sink_->Put(NOT_EXECUTABLE, "not executable large object"); |
| 1572 } | 1598 } |
| 1573 back_reference = serializer_->AllocateLargeObject(size); | 1599 back_reference = serializer_->AllocateLargeObject(size); |
| 1574 } else { | 1600 } else { |
| 1575 back_reference = serializer_->Allocate(space, size); | 1601 back_reference = serializer_->Allocate(space, reserved_size); |
| 1576 } | 1602 } |
| 1577 serializer_->back_reference_map()->Add(object_, back_reference); | 1603 serializer_->back_reference_map()->Add(object_, back_reference); |
| 1578 | 1604 |
| 1579 // Serialize the map (first word of the object). | 1605 // Serialize the map (first word of the object). |
| 1580 serializer_->SerializeObject(map, kPlain, kStartOfObject, 0); | 1606 serializer_->SerializeObject(map, kPlain, kStartOfObject, 0); |
| 1581 } | 1607 } |
| 1582 | 1608 |
| 1583 | 1609 |
| 1584 void Serializer::ObjectSerializer::SerializeExternalString() { | 1610 void Serializer::ObjectSerializer::SerializeExternalString() { |
| 1585 // Instead of serializing this as an external string, we serialize | 1611 // Instead of serializing this as an external string, we serialize |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 | 1937 |
| 1912 BackReference Serializer::AllocateLargeObject(int size) { | 1938 BackReference Serializer::AllocateLargeObject(int size) { |
| 1913 // Large objects are allocated one-by-one when deserializing. We do not | 1939 // Large objects are allocated one-by-one when deserializing. We do not |
| 1914 // have to keep track of multiple chunks. | 1940 // have to keep track of multiple chunks. |
| 1915 large_objects_total_size_ += size; | 1941 large_objects_total_size_ += size; |
| 1916 return BackReference::LargeObjectReference(seen_large_objects_index_++); | 1942 return BackReference::LargeObjectReference(seen_large_objects_index_++); |
| 1917 } | 1943 } |
| 1918 | 1944 |
| 1919 | 1945 |
| 1920 BackReference Serializer::Allocate(AllocationSpace space, int size) { | 1946 BackReference Serializer::Allocate(AllocationSpace space, int size) { |
| 1921 CHECK(space >= 0 && space < kNumberOfPreallocatedSpaces); | 1947 DCHECK(space >= 0 && space < kNumberOfPreallocatedSpaces); |
| 1922 DCHECK(size > 0 && size <= static_cast<int>(max_chunk_size(space))); | 1948 DCHECK(size > 0 && size <= static_cast<int>(max_chunk_size(space))); |
| 1923 uint32_t new_chunk_size = pending_chunk_[space] + size; | 1949 uint32_t new_chunk_size = pending_chunk_[space] + size; |
| 1924 if (new_chunk_size > max_chunk_size(space)) { | 1950 if (new_chunk_size > max_chunk_size(space)) { |
| 1925 // The new chunk size would not fit onto a single page. Complete the | 1951 // The new chunk size would not fit onto a single page. Complete the |
| 1926 // current chunk and start a new one. | 1952 // current chunk and start a new one. |
| 1927 completed_chunks_[space].Add(pending_chunk_[space]); | 1953 completed_chunks_[space].Add(pending_chunk_[space]); |
| 1928 pending_chunk_[space] = 0; | 1954 pending_chunk_[space] = 0; |
| 1929 new_chunk_size = size; | 1955 new_chunk_size = size; |
| 1930 } | 1956 } |
| 1931 uint32_t offset = pending_chunk_[space]; | 1957 uint32_t offset = pending_chunk_[space]; |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2321 bool SerializedCodeData::IsSane(String* source) { | 2347 bool SerializedCodeData::IsSane(String* source) { |
| 2322 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) && | 2348 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) && |
| 2323 PayloadLength() >= SharedFunctionInfo::kSize; | 2349 PayloadLength() >= SharedFunctionInfo::kSize; |
| 2324 } | 2350 } |
| 2325 | 2351 |
| 2326 | 2352 |
| 2327 int SerializedCodeData::CheckSum(String* string) { | 2353 int SerializedCodeData::CheckSum(String* string) { |
| 2328 return Version::Hash() ^ string->length(); | 2354 return Version::Hash() ^ string->length(); |
| 2329 } | 2355 } |
| 2330 } } // namespace v8::internal | 2356 } } // namespace v8::internal |
| OLD | NEW |