blob: 53e2190b2dc144f6b33d86d14a1c1ce4f23e1fb4 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2011 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005#include "src/compilation-cache.h"
Steve Blocka7e24c12009-10-30 11:49:00 +00006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/assembler.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/counters.h"
9#include "src/factory.h"
10#include "src/objects-inl.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000011
12namespace v8 {
13namespace internal {
14
Steve Blocka7e24c12009-10-30 11:49:00 +000015
16// The number of generations for each sub cache.
Steve Blocka7e24c12009-10-30 11:49:00 +000017static const int kRegExpGenerations = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +000018
Steve Block3ce2e202009-11-05 08:53:23 +000019// Initial size of each compilation cache table allocated.
Steve Blocka7e24c12009-10-30 11:49:00 +000020static const int kInitialCacheSize = 64;
21
Steve Block6ded16b2010-05-10 14:33:55 +010022
Steve Block44f0eee2011-05-26 01:26:41 +010023CompilationCache::CompilationCache(Isolate* isolate)
24 : isolate_(isolate),
Emily Bernierd0a1eb72015-03-24 16:35:39 -040025 script_(isolate, 1),
26 eval_global_(isolate, 1),
27 eval_contextual_(isolate, 1),
Steve Block44f0eee2011-05-26 01:26:41 +010028 reg_exp_(isolate, kRegExpGenerations),
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000029 enabled_(true) {
Steve Block44f0eee2011-05-26 01:26:41 +010030 CompilationSubCache* subcaches[kSubCacheCount] =
31 {&script_, &eval_global_, &eval_contextual_, &reg_exp_};
32 for (int i = 0; i < kSubCacheCount; ++i) {
33 subcaches_[i] = subcaches[i];
Steve Blocka7e24c12009-10-30 11:49:00 +000034 }
Steve Blocka7e24c12009-10-30 11:49:00 +000035}
36
37
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000038CompilationCache::~CompilationCache() {}
Steve Block44f0eee2011-05-26 01:26:41 +010039
40
Steve Blocka7e24c12009-10-30 11:49:00 +000041Handle<CompilationCacheTable> CompilationSubCache::GetTable(int generation) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042 DCHECK(generation < generations_);
Steve Blocka7e24c12009-10-30 11:49:00 +000043 Handle<CompilationCacheTable> result;
Ben Murdoch61f157c2016-09-16 13:49:30 +010044 if (tables_[generation]->IsUndefined(isolate())) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045 result = CompilationCacheTable::New(isolate(), kInitialCacheSize);
Steve Blocka7e24c12009-10-30 11:49:00 +000046 tables_[generation] = *result;
47 } else {
48 CompilationCacheTable* table =
49 CompilationCacheTable::cast(tables_[generation]);
Steve Block44f0eee2011-05-26 01:26:41 +010050 result = Handle<CompilationCacheTable>(table, isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +000051 }
52 return result;
53}
54
Ben Murdochb8a8cc12014-11-26 15:28:44 +000055
Steve Blocka7e24c12009-10-30 11:49:00 +000056void CompilationSubCache::Age() {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040057 // Don't directly age single-generation caches.
58 if (generations_ == 1) {
Ben Murdoch61f157c2016-09-16 13:49:30 +010059 if (!tables_[0]->IsUndefined(isolate())) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040060 CompilationCacheTable::cast(tables_[0])->Age();
61 }
62 return;
63 }
64
Steve Blocka7e24c12009-10-30 11:49:00 +000065 // Age the generations implicitly killing off the oldest.
66 for (int i = generations_ - 1; i > 0; i--) {
67 tables_[i] = tables_[i - 1];
68 }
69
70 // Set the first generation as unborn.
Steve Block44f0eee2011-05-26 01:26:41 +010071 tables_[0] = isolate()->heap()->undefined_value();
Steve Blocka7e24c12009-10-30 11:49:00 +000072}
73
74
Iain Merrick75681382010-08-19 15:07:18 +010075void CompilationSubCache::IterateFunctions(ObjectVisitor* v) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000076 Object* undefined = isolate()->heap()->undefined_value();
Iain Merrick75681382010-08-19 15:07:18 +010077 for (int i = 0; i < generations_; i++) {
78 if (tables_[i] != undefined) {
79 reinterpret_cast<CompilationCacheTable*>(tables_[i])->IterateElements(v);
80 }
81 }
82}
83
84
Steve Blocka7e24c12009-10-30 11:49:00 +000085void CompilationSubCache::Iterate(ObjectVisitor* v) {
86 v->VisitPointers(&tables_[0], &tables_[generations_]);
87}
88
89
90void CompilationSubCache::Clear() {
Steve Block44f0eee2011-05-26 01:26:41 +010091 MemsetPointer(tables_, isolate()->heap()->undefined_value(), generations_);
Steve Blocka7e24c12009-10-30 11:49:00 +000092}
93
94
Ben Murdochb0fe1622011-05-05 13:52:32 +010095void CompilationSubCache::Remove(Handle<SharedFunctionInfo> function_info) {
96 // Probe the script generation tables. Make sure not to leak handles
97 // into the caller's handle scope.
Steve Block44f0eee2011-05-26 01:26:41 +010098 { HandleScope scope(isolate());
Ben Murdochb0fe1622011-05-05 13:52:32 +010099 for (int generation = 0; generation < generations(); generation++) {
100 Handle<CompilationCacheTable> table = GetTable(generation);
101 table->Remove(*function_info);
102 }
103 }
104}
105
106
Steve Block44f0eee2011-05-26 01:26:41 +0100107CompilationCacheScript::CompilationCacheScript(Isolate* isolate,
108 int generations)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400109 : CompilationSubCache(isolate, generations) {}
Steve Block44f0eee2011-05-26 01:26:41 +0100110
111
Steve Blocka7e24c12009-10-30 11:49:00 +0000112// We only re-use a cached function for some script source code if the
113// script originates from the same place. This is to avoid issues
114// when reporting errors, etc.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000115bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info,
116 Handle<Object> name, int line_offset,
117 int column_offset,
118 ScriptOriginOptions resource_options) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000119 Handle<Script> script =
Steve Block44f0eee2011-05-26 01:26:41 +0100120 Handle<Script>(Script::cast(function_info->script()), isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000121 // If the script name isn't set, the boilerplate script should have
122 // an undefined name to have the same origin.
123 if (name.is_null()) {
Ben Murdoch61f157c2016-09-16 13:49:30 +0100124 return script->name()->IsUndefined(isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000125 }
126 // Do the fast bailout checks first.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000127 if (line_offset != script->line_offset()) return false;
128 if (column_offset != script->column_offset()) return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000129 // Check that both names are strings. If not, no match.
130 if (!name->IsString() || !script->name()->IsString()) return false;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000131 // Are the origin_options same?
132 if (resource_options.Flags() != script->origin_options().Flags())
133 return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000134 // Compare the two name strings for equality.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000135 return String::Equals(Handle<String>::cast(name),
136 Handle<String>(String::cast(script->name())));
Steve Blocka7e24c12009-10-30 11:49:00 +0000137}
138
139
140// TODO(245): Need to allow identical code from different contexts to
141// be cached in the same script generation. Currently the first use
142// will be cached, but subsequent code from different source / line
143// won't.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000144Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000145 Handle<String> source, Handle<Object> name, int line_offset,
146 int column_offset, ScriptOriginOptions resource_options,
147 Handle<Context> context, LanguageMode language_mode) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000148 Object* result = NULL;
149 int generation;
150
151 // Probe the script generation tables. Make sure not to leak handles
152 // into the caller's handle scope.
Steve Block44f0eee2011-05-26 01:26:41 +0100153 { HandleScope scope(isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000154 for (generation = 0; generation < generations(); generation++) {
155 Handle<CompilationCacheTable> table = GetTable(generation);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000156 Handle<Object> probe = table->Lookup(source, context, language_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100157 if (probe->IsSharedFunctionInfo()) {
158 Handle<SharedFunctionInfo> function_info =
159 Handle<SharedFunctionInfo>::cast(probe);
160 // Break when we've found a suitable shared function info that
Steve Blocka7e24c12009-10-30 11:49:00 +0000161 // matches the origin.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000162 if (HasOrigin(function_info, name, line_offset, column_offset,
163 resource_options)) {
Steve Block6ded16b2010-05-10 14:33:55 +0100164 result = *function_info;
Steve Blocka7e24c12009-10-30 11:49:00 +0000165 break;
166 }
167 }
168 }
169 }
170
Steve Blocka7e24c12009-10-30 11:49:00 +0000171 // Once outside the manacles of the handle scope, we need to recheck
172 // to see if we actually found a cached script. If so, we return a
173 // handle created in the caller's handle scope.
174 if (result != NULL) {
Steve Block44f0eee2011-05-26 01:26:41 +0100175 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result),
176 isolate());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000177 DCHECK(
178 HasOrigin(shared, name, line_offset, column_offset, resource_options));
Steve Blocka7e24c12009-10-30 11:49:00 +0000179 // If the script was found in a later generation, we promote it to
180 // the first generation to let it survive longer in the cache.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000181 if (generation != 0) Put(source, context, language_mode, shared);
Steve Block44f0eee2011-05-26 01:26:41 +0100182 isolate()->counters()->compilation_cache_hits()->Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100183 return shared;
Steve Blocka7e24c12009-10-30 11:49:00 +0000184 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100185 isolate()->counters()->compilation_cache_misses()->Increment();
Steve Block6ded16b2010-05-10 14:33:55 +0100186 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000187 }
188}
189
190
Steve Block6ded16b2010-05-10 14:33:55 +0100191void CompilationCacheScript::Put(Handle<String> source,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000192 Handle<Context> context,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000193 LanguageMode language_mode,
Steve Block6ded16b2010-05-10 14:33:55 +0100194 Handle<SharedFunctionInfo> function_info) {
Steve Block44f0eee2011-05-26 01:26:41 +0100195 HandleScope scope(isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000196 Handle<CompilationCacheTable> table = GetFirstTable();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000197 SetFirstTable(CompilationCacheTable::Put(table, source, context,
198 language_mode, function_info));
Steve Block6ded16b2010-05-10 14:33:55 +0100199}
200
201
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000202MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup(
203 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000204 LanguageMode language_mode, int scope_position) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000205 HandleScope scope(isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000206 // Make sure not to leak the table into the surrounding handle
207 // scope. Otherwise, we risk keeping old tables around even after
208 // having cleared the cache.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000209 Handle<Object> result = isolate()->factory()->undefined_value();
Steve Blocka7e24c12009-10-30 11:49:00 +0000210 int generation;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000211 for (generation = 0; generation < generations(); generation++) {
212 Handle<CompilationCacheTable> table = GetTable(generation);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000213 result =
214 table->LookupEval(source, outer_info, language_mode, scope_position);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000215 if (result->IsSharedFunctionInfo()) break;
Steve Blocka7e24c12009-10-30 11:49:00 +0000216 }
Steve Block6ded16b2010-05-10 14:33:55 +0100217 if (result->IsSharedFunctionInfo()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218 Handle<SharedFunctionInfo> function_info =
219 Handle<SharedFunctionInfo>::cast(result);
Steve Blocka7e24c12009-10-30 11:49:00 +0000220 if (generation != 0) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000221 Put(source, outer_info, function_info, scope_position);
Steve Blocka7e24c12009-10-30 11:49:00 +0000222 }
Steve Block44f0eee2011-05-26 01:26:41 +0100223 isolate()->counters()->compilation_cache_hits()->Increment();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000224 return scope.CloseAndEscape(function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000225 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100226 isolate()->counters()->compilation_cache_misses()->Increment();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000227 return MaybeHandle<SharedFunctionInfo>();
Steve Blocka7e24c12009-10-30 11:49:00 +0000228 }
229}
230
231
232void CompilationCacheEval::Put(Handle<String> source,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000233 Handle<SharedFunctionInfo> outer_info,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100234 Handle<SharedFunctionInfo> function_info,
235 int scope_position) {
Steve Block44f0eee2011-05-26 01:26:41 +0100236 HandleScope scope(isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237 Handle<CompilationCacheTable> table = GetFirstTable();
238 table = CompilationCacheTable::PutEval(table, source, outer_info,
239 function_info, scope_position);
240 SetFirstTable(table);
Steve Blocka7e24c12009-10-30 11:49:00 +0000241}
242
243
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000244MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup(
245 Handle<String> source,
246 JSRegExp::Flags flags) {
247 HandleScope scope(isolate());
Steve Blocka7e24c12009-10-30 11:49:00 +0000248 // Make sure not to leak the table into the surrounding handle
249 // scope. Otherwise, we risk keeping old tables around even after
250 // having cleared the cache.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000251 Handle<Object> result = isolate()->factory()->undefined_value();
Steve Blocka7e24c12009-10-30 11:49:00 +0000252 int generation;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253 for (generation = 0; generation < generations(); generation++) {
254 Handle<CompilationCacheTable> table = GetTable(generation);
255 result = table->LookupRegExp(source, flags);
256 if (result->IsFixedArray()) break;
Steve Blocka7e24c12009-10-30 11:49:00 +0000257 }
258 if (result->IsFixedArray()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000259 Handle<FixedArray> data = Handle<FixedArray>::cast(result);
Steve Blocka7e24c12009-10-30 11:49:00 +0000260 if (generation != 0) {
261 Put(source, flags, data);
262 }
Steve Block44f0eee2011-05-26 01:26:41 +0100263 isolate()->counters()->compilation_cache_hits()->Increment();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000264 return scope.CloseAndEscape(data);
Steve Blocka7e24c12009-10-30 11:49:00 +0000265 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100266 isolate()->counters()->compilation_cache_misses()->Increment();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000267 return MaybeHandle<FixedArray>();
Steve Blocka7e24c12009-10-30 11:49:00 +0000268 }
269}
270
271
272void CompilationCacheRegExp::Put(Handle<String> source,
273 JSRegExp::Flags flags,
274 Handle<FixedArray> data) {
Steve Block44f0eee2011-05-26 01:26:41 +0100275 HandleScope scope(isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276 Handle<CompilationCacheTable> table = GetFirstTable();
277 SetFirstTable(CompilationCacheTable::PutRegExp(table, source, flags, data));
Steve Blocka7e24c12009-10-30 11:49:00 +0000278}
279
280
Ben Murdochb0fe1622011-05-05 13:52:32 +0100281void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) {
282 if (!IsEnabled()) return;
283
Steve Block44f0eee2011-05-26 01:26:41 +0100284 eval_global_.Remove(function_info);
285 eval_contextual_.Remove(function_info);
286 script_.Remove(function_info);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100287}
288
289
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000290MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000291 Handle<String> source, Handle<Object> name, int line_offset,
292 int column_offset, ScriptOriginOptions resource_options,
293 Handle<Context> context, LanguageMode language_mode) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000294 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
Steve Blocka7e24c12009-10-30 11:49:00 +0000295
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000296 return script_.Lookup(source, name, line_offset, column_offset,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000297 resource_options, context, language_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000298}
299
300
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval(
302 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000303 Handle<Context> context, LanguageMode language_mode, int scope_position) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000304 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
Steve Blocka7e24c12009-10-30 11:49:00 +0000305
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000306 MaybeHandle<SharedFunctionInfo> result;
307 if (context->IsNativeContext()) {
308 result =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000309 eval_global_.Lookup(source, outer_info, language_mode, scope_position);
Steve Blocka7e24c12009-10-30 11:49:00 +0000310 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000311 DCHECK(scope_position != RelocInfo::kNoPosition);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000312 result = eval_contextual_.Lookup(source, outer_info, language_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000313 scope_position);
Steve Blocka7e24c12009-10-30 11:49:00 +0000314 }
315 return result;
316}
317
318
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000319MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source,
320 JSRegExp::Flags flags) {
321 if (!IsEnabled()) return MaybeHandle<FixedArray>();
Steve Blocka7e24c12009-10-30 11:49:00 +0000322
Steve Block44f0eee2011-05-26 01:26:41 +0100323 return reg_exp_.Lookup(source, flags);
Steve Blocka7e24c12009-10-30 11:49:00 +0000324}
325
326
327void CompilationCache::PutScript(Handle<String> source,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000328 Handle<Context> context,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000329 LanguageMode language_mode,
Steve Block6ded16b2010-05-10 14:33:55 +0100330 Handle<SharedFunctionInfo> function_info) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000331 if (!IsEnabled()) return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000332
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000333 script_.Put(source, context, language_mode, function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000334}
335
336
337void CompilationCache::PutEval(Handle<String> source,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000338 Handle<SharedFunctionInfo> outer_info,
Steve Blocka7e24c12009-10-30 11:49:00 +0000339 Handle<Context> context,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100340 Handle<SharedFunctionInfo> function_info,
341 int scope_position) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000342 if (!IsEnabled()) return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000343
Steve Block44f0eee2011-05-26 01:26:41 +0100344 HandleScope scope(isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000345 if (context->IsNativeContext()) {
346 eval_global_.Put(source, outer_info, function_info, scope_position);
Steve Blocka7e24c12009-10-30 11:49:00 +0000347 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000348 DCHECK(scope_position != RelocInfo::kNoPosition);
349 eval_contextual_.Put(source, outer_info, function_info, scope_position);
Steve Blocka7e24c12009-10-30 11:49:00 +0000350 }
351}
352
353
354
355void CompilationCache::PutRegExp(Handle<String> source,
356 JSRegExp::Flags flags,
357 Handle<FixedArray> data) {
358 if (!IsEnabled()) {
359 return;
360 }
361
Steve Block44f0eee2011-05-26 01:26:41 +0100362 reg_exp_.Put(source, flags, data);
Steve Blocka7e24c12009-10-30 11:49:00 +0000363}
364
365
366void CompilationCache::Clear() {
367 for (int i = 0; i < kSubCacheCount; i++) {
Steve Block44f0eee2011-05-26 01:26:41 +0100368 subcaches_[i]->Clear();
Steve Blocka7e24c12009-10-30 11:49:00 +0000369 }
370}
371
Steve Block44f0eee2011-05-26 01:26:41 +0100372
Steve Blocka7e24c12009-10-30 11:49:00 +0000373void CompilationCache::Iterate(ObjectVisitor* v) {
374 for (int i = 0; i < kSubCacheCount; i++) {
Steve Block44f0eee2011-05-26 01:26:41 +0100375 subcaches_[i]->Iterate(v);
Steve Blocka7e24c12009-10-30 11:49:00 +0000376 }
377}
378
379
Iain Merrick75681382010-08-19 15:07:18 +0100380void CompilationCache::IterateFunctions(ObjectVisitor* v) {
381 for (int i = 0; i < kSubCacheCount; i++) {
Steve Block44f0eee2011-05-26 01:26:41 +0100382 subcaches_[i]->IterateFunctions(v);
Iain Merrick75681382010-08-19 15:07:18 +0100383 }
384}
385
386
Steve Blocka7e24c12009-10-30 11:49:00 +0000387void CompilationCache::MarkCompactPrologue() {
388 for (int i = 0; i < kSubCacheCount; i++) {
Steve Block44f0eee2011-05-26 01:26:41 +0100389 subcaches_[i]->Age();
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 }
391}
392
393
394void CompilationCache::Enable() {
Steve Block44f0eee2011-05-26 01:26:41 +0100395 enabled_ = true;
Steve Blocka7e24c12009-10-30 11:49:00 +0000396}
397
398
399void CompilationCache::Disable() {
Steve Block44f0eee2011-05-26 01:26:41 +0100400 enabled_ = false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000401 Clear();
402}
403
404
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000405} // namespace internal
406} // namespace v8