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

Side by Side Diff: src/serialize.cc

Issue 604373008: Serialize all external strings except for native source code strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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/heap/heap.cc ('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 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 } 1545 }
1546 1546
1547 // Serialize the map (first word of the object). 1547 // Serialize the map (first word of the object).
1548 serializer_->SerializeObject(map, kPlain, kStartOfObject, 0); 1548 serializer_->SerializeObject(map, kPlain, kStartOfObject, 0);
1549 } 1549 }
1550 1550
1551 1551
1552 void Serializer::ObjectSerializer::SerializeExternalString() { 1552 void Serializer::ObjectSerializer::SerializeExternalString() {
1553 // Instead of serializing this as an external string, we serialize 1553 // Instead of serializing this as an external string, we serialize
1554 // an imaginary sequential string with the same content. 1554 // an imaginary sequential string with the same content.
1555 DCHECK(object_->IsExternalString() && object_->IsInternalizedString());
1556 Isolate* isolate = serializer_->isolate(); 1555 Isolate* isolate = serializer_->isolate();
1556 DCHECK(object_->IsExternalString());
1557 DCHECK(object_->map() != isolate->heap()->native_source_string_map());
1557 ExternalString* string = ExternalString::cast(object_); 1558 ExternalString* string = ExternalString::cast(object_);
1558 int length = string->length(); 1559 int length = string->length();
1559 Map* map; 1560 Map* map;
1560 int size; 1561 int size;
1561 const char* resource; 1562 const char* resource;
1562 // Find the map and size for the imaginary sequential string. 1563 // Find the map and size for the imaginary sequential string.
1563 if (object_->IsExternalOneByteString()) { 1564 if (object_->IsExternalOneByteString()) {
1564 map = isolate->heap()->one_byte_internalized_string_map(); 1565 map = isolate->heap()->one_byte_internalized_string_map();
1565 size = SeqOneByteString::SizeFor(length); 1566 size = SeqOneByteString::SizeFor(length);
1566 resource = ExternalOneByteString::cast(string)->resource()->data(); 1567 resource = ExternalOneByteString::cast(string)->resource()->data();
(...skipping 26 matching lines...) Expand all
1593 for (int i = 0; i < content_length; i++) { 1594 for (int i = 0; i < content_length; i++) {
1594 sink_->PutSection(resource[i], "StringContent"); 1595 sink_->PutSection(resource[i], "StringContent");
1595 } 1596 }
1596 1597
1597 sink_->Put(kSkip, "SkipAfterString"); 1598 sink_->Put(kSkip, "SkipAfterString");
1598 sink_->PutInt(bytes_to_output, "SkipDistance"); 1599 sink_->PutInt(bytes_to_output, "SkipDistance");
1599 } 1600 }
1600 1601
1601 1602
1602 void Serializer::ObjectSerializer::Serialize() { 1603 void Serializer::ObjectSerializer::Serialize() {
1603 if (object_->IsExternalString() && object_->IsInternalizedString()) { 1604 if (object_->IsExternalString()) {
1604 // Native source code strings are not internalized and are handled in 1605 Heap* heap = serializer_->isolate()->heap();
1605 // VisitExternalOneByteString. We deal with embedded external strings 1606 if (object_->map() != heap->native_source_string_map()) {
1606 // by serializing them as sequential strings on the heap. 1607 // Usually we cannot recreate resources for external strings. To work
1607 // This can only happen with CodeSerializer. 1608 // around this, external strings are serialized to look like ordinary
1608 SerializeExternalString(); 1609 // sequential strings.
1609 } else { 1610 // The exception are native source code strings, since we can recreate
1610 int size = object_->Size(); 1611 // their resources. In that case we fall through and leave it to
1611 Map* map = object_->map(); 1612 // VisitExternalOneByteString further down.
1612 SerializePrologue(Serializer::SpaceOfObject(object_), size, map); 1613 SerializeExternalString();
1614 return;
1615 }
1616 }
1613 1617
1614 // Serialize the rest of the object. 1618 int size = object_->Size();
1615 CHECK_EQ(0, bytes_processed_so_far_); 1619 Map* map = object_->map();
1616 bytes_processed_so_far_ = kPointerSize; 1620 SerializePrologue(Serializer::SpaceOfObject(object_), size, map);
1617 1621
1618 object_->IterateBody(map->instance_type(), size, this); 1622 // Serialize the rest of the object.
1619 OutputRawData(object_->address() + size); 1623 CHECK_EQ(0, bytes_processed_so_far_);
1620 } 1624 bytes_processed_so_far_ = kPointerSize;
1625
1626 object_->IterateBody(map->instance_type(), size, this);
1627 OutputRawData(object_->address() + size);
1621 } 1628 }
1622 1629
1623 1630
1624 void Serializer::ObjectSerializer::VisitPointers(Object** start, 1631 void Serializer::ObjectSerializer::VisitPointers(Object** start,
1625 Object** end) { 1632 Object** end) {
1626 Object** current = start; 1633 Object** current = start;
1627 while (current < end) { 1634 while (current < end) {
1628 while (current < end && (*current)->IsSmi()) current++; 1635 while (current < end && (*current)->IsSmi()) current++;
1629 if (current < end) OutputRawData(reinterpret_cast<Address>(current)); 1636 if (current < end) OutputRawData(reinterpret_cast<Address>(current));
1630 1637
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 2186
2180 int SerializedCodeData::CheckSum(String* string) { 2187 int SerializedCodeData::CheckSum(String* string) {
2181 int checksum = Version::Hash(); 2188 int checksum = Version::Hash();
2182 #ifdef DEBUG 2189 #ifdef DEBUG
2183 uint32_t seed = static_cast<uint32_t>(checksum); 2190 uint32_t seed = static_cast<uint32_t>(checksum);
2184 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed)); 2191 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed));
2185 #endif // DEBUG 2192 #endif // DEBUG
2186 return checksum; 2193 return checksum;
2187 } 2194 }
2188 } } // namespace v8::internal 2195 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698