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

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

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
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 255
256 Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( 256 Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
257 Handle<String> source, 257 Handle<String> source,
258 Handle<Context> context, 258 Handle<Context> context,
259 LanguageMode language_mode, 259 LanguageMode language_mode,
260 int scope_position) { 260 int scope_position) {
261 // Make sure not to leak the table into the surrounding handle 261 // Make sure not to leak the table into the surrounding handle
262 // scope. Otherwise, we risk keeping old tables around even after 262 // scope. Otherwise, we risk keeping old tables around even after
263 // having cleared the cache. 263 // having cleared the cache.
264 Object* result = NULL; 264 Object* result = NULL;
265 int generation; 265 int generation = -1;
266 { HandleScope scope(isolate()); 266 { HandleScope scope(isolate());
267 for (generation = 0; generation < generations(); generation++) { 267 if (FLAG_json_eval_cache &&
268 Handle<CompilationCacheTable> table = GetTable(generation); 268 json_table_->IsShortTermJSONEvalCacheTable()) {
269 result = table->LookupEval( 269 ShortTermJSONEvalCacheTable* table =
270 *source, *context, language_mode, scope_position); 270 ShortTermJSONEvalCacheTable::cast(json_table_);
271 if (result->IsSharedFunctionInfo()) { 271 result = table->Lookup(*source);
272 break; 272 }
273 if (!result->IsSharedFunctionInfo()) {
274 for (generation = 0; generation < generations(); generation++) {
275 Handle<CompilationCacheTable> table = GetTable(generation);
276 result = table->LookupEval(
277 *source, *context, language_mode, scope_position);
278 if (result->IsSharedFunctionInfo()) {
279 break;
280 }
273 } 281 }
274 } 282 }
275 } 283 }
276 if (result->IsSharedFunctionInfo()) { 284 if (result->IsSharedFunctionInfo()) {
277 Handle<SharedFunctionInfo> 285 Handle<SharedFunctionInfo>
278 function_info(SharedFunctionInfo::cast(result), isolate()); 286 function_info(SharedFunctionInfo::cast(result), isolate());
279 if (generation != 0) { 287 if (generation > 0) {
280 Put(source, context, function_info, scope_position); 288 Put(source, context, function_info, scope_position);
281 } 289 }
282 isolate()->counters()->compilation_cache_hits()->Increment(); 290 isolate()->counters()->compilation_cache_hits()->Increment();
283 return function_info; 291 return function_info;
284 } else { 292 } else {
285 isolate()->counters()->compilation_cache_misses()->Increment(); 293 isolate()->counters()->compilation_cache_misses()->Increment();
286 return Handle<SharedFunctionInfo>::null(); 294 return Handle<SharedFunctionInfo>::null();
287 } 295 }
288 } 296 }
289 297
290 298
291 MaybeObject* CompilationCacheEval::TryTablePut( 299 MaybeObject* CompilationCacheEval::TryTablePut(
292 Handle<String> source, 300 Handle<String> source,
293 Handle<Context> context, 301 Handle<Context> context,
294 Handle<SharedFunctionInfo> function_info, 302 Handle<SharedFunctionInfo> function_info,
295 int scope_position) { 303 int scope_position) {
296 Handle<CompilationCacheTable> table = GetFirstTable(); 304 if (FLAG_json_eval_cache && function_info->is_json_eval()) {
297 return table->PutEval(*source, *context, *function_info, scope_position); 305 ShortTermJSONEvalCacheTable* json_table = NULL;
306 if (json_table_->IsUndefined()) {
307 MaybeObject* maybe_table = ShortTermJSONEvalCacheTable::Allocate();
308 if (!maybe_table->To<ShortTermJSONEvalCacheTable>(&json_table)) {
309 return maybe_table;
310 }
311 } else {
312 json_table = ShortTermJSONEvalCacheTable::cast(json_table_);
313 }
314 { MaybeObject* maybe_table = json_table->Put(*source, *function_info);
315 if (!maybe_table->ToObject(&json_table_)) return maybe_table;
316 }
317 }
318
319 CompilationCacheTable* table = *GetFirstTable();
320 { MaybeObject* maybe_table =
321 table->PutEval(*source, *context, *function_info, scope_position);
322 if (!maybe_table->To<CompilationCacheTable>(&table)) return maybe_table;
323 }
324 SetFirstTable(Handle<CompilationCacheTable>(table));
325 return isolate()->heap()->undefined_value();
298 } 326 }
299 327
300 328
301 Handle<CompilationCacheTable> CompilationCacheEval::TablePut( 329 void CompilationCacheEval::TablePut(
302 Handle<String> source, 330 Handle<String> source,
303 Handle<Context> context, 331 Handle<Context> context,
304 Handle<SharedFunctionInfo> function_info, 332 Handle<SharedFunctionInfo> function_info,
305 int scope_position) { 333 int scope_position) {
306 CALL_HEAP_FUNCTION(isolate(), 334 CALL_HEAP_FUNCTION_VOID(isolate(),
307 TryTablePut( 335 TryTablePut(
308 source, context, function_info, scope_position), 336 source, context, function_info, scope_position));
309 CompilationCacheTable);
310 } 337 }
311 338
312 339
313 void CompilationCacheEval::Put(Handle<String> source, 340 void CompilationCacheEval::Put(Handle<String> source,
314 Handle<Context> context, 341 Handle<Context> context,
315 Handle<SharedFunctionInfo> function_info, 342 Handle<SharedFunctionInfo> function_info,
316 int scope_position) { 343 int scope_position) {
317 HandleScope scope(isolate()); 344 HandleScope scope(isolate());
318 SetFirstTable(TablePut(source, context, function_info, scope_position)); 345 TablePut(source, context, function_info, scope_position);
346 }
347
348
349 void CompilationCacheEval::Iterate(ObjectVisitor* v) {
350 CompilationSubCache::Iterate(v);
351 v->VisitPointer(&json_table_);
352 }
353
354
355 void CompilationCacheEval::IterateFunctions(ObjectVisitor* v) {
356 CompilationSubCache::IterateFunctions(v);
357 Object* undefined = isolate()->heap()->raw_unchecked_undefined_value();
358 if (json_table_ != undefined) {
359 ShortTermJSONEvalCacheTable* table =
360 reinterpret_cast<ShortTermJSONEvalCacheTable*>(json_table_);
361 table->IterateElements(v);
362 }
363 }
364
365
366 void CompilationCacheEval::Clear() {
367 CompilationSubCache::Clear();
368 ClearShortTerm();
369 }
370
371
372 bool CompilationCacheEval::ClearShortTerm() {
373 bool already_clear = json_table_ != NULL &&
374 json_table_->IsUndefined();
375 if (!already_clear) {
376 json_table_ = isolate()->heap()->undefined_value();
377 }
378 return already_clear;
379 }
380
381
382 void CompilationCacheEval::Remove(Handle<SharedFunctionInfo> function_info) {
383 CompilationSubCache::Remove(function_info);
384 if (json_table_ != NULL &&
385 json_table_->IsShortTermJSONEvalCacheTable()) {
386 ShortTermJSONEvalCacheTable* short_term_table =
387 ShortTermJSONEvalCacheTable::cast(json_table_);
388 short_term_table->Remove(*function_info);
389 }
390 }
391
392
393 void CompilationCacheEval::GetShortTermStatistics(int* entry_count,
394 int* max_entries,
395 int* total_size,
396 int* max_total_size) {
397 if (json_table_ == NULL ||
398 !json_table_->IsShortTermJSONEvalCacheTable()) {
399 *entry_count = 0;
400 *max_entries = 0;
401 *total_size = 0;
402 *max_total_size = 0;
403 } else {
404 ShortTermJSONEvalCacheTable* table =
405 ShortTermJSONEvalCacheTable::cast(json_table_);
406 *entry_count = table->NumberOfElements();
407 *max_entries = ShortTermJSONEvalCacheTable::max_entries();
408 *total_size = table->total_source_size();
409 *max_total_size = ShortTermJSONEvalCacheTable::max_total_source_size();
410 }
319 } 411 }
320 412
321 413
322 Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, 414 Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source,
323 JSRegExp::Flags flags) { 415 JSRegExp::Flags flags) {
324 // Make sure not to leak the table into the surrounding handle 416 // Make sure not to leak the table into the surrounding handle
325 // scope. Otherwise, we risk keeping old tables around even after 417 // scope. Otherwise, we risk keeping old tables around even after
326 // having cleared the cache. 418 // having cleared the cache.
327 Object* result = NULL; 419 Object* result = NULL;
328 int generation; 420 int generation;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 566 }
475 567
476 568
477 void CompilationCache::Clear() { 569 void CompilationCache::Clear() {
478 for (int i = 0; i < kSubCacheCount; i++) { 570 for (int i = 0; i < kSubCacheCount; i++) {
479 subcaches_[i]->Clear(); 571 subcaches_[i]->Clear();
480 } 572 }
481 } 573 }
482 574
483 575
576 bool CompilationCache::ClearShortTerm() {
577 bool already_clear = true;
578 for (int i = 0; i < kSubCacheCount; i++) {
579 already_clear &= subcaches_[i]->ClearShortTerm();
580 }
581 return already_clear;
582 }
583
584
484 void CompilationCache::Iterate(ObjectVisitor* v) { 585 void CompilationCache::Iterate(ObjectVisitor* v) {
485 for (int i = 0; i < kSubCacheCount; i++) { 586 for (int i = 0; i < kSubCacheCount; i++) {
486 subcaches_[i]->Iterate(v); 587 subcaches_[i]->Iterate(v);
487 } 588 }
488 } 589 }
489 590
490 591
491 void CompilationCache::IterateFunctions(ObjectVisitor* v) { 592 void CompilationCache::IterateFunctions(ObjectVisitor* v) {
492 for (int i = 0; i < kSubCacheCount; i++) { 593 for (int i = 0; i < kSubCacheCount; i++) {
493 subcaches_[i]->IterateFunctions(v); 594 subcaches_[i]->IterateFunctions(v);
(...skipping 12 matching lines...) Expand all
506 enabled_ = true; 607 enabled_ = true;
507 } 608 }
508 609
509 610
510 void CompilationCache::Disable() { 611 void CompilationCache::Disable() {
511 enabled_ = false; 612 enabled_ = false;
512 Clear(); 613 Clear();
513 } 614 }
514 615
515 616
617 void CompilationCache::GetShortTermEvalStatistics(int* entry_count,
618 int* max_entries,
619 int* total_size,
620 int* max_total_size) {
621 eval_global_.GetShortTermStatistics(entry_count, max_entries,
622 total_size, max_total_size);
623 }
624
625
516 } } // namespace v8::internal 626 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compilation-cache.h ('k') | src/compiler.cc » ('j') | src/v8.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698