1// Copyright 2017 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_SETUP_ISOLATE_H_
6#define V8_SETUP_ISOLATE_H_
7
8#include "src/base/macros.h"
9
10namespace v8 {
11namespace internal {
12
13class Builtins;
14class Code;
15class Heap;
16class Isolate;
17
18namespace interpreter {
19class Interpreter;
20} // namespace interpreter
21
22// This class is an abstraction layer around initialization of components
23// that are either deserialized from the snapshot or generated from scratch.
24// Currently this includes builtins and interpreter bytecode handlers.
25// There are two implementations to choose from at link time:
26// - setup-isolate-deserialize.cc: always loads things from snapshot.
27// - setup-isolate-full.cc: loads from snapshot or bootstraps from scratch,
28// controlled by the |create_heap_objects| flag.
29// For testing, the implementation in setup-isolate-for-tests.cc can be chosen
30// to force the behavior of setup-isolate-full.cc at runtime.
31//
32// The actual implementations of generation of builtins and handlers is in
33// setup-builtins-internal.cc and setup-interpreter-internal.cc, and is
34// linked in by the latter two Delegate implementations.
35class V8_EXPORT_PRIVATE SetupIsolateDelegate {
36 public:
37 explicit SetupIsolateDelegate(bool create_heap_objects)
38 : create_heap_objects_(create_heap_objects) {}
39 virtual ~SetupIsolateDelegate() = default;
40
41 virtual void SetupBuiltins(Isolate* isolate);
42
43 virtual bool SetupHeap(Heap* heap);
44
45 protected:
46 static void SetupBuiltinsInternal(Isolate* isolate);
47 static void AddBuiltin(Builtins* builtins, int index, Code code);
48 static void PopulateWithPlaceholders(Isolate* isolate);
49 static void ReplacePlaceholders(Isolate* isolate);
50
51 static bool SetupHeapInternal(Heap* heap);
52
53 const bool create_heap_objects_;
54};
55
56} // namespace internal
57} // namespace v8
58
59#endif // V8_SETUP_ISOLATE_H_
60