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
compilation-cache.h
Go to the documentation of this file.
1 // Copyright 2012 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 #ifndef V8_COMPILATION_CACHE_H_
29 #define V8_COMPILATION_CACHE_H_
30 
31 namespace v8 {
32 namespace internal {
33 
34 // The compilation cache consists of several generational sub-caches which uses
35 // this class as a base class. A sub-cache contains a compilation cache tables
36 // for each generation of the sub-cache. Since the same source code string has
37 // different compiled code for scripts and evals, we use separate sub-caches
38 // for different compilation modes, to avoid retrieving the wrong result.
40  public:
42  : isolate_(isolate),
43  generations_(generations) {
44  tables_ = NewArray<Object*>(generations);
45  }
46 
48 
49  // Index for the first generation in the cache.
50  static const int kFirstGeneration = 0;
51 
52  // Get the compilation cache tables for a specific generation.
54 
55  // Accessors for first generation.
57  return GetTable(kFirstGeneration);
58  }
60  ASSERT(kFirstGeneration < generations_);
61  tables_[kFirstGeneration] = *value;
62  }
63 
64  // Age the sub-cache by evicting the oldest generation and creating a new
65  // young generation.
66  void Age();
67 
68  // GC support.
69  void Iterate(ObjectVisitor* v);
70  void IterateFunctions(ObjectVisitor* v);
71 
72  // Clear this sub-cache evicting all its content.
73  void Clear();
74 
75  // Remove given shared function info from sub-cache.
76  void Remove(Handle<SharedFunctionInfo> function_info);
77 
78  // Number of generations in this sub-cache.
79  inline int generations() { return generations_; }
80 
81  protected:
82  Isolate* isolate() { return isolate_; }
83 
84  private:
85  Isolate* isolate_;
86  int generations_; // Number of generations.
87  Object** tables_; // Compilation cache tables - one for each generation.
88 
89  DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache);
90 };
91 
92 
93 // Sub-cache for scripts.
95  public:
97 
100  int line_offset,
101  int column_offset,
102  bool is_shared_cross_origin,
103  Handle<Context> context);
104  void Put(Handle<String> source,
105  Handle<Context> context,
106  Handle<SharedFunctionInfo> function_info);
107 
108  private:
109  MUST_USE_RESULT MaybeObject* TryTablePut(
110  Handle<String> source,
111  Handle<Context> context,
112  Handle<SharedFunctionInfo> function_info);
113 
114  // Note: Returns a new hash table if operation results in expansion.
116  Handle<String> source,
117  Handle<Context> context,
118  Handle<SharedFunctionInfo> function_info);
119 
120  bool HasOrigin(Handle<SharedFunctionInfo> function_info,
121  Handle<Object> name,
122  int line_offset,
123  int column_offset,
124  bool is_shared_cross_origin);
125 
126  void* script_histogram_;
127  bool script_histogram_initialized_;
128 
129  DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript);
130 };
131 
132 
133 // Sub-cache for eval scripts. Two caches for eval are used. One for eval calls
134 // in native contexts and one for eval calls in other contexts. The cache
135 // considers the following pieces of information when checking for matching
136 // entries:
137 // 1. The source string.
138 // 2. The shared function info of the calling function.
139 // 3. Whether the source should be compiled as strict code or as sloppy code.
140 // Note: Currently there are clients of CompileEval that always compile
141 // sloppy code even if the calling function is a strict mode function.
142 // More specifically these are the CompileString, DebugEvaluate and
143 // DebugEvaluateGlobal runtime functions.
144 // 4. The start position of the calling scope.
146  public:
148  : CompilationSubCache(isolate, generations) { }
149 
151  Handle<Context> context,
152  StrictMode strict_mode,
153  int scope_position);
154 
155  void Put(Handle<String> source,
156  Handle<Context> context,
157  Handle<SharedFunctionInfo> function_info,
158  int scope_position);
159 
160  private:
161  MUST_USE_RESULT MaybeObject* TryTablePut(
162  Handle<String> source,
163  Handle<Context> context,
164  Handle<SharedFunctionInfo> function_info,
165  int scope_position);
166 
167  // Note: Returns a new hash table if operation results in expansion.
169  Handle<String> source,
170  Handle<Context> context,
171  Handle<SharedFunctionInfo> function_info,
172  int scope_position);
173 
174  DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval);
175 };
176 
177 
178 // Sub-cache for regular expressions.
180  public:
182  : CompilationSubCache(isolate, generations) { }
183 
185 
186  void Put(Handle<String> source,
188  Handle<FixedArray> data);
189  private:
190  MUST_USE_RESULT MaybeObject* TryTablePut(Handle<String> source,
192  Handle<FixedArray> data);
193 
194  // Note: Returns a new hash table if operation results in expansion.
197  Handle<FixedArray> data);
198 
199  DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp);
200 };
201 
202 
203 // The compilation cache keeps shared function infos for compiled
204 // scripts and evals. The shared function infos are looked up using
205 // the source string as the key. For regular expressions the
206 // compilation data is cached.
208  public:
209  // Finds the script shared function info for a source
210  // string. Returns an empty handle if the cache doesn't contain a
211  // script for the given source string with the right origin.
214  int line_offset,
215  int column_offset,
216  bool is_shared_cross_origin,
217  Handle<Context> context);
218 
219  // Finds the shared function info for a source string for eval in a
220  // given context. Returns an empty handle if the cache doesn't
221  // contain a script for the given source string.
223  Handle<Context> context,
224  StrictMode strict_mode,
225  int scope_position);
226 
227  // Returns the regexp data associated with the given regexp if it
228  // is in cache, otherwise an empty handle.
231 
232  // Associate the (source, kind) pair to the shared function
233  // info. This may overwrite an existing mapping.
234  void PutScript(Handle<String> source,
235  Handle<Context> context,
236  Handle<SharedFunctionInfo> function_info);
237 
238  // Associate the (source, context->closure()->shared(), kind) triple
239  // with the shared function info. This may overwrite an existing mapping.
240  void PutEval(Handle<String> source,
241  Handle<Context> context,
242  Handle<SharedFunctionInfo> function_info,
243  int scope_position);
244 
245  // Associate the (source, flags) pair to the given regexp data.
246  // This may overwrite an existing mapping.
247  void PutRegExp(Handle<String> source,
248  JSRegExp::Flags flags,
249  Handle<FixedArray> data);
250 
251  // Clear the cache - also used to initialize the cache at startup.
252  void Clear();
253 
254  // Remove given shared function info from all caches.
255  void Remove(Handle<SharedFunctionInfo> function_info);
256 
257  // GC support.
258  void Iterate(ObjectVisitor* v);
259  void IterateFunctions(ObjectVisitor* v);
260 
261  // Notify the cache that a mark-sweep garbage collection is about to
262  // take place. This is used to retire entries from the cache to
263  // avoid keeping them alive too long without using them.
264  void MarkCompactPrologue();
265 
266  // Enable/disable compilation cache. Used by debugger to disable compilation
267  // cache during debugging to make sure new scripts are always compiled.
268  void Enable();
269  void Disable();
270 
271  private:
272  explicit CompilationCache(Isolate* isolate);
273  ~CompilationCache();
274 
275  HashMap* EagerOptimizingSet();
276 
277  // The number of sub caches covering the different types to cache.
278  static const int kSubCacheCount = 4;
279 
280  bool IsEnabled() { return FLAG_compilation_cache && enabled_; }
281 
282  Isolate* isolate() { return isolate_; }
283 
284  Isolate* isolate_;
285 
286  CompilationCacheScript script_;
287  CompilationCacheEval eval_global_;
288  CompilationCacheEval eval_contextual_;
289  CompilationCacheRegExp reg_exp_;
290  CompilationSubCache* subcaches_[kSubCacheCount];
291 
292  // Current enable state of the compilation cache.
293  bool enabled_;
294 
295  friend class Isolate;
296 
298 };
299 
300 
301 } } // namespace v8::internal
302 
303 #endif // V8_COMPILATION_CACHE_H_
void Put(Handle< String > source, Handle< Context > context, Handle< SharedFunctionInfo > function_info, int scope_position)
void Put(Handle< String > source, Handle< Context > context, Handle< SharedFunctionInfo > function_info)
Handle< SharedFunctionInfo > LookupScript(Handle< String > source, Handle< Object > name, int line_offset, int column_offset, bool is_shared_cross_origin, Handle< Context > context)
Handle< FixedArray > LookupRegExp(Handle< String > source, JSRegExp::Flags flags)
Handle< SharedFunctionInfo > LookupEval(Handle< String > source, Handle< Context > context, StrictMode strict_mode, int scope_position)
#define ASSERT(condition)
Definition: checks.h:329
CompilationCacheEval(Isolate *isolate, int generations)
void SetFirstTable(Handle< CompilationCacheTable > value)
Handle< CompilationCacheTable > GetTable(int generation)
void PutScript(Handle< String > source, Handle< Context > context, Handle< SharedFunctionInfo > function_info)
Handle< SharedFunctionInfo > Lookup(Handle< String > source, Handle< Context > context, StrictMode strict_mode, int scope_position)
void PutEval(Handle< String > source, Handle< Context > context, Handle< SharedFunctionInfo > function_info, int scope_position)
#define MUST_USE_RESULT
Definition: globals.h:381
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 only print modified registers Don t break for ASM_UNIMPLEMENTED_BREAK macros print stack trace when an illegal exception is thrown randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot testing_bool_flag testing_int_flag string flag tmp file in which to serialize heap Print the time it takes to lazily compile hydrogen code stubs concurrent_recompilation concurrent_sweeping Print usage including flags
Definition: flags.cc:665
CompilationCacheRegExp(Isolate *isolate, int generations)
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:359
void Iterate(ObjectVisitor *v)
Handle< SharedFunctionInfo > Lookup(Handle< String > source, Handle< Object > name, int line_offset, int column_offset, bool is_shared_cross_origin, Handle< Context > context)
void PutRegExp(Handle< String > source, JSRegExp::Flags flags, Handle< FixedArray > data)
Handle< FixedArray > Lookup(Handle< String > source, JSRegExp::Flags flags)
CompilationSubCache(Isolate *isolate, int generations)
Handle< CompilationCacheTable > GetFirstTable()
void IterateFunctions(ObjectVisitor *v)
CompilationCacheScript(Isolate *isolate, int generations)
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 generation(in kBytes)") DEFINE_int(max_old_space_size
void Remove(Handle< SharedFunctionInfo > function_info)
void DeleteArray(T *array)
Definition: allocation.h:91
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
void Remove(Handle< SharedFunctionInfo > function_info)
void IterateFunctions(ObjectVisitor *v)
void Put(Handle< String > source, JSRegExp::Flags flags, Handle< FixedArray > data)