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 namespace v8 {
9 namespace internal {
10 
11 class Builtins;
12 class Code;
13 class Heap;
14 class Isolate;
15 
16 namespace interpreter {
17 class Interpreter;
18 }  // namespace interpreter
19 
20 // This class is an abstraction layer around initialization of components
21 // that are either deserialized from the snapshot or generated from scratch.
22 // Currently this includes builtins and interpreter bytecode handlers.
23 // There are two implementations to choose from at link time:
24 // - setup-isolate-deserialize.cc: always loads things from snapshot.
25 // - setup-isolate-full.cc: loads from snapshot or bootstraps from scratch,
26 //                          controlled by the |create_heap_objects| flag.
27 // For testing, the implementation in setup-isolate-for-tests.cc can be chosen
28 // to force the behavior of setup-isolate-full.cc at runtime.
29 //
30 // The actual implementations of generation of builtins and handlers is in
31 // setup-builtins-internal.cc and setup-interpreter-internal.cc, and is
32 // linked in by the latter two Delegate implementations.
33 class SetupIsolateDelegate {
34  public:
SetupIsolateDelegate(bool create_heap_objects)35   explicit SetupIsolateDelegate(bool create_heap_objects)
36       : create_heap_objects_(create_heap_objects) {}
~SetupIsolateDelegate()37   virtual ~SetupIsolateDelegate() {}
38 
39   virtual void SetupBuiltins(Isolate* isolate);
40 
41   virtual void SetupInterpreter(interpreter::Interpreter* interpreter);
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