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