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

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

Issue 10878007: Index script compilation cache over context (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Respect language flags. Created 8 years, 4 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 | « src/compilation-cache.h ('k') | src/compiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (!name->IsString() || !script->name()->IsString()) return false; 158 if (!name->IsString() || !script->name()->IsString()) return false;
159 // Compare the two name strings for equality. 159 // Compare the two name strings for equality.
160 return String::cast(*name)->Equals(String::cast(script->name())); 160 return String::cast(*name)->Equals(String::cast(script->name()));
161 } 161 }
162 162
163 163
164 // TODO(245): Need to allow identical code from different contexts to 164 // TODO(245): Need to allow identical code from different contexts to
165 // be cached in the same script generation. Currently the first use 165 // be cached in the same script generation. Currently the first use
166 // will be cached, but subsequent code from different source / line 166 // will be cached, but subsequent code from different source / line
167 // won't. 167 // won't.
168 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source, 168 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
169 Handle<Object> name, 169 Handle<String> source,
170 int line_offset, 170 Handle<Object> name,
171 int column_offset) { 171 int line_offset,
172 int column_offset,
173 Handle<Context> context) {
172 Object* result = NULL; 174 Object* result = NULL;
173 int generation; 175 int generation;
174 176
175 // Probe the script generation tables. Make sure not to leak handles 177 // Probe the script generation tables. Make sure not to leak handles
176 // into the caller's handle scope. 178 // into the caller's handle scope.
177 { HandleScope scope(isolate()); 179 { HandleScope scope(isolate());
178 for (generation = 0; generation < generations(); generation++) { 180 for (generation = 0; generation < generations(); generation++) {
179 Handle<CompilationCacheTable> table = GetTable(generation); 181 Handle<CompilationCacheTable> table = GetTable(generation);
180 Handle<Object> probe(table->Lookup(*source), isolate()); 182 Handle<Object> probe(table->Lookup(*source, *context), isolate());
181 if (probe->IsSharedFunctionInfo()) { 183 if (probe->IsSharedFunctionInfo()) {
182 Handle<SharedFunctionInfo> function_info = 184 Handle<SharedFunctionInfo> function_info =
183 Handle<SharedFunctionInfo>::cast(probe); 185 Handle<SharedFunctionInfo>::cast(probe);
184 // Break when we've found a suitable shared function info that 186 // Break when we've found a suitable shared function info that
185 // matches the origin. 187 // matches the origin.
186 if (HasOrigin(function_info, name, line_offset, column_offset)) { 188 if (HasOrigin(function_info, name, line_offset, column_offset)) {
187 result = *function_info; 189 result = *function_info;
188 break; 190 break;
189 } 191 }
190 } 192 }
(...skipping 16 matching lines...) Expand all
207 209
208 // Once outside the manacles of the handle scope, we need to recheck 210 // Once outside the manacles of the handle scope, we need to recheck
209 // to see if we actually found a cached script. If so, we return a 211 // to see if we actually found a cached script. If so, we return a
210 // handle created in the caller's handle scope. 212 // handle created in the caller's handle scope.
211 if (result != NULL) { 213 if (result != NULL) {
212 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result), 214 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result),
213 isolate()); 215 isolate());
214 ASSERT(HasOrigin(shared, name, line_offset, column_offset)); 216 ASSERT(HasOrigin(shared, name, line_offset, column_offset));
215 // If the script was found in a later generation, we promote it to 217 // If the script was found in a later generation, we promote it to
216 // the first generation to let it survive longer in the cache. 218 // the first generation to let it survive longer in the cache.
217 if (generation != 0) Put(source, shared); 219 if (generation != 0) Put(source, context, shared);
218 isolate()->counters()->compilation_cache_hits()->Increment(); 220 isolate()->counters()->compilation_cache_hits()->Increment();
219 return shared; 221 return shared;
220 } else { 222 } else {
221 isolate()->counters()->compilation_cache_misses()->Increment(); 223 isolate()->counters()->compilation_cache_misses()->Increment();
222 return Handle<SharedFunctionInfo>::null(); 224 return Handle<SharedFunctionInfo>::null();
223 } 225 }
224 } 226 }
225 227
226 228
227 MaybeObject* CompilationCacheScript::TryTablePut( 229 MaybeObject* CompilationCacheScript::TryTablePut(
228 Handle<String> source, 230 Handle<String> source,
231 Handle<Context> context,
229 Handle<SharedFunctionInfo> function_info) { 232 Handle<SharedFunctionInfo> function_info) {
230 Handle<CompilationCacheTable> table = GetFirstTable(); 233 Handle<CompilationCacheTable> table = GetFirstTable();
231 return table->Put(*source, *function_info); 234 return table->Put(*source, *context, *function_info);
232 } 235 }
233 236
234 237
235 Handle<CompilationCacheTable> CompilationCacheScript::TablePut( 238 Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
236 Handle<String> source, 239 Handle<String> source,
240 Handle<Context> context,
237 Handle<SharedFunctionInfo> function_info) { 241 Handle<SharedFunctionInfo> function_info) {
238 CALL_HEAP_FUNCTION(isolate(), 242 CALL_HEAP_FUNCTION(isolate(),
239 TryTablePut(source, function_info), 243 TryTablePut(source, context, function_info),
240 CompilationCacheTable); 244 CompilationCacheTable);
241 } 245 }
242 246
243 247
244 void CompilationCacheScript::Put(Handle<String> source, 248 void CompilationCacheScript::Put(Handle<String> source,
249 Handle<Context> context,
245 Handle<SharedFunctionInfo> function_info) { 250 Handle<SharedFunctionInfo> function_info) {
246 HandleScope scope(isolate()); 251 HandleScope scope(isolate());
247 SetFirstTable(TablePut(source, function_info)); 252 SetFirstTable(TablePut(source, context, function_info));
248 } 253 }
249 254
250 255
251 Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( 256 Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
252 Handle<String> source, 257 Handle<String> source,
253 Handle<Context> context, 258 Handle<Context> context,
254 LanguageMode language_mode, 259 LanguageMode language_mode,
255 int scope_position) { 260 int scope_position) {
256 // Make sure not to leak the table into the surrounding handle 261 // Make sure not to leak the table into the surrounding handle
257 // scope. Otherwise, we risk keeping old tables around even after 262 // scope. Otherwise, we risk keeping old tables around even after
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 378
374 void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { 379 void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) {
375 if (!IsEnabled()) return; 380 if (!IsEnabled()) return;
376 381
377 eval_global_.Remove(function_info); 382 eval_global_.Remove(function_info);
378 eval_contextual_.Remove(function_info); 383 eval_contextual_.Remove(function_info);
379 script_.Remove(function_info); 384 script_.Remove(function_info);
380 } 385 }
381 386
382 387
383 Handle<SharedFunctionInfo> CompilationCache::LookupScript(Handle<String> source, 388 Handle<SharedFunctionInfo> CompilationCache::LookupScript(
384 Handle<Object> name, 389 Handle<String> source,
385 int line_offset, 390 Handle<Object> name,
386 int column_offset) { 391 int line_offset,
392 int column_offset,
393 Handle<Context> context) {
387 if (!IsEnabled()) { 394 if (!IsEnabled()) {
388 return Handle<SharedFunctionInfo>::null(); 395 return Handle<SharedFunctionInfo>::null();
389 } 396 }
390 397
391 return script_.Lookup(source, name, line_offset, column_offset); 398 return script_.Lookup(source, name, line_offset, column_offset, context);
392 } 399 }
393 400
394 401
395 Handle<SharedFunctionInfo> CompilationCache::LookupEval( 402 Handle<SharedFunctionInfo> CompilationCache::LookupEval(
396 Handle<String> source, 403 Handle<String> source,
397 Handle<Context> context, 404 Handle<Context> context,
398 bool is_global, 405 bool is_global,
399 LanguageMode language_mode, 406 LanguageMode language_mode,
400 int scope_position) { 407 int scope_position) {
401 if (!IsEnabled()) { 408 if (!IsEnabled()) {
(...skipping 17 matching lines...) Expand all
419 JSRegExp::Flags flags) { 426 JSRegExp::Flags flags) {
420 if (!IsEnabled()) { 427 if (!IsEnabled()) {
421 return Handle<FixedArray>::null(); 428 return Handle<FixedArray>::null();
422 } 429 }
423 430
424 return reg_exp_.Lookup(source, flags); 431 return reg_exp_.Lookup(source, flags);
425 } 432 }
426 433
427 434
428 void CompilationCache::PutScript(Handle<String> source, 435 void CompilationCache::PutScript(Handle<String> source,
436 Handle<Context> context,
429 Handle<SharedFunctionInfo> function_info) { 437 Handle<SharedFunctionInfo> function_info) {
430 if (!IsEnabled()) { 438 if (!IsEnabled()) {
431 return; 439 return;
432 } 440 }
433 441
434 script_.Put(source, function_info); 442 script_.Put(source, context, function_info);
435 } 443 }
436 444
437 445
438 void CompilationCache::PutEval(Handle<String> source, 446 void CompilationCache::PutEval(Handle<String> source,
439 Handle<Context> context, 447 Handle<Context> context,
440 bool is_global, 448 bool is_global,
441 Handle<SharedFunctionInfo> function_info, 449 Handle<SharedFunctionInfo> function_info,
442 int scope_position) { 450 int scope_position) {
443 if (!IsEnabled()) { 451 if (!IsEnabled()) {
444 return; 452 return;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 507 }
500 508
501 509
502 void CompilationCache::Disable() { 510 void CompilationCache::Disable() {
503 enabled_ = false; 511 enabled_ = false;
504 Clear(); 512 Clear();
505 } 513 }
506 514
507 515
508 } } // namespace v8::internal 516 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compilation-cache.h ('k') | src/compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698