• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CONTEXT_SERIALIZER_H_
6 #define V8_SNAPSHOT_CONTEXT_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 ContextSerializer : public Serializer {
18  public:
19   ContextSerializer(Isolate* isolate, Snapshot::SerializerFlags flags,
20                     StartupSerializer* startup_serializer,
21                     v8::SerializeEmbedderFieldsCallback callback);
22 
23   ~ContextSerializer() override;
24   ContextSerializer(const ContextSerializer&) = delete;
25   ContextSerializer& operator=(const ContextSerializer&) = delete;
26 
27   // Serialize the objects reachable from a single object pointer.
28   void Serialize(Context* o, const DisallowGarbageCollection& no_gc);
29 
can_be_rehashed()30   bool can_be_rehashed() const { return can_be_rehashed_; }
31 
32  private:
33   void SerializeObjectImpl(Handle<HeapObject> o) override;
34   bool ShouldBeInTheStartupObjectCache(HeapObject o);
35   bool SerializeJSObjectWithEmbedderFields(Handle<HeapObject> obj);
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 };
48 
49 }  // namespace internal
50 }  // namespace v8
51 
52 #endif  // V8_SNAPSHOT_CONTEXT_SERIALIZER_H_
53