OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef V8_SNAPSHOT_STARTUP_SERIALIZER_H_ | 5 #ifndef V8_SNAPSHOT_STARTUP_SERIALIZER_H_ |
6 #define V8_SNAPSHOT_STARTUP_SERIALIZER_H_ | 6 #define V8_SNAPSHOT_STARTUP_SERIALIZER_H_ |
7 | 7 |
8 #include <bitset> | 8 #include <bitset> |
9 #include "include/v8.h" | 9 #include "include/v8.h" |
10 #include "src/snapshot/serializer.h" | 10 #include "src/snapshot/serializer.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 class StartupSerializer : public Serializer { | 15 class StartupSerializer : public Serializer { |
16 public: | 16 public: |
17 StartupSerializer( | 17 StartupSerializer( |
18 Isolate* isolate, | 18 Isolate* isolate, |
19 v8::SnapshotCreator::FunctionCodeHandling function_code_handling); | 19 v8::SnapshotCreator::FunctionCodeHandling function_code_handling); |
20 ~StartupSerializer() override; | 20 ~StartupSerializer() override; |
21 | 21 |
22 // Serialize the current state of the heap. The order is: | 22 // Serialize the current state of the heap. The order is: |
23 // 1) Immortal immovable roots | 23 // 1) Immortal immovable roots |
24 // 2) Remaining strong references. | 24 // 2) Remaining strong references. |
25 // 3) Partial snapshot cache. | 25 // 3) Partial snapshot cache. |
26 // 4) Weak references (e.g. the string table). | 26 // 4) Weak references (e.g. the string table). |
27 void SerializeStrongReferences(); | 27 void SerializeStrongReferences(); |
28 void SerializeWeakReferencesAndDeferred(); | 28 void SerializeWeakReferencesAndDeferred(); |
29 | 29 |
| 30 int PartialSnapshotCacheIndex(HeapObject* o); |
| 31 |
30 private: | 32 private: |
| 33 class PartialCacheIndexMap : public AddressMapBase { |
| 34 public: |
| 35 PartialCacheIndexMap() |
| 36 : map_(base::HashMap::PointersMatch), next_index_(0) {} |
| 37 |
| 38 // Lookup object in the map. Return its index if found, or create |
| 39 // a new entry with new_index as value, and return kInvalidIndex. |
| 40 bool LookupOrInsert(HeapObject* obj, int* index_out) { |
| 41 base::HashMap::Entry* entry = LookupEntry(&map_, obj, false); |
| 42 if (entry != NULL) { |
| 43 *index_out = GetValue(entry); |
| 44 return true; |
| 45 } |
| 46 *index_out = next_index_; |
| 47 SetValue(LookupEntry(&map_, obj, true), next_index_++); |
| 48 return false; |
| 49 } |
| 50 |
| 51 private: |
| 52 base::HashMap map_; |
| 53 int next_index_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(PartialCacheIndexMap); |
| 56 }; |
| 57 |
31 // The StartupSerializer has to serialize the root array, which is slightly | 58 // The StartupSerializer has to serialize the root array, which is slightly |
32 // different. | 59 // different. |
33 void VisitPointers(Object** start, Object** end) override; | 60 void VisitPointers(Object** start, Object** end) override; |
34 void SerializeObject(HeapObject* o, HowToCode how_to_code, | 61 void SerializeObject(HeapObject* o, HowToCode how_to_code, |
35 WhereToPoint where_to_point, int skip) override; | 62 WhereToPoint where_to_point, int skip) override; |
36 void Synchronize(VisitorSynchronization::SyncTag tag) override; | 63 void Synchronize(VisitorSynchronization::SyncTag tag) override; |
37 | 64 |
38 // Some roots should not be serialized, because their actual value depends on | 65 // Some roots should not be serialized, because their actual value depends on |
39 // absolute addresses and they are reset after deserialization, anyway. | 66 // absolute addresses and they are reset after deserialization, anyway. |
40 // In the first pass over the root list, we only serialize immortal immovable | 67 // In the first pass over the root list, we only serialize immortal immovable |
41 // roots. In the second pass, we serialize the rest. | 68 // roots. In the second pass, we serialize the rest. |
42 bool RootShouldBeSkipped(int root_index); | 69 bool RootShouldBeSkipped(int root_index); |
43 | 70 |
44 bool clear_function_code_; | 71 bool clear_function_code_; |
45 bool serializing_builtins_; | 72 bool serializing_builtins_; |
46 bool serializing_immortal_immovables_roots_; | 73 bool serializing_immortal_immovables_roots_; |
47 std::bitset<Heap::kStrongRootListLength> root_has_been_serialized_; | 74 std::bitset<Heap::kStrongRootListLength> root_has_been_serialized_; |
| 75 PartialCacheIndexMap partial_cache_index_map_; |
48 DISALLOW_COPY_AND_ASSIGN(StartupSerializer); | 76 DISALLOW_COPY_AND_ASSIGN(StartupSerializer); |
49 }; | 77 }; |
50 | 78 |
51 } // namespace internal | 79 } // namespace internal |
52 } // namespace v8 | 80 } // namespace v8 |
53 | 81 |
54 #endif // V8_SNAPSHOT_STARTUP_SERIALIZER_H_ | 82 #endif // V8_SNAPSHOT_STARTUP_SERIALIZER_H_ |
OLD | NEW |