blob: b0449c47f4e65ad74e2e6fa62c3ecd70a062946c [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 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#include "v8.h"
29
30#include "compilation-cache.h"
Andrei Popescu31002712010-02-23 13:46:05 +000031#include "serialize.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000032
33namespace v8 {
34namespace internal {
35
Steve Blocka7e24c12009-10-30 11:49:00 +000036// The number of sub caches covering the different types to cache.
37static const int kSubCacheCount = 4;
38
39// The number of generations for each sub cache.
Steve Block3ce2e202009-11-05 08:53:23 +000040// The number of ScriptGenerations is carefully chosen based on histograms.
41// See issue 458: http://code.google.com/p/v8/issues/detail?id=458
Steve Blocka7e24c12009-10-30 11:49:00 +000042static const int kScriptGenerations = 5;
43static const int kEvalGlobalGenerations = 2;
44static const int kEvalContextualGenerations = 2;
45static const int kRegExpGenerations = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +000046
Steve Block3ce2e202009-11-05 08:53:23 +000047// Initial size of each compilation cache table allocated.
Steve Blocka7e24c12009-10-30 11:49:00 +000048static const int kInitialCacheSize = 64;
49
Steve Block6ded16b2010-05-10 14:33:55 +010050// Index for the first generation in the cache.
51static const int kFirstGeneration = 0;
52
Steve Blocka7e24c12009-10-30 11:49:00 +000053// The compilation cache consists of several generational sub-caches which uses
54// this class as a base class. A sub-cache contains a compilation cache tables
Steve Block3ce2e202009-11-05 08:53:23 +000055// for each generation of the sub-cache. Since the same source code string has
56// different compiled code for scripts and evals, we use separate sub-caches
57// for different compilation modes, to avoid retrieving the wrong result.
Steve Blocka7e24c12009-10-30 11:49:00 +000058class CompilationSubCache {
59 public:
60 explicit CompilationSubCache(int generations): generations_(generations) {
61 tables_ = NewArray<Object*>(generations);
62 }
63
64 ~CompilationSubCache() { DeleteArray(tables_); }
65
66 // Get the compilation cache tables for a specific generation.
67 Handle<CompilationCacheTable> GetTable(int generation);
68
Steve Block6ded16b2010-05-10 14:33:55 +010069 // Accessors for first generation.
70 Handle<CompilationCacheTable> GetFirstTable() {
71 return GetTable(kFirstGeneration);
72 }
73 void SetFirstTable(Handle<CompilationCacheTable> value) {
74 ASSERT(kFirstGeneration < generations_);
75 tables_[kFirstGeneration] = *value;
76 }
77
Steve Blocka7e24c12009-10-30 11:49:00 +000078 // Age the sub-cache by evicting the oldest generation and creating a new
79 // young generation.
80 void Age();
81
82 // GC support.
83 void Iterate(ObjectVisitor* v);
Iain Merrick75681382010-08-19 15:07:18 +010084 void IterateFunctions(ObjectVisitor* v);
Steve Blocka7e24c12009-10-30 11:49:00 +000085
86 // Clear this sub-cache evicting all its content.
87 void Clear();
88
89 // Number of generations in this sub-cache.
90 inline int generations() { return generations_; }
91
92 private:
93 int generations_; // Number of generations.
94 Object** tables_; // Compilation cache tables - one for each generation.
95
96 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache);
97};
98
99
100// Sub-cache for scripts.
101class CompilationCacheScript : public CompilationSubCache {
102 public:
103 explicit CompilationCacheScript(int generations)
104 : CompilationSubCache(generations) { }
105
Steve Block6ded16b2010-05-10 14:33:55 +0100106 Handle<SharedFunctionInfo> Lookup(Handle<String> source,
107 Handle<Object> name,
108 int line_offset,
109 int column_offset);
110 void Put(Handle<String> source, Handle<SharedFunctionInfo> function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000111
112 private:
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100113 MUST_USE_RESULT Object* TryTablePut(
114 Handle<String> source, Handle<SharedFunctionInfo> function_info);
115
Steve Block6ded16b2010-05-10 14:33:55 +0100116 // Note: Returns a new hash table if operation results in expansion.
117 Handle<CompilationCacheTable> TablePut(
118 Handle<String> source, Handle<SharedFunctionInfo> function_info);
119
120 bool HasOrigin(Handle<SharedFunctionInfo> function_info,
Steve Blocka7e24c12009-10-30 11:49:00 +0000121 Handle<Object> name,
122 int line_offset,
123 int column_offset);
124
125 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript);
126};
127
128
129// Sub-cache for eval scripts.
130class CompilationCacheEval: public CompilationSubCache {
131 public:
132 explicit CompilationCacheEval(int generations)
133 : CompilationSubCache(generations) { }
134
Steve Block6ded16b2010-05-10 14:33:55 +0100135 Handle<SharedFunctionInfo> Lookup(Handle<String> source,
136 Handle<Context> context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000137
138 void Put(Handle<String> source,
139 Handle<Context> context,
Steve Block6ded16b2010-05-10 14:33:55 +0100140 Handle<SharedFunctionInfo> function_info);
141
142 private:
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100143 MUST_USE_RESULT Object* TryTablePut(
144 Handle<String> source,
145 Handle<Context> context,
146 Handle<SharedFunctionInfo> function_info);
147
148
Steve Block6ded16b2010-05-10 14:33:55 +0100149 // Note: Returns a new hash table if operation results in expansion.
150 Handle<CompilationCacheTable> TablePut(
151 Handle<String> source,
152 Handle<Context> context,
153 Handle<SharedFunctionInfo> function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000154
155 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval);
156};
157
158
159// Sub-cache for regular expressions.
160class CompilationCacheRegExp: public CompilationSubCache {
161 public:
162 explicit CompilationCacheRegExp(int generations)
163 : CompilationSubCache(generations) { }
164
165 Handle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags);
166
167 void Put(Handle<String> source,
168 JSRegExp::Flags flags,
169 Handle<FixedArray> data);
Steve Block6ded16b2010-05-10 14:33:55 +0100170 private:
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100171 MUST_USE_RESULT Object* TryTablePut(Handle<String> source,
172 JSRegExp::Flags flags,
173 Handle<FixedArray> data);
174
Steve Block6ded16b2010-05-10 14:33:55 +0100175 // Note: Returns a new hash table if operation results in expansion.
176 Handle<CompilationCacheTable> TablePut(Handle<String> source,
177 JSRegExp::Flags flags,
178 Handle<FixedArray> data);
Steve Blocka7e24c12009-10-30 11:49:00 +0000179
180 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp);
181};
182
183
184// Statically allocate all the sub-caches.
185static CompilationCacheScript script(kScriptGenerations);
186static CompilationCacheEval eval_global(kEvalGlobalGenerations);
187static CompilationCacheEval eval_contextual(kEvalContextualGenerations);
188static CompilationCacheRegExp reg_exp(kRegExpGenerations);
189static CompilationSubCache* subcaches[kSubCacheCount] =
190 {&script, &eval_global, &eval_contextual, &reg_exp};
191
192
193// Current enable state of the compilation cache.
194static bool enabled = true;
195static inline bool IsEnabled() {
196 return FLAG_compilation_cache && enabled;
197}
198
199
200static Handle<CompilationCacheTable> AllocateTable(int size) {
201 CALL_HEAP_FUNCTION(CompilationCacheTable::Allocate(size),
202 CompilationCacheTable);
203}
204
205
206Handle<CompilationCacheTable> CompilationSubCache::GetTable(int generation) {
207 ASSERT(generation < generations_);
208 Handle<CompilationCacheTable> result;
209 if (tables_[generation]->IsUndefined()) {
210 result = AllocateTable(kInitialCacheSize);
211 tables_[generation] = *result;
212 } else {
213 CompilationCacheTable* table =
214 CompilationCacheTable::cast(tables_[generation]);
215 result = Handle<CompilationCacheTable>(table);
216 }
217 return result;
218}
219
220
221void CompilationSubCache::Age() {
222 // Age the generations implicitly killing off the oldest.
223 for (int i = generations_ - 1; i > 0; i--) {
224 tables_[i] = tables_[i - 1];
225 }
226
227 // Set the first generation as unborn.
228 tables_[0] = Heap::undefined_value();
229}
230
231
Iain Merrick75681382010-08-19 15:07:18 +0100232void CompilationSubCache::IterateFunctions(ObjectVisitor* v) {
233 Object* undefined = Heap::raw_unchecked_undefined_value();
234 for (int i = 0; i < generations_; i++) {
235 if (tables_[i] != undefined) {
236 reinterpret_cast<CompilationCacheTable*>(tables_[i])->IterateElements(v);
237 }
238 }
239}
240
241
Steve Blocka7e24c12009-10-30 11:49:00 +0000242void CompilationSubCache::Iterate(ObjectVisitor* v) {
243 v->VisitPointers(&tables_[0], &tables_[generations_]);
244}
245
246
247void CompilationSubCache::Clear() {
Steve Block6ded16b2010-05-10 14:33:55 +0100248 MemsetPointer(tables_, Heap::undefined_value(), generations_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000249}
250
251
252// We only re-use a cached function for some script source code if the
253// script originates from the same place. This is to avoid issues
254// when reporting errors, etc.
Steve Block6ded16b2010-05-10 14:33:55 +0100255bool CompilationCacheScript::HasOrigin(
256 Handle<SharedFunctionInfo> function_info,
257 Handle<Object> name,
258 int line_offset,
259 int column_offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000260 Handle<Script> script =
Steve Block6ded16b2010-05-10 14:33:55 +0100261 Handle<Script>(Script::cast(function_info->script()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000262 // If the script name isn't set, the boilerplate script should have
263 // an undefined name to have the same origin.
264 if (name.is_null()) {
265 return script->name()->IsUndefined();
266 }
267 // Do the fast bailout checks first.
268 if (line_offset != script->line_offset()->value()) return false;
269 if (column_offset != script->column_offset()->value()) return false;
270 // Check that both names are strings. If not, no match.
271 if (!name->IsString() || !script->name()->IsString()) return false;
272 // Compare the two name strings for equality.
273 return String::cast(*name)->Equals(String::cast(script->name()));
274}
275
276
277// TODO(245): Need to allow identical code from different contexts to
278// be cached in the same script generation. Currently the first use
279// will be cached, but subsequent code from different source / line
280// won't.
Steve Block6ded16b2010-05-10 14:33:55 +0100281Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source,
282 Handle<Object> name,
283 int line_offset,
284 int column_offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000285 Object* result = NULL;
286 int generation;
287
288 // Probe the script generation tables. Make sure not to leak handles
289 // into the caller's handle scope.
290 { HandleScope scope;
291 for (generation = 0; generation < generations(); generation++) {
292 Handle<CompilationCacheTable> table = GetTable(generation);
293 Handle<Object> probe(table->Lookup(*source));
Steve Block6ded16b2010-05-10 14:33:55 +0100294 if (probe->IsSharedFunctionInfo()) {
295 Handle<SharedFunctionInfo> function_info =
296 Handle<SharedFunctionInfo>::cast(probe);
297 // Break when we've found a suitable shared function info that
Steve Blocka7e24c12009-10-30 11:49:00 +0000298 // matches the origin.
Steve Block6ded16b2010-05-10 14:33:55 +0100299 if (HasOrigin(function_info, name, line_offset, column_offset)) {
300 result = *function_info;
Steve Blocka7e24c12009-10-30 11:49:00 +0000301 break;
302 }
303 }
304 }
305 }
306
307 static void* script_histogram = StatsTable::CreateHistogram(
308 "V8.ScriptCache",
309 0,
310 kScriptGenerations,
311 kScriptGenerations + 1);
312
313 if (script_histogram != NULL) {
314 // The level NUMBER_OF_SCRIPT_GENERATIONS is equivalent to a cache miss.
315 StatsTable::AddHistogramSample(script_histogram, generation);
316 }
317
318 // Once outside the manacles of the handle scope, we need to recheck
319 // to see if we actually found a cached script. If so, we return a
320 // handle created in the caller's handle scope.
321 if (result != NULL) {
Steve Block6ded16b2010-05-10 14:33:55 +0100322 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result));
323 ASSERT(HasOrigin(shared, name, line_offset, column_offset));
Steve Blocka7e24c12009-10-30 11:49:00 +0000324 // If the script was found in a later generation, we promote it to
325 // the first generation to let it survive longer in the cache.
Steve Block6ded16b2010-05-10 14:33:55 +0100326 if (generation != 0) Put(source, shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000327 Counters::compilation_cache_hits.Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100328 return shared;
Steve Blocka7e24c12009-10-30 11:49:00 +0000329 } else {
330 Counters::compilation_cache_misses.Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100331 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000332 }
333}
334
335
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100336Object* CompilationCacheScript::TryTablePut(
337 Handle<String> source,
338 Handle<SharedFunctionInfo> function_info) {
339 Handle<CompilationCacheTable> table = GetFirstTable();
340 return table->Put(*source, *function_info);
341}
342
343
Steve Block6ded16b2010-05-10 14:33:55 +0100344Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
345 Handle<String> source,
346 Handle<SharedFunctionInfo> function_info) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100347 CALL_HEAP_FUNCTION(TryTablePut(source, function_info), CompilationCacheTable);
Steve Blocka7e24c12009-10-30 11:49:00 +0000348}
349
350
Steve Block6ded16b2010-05-10 14:33:55 +0100351void CompilationCacheScript::Put(Handle<String> source,
352 Handle<SharedFunctionInfo> function_info) {
353 HandleScope scope;
354 SetFirstTable(TablePut(source, function_info));
355}
356
357
358Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
359 Handle<String> source, Handle<Context> context) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000360 // Make sure not to leak the table into the surrounding handle
361 // scope. Otherwise, we risk keeping old tables around even after
362 // having cleared the cache.
363 Object* result = NULL;
364 int generation;
365 { HandleScope scope;
366 for (generation = 0; generation < generations(); generation++) {
367 Handle<CompilationCacheTable> table = GetTable(generation);
368 result = table->LookupEval(*source, *context);
Steve Block6ded16b2010-05-10 14:33:55 +0100369 if (result->IsSharedFunctionInfo()) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000370 break;
371 }
372 }
373 }
Steve Block6ded16b2010-05-10 14:33:55 +0100374 if (result->IsSharedFunctionInfo()) {
375 Handle<SharedFunctionInfo>
376 function_info(SharedFunctionInfo::cast(result));
Steve Blocka7e24c12009-10-30 11:49:00 +0000377 if (generation != 0) {
Steve Block6ded16b2010-05-10 14:33:55 +0100378 Put(source, context, function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000379 }
380 Counters::compilation_cache_hits.Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100381 return function_info;
Steve Blocka7e24c12009-10-30 11:49:00 +0000382 } else {
383 Counters::compilation_cache_misses.Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100384 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000385 }
386}
387
388
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100389Object* CompilationCacheEval::TryTablePut(
390 Handle<String> source,
391 Handle<Context> context,
392 Handle<SharedFunctionInfo> function_info) {
393 Handle<CompilationCacheTable> table = GetFirstTable();
394 return table->PutEval(*source, *context, *function_info);
395}
396
397
Steve Block6ded16b2010-05-10 14:33:55 +0100398Handle<CompilationCacheTable> CompilationCacheEval::TablePut(
399 Handle<String> source,
400 Handle<Context> context,
401 Handle<SharedFunctionInfo> function_info) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100402 CALL_HEAP_FUNCTION(TryTablePut(source, context, function_info),
Steve Block6ded16b2010-05-10 14:33:55 +0100403 CompilationCacheTable);
404}
405
406
Steve Blocka7e24c12009-10-30 11:49:00 +0000407void CompilationCacheEval::Put(Handle<String> source,
408 Handle<Context> context,
Steve Block6ded16b2010-05-10 14:33:55 +0100409 Handle<SharedFunctionInfo> function_info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000410 HandleScope scope;
Steve Block6ded16b2010-05-10 14:33:55 +0100411 SetFirstTable(TablePut(source, context, function_info));
Steve Blocka7e24c12009-10-30 11:49:00 +0000412}
413
414
415Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
416 JSRegExp::Flags flags) {
417 // Make sure not to leak the table into the surrounding handle
418 // scope. Otherwise, we risk keeping old tables around even after
419 // having cleared the cache.
420 Object* result = NULL;
421 int generation;
422 { HandleScope scope;
423 for (generation = 0; generation < generations(); generation++) {
424 Handle<CompilationCacheTable> table = GetTable(generation);
425 result = table->LookupRegExp(*source, flags);
426 if (result->IsFixedArray()) {
427 break;
428 }
429 }
430 }
431 if (result->IsFixedArray()) {
432 Handle<FixedArray> data(FixedArray::cast(result));
433 if (generation != 0) {
434 Put(source, flags, data);
435 }
436 Counters::compilation_cache_hits.Increment();
437 return data;
438 } else {
439 Counters::compilation_cache_misses.Increment();
440 return Handle<FixedArray>::null();
441 }
442}
443
444
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100445Object* CompilationCacheRegExp::TryTablePut(
446 Handle<String> source,
447 JSRegExp::Flags flags,
448 Handle<FixedArray> data) {
449 Handle<CompilationCacheTable> table = GetFirstTable();
450 return table->PutRegExp(*source, flags, *data);
451}
452
453
Steve Block6ded16b2010-05-10 14:33:55 +0100454Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut(
455 Handle<String> source,
456 JSRegExp::Flags flags,
457 Handle<FixedArray> data) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100458 CALL_HEAP_FUNCTION(TryTablePut(source, flags, data), CompilationCacheTable);
Steve Block6ded16b2010-05-10 14:33:55 +0100459}
460
461
Steve Blocka7e24c12009-10-30 11:49:00 +0000462void CompilationCacheRegExp::Put(Handle<String> source,
463 JSRegExp::Flags flags,
464 Handle<FixedArray> data) {
465 HandleScope scope;
Steve Block6ded16b2010-05-10 14:33:55 +0100466 SetFirstTable(TablePut(source, flags, data));
Steve Blocka7e24c12009-10-30 11:49:00 +0000467}
468
469
Steve Block6ded16b2010-05-10 14:33:55 +0100470Handle<SharedFunctionInfo> CompilationCache::LookupScript(Handle<String> source,
471 Handle<Object> name,
472 int line_offset,
473 int column_offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000474 if (!IsEnabled()) {
Steve Block6ded16b2010-05-10 14:33:55 +0100475 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000476 }
477
478 return script.Lookup(source, name, line_offset, column_offset);
479}
480
481
Steve Block6ded16b2010-05-10 14:33:55 +0100482Handle<SharedFunctionInfo> CompilationCache::LookupEval(Handle<String> source,
483 Handle<Context> context,
484 bool is_global) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000485 if (!IsEnabled()) {
Steve Block6ded16b2010-05-10 14:33:55 +0100486 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000487 }
488
Steve Block6ded16b2010-05-10 14:33:55 +0100489 Handle<SharedFunctionInfo> result;
Steve Blocka7e24c12009-10-30 11:49:00 +0000490 if (is_global) {
491 result = eval_global.Lookup(source, context);
492 } else {
493 result = eval_contextual.Lookup(source, context);
494 }
495 return result;
496}
497
498
499Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source,
500 JSRegExp::Flags flags) {
501 if (!IsEnabled()) {
502 return Handle<FixedArray>::null();
503 }
504
505 return reg_exp.Lookup(source, flags);
506}
507
508
509void CompilationCache::PutScript(Handle<String> source,
Steve Block6ded16b2010-05-10 14:33:55 +0100510 Handle<SharedFunctionInfo> function_info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000511 if (!IsEnabled()) {
512 return;
513 }
514
Steve Block6ded16b2010-05-10 14:33:55 +0100515 script.Put(source, function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000516}
517
518
519void CompilationCache::PutEval(Handle<String> source,
520 Handle<Context> context,
521 bool is_global,
Steve Block6ded16b2010-05-10 14:33:55 +0100522 Handle<SharedFunctionInfo> function_info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000523 if (!IsEnabled()) {
524 return;
525 }
526
527 HandleScope scope;
Steve Blocka7e24c12009-10-30 11:49:00 +0000528 if (is_global) {
Steve Block6ded16b2010-05-10 14:33:55 +0100529 eval_global.Put(source, context, function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000530 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100531 eval_contextual.Put(source, context, function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000532 }
533}
534
535
536
537void CompilationCache::PutRegExp(Handle<String> source,
538 JSRegExp::Flags flags,
539 Handle<FixedArray> data) {
540 if (!IsEnabled()) {
541 return;
542 }
543
544 reg_exp.Put(source, flags, data);
545}
546
547
548void CompilationCache::Clear() {
549 for (int i = 0; i < kSubCacheCount; i++) {
550 subcaches[i]->Clear();
551 }
552}
553
Steve Blocka7e24c12009-10-30 11:49:00 +0000554void CompilationCache::Iterate(ObjectVisitor* v) {
555 for (int i = 0; i < kSubCacheCount; i++) {
556 subcaches[i]->Iterate(v);
557 }
558}
559
560
Iain Merrick75681382010-08-19 15:07:18 +0100561void CompilationCache::IterateFunctions(ObjectVisitor* v) {
562 for (int i = 0; i < kSubCacheCount; i++) {
563 subcaches[i]->IterateFunctions(v);
564 }
565}
566
567
Steve Blocka7e24c12009-10-30 11:49:00 +0000568void CompilationCache::MarkCompactPrologue() {
569 for (int i = 0; i < kSubCacheCount; i++) {
570 subcaches[i]->Age();
571 }
572}
573
574
575void CompilationCache::Enable() {
576 enabled = true;
577}
578
579
580void CompilationCache::Disable() {
581 enabled = false;
582 Clear();
583}
584
585
586} } // namespace v8::internal