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
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/objects/contexts.h"
9 #include "src/snapshot/serializer.h"
10 #include "src/utils/address-map.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class StartupSerializer;
16 
17 class V8_EXPORT_PRIVATE PartialSerializer : public Serializer {
18  public:
19   PartialSerializer(Isolate* isolate, StartupSerializer* startup_serializer,
20                     v8::SerializeEmbedderFieldsCallback callback);
21 
22   ~PartialSerializer() override;
23 
24   // Serialize the objects reachable from a single object pointer.
25   void Serialize(Context* o, bool include_global_proxy);
26 
can_be_rehashed()27   bool can_be_rehashed() const { return can_be_rehashed_; }
28 
29  private:
30   void SerializeObject(HeapObject o) override;
31 
32   bool ShouldBeInThePartialSnapshotCache(HeapObject o);
33 
34   bool SerializeJSObjectWithEmbedderFields(Object obj);
35 
36   void CheckRehashability(HeapObject obj);
37 
38   StartupSerializer* startup_serializer_;
39   v8::SerializeEmbedderFieldsCallback serialize_embedder_fields_;
40   // Indicates whether we only serialized hash tables that we can rehash.
41   // TODO(yangguo): generalize rehashing, and remove this flag.
42   bool can_be_rehashed_;
43   Context context_;
44 
45   // Used to store serialized data for embedder fields.
46   SnapshotByteSink embedder_fields_sink_;
47   DISALLOW_COPY_AND_ASSIGN(PartialSerializer);
48 };
49 
50 }  // namespace internal
51 }  // namespace v8
52 
53 #endif  // V8_SNAPSHOT_PARTIAL_SERIALIZER_H_
54