Line data Source code
1 : // Copyright 2018 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_ROOTS_SERIALIZER_H_
6 : #define V8_SNAPSHOT_ROOTS_SERIALIZER_H_
7 :
8 : #include <bitset>
9 :
10 : #include "src/snapshot/serializer.h"
11 : #include "src/visitors.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 : class HeapObject;
17 : class Object;
18 : class Isolate;
19 : enum class RootIndex : uint16_t;
20 :
21 : // Base class for serializer that iterate over roots. Also maintains a cache
22 : // that can be used to share non-root objects with other serializers.
23 1044 : class RootsSerializer : public Serializer {
24 : public:
25 : // The serializer expects that all roots before |first_root_to_be_serialized|
26 : // are already serialized.
27 : RootsSerializer(Isolate* isolate, RootIndex first_root_to_be_serialized);
28 :
29 : bool can_be_rehashed() const { return can_be_rehashed_; }
30 : bool root_has_been_serialized(RootIndex root_index) const {
31 3037139 : return root_has_been_serialized_.test(static_cast<size_t>(root_index));
32 : }
33 :
34 4193507 : bool IsRootAndHasBeenSerialized(HeapObject obj) const {
35 : RootIndex root_index;
36 6639220 : return root_index_map()->Lookup(obj, &root_index) &&
37 6639220 : root_has_been_serialized(root_index);
38 : }
39 :
40 : protected:
41 : void CheckRehashability(HeapObject obj);
42 :
43 : // Serializes |object| if not previously seen and returns its cache index.
44 : int SerializeInObjectCache(HeapObject object);
45 :
46 : private:
47 : void VisitRootPointers(Root root, const char* description,
48 : FullObjectSlot start, FullObjectSlot end) override;
49 : void Synchronize(VisitorSynchronization::SyncTag tag) override;
50 :
51 : const RootIndex first_root_to_be_serialized_;
52 : std::bitset<RootsTable::kEntriesCount> root_has_been_serialized_;
53 : ObjectCacheIndexMap object_cache_index_map_;
54 : // Indicates whether we only serialized hash tables that we can rehash.
55 : // TODO(yangguo): generalize rehashing, and remove this flag.
56 : bool can_be_rehashed_;
57 :
58 : DISALLOW_COPY_AND_ASSIGN(RootsSerializer);
59 : };
60 :
61 : } // namespace internal
62 : } // namespace v8
63 :
64 : #endif // V8_SNAPSHOT_ROOTS_SERIALIZER_H_
|