summaryrefslogtreecommitdiff
path: root/deps/v8/src/snapshot/builtin-serializer.h
blob: 132aa0894b8f9859fd4d10d6077ad32b01dcfa88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2017 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.

#ifndef V8_SNAPSHOT_BUILTIN_SERIALIZER_H_
#define V8_SNAPSHOT_BUILTIN_SERIALIZER_H_

#include "src/builtins/builtins.h"
#include "src/interpreter/interpreter.h"
#include "src/snapshot/builtin-serializer-allocator.h"
#include "src/snapshot/serializer.h"

namespace v8 {
namespace internal {

class StartupSerializer;

// Responsible for serializing builtin objects during startup snapshot creation
// into a dedicated area of the snapshot.
// See snapshot.h for documentation of the snapshot layout.
class BuiltinSerializer : public Serializer<BuiltinSerializerAllocator> {
 public:
  BuiltinSerializer(Isolate* isolate, StartupSerializer* startup_serializer);
  ~BuiltinSerializer() override;

  void SerializeBuiltinsAndHandlers();

 private:
  void VisitRootPointers(Root root, const char* description, Object** start,
                         Object** end) override;

  void SerializeBuiltin(Code* code);
  void SerializeObject(HeapObject* o, HowToCode how_to_code,
                       WhereToPoint where_to_point, int skip) override;

  void SetBuiltinOffset(int builtin_id, uint32_t offset);
  void SetHandlerOffset(interpreter::Bytecode bytecode,
                        interpreter::OperandScale operand_scale,
                        uint32_t offset);

  // The startup serializer is needed for access to the partial snapshot cache,
  // which is used to serialize things like embedded constants.
  StartupSerializer* startup_serializer_;

  // Stores the starting offset, within the serialized data, of each code
  // object. This is later packed into the builtin snapshot, and used by the
  // builtin deserializer to deserialize individual builtins.
  //
  // Indices [kFirstBuiltinIndex, kFirstBuiltinIndex + kNumberOfBuiltins[:
  //     Builtin offsets.
  uint32_t code_offsets_[Builtins::builtin_count];

  DISALLOW_COPY_AND_ASSIGN(BuiltinSerializer);
};

}  // namespace internal
}  // namespace v8

#endif  // V8_SNAPSHOT_BUILTIN_SERIALIZER_H_