Chromium Code Reviews| 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 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1579 | 1579 |
| 1580 void Serializer::ObjectSerializer::SerializeExternalString() { | 1580 void Serializer::ObjectSerializer::SerializeExternalString() { |
| 1581 // Instead of serializing this as an external string, we serialize | 1581 // Instead of serializing this as an external string, we serialize |
| 1582 // an imaginary sequential string with the same content. | 1582 // an imaginary sequential string with the same content. |
| 1583 Isolate* isolate = serializer_->isolate(); | 1583 Isolate* isolate = serializer_->isolate(); |
| 1584 DCHECK(object_->IsExternalString()); | 1584 DCHECK(object_->IsExternalString()); |
| 1585 DCHECK(object_->map() != isolate->heap()->native_source_string_map()); | 1585 DCHECK(object_->map() != isolate->heap()->native_source_string_map()); |
| 1586 ExternalString* string = ExternalString::cast(object_); | 1586 ExternalString* string = ExternalString::cast(object_); |
| 1587 int length = string->length(); | 1587 int length = string->length(); |
| 1588 Map* map; | 1588 Map* map; |
| 1589 int size; | 1589 int content_size; |
| 1590 const char* resource; | 1590 int allocation_size; |
| 1591 const byte* resource; | |
| 1591 // Find the map and size for the imaginary sequential string. | 1592 // Find the map and size for the imaginary sequential string. |
| 1592 bool internalized = object_->IsInternalizedString(); | 1593 bool internalized = object_->IsInternalizedString(); |
| 1593 if (object_->IsExternalOneByteString()) { | 1594 if (object_->IsExternalOneByteString()) { |
| 1594 map = internalized ? isolate->heap()->one_byte_internalized_string_map() | 1595 map = internalized ? isolate->heap()->one_byte_internalized_string_map() |
| 1595 : isolate->heap()->one_byte_string_map(); | 1596 : isolate->heap()->one_byte_string_map(); |
| 1596 size = SeqOneByteString::SizeFor(length); | 1597 allocation_size = SeqOneByteString::SizeFor(length); |
| 1597 resource = ExternalOneByteString::cast(string)->resource()->data(); | 1598 content_size = length * kCharSize; |
| 1599 resource = reinterpret_cast<const byte*>( | |
| 1600 ExternalOneByteString::cast(string)->resource()->data()); | |
| 1598 } else { | 1601 } else { |
| 1599 map = internalized ? isolate->heap()->internalized_string_map() | 1602 map = internalized ? isolate->heap()->internalized_string_map() |
| 1600 : isolate->heap()->string_map(); | 1603 : isolate->heap()->string_map(); |
| 1601 size = SeqTwoByteString::SizeFor(length); | 1604 allocation_size = SeqTwoByteString::SizeFor(length); |
| 1602 resource = reinterpret_cast<const char*>( | 1605 content_size = length * kShortSize; |
| 1606 resource = reinterpret_cast<const byte*>( | |
| 1603 ExternalTwoByteString::cast(string)->resource()->data()); | 1607 ExternalTwoByteString::cast(string)->resource()->data()); |
| 1604 } | 1608 } |
| 1605 | 1609 |
| 1606 AllocationSpace space = | 1610 AllocationSpace space = (allocation_size > Page::kMaxRegularHeapObjectSize) |
| 1607 (size > Page::kMaxRegularHeapObjectSize) ? LO_SPACE : OLD_DATA_SPACE; | 1611 ? LO_SPACE |
| 1608 SerializePrologue(space, size, map); | 1612 : OLD_DATA_SPACE; |
| 1613 SerializePrologue(space, allocation_size, map); | |
| 1609 | 1614 |
| 1610 // Output the rest of the imaginary string. | 1615 // Output the rest of the imaginary string. |
| 1611 int bytes_to_output = size - HeapObject::kHeaderSize; | 1616 int bytes_to_output = allocation_size - HeapObject::kHeaderSize; |
| 1612 | 1617 |
| 1613 // Output raw data header. Do not bother with common raw length cases here. | 1618 // Output raw data header. Do not bother with common raw length cases here. |
| 1614 sink_->Put(kRawData, "RawDataForString"); | 1619 sink_->Put(kRawData, "RawDataForString"); |
| 1615 sink_->PutInt(bytes_to_output, "length"); | 1620 sink_->PutInt(bytes_to_output, "length"); |
| 1616 | 1621 |
| 1617 // Serialize string header (except for map). | 1622 // Serialize string header (except for map). |
| 1618 Address string_start = string->address(); | 1623 Address string_start = string->address(); |
| 1619 for (int i = HeapObject::kHeaderSize; i < SeqString::kHeaderSize; i++) { | 1624 for (int i = HeapObject::kHeaderSize; i < SeqString::kHeaderSize; i++) { |
| 1620 sink_->PutSection(string_start[i], "StringHeader"); | 1625 sink_->PutSection(string_start[i], "StringHeader"); |
| 1621 } | 1626 } |
| 1622 | 1627 |
| 1623 // Serialize string content. | 1628 // Serialize string content. |
| 1624 int content_length = size - SeqString::kHeaderSize; | 1629 sink_->PutRaw(const_cast<byte*>(resource), content_size, "StringContent"); |
| 1625 for (int i = 0; i < content_length; i++) { | 1630 |
| 1626 sink_->PutSection(resource[i], "StringContent"); | 1631 // Since the allocation size is rounded up to object alignment, there |
| 1627 } | 1632 // maybe left-over bytes that need to be padded. |
| 1633 int padding_size = allocation_size - SeqString::kHeaderSize - content_size; | |
| 1634 DCHECK(0 <= padding_size && padding_size < kObjectAlignment); | |
| 1635 for (int i = 0; i < padding_size; i++) sink_->PutSection(0, "StringPadding"); | |
|
vogelheim
2014/10/23 16:48:44
If I get this correctly, this makes sure that you
Yang
2014/10/24 07:14:24
This is a single use case, so I'd leave it at this
| |
| 1628 | 1636 |
| 1629 sink_->Put(kSkip, "SkipAfterString"); | 1637 sink_->Put(kSkip, "SkipAfterString"); |
| 1630 sink_->PutInt(bytes_to_output, "SkipDistance"); | 1638 sink_->PutInt(bytes_to_output, "SkipDistance"); |
| 1631 } | 1639 } |
| 1632 | 1640 |
| 1633 | 1641 |
| 1634 void Serializer::ObjectSerializer::Serialize() { | 1642 void Serializer::ObjectSerializer::Serialize() { |
| 1635 if (object_->IsExternalString()) { | 1643 if (object_->IsExternalString()) { |
| 1636 Heap* heap = serializer_->isolate()->heap(); | 1644 Heap* heap = serializer_->isolate()->heap(); |
| 1637 if (object_->map() != heap->native_source_string_map()) { | 1645 if (object_->map() != heap->native_source_string_map()) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1864 if (code_object_) { | 1872 if (code_object_) { |
| 1865 Code* code = CloneCodeObject(object_); | 1873 Code* code = CloneCodeObject(object_); |
| 1866 WipeOutRelocations(code); | 1874 WipeOutRelocations(code); |
| 1867 // We need to wipe out the header fields *after* wiping out the | 1875 // We need to wipe out the header fields *after* wiping out the |
| 1868 // relocations, because some of these fields are needed for the latter. | 1876 // relocations, because some of these fields are needed for the latter. |
| 1869 code->WipeOutHeader(); | 1877 code->WipeOutHeader(); |
| 1870 object_start = code->address(); | 1878 object_start = code->address(); |
| 1871 } | 1879 } |
| 1872 | 1880 |
| 1873 const char* description = code_object_ ? "Code" : "Byte"; | 1881 const char* description = code_object_ ? "Code" : "Byte"; |
| 1874 for (int i = 0; i < bytes_to_output; i++) { | 1882 sink_->PutRaw(object_start + base, bytes_to_output, description); |
| 1875 sink_->PutSection(object_start[base + i], description); | |
| 1876 } | |
| 1877 if (code_object_) delete[] object_start; | 1883 if (code_object_) delete[] object_start; |
| 1878 } | 1884 } |
| 1879 if (to_skip != 0 && return_skip == kIgnoringReturn) { | 1885 if (to_skip != 0 && return_skip == kIgnoringReturn) { |
| 1880 sink_->Put(kSkip, "Skip"); | 1886 sink_->Put(kSkip, "Skip"); |
| 1881 sink_->PutInt(to_skip, "SkipDistance"); | 1887 sink_->PutInt(to_skip, "SkipDistance"); |
| 1882 to_skip = 0; | 1888 to_skip = 0; |
| 1883 } | 1889 } |
| 1884 return to_skip; | 1890 return to_skip; |
| 1885 } | 1891 } |
| 1886 | 1892 |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2306 | 2312 |
| 2307 int SerializedCodeData::CheckSum(String* string) { | 2313 int SerializedCodeData::CheckSum(String* string) { |
| 2308 int checksum = Version::Hash(); | 2314 int checksum = Version::Hash(); |
| 2309 #ifdef DEBUG | 2315 #ifdef DEBUG |
| 2310 uint32_t seed = static_cast<uint32_t>(checksum); | 2316 uint32_t seed = static_cast<uint32_t>(checksum); |
| 2311 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed)); | 2317 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed)); |
| 2312 #endif // DEBUG | 2318 #endif // DEBUG |
| 2313 return checksum; | 2319 return checksum; |
| 2314 } | 2320 } |
| 2315 } } // namespace v8::internal | 2321 } } // namespace v8::internal |
| OLD | NEW |