v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bootstrapper.h
Go to the documentation of this file.
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 
29 #ifndef V8_BOOTSTRAPPER_H_
30 #define V8_BOOTSTRAPPER_H_
31 
32 #include "allocation.h"
33 
34 namespace v8 {
35 namespace internal {
36 
37 
38 // A SourceCodeCache uses a FixedArray to store pairs of
39 // (AsciiString*, JSFunction*), mapping names of native code files
40 // (runtime.js, etc.) to precompiled functions. Instead of mapping
41 // names to functions it might make sense to let the JS2C tool
42 // generate an index for each native JS file.
43 class SourceCodeCache BASE_EMBEDDED {
44  public:
45  explicit SourceCodeCache(Script::Type type): type_(type), cache_(NULL) { }
46 
47  void Initialize(Isolate* isolate, bool create_heap_objects) {
48  cache_ = create_heap_objects ? isolate->heap()->empty_fixed_array() : NULL;
49  }
50 
51  void Iterate(ObjectVisitor* v) {
52  v->VisitPointer(BitCast<Object**, FixedArray**>(&cache_));
53  }
54 
56  for (int i = 0; i < cache_->length(); i+=2) {
57  SeqOneByteString* str = SeqOneByteString::cast(cache_->get(i));
58  if (str->IsUtf8EqualTo(name)) {
60  SharedFunctionInfo::cast(cache_->get(i + 1)));
61  return true;
62  }
63  }
64  return false;
65  }
66 
68  Isolate* isolate = shared->GetIsolate();
69  Factory* factory = isolate->factory();
70  HandleScope scope(isolate);
71  int length = cache_->length();
72  Handle<FixedArray> new_array = factory->NewFixedArray(length + 2, TENURED);
73  cache_->CopyTo(0, *new_array, 0, cache_->length());
74  cache_ = *new_array;
75  Handle<String> str = factory->NewStringFromAscii(name, TENURED);
76  ASSERT(!str.is_null());
77  cache_->set(length, *str);
78  cache_->set(length + 1, *shared);
79  Script::cast(shared->script())->set_type(Smi::FromInt(type_));
80  }
81 
82  private:
83  Script::Type type_;
84  FixedArray* cache_;
85  DISALLOW_COPY_AND_ASSIGN(SourceCodeCache);
86 };
87 
88 
89 // The Boostrapper is the public interface for creating a JavaScript global
90 // context.
91 class Bootstrapper {
92  public:
93  static void InitializeOncePerProcess();
94  static void TearDownExtensions();
95 
96  // Requires: Heap::SetUp has been called.
97  void Initialize(bool create_heap_objects);
98  void TearDown();
99 
100  // Creates a JavaScript Global Context with initial object graph.
101  // The returned value is a global handle casted to V8Environment*.
103  Handle<Object> global_object,
104  v8::Handle<v8::ObjectTemplate> global_template,
105  v8::ExtensionConfiguration* extensions);
106 
107  // Detach the environment from its outer global object.
108  void DetachGlobal(Handle<Context> env);
109 
110  // Traverses the pointers for memory management.
111  void Iterate(ObjectVisitor* v);
112 
113  // Accessor for the native scripts source code.
115 
116  // Tells whether bootstrapping is active.
117  bool IsActive() const { return nesting_ != 0; }
118 
119  // Support for thread preemption.
120  static int ArchiveSpacePerThread();
121  char* ArchiveState(char* to);
122  char* RestoreState(char* from);
123  void FreeThreadResources();
124 
125  // This will allocate a char array that is deleted when V8 is shut down.
126  // It should only be used for strictly finite allocations.
127  char* AllocateAutoDeletedArray(int bytes);
128 
129  // Used for new context creation.
130  bool InstallExtensions(Handle<Context> native_context,
131  v8::ExtensionConfiguration* extensions);
132 
133  SourceCodeCache* extensions_cache() { return &extensions_cache_; }
134 
135  private:
136  Isolate* isolate_;
137  typedef int NestingCounterType;
138  NestingCounterType nesting_;
139  SourceCodeCache extensions_cache_;
140  // This is for delete, not delete[].
141  List<char*>* delete_these_non_arrays_on_tear_down_;
142  // This is for delete[]
143  List<char*>* delete_these_arrays_on_tear_down_;
144 
145  friend class BootstrapperActive;
146  friend class Isolate;
148 
149  explicit Bootstrapper(Isolate* isolate);
150 
151  static v8::Extension* free_buffer_extension_;
152  static v8::Extension* gc_extension_;
153  static v8::Extension* externalize_string_extension_;
154  static v8::Extension* statistics_extension_;
155  static v8::Extension* trigger_failure_extension_;
156 
158 };
159 
160 
161 class BootstrapperActive BASE_EMBEDDED {
162  public:
163  explicit BootstrapperActive(Bootstrapper* bootstrapper)
164  : bootstrapper_(bootstrapper) {
165  ++bootstrapper_->nesting_;
166  }
167 
169  --bootstrapper_->nesting_;
170  }
171 
172  private:
173  Bootstrapper* bootstrapper_;
174 
175  DISALLOW_COPY_AND_ASSIGN(BootstrapperActive);
176 };
177 
178 
181  public:
183  const char* source,
184  size_t length);
185 
186  const char* data() const {
187  return data_;
188  }
189 
190  size_t length() const {
191  return length_;
192  }
193  private:
194  const char* data_;
195  size_t length_;
196 };
197 
198 }} // namespace v8::internal
199 
200 #endif // V8_BOOTSTRAPPER_H_
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
char * ArchiveState(char *to)
void Initialize(bool create_heap_objects)
char * AllocateAutoDeletedArray(int bytes)
static Smi * FromInt(int value)
Definition: objects-inl.h:1209
SourceCodeCache * extensions_cache()
Definition: bootstrapper.h:133
Handle< String > NewStringFromAscii(Vector< const char > str, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.h:141
static SeqOneByteString * cast(Object *obj)
#define ASSERT(condition)
Definition: checks.h:329
char * RestoreState(char *from)
static Script * cast(Object *obj)
bool InstallExtensions(Handle< Context > native_context, v8::ExtensionConfiguration *extensions)
static SharedFunctionInfo * cast(Object *obj)
Handle< Context > CreateEnvironment(Handle< Object > global_object, v8::Handle< v8::ObjectTemplate > global_template, v8::ExtensionConfiguration *extensions)
Factory * factory()
Definition: isolate.h:995
bool Lookup(Vector< const char > name, Handle< SharedFunctionInfo > *handle)
Definition: bootstrapper.h:55
bool IsUtf8EqualTo(Vector< const char > str, bool allow_prefix_match=false)
Definition: objects.cc:8972
friend class BootstrapperActive
Definition: bootstrapper.h:145
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:359
Handle< String > NativesSourceLookup(int index)
Definition: bootstrapper.cc:79
Handle< FixedArray > NewFixedArray(int size, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:53
#define BASE_EMBEDDED
Definition: allocation.h:68
void Add(Vector< const char > name, Handle< SharedFunctionInfo > shared)
Definition: bootstrapper.h:67
void Iterate(ObjectVisitor *v)
bool is_null() const
Definition: handles.h:81
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:103
static void InitializeOncePerProcess()
void DetachGlobal(Handle< Context > env)
void Iterate(ObjectVisitor *v)
Definition: bootstrapper.h:51
BootstrapperActive(Bootstrapper *bootstrapper)
Definition: bootstrapper.h:163
SourceCodeCache(Script::Type type)
Definition: bootstrapper.h:45
NativesExternalStringResource(Bootstrapper *bootstrapper, const char *source, size_t length)
Definition: bootstrapper.cc:55
void Initialize(Isolate *isolate, bool create_heap_objects)
Definition: bootstrapper.h:47
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV 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 expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
Definition: flags.cc:505
static int ArchiveSpacePerThread()
static void TearDownExtensions()