Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: src/compilation-cache.h

Issue 10990076: Short term JSON eval cache Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « AUTHORS ('k') | src/compilation-cache.cc » ('j') | src/v8.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 26 matching lines...) Expand all
37 // different compiled code for scripts and evals, we use separate sub-caches 37 // different compiled code for scripts and evals, we use separate sub-caches
38 // for different compilation modes, to avoid retrieving the wrong result. 38 // for different compilation modes, to avoid retrieving the wrong result.
39 class CompilationSubCache { 39 class CompilationSubCache {
40 public: 40 public:
41 CompilationSubCache(Isolate* isolate, int generations) 41 CompilationSubCache(Isolate* isolate, int generations)
42 : isolate_(isolate), 42 : isolate_(isolate),
43 generations_(generations) { 43 generations_(generations) {
44 tables_ = NewArray<Object*>(generations); 44 tables_ = NewArray<Object*>(generations);
45 } 45 }
46 46
47 ~CompilationSubCache() { DeleteArray(tables_); } 47 virtual ~CompilationSubCache() { DeleteArray(tables_); }
48 48
49 // Index for the first generation in the cache. 49 // Index for the first generation in the cache.
50 static const int kFirstGeneration = 0; 50 static const int kFirstGeneration = 0;
51 51
52 // Get the compilation cache tables for a specific generation. 52 // Get the compilation cache tables for a specific generation.
53 Handle<CompilationCacheTable> GetTable(int generation); 53 Handle<CompilationCacheTable> GetTable(int generation);
54 54
55 // Accessors for first generation. 55 // Accessors for first generation.
56 Handle<CompilationCacheTable> GetFirstTable() { 56 Handle<CompilationCacheTable> GetFirstTable() {
57 return GetTable(kFirstGeneration); 57 return GetTable(kFirstGeneration);
58 } 58 }
59 void SetFirstTable(Handle<CompilationCacheTable> value) { 59 void SetFirstTable(Handle<CompilationCacheTable> value) {
60 ASSERT(kFirstGeneration < generations_); 60 ASSERT(kFirstGeneration < generations_);
61 tables_[kFirstGeneration] = *value; 61 tables_[kFirstGeneration] = *value;
62 } 62 }
63 63
64 // Age the sub-cache by evicting the oldest generation and creating a new 64 // Age the sub-cache by evicting the oldest generation and creating a new
65 // young generation. 65 // young generation.
66 void Age(); 66 void Age();
67 67
68 // GC support. 68 // GC support.
69 void Iterate(ObjectVisitor* v); 69 virtual void Iterate(ObjectVisitor* v);
70 void IterateFunctions(ObjectVisitor* v); 70 virtual void IterateFunctions(ObjectVisitor* v);
71 71
72 // Clear this sub-cache evicting all its content. 72 // Clear this sub-cache evicting all its content.
73 void Clear(); 73 virtual void Clear();
74 // Clear out any short term elements. Returns true if the cache is
75 // already cleared.
76 virtual bool ClearShortTerm() { return true; }
74 77
75 // Remove given shared function info from sub-cache. 78 // Remove given shared function info from sub-cache.
76 void Remove(Handle<SharedFunctionInfo> function_info); 79 virtual void Remove(Handle<SharedFunctionInfo> function_info);
77 80
78 // Number of generations in this sub-cache. 81 // Number of generations in this sub-cache.
79 inline int generations() { return generations_; } 82 inline int generations() { return generations_; }
80 83
81 protected: 84 protected:
82 Isolate* isolate() { return isolate_; } 85 Isolate* isolate() { return isolate_; }
83 86
84 private: 87 private:
85 Isolate* isolate_; 88 Isolate* isolate_;
86 int generations_; // Number of generations. 89 int generations_; // Number of generations.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // 3. Whether the source should be compiled as strict code or as non-strict 140 // 3. Whether the source should be compiled as strict code or as non-strict
138 // code. 141 // code.
139 // Note: Currently there are clients of CompileEval that always compile 142 // Note: Currently there are clients of CompileEval that always compile
140 // non-strict code even if the calling function is a strict mode function. 143 // non-strict code even if the calling function is a strict mode function.
141 // More specifically these are the CompileString, DebugEvaluate and 144 // More specifically these are the CompileString, DebugEvaluate and
142 // DebugEvaluateGlobal runtime functions. 145 // DebugEvaluateGlobal runtime functions.
143 // 4. The start position of the calling scope. 146 // 4. The start position of the calling scope.
144 class CompilationCacheEval: public CompilationSubCache { 147 class CompilationCacheEval: public CompilationSubCache {
145 public: 148 public:
146 CompilationCacheEval(Isolate* isolate, int generations) 149 CompilationCacheEval(Isolate* isolate, int generations)
147 : CompilationSubCache(isolate, generations) { } 150 : CompilationSubCache(isolate, generations),
151 json_table_(NULL) { }
148 152
149 Handle<SharedFunctionInfo> Lookup(Handle<String> source, 153 Handle<SharedFunctionInfo> Lookup(Handle<String> source,
150 Handle<Context> context, 154 Handle<Context> context,
151 LanguageMode language_mode, 155 LanguageMode language_mode,
152 int scope_position); 156 int scope_position);
153 157
154 void Put(Handle<String> source, 158 void Put(Handle<String> source,
155 Handle<Context> context, 159 Handle<Context> context,
156 Handle<SharedFunctionInfo> function_info, 160 Handle<SharedFunctionInfo> function_info,
157 int scope_position); 161 int scope_position);
158 162
163 virtual void Iterate(ObjectVisitor* v);
164 virtual void IterateFunctions(ObjectVisitor* v);
165 virtual void Clear();
166 virtual bool ClearShortTerm();
167 virtual void Remove(Handle<SharedFunctionInfo> function_info);
168
169 void GetShortTermStatistics(int* entry_count,
170 int* max_entries,
171 int* total_size,
172 int* max_total_size);
173
159 private: 174 private:
160 MUST_USE_RESULT MaybeObject* TryTablePut( 175 MUST_USE_RESULT MaybeObject* TryTablePut(
161 Handle<String> source, 176 Handle<String> source,
162 Handle<Context> context, 177 Handle<Context> context,
163 Handle<SharedFunctionInfo> function_info, 178 Handle<SharedFunctionInfo> function_info,
164 int scope_position); 179 int scope_position);
165 180
166 // Note: Returns a new hash table if operation results in expansion. 181 // Note: Returns a new hash table if operation results in expansion.
167 Handle<CompilationCacheTable> TablePut( 182 void TablePut(
168 Handle<String> source, 183 Handle<String> source,
169 Handle<Context> context, 184 Handle<Context> context,
170 Handle<SharedFunctionInfo> function_info, 185 Handle<SharedFunctionInfo> function_info,
171 int scope_position); 186 int scope_position);
172 187
188 Object* json_table_;
189
173 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); 190 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval);
174 }; 191 };
175 192
176 193
177 // Sub-cache for regular expressions. 194 // Sub-cache for regular expressions.
178 class CompilationCacheRegExp: public CompilationSubCache { 195 class CompilationCacheRegExp: public CompilationSubCache {
179 public: 196 public:
180 CompilationCacheRegExp(Isolate* isolate, int generations) 197 CompilationCacheRegExp(Isolate* isolate, int generations)
181 : CompilationSubCache(isolate, generations) { } 198 : CompilationSubCache(isolate, generations) { }
182 199
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 Handle<SharedFunctionInfo> function_info, 259 Handle<SharedFunctionInfo> function_info,
243 int scope_position); 260 int scope_position);
244 261
245 // Associate the (source, flags) pair to the given regexp data. 262 // Associate the (source, flags) pair to the given regexp data.
246 // This may overwrite an existing mapping. 263 // This may overwrite an existing mapping.
247 void PutRegExp(Handle<String> source, 264 void PutRegExp(Handle<String> source,
248 JSRegExp::Flags flags, 265 JSRegExp::Flags flags,
249 Handle<FixedArray> data); 266 Handle<FixedArray> data);
250 267
251 // Clear the cache - also used to initialize the cache at startup. 268 // Clear the cache - also used to initialize the cache at startup.
252 void Clear(); 269 virtual void Clear();
270 // Clear any short term elements. Returns true if the cache is already clear.
271 virtual bool ClearShortTerm();
253 272
254 // Remove given shared function info from all caches. 273 // Remove given shared function info from all caches.
255 void Remove(Handle<SharedFunctionInfo> function_info); 274 void Remove(Handle<SharedFunctionInfo> function_info);
256 275
257 // GC support. 276 // GC support.
258 void Iterate(ObjectVisitor* v); 277 void Iterate(ObjectVisitor* v);
259 void IterateFunctions(ObjectVisitor* v); 278 void IterateFunctions(ObjectVisitor* v);
260 279
261 // Notify the cache that a mark-sweep garbage collection is about to 280 // 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 281 // take place. This is used to retire entries from the cache to
263 // avoid keeping them alive too long without using them. 282 // avoid keeping them alive too long without using them.
264 void MarkCompactPrologue(); 283 void MarkCompactPrologue();
265 284
266 // Enable/disable compilation cache. Used by debugger to disable compilation 285 // Enable/disable compilation cache. Used by debugger to disable compilation
267 // cache during debugging to make sure new scripts are always compiled. 286 // cache during debugging to make sure new scripts are always compiled.
268 void Enable(); 287 void Enable();
269 void Disable(); 288 void Disable();
270 289
290 void GetShortTermEvalStatistics(int* entry_count,
291 int* max_entries,
292 int* total_size,
293 int* max_total_size);
294
271 private: 295 private:
272 explicit CompilationCache(Isolate* isolate); 296 explicit CompilationCache(Isolate* isolate);
273 ~CompilationCache(); 297 virtual ~CompilationCache();
274 298
275 HashMap* EagerOptimizingSet(); 299 HashMap* EagerOptimizingSet();
276 300
277 // The number of sub caches covering the different types to cache. 301 // The number of sub caches covering the different types to cache.
278 static const int kSubCacheCount = 4; 302 static const int kSubCacheCount = 4;
279 303
280 bool IsEnabled() { return FLAG_compilation_cache && enabled_; } 304 bool IsEnabled() { return FLAG_compilation_cache && enabled_; }
281 305
282 Isolate* isolate() { return isolate_; } 306 Isolate* isolate() { return isolate_; }
283 307
(...skipping 10 matching lines...) Expand all
294 318
295 friend class Isolate; 319 friend class Isolate;
296 320
297 DISALLOW_COPY_AND_ASSIGN(CompilationCache); 321 DISALLOW_COPY_AND_ASSIGN(CompilationCache);
298 }; 322 };
299 323
300 324
301 } } // namespace v8::internal 325 } } // namespace v8::internal
302 326
303 #endif // V8_COMPILATION_CACHE_H_ 327 #endif // V8_COMPILATION_CACHE_H_
OLDNEW
« no previous file with comments | « AUTHORS ('k') | src/compilation-cache.cc » ('j') | src/v8.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698