• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/snapshot/shared-heap-deserializer.h"
6 
7 #include "src/heap/heap-inl.h"
8 #include "src/snapshot/shared-heap-serializer.h"
9 
10 namespace v8 {
11 namespace internal {
12 
DeserializeIntoIsolate()13 void SharedHeapDeserializer::DeserializeIntoIsolate() {
14   // Don't deserialize into client Isolates. If there are client Isolates, the
15   // shared heap object cache should already be populated.
16   DCHECK_IMPLIES(isolate()->shared_isolate() != nullptr,
17                  !isolate()->shared_heap_object_cache()->empty());
18   if (isolate()->shared_isolate() != nullptr) return;
19   DCHECK(isolate()->shared_heap_object_cache()->empty());
20   HandleScope scope(isolate());
21 
22   IterateSharedHeapObjectCache(isolate(), this);
23   DeserializeStringTable();
24   DeserializeDeferredObjects();
25 
26   if (should_rehash()) {
27     // Hash seed was initialized in ReadOnlyDeserializer.
28     Rehash();
29   }
30 }
31 
DeserializeStringTable()32 void SharedHeapDeserializer::DeserializeStringTable() {
33   // See SharedHeapSerializer::SerializeStringTable.
34 
35   DCHECK(isolate()->OwnsStringTable());
36 
37   // Get the string table size.
38   int string_table_size = source()->GetInt();
39 
40   // Add each string to the Isolate's string table.
41   // TODO(leszeks): Consider pre-sizing the string table.
42   for (int i = 0; i < string_table_size; ++i) {
43     Handle<String> string = Handle<String>::cast(ReadObject());
44     StringTableInsertionKey key(
45         isolate(), string,
46         DeserializingUserCodeOption::kNotDeserializingUserCode);
47     Handle<String> result =
48         isolate()->string_table()->LookupKey(isolate(), &key);
49 
50     // Since this is startup, there should be no duplicate entries in the
51     // string table, and the lookup should unconditionally add the given
52     // string.
53     DCHECK_EQ(*result, *string);
54     USE(result);
55   }
56 
57   DCHECK_EQ(string_table_size, isolate()->string_table()->NumberOfElements());
58 }
59 
60 }  // namespace internal
61 }  // namespace v8
62