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
12namespace v8 {
13namespace internal {
14
15class StartupSerializer;
16
17class 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
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 ShouldBeInTheSharedObjectCache(HeapObject o);
36  bool SerializeJSObjectWithEmbedderFields(Handle<JSObject> obj);
37  void CheckRehashability(HeapObject obj);
38
39  StartupSerializer* startup_serializer_;
40  v8::SerializeEmbedderFieldsCallback serialize_embedder_fields_;
41  // Indicates whether we only serialized hash tables that we can rehash.
42  // TODO(yangguo): generalize rehashing, and remove this flag.
43  bool can_be_rehashed_;
44  Context context_;
45
46  // Used to store serialized data for embedder fields.
47  SnapshotByteSink embedder_fields_sink_;
48};
49
50}  // namespace internal
51}  // namespace v8
52
53#endif  // V8_SNAPSHOT_CONTEXT_SERIALIZER_H_
54