context-serializer.h 1.73 KB
Newer Older
1 2 3 4
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_SNAPSHOT_CONTEXT_SERIALIZER_H_
#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 13 14

namespace v8 {
namespace internal {

15 16
class StartupSerializer;

17
class V8_EXPORT_PRIVATE ContextSerializer : public Serializer {
18
 public:
19 20
  ContextSerializer(Isolate* isolate, Snapshot::SerializerFlags flags,
                    StartupSerializer* startup_serializer,
21
                    v8::SerializeEmbedderFieldsCallback callback);
22

23
  ~ContextSerializer() override;
24 25
  ContextSerializer(const ContextSerializer&) = delete;
  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

30 31
  bool can_be_rehashed() const { return can_be_rehashed_; }

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 41 42
  // Indicates whether we only serialized hash tables that we can rehash.
  // TODO(yangguo): generalize rehashing, and remove this flag.
  bool can_be_rehashed_;
43
  Context context_;
44 45 46

  // Used to store serialized data for embedder fields.
  SnapshotByteSink embedder_fields_sink_;
47 48 49 50 51
};

}  // namespace internal
}  // namespace v8

52
#endif  // V8_SNAPSHOT_CONTEXT_SERIALIZER_H_