}
+void StringTable::EnsureCapacityForDeserialization(Isolate* isolate,
+ int expected) {
+ Handle<StringTable> table = isolate->factory()->string_table();
+ // We need a key instance for the virtual hash function.
+ InternalizedStringKey dummy_key(Handle<String>::null());
+ table = StringTable::EnsureCapacity(table, expected, &dummy_key);
+ isolate->factory()->set_string_table(table);
+}
+
+
Handle<String> StringTable::LookupString(Isolate* isolate,
Handle<String> string) {
InternalizedStringKey key(string);
uint16_t c1,
uint16_t c2);
+ static void EnsureCapacityForDeserialization(Isolate* isolate, int expected);
+
DECLARE_CAST(StringTable)
private:
int size;
const char* resource;
// Find the map and size for the imaginary sequential string.
+ bool internalized = object_->IsInternalizedString();
if (object_->IsExternalOneByteString()) {
- map = isolate->heap()->one_byte_internalized_string_map();
+ map = internalized ? isolate->heap()->one_byte_internalized_string_map()
+ : isolate->heap()->one_byte_string_map();
size = SeqOneByteString::SizeFor(length);
resource = ExternalOneByteString::cast(string)->resource()->data();
} else {
- map = isolate->heap()->internalized_string_map();
+ map = internalized ? isolate->heap()->internalized_string_map()
+ : isolate->heap()->string_map();
size = SeqTwoByteString::SizeFor(length);
resource = reinterpret_cast<const char*>(
ExternalTwoByteString::cast(string)->resource()->data());
uint32_t Serializer::Allocate(int space, int size) {
CHECK(space >= 0 && space < kNumberOfPreallocatedSpaces);
- DCHECK(size > 0 && size < Page::kMaxRegularHeapObjectSize);
+ DCHECK(size > 0 && size <= Page::kMaxRegularHeapObjectSize);
uint32_t new_chunk_size = pending_chunk_[space] + size;
uint32_t allocation;
if (new_chunk_size > static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize)) {
PrintF("\n");
}
+ if (heap_object->IsInternalizedString()) num_internalized_strings_++;
+
// Object has not yet been serialized. Serialize it here.
ObjectSerializer serializer(this, heap_object, sink_, how_to_code,
where_to_point);
SnapshotByteSource payload(scd.Payload(), scd.PayloadLength());
Deserializer deserializer(&payload);
+ // Eagerly expand string table to avoid allocations during deserialization.
+ StringTable::EnsureCapacityForDeserialization(isolate,
+ scd.NumInternalizedStrings());
+
+ // Set reservations.
STATIC_ASSERT(NEW_SPACE == 0);
int current_space = NEW_SPACE;
Vector<const SerializedCodeData::Reservation> res = scd.Reservations();
Vector<const uint32_t> chunks = cs->FinalAllocationChunks(i);
for (int j = 0; j < chunks.length(); j++) {
DCHECK(i == LO_SPACE ||
- chunks[j] <
+ chunks[j] <=
static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize));
uint32_t chunk = ChunkSizeBits::encode(chunks[j]) |
IsLastChunkBits::encode(j == chunks.length() - 1);
// Set header values.
SetHeaderValue(kCheckSumOffset, CheckSum(cs->source()));
+ SetHeaderValue(kNumInternalizedStringsOffset, cs->num_internalized_strings());
SetHeaderValue(kReservationsOffset, reservations.length());
SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys);
SetHeaderValue(kPayloadLengthOffset, payload->length());
DCHECK(space >= 0);
DCHECK(space < kNumberOfSpaces);
DCHECK(space == LO_SPACE ||
- chunk < static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize));
+ chunk <= static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize));
reservations_[space].Add({chunk, NULL, NULL});
}
static const int kSourceObjectIndex = 0;
static const int kCodeStubsBaseIndex = 1;
- String* source() {
+ String* source() const {
DCHECK(!AllowHeapAllocation::IsAllowed());
return source_;
}
List<uint32_t>* stub_keys() { return &stub_keys_; }
+ int num_internalized_strings() const { return num_internalized_strings_; }
private:
CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source,
Code* main_code)
- : Serializer(isolate, sink), source_(source), main_code_(main_code) {
+ : Serializer(isolate, sink),
+ source_(source),
+ main_code_(main_code),
+ num_internalized_strings_(0) {
set_root_index_wave_front(Heap::kStrongRootListLength);
InitializeCodeAddressMap();
}
DisallowHeapAllocation no_gc_;
String* source_;
Code* main_code_;
+ int num_internalized_strings_;
List<uint32_t> stub_keys_;
DISALLOW_COPY_AND_ASSIGN(CodeSerializer);
};
DISALLOW_COPY_AND_ASSIGN(Reservation);
};
+ int NumInternalizedStrings() const {
+ return GetHeaderValue(kNumInternalizedStringsOffset);
+ }
+
Vector<const Reservation> Reservations() const {
return Vector<const Reservation>(reinterpret_cast<const Reservation*>(
script_data_->data() + kHeaderSize),
// The data header consists of int-sized entries:
// [0] version hash
- // [1] number of code stub keys
- // [2] payload length
- // [3..9] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
+ // [1] number of internalized strings
+ // [2] number of code stub keys
+ // [3] payload length
+ // [4..10] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
static const int kCheckSumOffset = 0;
- static const int kReservationsOffset = 1;
- static const int kNumCodeStubKeysOffset = 2;
- static const int kPayloadLengthOffset = 3;
+ static const int kNumInternalizedStringsOffset = 1;
+ static const int kReservationsOffset = 2;
+ static const int kNumCodeStubKeysOffset = 3;
+ static const int kPayloadLengthOffset = 4;
static const int kHeaderSize = (kPayloadLengthOffset + 1) * kIntSize;
class ChunkSizeBits : public BitField<uint32_t, 0, 31> {};