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