V8 Project
bootstrapper.h
Go to the documentation of this file.
1 // Copyright 2014 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_BOOTSTRAPPER_H_
6 #define V8_BOOTSTRAPPER_H_
7 
8 #include "src/factory.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 // A SourceCodeCache uses a FixedArray to store pairs of
14 // (OneByteString*, JSFunction*), mapping names of native code files
15 // (runtime.js, etc.) to precompiled functions. Instead of mapping
16 // names to functions it might make sense to let the JS2C tool
17 // generate an index for each native JS file.
18 class SourceCodeCache FINAL BASE_EMBEDDED {
19  public:
20  explicit SourceCodeCache(Script::Type type): type_(type), cache_(NULL) { }
21 
22  void Initialize(Isolate* isolate, bool create_heap_objects) {
23  cache_ = create_heap_objects ? isolate->heap()->empty_fixed_array() : NULL;
24  }
25 
27  v->VisitPointer(bit_cast<Object**, FixedArray**>(&cache_));
28  }
29 
31  for (int i = 0; i < cache_->length(); i+=2) {
32  SeqOneByteString* str = SeqOneByteString::cast(cache_->get(i));
33  if (str->IsUtf8EqualTo(name)) {
35  SharedFunctionInfo::cast(cache_->get(i + 1)));
36  return true;
37  }
38  }
39  return false;
40  }
41 
43  Isolate* isolate = shared->GetIsolate();
44  Factory* factory = isolate->factory();
45  HandleScope scope(isolate);
46  int length = cache_->length();
47  Handle<FixedArray> new_array = factory->NewFixedArray(length + 2, TENURED);
48  cache_->CopyTo(0, *new_array, 0, cache_->length());
49  cache_ = *new_array;
50  Handle<String> str =
51  factory->NewStringFromAscii(name, TENURED).ToHandleChecked();
52  DCHECK(!str.is_null());
53  cache_->set(length, *str);
54  cache_->set(length + 1, *shared);
55  Script::cast(shared->script())->set_type(Smi::FromInt(type_));
56  }
57 
58  private:
61  DISALLOW_COPY_AND_ASSIGN(SourceCodeCache);
62 };
63 
64 
65 // The Boostrapper is the public interface for creating a JavaScript global
66 // context.
67 class Bootstrapper FINAL {
68  public:
69  static void InitializeOncePerProcess();
70  static void TearDownExtensions();
71 
72  // Requires: Heap::SetUp has been called.
73  void Initialize(bool create_heap_objects);
74  void TearDown();
75 
76  // Creates a JavaScript Global Context with initial object graph.
77  // The returned value is a global handle casted to V8Environment*.
79  MaybeHandle<JSGlobalProxy> maybe_global_proxy,
80  v8::Handle<v8::ObjectTemplate> global_object_template,
81  v8::ExtensionConfiguration* extensions);
82 
83  // Detach the environment from its outer global object.
85 
86  // Traverses the pointers for memory management.
88 
89  // Accessor for the native scripts source code.
91 
92  // Tells whether bootstrapping is active.
93  bool IsActive() const { return nesting_ != 0; }
94 
95  // Support for thread preemption.
96  static int ArchiveSpacePerThread();
97  char* ArchiveState(char* to);
98  char* RestoreState(char* from);
100 
101  // This will allocate a char array that is deleted when V8 is shut down.
102  // It should only be used for strictly finite allocations.
103  char* AllocateAutoDeletedArray(int bytes);
104 
105  // Used for new context creation.
106  bool InstallExtensions(Handle<Context> native_context,
107  v8::ExtensionConfiguration* extensions);
108 
109  SourceCodeCache* extensions_cache() { return &extensions_cache_; }
110 
111  private:
112  Isolate* isolate_;
113  typedef int NestingCounterType;
115  SourceCodeCache extensions_cache_;
116  // This is for delete, not delete[].
118  // This is for delete[]
120 
121  friend class BootstrapperActive;
122  friend class Isolate;
123  friend class NativesExternalStringResource;
124 
125  explicit Bootstrapper(Isolate* isolate);
126 
132 
134 };
135 
136 
137 class BootstrapperActive FINAL BASE_EMBEDDED {
138  public:
139  explicit BootstrapperActive(Bootstrapper* bootstrapper)
140  : bootstrapper_(bootstrapper) {
141  ++bootstrapper_->nesting_;
142  }
143 
145  --bootstrapper_->nesting_;
146  }
147 
148  private:
149  Bootstrapper* bootstrapper_;
150 
151  DISALLOW_COPY_AND_ASSIGN(BootstrapperActive);
152 };
153 
154 
155 class NativesExternalStringResource FINAL
157  public:
158  NativesExternalStringResource(Bootstrapper* bootstrapper,
159  const char* source,
160  size_t length);
161  virtual const char* data() const OVERRIDE { return data_; }
162  virtual size_t length() const OVERRIDE { return length_; }
163 
164  private:
165  const char* data_;
166  size_t length_;
167 };
168 
169 }} // namespace v8::internal
170 
171 #endif // V8_BOOTSTRAPPER_H_
#define BASE_EMBEDDED
Definition: allocation.h:45
A container for extension names.
Definition: v8.h:5424
Ignore.
Definition: v8.h:4008
An object reference managed by the v8 garbage collector.
Definition: v8.h:198
An ExternalOneByteStringResource is a wrapper around an one-byte string buffer that resides outside V...
Definition: v8.h:1918
SourceCodeCache(Script::Type type)
Definition: bootstrapper.h:20
void Initialize(Isolate *isolate, bool create_heap_objects)
Definition: bootstrapper.h:22
Bootstrapper * bootstrapper_
Definition: bootstrapper.h:149
DISALLOW_COPY_AND_ASSIGN(BootstrapperActive)
bool Lookup(Vector< const char > name, Handle< SharedFunctionInfo > *handle)
Definition: bootstrapper.h:30
void Add(Vector< const char > name, Handle< SharedFunctionInfo > shared)
Definition: bootstrapper.h:42
void Iterate(ObjectVisitor *v)
Definition: bootstrapper.h:26
BootstrapperActive(Bootstrapper *bootstrapper)
Definition: bootstrapper.h:139
DISALLOW_COPY_AND_ASSIGN(SourceCodeCache)
Source to read snapshot and builtins files from.
Definition: lithium-arm.h:372
char * RestoreState(char *from)
NestingCounterType nesting_
Definition: bootstrapper.h:114
void Iterate(ObjectVisitor *v)
virtual const char * data() const OVERRIDE
The string data from the underlying buffer.
Definition: bootstrapper.h:161
static void TearDownExtensions()
void DetachGlobal(Handle< Context > env)
Bootstrapper(Isolate *isolate)
static v8::Extension * statistics_extension_
Definition: bootstrapper.h:130
DISALLOW_COPY_AND_ASSIGN(Bootstrapper)
Handle< Context > CreateEnvironment(MaybeHandle< JSGlobalProxy > maybe_global_proxy, v8::Handle< v8::ObjectTemplate > global_object_template, v8::ExtensionConfiguration *extensions)
Handle< String > NativesSourceLookup(int index)
void Initialize(bool create_heap_objects)
List< char * > * delete_these_non_arrays_on_tear_down_
Definition: bootstrapper.h:117
SourceCodeCache * extensions_cache()
Definition: bootstrapper.h:109
char * AllocateAutoDeletedArray(int bytes)
bool InstallExtensions(Handle< Context > native_context, v8::ExtensionConfiguration *extensions)
char * ArchiveState(char *to)
virtual size_t length() const OVERRIDE
The number of Latin-1 characters in the string.
Definition: bootstrapper.h:162
static v8::Extension * free_buffer_extension_
Definition: bootstrapper.h:127
bool IsActive() const
Definition: bootstrapper.h:93
List< char * > * delete_these_arrays_on_tear_down_
Definition: bootstrapper.h:119
NativesExternalStringResource(Bootstrapper *bootstrapper, const char *source, size_t length)
static v8::Extension * gc_extension_
Definition: bootstrapper.h:128
static int ArchiveSpacePerThread()
const char * data_
Definition: bootstrapper.h:165
static void InitializeOncePerProcess()
static v8::Extension * trigger_failure_extension_
Definition: bootstrapper.h:131
SourceCodeCache extensions_cache_
Definition: bootstrapper.h:115
static v8::Extension * externalize_string_extension_
Definition: bootstrapper.h:129
bool is_null() const
Definition: handles.h:124
Factory * factory()
Definition: isolate.h:982
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
bool IsUtf8EqualTo(Vector< const char > str, bool allow_prefix_match=false)
Definition: objects.cc:8783
#define OVERRIDE
#define FINAL
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:146
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20