11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_SNAPSHOT_CONTEXT_SERIALIZER_H_
61cb0ef41Sopenharmony_ci#define V8_SNAPSHOT_CONTEXT_SERIALIZER_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/objects/contexts.h"
91cb0ef41Sopenharmony_ci#include "src/snapshot/serializer.h"
101cb0ef41Sopenharmony_ci#include "src/utils/address-map.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciclass StartupSerializer;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE ContextSerializer : public Serializer {
181cb0ef41Sopenharmony_ci public:
191cb0ef41Sopenharmony_ci  ContextSerializer(Isolate* isolate, Snapshot::SerializerFlags flags,
201cb0ef41Sopenharmony_ci                    StartupSerializer* startup_serializer,
211cb0ef41Sopenharmony_ci                    v8::SerializeEmbedderFieldsCallback callback);
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  ~ContextSerializer() override;
241cb0ef41Sopenharmony_ci  ContextSerializer(const ContextSerializer&) = delete;
251cb0ef41Sopenharmony_ci  ContextSerializer& operator=(const ContextSerializer&) = delete;
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  // Serialize the objects reachable from a single object pointer.
281cb0ef41Sopenharmony_ci  void Serialize(Context* o, const DisallowGarbageCollection& no_gc);
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  bool can_be_rehashed() const { return can_be_rehashed_; }
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci private:
331cb0ef41Sopenharmony_ci  void SerializeObjectImpl(Handle<HeapObject> o) override;
341cb0ef41Sopenharmony_ci  bool ShouldBeInTheStartupObjectCache(HeapObject o);
351cb0ef41Sopenharmony_ci  bool ShouldBeInTheSharedObjectCache(HeapObject o);
361cb0ef41Sopenharmony_ci  bool SerializeJSObjectWithEmbedderFields(Handle<JSObject> obj);
371cb0ef41Sopenharmony_ci  void CheckRehashability(HeapObject obj);
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  StartupSerializer* startup_serializer_;
401cb0ef41Sopenharmony_ci  v8::SerializeEmbedderFieldsCallback serialize_embedder_fields_;
411cb0ef41Sopenharmony_ci  // Indicates whether we only serialized hash tables that we can rehash.
421cb0ef41Sopenharmony_ci  // TODO(yangguo): generalize rehashing, and remove this flag.
431cb0ef41Sopenharmony_ci  bool can_be_rehashed_;
441cb0ef41Sopenharmony_ci  Context context_;
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  // Used to store serialized data for embedder fields.
471cb0ef41Sopenharmony_ci  SnapshotByteSink embedder_fields_sink_;
481cb0ef41Sopenharmony_ci};
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci}  // namespace internal
511cb0ef41Sopenharmony_ci}  // namespace v8
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci#endif  // V8_SNAPSHOT_CONTEXT_SERIALIZER_H_
54