| 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_PARTIAL_SERIALIZER_H_ | 5 #ifndef V8_SNAPSHOT_PARTIAL_SERIALIZER_H_ |
| 6 #define V8_SNAPSHOT_PARTIAL_SERIALIZER_H_ | 6 #define V8_SNAPSHOT_PARTIAL_SERIALIZER_H_ |
| 7 | 7 |
| 8 #include "src/address-map.h" | 8 #include "src/address-map.h" |
| 9 #include "src/snapshot/serializer.h" | 9 #include "src/snapshot/serializer.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 class StartupSerializer; |
| 15 |
| 14 class PartialSerializer : public Serializer { | 16 class PartialSerializer : public Serializer { |
| 15 public: | 17 public: |
| 16 PartialSerializer(Isolate* isolate, Serializer* startup_snapshot_serializer); | 18 PartialSerializer(Isolate* isolate, StartupSerializer* startup_serializer); |
| 17 | 19 |
| 18 ~PartialSerializer() override; | 20 ~PartialSerializer() override; |
| 19 | 21 |
| 20 // Serialize the objects reachable from a single object pointer. | 22 // Serialize the objects reachable from a single object pointer. |
| 21 void Serialize(Object** o); | 23 void Serialize(Object** o); |
| 22 | 24 |
| 23 private: | 25 private: |
| 24 class PartialCacheIndexMap : public AddressMapBase { | |
| 25 public: | |
| 26 PartialCacheIndexMap() : map_(base::HashMap::PointersMatch) {} | |
| 27 | |
| 28 static const int kInvalidIndex = -1; | |
| 29 | |
| 30 // Lookup object in the map. Return its index if found, or create | |
| 31 // a new entry with new_index as value, and return kInvalidIndex. | |
| 32 int LookupOrInsert(HeapObject* obj, int new_index) { | |
| 33 base::HashMap::Entry* entry = LookupEntry(&map_, obj, false); | |
| 34 if (entry != NULL) return GetValue(entry); | |
| 35 SetValue(LookupEntry(&map_, obj, true), static_cast<uint32_t>(new_index)); | |
| 36 return kInvalidIndex; | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 base::HashMap map_; | |
| 41 | |
| 42 DISALLOW_COPY_AND_ASSIGN(PartialCacheIndexMap); | |
| 43 }; | |
| 44 | |
| 45 void SerializeObject(HeapObject* o, HowToCode how_to_code, | 26 void SerializeObject(HeapObject* o, HowToCode how_to_code, |
| 46 WhereToPoint where_to_point, int skip) override; | 27 WhereToPoint where_to_point, int skip) override; |
| 47 | 28 |
| 48 int PartialSnapshotCacheIndex(HeapObject* o); | |
| 49 bool ShouldBeInThePartialSnapshotCache(HeapObject* o); | 29 bool ShouldBeInThePartialSnapshotCache(HeapObject* o); |
| 50 | 30 |
| 51 Serializer* startup_serializer_; | 31 StartupSerializer* startup_serializer_; |
| 52 PartialCacheIndexMap partial_cache_index_map_; | |
| 53 int next_partial_cache_index_; | |
| 54 DISALLOW_COPY_AND_ASSIGN(PartialSerializer); | 32 DISALLOW_COPY_AND_ASSIGN(PartialSerializer); |
| 55 }; | 33 }; |
| 56 | 34 |
| 57 } // namespace internal | 35 } // namespace internal |
| 58 } // namespace v8 | 36 } // namespace v8 |
| 59 | 37 |
| 60 #endif // V8_SNAPSHOT_PARTIAL_SERIALIZER_H_ | 38 #endif // V8_SNAPSHOT_PARTIAL_SERIALIZER_H_ |
| OLD | NEW |