blob: 28e833a4933e1457a5f08ac8132338aef82c7938 [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
37// The number of generations for each sub cache.
Steve Block3ce2e202009-11-05 08:53:23 +000038// The number of ScriptGenerations is carefully chosen based on histograms.
39// See issue 458: http://code.google.com/p/v8/issues/detail?id=458
Steve Blocka7e24c12009-10-30 11:49:00 +000040static const int kScriptGenerations = 5;
41static const int kEvalGlobalGenerations = 2;
42static const int kEvalContextualGenerations = 2;
43static const int kRegExpGenerations = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +000044
Steve Block3ce2e202009-11-05 08:53:23 +000045// Initial size of each compilation cache table allocated.
Steve Blocka7e24c12009-10-30 11:49:00 +000046static const int kInitialCacheSize = 64;
47
Steve Block6ded16b2010-05-10 14:33:55 +010048
Steve Block44f0eee2011-05-26 01:26:41 +010049CompilationCache::CompilationCache(Isolate* isolate)
50 : isolate_(isolate),
51 script_(isolate, kScriptGenerations),
52 eval_global_(isolate, kEvalGlobalGenerations),
53 eval_contextual_(isolate, kEvalContextualGenerations),
54 reg_exp_(isolate, kRegExpGenerations),
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000055 enabled_(true) {
Steve Block44f0eee2011-05-26 01:26:41 +010056 CompilationSubCache* subcaches[kSubCacheCount] =
57 {&script_, &eval_global_, &eval_contextual_, &reg_exp_};
58 for (int i = 0; i < kSubCacheCount; ++i) {
59 subcaches_[i] = subcaches[i];
Steve Blocka7e24c12009-10-30 11:49:00 +000060 }
Steve Blocka7e24c12009-10-30 11:49:00 +000061}
62
63
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000064CompilationCache::~CompilationCache() {}
Steve Block44f0eee2011-05-26 01:26:41 +010065
66
67static Handle<CompilationCacheTable> AllocateTable(Isolate* isolate, int size) {
68 CALL_HEAP_FUNCTION(isolate,
69 CompilationCacheTable::Allocate(size),
Steve Blocka7e24c12009-10-30 11:49:00 +000070 CompilationCacheTable);
71}
72
73
74Handle<CompilationCacheTable> CompilationSubCache::GetTable(int generation) {
75 ASSERT(generation < generations_);
76 Handle<CompilationCacheTable> result;
77 if (tables_[generation]->IsUndefined()) {
Steve Block44f0eee2011-05-26 01:26:41 +010078 result = AllocateTable(isolate(), kInitialCacheSize);
Steve Blocka7e24c12009-10-30 11:49:00 +000079 tables_[generation] = *result;
80 } else {
81 CompilationCacheTable* table =
82 CompilationCacheTable::cast(tables_[generation]);
Steve Block44f0eee2011-05-26 01:26:41 +010083 result = Handle<CompilationCacheTable>(table, isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +000084 }
85 return result;
86}
87
Steve Blocka7e24c12009-10-30 11:49:00 +000088void CompilationSubCache::Age() {
89 // Age the generations implicitly killing off the oldest.
90 for (int i = generations_ - 1; i > 0; i--) {
91 tables_[i] = tables_[i - 1];
92 }
93
94 // Set the first generation as unborn.
Steve Block44f0eee2011-05-26 01:26:41 +010095 tables_[0] = isolate()->heap()->undefined_value();
Steve Blocka7e24c12009-10-30 11:49:00 +000096}
97
98
Iain Merrick75681382010-08-19 15:07:18 +010099void CompilationSubCache::IterateFunctions(ObjectVisitor* v) {
Steve Block44f0eee2011-05-26 01:26:41 +0100100 Object* undefined = isolate()->heap()->raw_unchecked_undefined_value();
Iain Merrick75681382010-08-19 15:07:18 +0100101 for (int i = 0; i < generations_; i++) {
102 if (tables_[i] != undefined) {
103 reinterpret_cast<CompilationCacheTable*>(tables_[i])->IterateElements(v);
104 }
105 }
106}
107
108
Steve Blocka7e24c12009-10-30 11:49:00 +0000109void CompilationSubCache::Iterate(ObjectVisitor* v) {
110 v->VisitPointers(&tables_[0], &tables_[generations_]);
111}
112
113
114void CompilationSubCache::Clear() {
Steve Block44f0eee2011-05-26 01:26:41 +0100115 MemsetPointer(tables_, isolate()->heap()->undefined_value(), generations_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000116}
117
118
Ben Murdochb0fe1622011-05-05 13:52:32 +0100119void CompilationSubCache::Remove(Handle<SharedFunctionInfo> function_info) {
120 // Probe the script generation tables. Make sure not to leak handles
121 // into the caller's handle scope.
Steve Block44f0eee2011-05-26 01:26:41 +0100122 { HandleScope scope(isolate());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100123 for (int generation = 0; generation < generations(); generation++) {
124 Handle<CompilationCacheTable> table = GetTable(generation);
125 table->Remove(*function_info);
126 }
127 }
128}
129
130
Steve Block44f0eee2011-05-26 01:26:41 +0100131CompilationCacheScript::CompilationCacheScript(Isolate* isolate,
132 int generations)
133 : CompilationSubCache(isolate, generations),
134 script_histogram_(NULL),
135 script_histogram_initialized_(false) { }
136
137
Steve Blocka7e24c12009-10-30 11:49:00 +0000138// We only re-use a cached function for some script source code if the
139// script originates from the same place. This is to avoid issues
140// when reporting errors, etc.
Steve Block6ded16b2010-05-10 14:33:55 +0100141bool CompilationCacheScript::HasOrigin(
142 Handle<SharedFunctionInfo> function_info,
143 Handle<Object> name,
144 int line_offset,
145 int column_offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000146 Handle<Script> script =
Steve Block44f0eee2011-05-26 01:26:41 +0100147 Handle<Script>(Script::cast(function_info->script()), isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000148 // If the script name isn't set, the boilerplate script should have
149 // an undefined name to have the same origin.
150 if (name.is_null()) {
151 return script->name()->IsUndefined();
152 }
153 // Do the fast bailout checks first.
154 if (line_offset != script->line_offset()->value()) return false;
155 if (column_offset != script->column_offset()->value()) return false;
156 // Check that both names are strings. If not, no match.
157 if (!name->IsString() || !script->name()->IsString()) return false;
158 // Compare the two name strings for equality.
159 return String::cast(*name)->Equals(String::cast(script->name()));
160}
161
162
163// TODO(245): Need to allow identical code from different contexts to
164// be cached in the same script generation. Currently the first use
165// will be cached, but subsequent code from different source / line
166// won't.
Steve Block6ded16b2010-05-10 14:33:55 +0100167Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source,
168 Handle<Object> name,
169 int line_offset,
170 int column_offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000171 Object* result = NULL;
172 int generation;
173
174 // Probe the script generation tables. Make sure not to leak handles
175 // into the caller's handle scope.
Steve Block44f0eee2011-05-26 01:26:41 +0100176 { HandleScope scope(isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000177 for (generation = 0; generation < generations(); generation++) {
178 Handle<CompilationCacheTable> table = GetTable(generation);
Steve Block44f0eee2011-05-26 01:26:41 +0100179 Handle<Object> probe(table->Lookup(*source), isolate());
Steve Block6ded16b2010-05-10 14:33:55 +0100180 if (probe->IsSharedFunctionInfo()) {
181 Handle<SharedFunctionInfo> function_info =
182 Handle<SharedFunctionInfo>::cast(probe);
183 // Break when we've found a suitable shared function info that
Steve Blocka7e24c12009-10-30 11:49:00 +0000184 // matches the origin.
Steve Block6ded16b2010-05-10 14:33:55 +0100185 if (HasOrigin(function_info, name, line_offset, column_offset)) {
186 result = *function_info;
Steve Blocka7e24c12009-10-30 11:49:00 +0000187 break;
188 }
189 }
190 }
191 }
192
Steve Block44f0eee2011-05-26 01:26:41 +0100193 if (!script_histogram_initialized_) {
194 script_histogram_ = isolate()->stats_table()->CreateHistogram(
195 "V8.ScriptCache",
196 0,
197 kScriptGenerations,
198 kScriptGenerations + 1);
199 script_histogram_initialized_ = true;
200 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000201
Steve Block44f0eee2011-05-26 01:26:41 +0100202 if (script_histogram_ != NULL) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000203 // The level NUMBER_OF_SCRIPT_GENERATIONS is equivalent to a cache miss.
Steve Block44f0eee2011-05-26 01:26:41 +0100204 isolate()->stats_table()->AddHistogramSample(script_histogram_, generation);
Steve Blocka7e24c12009-10-30 11:49:00 +0000205 }
206
207 // Once outside the manacles of the handle scope, we need to recheck
208 // to see if we actually found a cached script. If so, we return a
209 // handle created in the caller's handle scope.
210 if (result != NULL) {
Steve Block44f0eee2011-05-26 01:26:41 +0100211 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result),
212 isolate());
Steve Block6ded16b2010-05-10 14:33:55 +0100213 ASSERT(HasOrigin(shared, name, line_offset, column_offset));
Steve Blocka7e24c12009-10-30 11:49:00 +0000214 // If the script was found in a later generation, we promote it to
215 // the first generation to let it survive longer in the cache.
Steve Block6ded16b2010-05-10 14:33:55 +0100216 if (generation != 0) Put(source, shared);
Steve Block44f0eee2011-05-26 01:26:41 +0100217 isolate()->counters()->compilation_cache_hits()->Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100218 return shared;
Steve Blocka7e24c12009-10-30 11:49:00 +0000219 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100220 isolate()->counters()->compilation_cache_misses()->Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100221 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000222 }
223}
224
225
John Reck59135872010-11-02 12:39:01 -0700226MaybeObject* CompilationCacheScript::TryTablePut(
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100227 Handle<String> source,
228 Handle<SharedFunctionInfo> function_info) {
229 Handle<CompilationCacheTable> table = GetFirstTable();
230 return table->Put(*source, *function_info);
231}
232
233
Steve Block6ded16b2010-05-10 14:33:55 +0100234Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
235 Handle<String> source,
236 Handle<SharedFunctionInfo> function_info) {
Steve Block44f0eee2011-05-26 01:26:41 +0100237 CALL_HEAP_FUNCTION(isolate(),
238 TryTablePut(source, function_info),
239 CompilationCacheTable);
Steve Blocka7e24c12009-10-30 11:49:00 +0000240}
241
242
Steve Block6ded16b2010-05-10 14:33:55 +0100243void CompilationCacheScript::Put(Handle<String> source,
244 Handle<SharedFunctionInfo> function_info) {
Steve Block44f0eee2011-05-26 01:26:41 +0100245 HandleScope scope(isolate());
Steve Block6ded16b2010-05-10 14:33:55 +0100246 SetFirstTable(TablePut(source, function_info));
247}
248
249
250Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
Steve Block1e0659c2011-05-24 12:43:12 +0100251 Handle<String> source,
252 Handle<Context> context,
253 StrictModeFlag strict_mode) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000254 // Make sure not to leak the table into the surrounding handle
255 // scope. Otherwise, we risk keeping old tables around even after
256 // having cleared the cache.
257 Object* result = NULL;
258 int generation;
Steve Block44f0eee2011-05-26 01:26:41 +0100259 { HandleScope scope(isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000260 for (generation = 0; generation < generations(); generation++) {
261 Handle<CompilationCacheTable> table = GetTable(generation);
Steve Block1e0659c2011-05-24 12:43:12 +0100262 result = table->LookupEval(*source, *context, strict_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100263 if (result->IsSharedFunctionInfo()) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000264 break;
265 }
266 }
267 }
Steve Block6ded16b2010-05-10 14:33:55 +0100268 if (result->IsSharedFunctionInfo()) {
269 Handle<SharedFunctionInfo>
Steve Block44f0eee2011-05-26 01:26:41 +0100270 function_info(SharedFunctionInfo::cast(result), isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000271 if (generation != 0) {
Steve Block6ded16b2010-05-10 14:33:55 +0100272 Put(source, context, function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000273 }
Steve Block44f0eee2011-05-26 01:26:41 +0100274 isolate()->counters()->compilation_cache_hits()->Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100275 return function_info;
Steve Blocka7e24c12009-10-30 11:49:00 +0000276 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100277 isolate()->counters()->compilation_cache_misses()->Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100278 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000279 }
280}
281
282
John Reck59135872010-11-02 12:39:01 -0700283MaybeObject* CompilationCacheEval::TryTablePut(
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100284 Handle<String> source,
285 Handle<Context> context,
286 Handle<SharedFunctionInfo> function_info) {
287 Handle<CompilationCacheTable> table = GetFirstTable();
288 return table->PutEval(*source, *context, *function_info);
289}
290
291
Steve Block6ded16b2010-05-10 14:33:55 +0100292Handle<CompilationCacheTable> CompilationCacheEval::TablePut(
293 Handle<String> source,
294 Handle<Context> context,
295 Handle<SharedFunctionInfo> function_info) {
Steve Block44f0eee2011-05-26 01:26:41 +0100296 CALL_HEAP_FUNCTION(isolate(),
297 TryTablePut(source, context, function_info),
Steve Block6ded16b2010-05-10 14:33:55 +0100298 CompilationCacheTable);
299}
300
301
Steve Blocka7e24c12009-10-30 11:49:00 +0000302void CompilationCacheEval::Put(Handle<String> source,
303 Handle<Context> context,
Steve Block6ded16b2010-05-10 14:33:55 +0100304 Handle<SharedFunctionInfo> function_info) {
Steve Block44f0eee2011-05-26 01:26:41 +0100305 HandleScope scope(isolate());
Steve Block6ded16b2010-05-10 14:33:55 +0100306 SetFirstTable(TablePut(source, context, function_info));
Steve Blocka7e24c12009-10-30 11:49:00 +0000307}
308
309
310Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
311 JSRegExp::Flags flags) {
312 // Make sure not to leak the table into the surrounding handle
313 // scope. Otherwise, we risk keeping old tables around even after
314 // having cleared the cache.
315 Object* result = NULL;
316 int generation;
Steve Block44f0eee2011-05-26 01:26:41 +0100317 { HandleScope scope(isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000318 for (generation = 0; generation < generations(); generation++) {
319 Handle<CompilationCacheTable> table = GetTable(generation);
320 result = table->LookupRegExp(*source, flags);
321 if (result->IsFixedArray()) {
322 break;
323 }
324 }
325 }
326 if (result->IsFixedArray()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100327 Handle<FixedArray> data(FixedArray::cast(result), isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000328 if (generation != 0) {
329 Put(source, flags, data);
330 }
Steve Block44f0eee2011-05-26 01:26:41 +0100331 isolate()->counters()->compilation_cache_hits()->Increment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000332 return data;
333 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100334 isolate()->counters()->compilation_cache_misses()->Increment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000335 return Handle<FixedArray>::null();
336 }
337}
338
339
John Reck59135872010-11-02 12:39:01 -0700340MaybeObject* CompilationCacheRegExp::TryTablePut(
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100341 Handle<String> source,
342 JSRegExp::Flags flags,
343 Handle<FixedArray> data) {
344 Handle<CompilationCacheTable> table = GetFirstTable();
345 return table->PutRegExp(*source, flags, *data);
346}
347
348
Steve Block6ded16b2010-05-10 14:33:55 +0100349Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut(
350 Handle<String> source,
351 JSRegExp::Flags flags,
352 Handle<FixedArray> data) {
Steve Block44f0eee2011-05-26 01:26:41 +0100353 CALL_HEAP_FUNCTION(isolate(),
354 TryTablePut(source, flags, data),
355 CompilationCacheTable);
Steve Block6ded16b2010-05-10 14:33:55 +0100356}
357
358
Steve Blocka7e24c12009-10-30 11:49:00 +0000359void CompilationCacheRegExp::Put(Handle<String> source,
360 JSRegExp::Flags flags,
361 Handle<FixedArray> data) {
Steve Block44f0eee2011-05-26 01:26:41 +0100362 HandleScope scope(isolate());
Steve Block6ded16b2010-05-10 14:33:55 +0100363 SetFirstTable(TablePut(source, flags, data));
Steve Blocka7e24c12009-10-30 11:49:00 +0000364}
365
366
Ben Murdochb0fe1622011-05-05 13:52:32 +0100367void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) {
368 if (!IsEnabled()) return;
369
Steve Block44f0eee2011-05-26 01:26:41 +0100370 eval_global_.Remove(function_info);
371 eval_contextual_.Remove(function_info);
372 script_.Remove(function_info);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100373}
374
375
Steve Block6ded16b2010-05-10 14:33:55 +0100376Handle<SharedFunctionInfo> CompilationCache::LookupScript(Handle<String> source,
377 Handle<Object> name,
378 int line_offset,
379 int column_offset) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000380 if (!IsEnabled()) {
Steve Block6ded16b2010-05-10 14:33:55 +0100381 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000382 }
383
Steve Block44f0eee2011-05-26 01:26:41 +0100384 return script_.Lookup(source, name, line_offset, column_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000385}
386
387
Steve Block1e0659c2011-05-24 12:43:12 +0100388Handle<SharedFunctionInfo> CompilationCache::LookupEval(
389 Handle<String> source,
390 Handle<Context> context,
391 bool is_global,
392 StrictModeFlag strict_mode) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000393 if (!IsEnabled()) {
Steve Block6ded16b2010-05-10 14:33:55 +0100394 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000395 }
396
Steve Block6ded16b2010-05-10 14:33:55 +0100397 Handle<SharedFunctionInfo> result;
Steve Blocka7e24c12009-10-30 11:49:00 +0000398 if (is_global) {
Steve Block44f0eee2011-05-26 01:26:41 +0100399 result = eval_global_.Lookup(source, context, strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000400 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100401 result = eval_contextual_.Lookup(source, context, strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000402 }
403 return result;
404}
405
406
407Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source,
408 JSRegExp::Flags flags) {
409 if (!IsEnabled()) {
410 return Handle<FixedArray>::null();
411 }
412
Steve Block44f0eee2011-05-26 01:26:41 +0100413 return reg_exp_.Lookup(source, flags);
Steve Blocka7e24c12009-10-30 11:49:00 +0000414}
415
416
417void CompilationCache::PutScript(Handle<String> source,
Steve Block6ded16b2010-05-10 14:33:55 +0100418 Handle<SharedFunctionInfo> function_info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000419 if (!IsEnabled()) {
420 return;
421 }
422
Steve Block44f0eee2011-05-26 01:26:41 +0100423 script_.Put(source, function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000424}
425
426
427void CompilationCache::PutEval(Handle<String> source,
428 Handle<Context> context,
429 bool is_global,
Steve Block6ded16b2010-05-10 14:33:55 +0100430 Handle<SharedFunctionInfo> function_info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000431 if (!IsEnabled()) {
432 return;
433 }
434
Steve Block44f0eee2011-05-26 01:26:41 +0100435 HandleScope scope(isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000436 if (is_global) {
Steve Block44f0eee2011-05-26 01:26:41 +0100437 eval_global_.Put(source, context, function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000438 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100439 eval_contextual_.Put(source, context, function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000440 }
441}
442
443
444
445void CompilationCache::PutRegExp(Handle<String> source,
446 JSRegExp::Flags flags,
447 Handle<FixedArray> data) {
448 if (!IsEnabled()) {
449 return;
450 }
451
Steve Block44f0eee2011-05-26 01:26:41 +0100452 reg_exp_.Put(source, flags, data);
Steve Blocka7e24c12009-10-30 11:49:00 +0000453}
454
455
456void CompilationCache::Clear() {
457 for (int i = 0; i < kSubCacheCount; i++) {
Steve Block44f0eee2011-05-26 01:26:41 +0100458 subcaches_[i]->Clear();
Steve Blocka7e24c12009-10-30 11:49:00 +0000459 }
460}
461
Steve Block44f0eee2011-05-26 01:26:41 +0100462
Steve Blocka7e24c12009-10-30 11:49:00 +0000463void CompilationCache::Iterate(ObjectVisitor* v) {
464 for (int i = 0; i < kSubCacheCount; i++) {
Steve Block44f0eee2011-05-26 01:26:41 +0100465 subcaches_[i]->Iterate(v);
Steve Blocka7e24c12009-10-30 11:49:00 +0000466 }
467}
468
469
Iain Merrick75681382010-08-19 15:07:18 +0100470void CompilationCache::IterateFunctions(ObjectVisitor* v) {
471 for (int i = 0; i < kSubCacheCount; i++) {
Steve Block44f0eee2011-05-26 01:26:41 +0100472 subcaches_[i]->IterateFunctions(v);
Iain Merrick75681382010-08-19 15:07:18 +0100473 }
474}
475
476
Steve Blocka7e24c12009-10-30 11:49:00 +0000477void CompilationCache::MarkCompactPrologue() {
478 for (int i = 0; i < kSubCacheCount; i++) {
Steve Block44f0eee2011-05-26 01:26:41 +0100479 subcaches_[i]->Age();
Steve Blocka7e24c12009-10-30 11:49:00 +0000480 }
481}
482
483
484void CompilationCache::Enable() {
Steve Block44f0eee2011-05-26 01:26:41 +0100485 enabled_ = true;
Steve Blocka7e24c12009-10-30 11:49:00 +0000486}
487
488
489void CompilationCache::Disable() {
Steve Block44f0eee2011-05-26 01:26:41 +0100490 enabled_ = false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000491 Clear();
492}
493
494
495} } // namespace v8::internal