OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 void SetFirstTable(Handle<CompilationCacheTable> value) { | 73 void SetFirstTable(Handle<CompilationCacheTable> value) { |
74 ASSERT(kFirstGeneration < generations_); | 74 ASSERT(kFirstGeneration < generations_); |
75 tables_[kFirstGeneration] = *value; | 75 tables_[kFirstGeneration] = *value; |
76 } | 76 } |
77 | 77 |
78 // Age the sub-cache by evicting the oldest generation and creating a new | 78 // Age the sub-cache by evicting the oldest generation and creating a new |
79 // young generation. | 79 // young generation. |
80 void Age(); | 80 void Age(); |
81 | 81 |
| 82 bool HasFunction(SharedFunctionInfo* function_info); |
| 83 |
82 // GC support. | 84 // GC support. |
83 void Iterate(ObjectVisitor* v); | 85 void Iterate(ObjectVisitor* v); |
84 | 86 |
85 // Clear this sub-cache evicting all its content. | 87 // Clear this sub-cache evicting all its content. |
86 void Clear(); | 88 void Clear(); |
87 | 89 |
88 // Number of generations in this sub-cache. | 90 // Number of generations in this sub-cache. |
89 inline int generations() { return generations_; } | 91 inline int generations() { return generations_; } |
90 | 92 |
91 private: | 93 private: |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 tables_[generation] = *result; | 199 tables_[generation] = *result; |
198 } else { | 200 } else { |
199 CompilationCacheTable* table = | 201 CompilationCacheTable* table = |
200 CompilationCacheTable::cast(tables_[generation]); | 202 CompilationCacheTable::cast(tables_[generation]); |
201 result = Handle<CompilationCacheTable>(table); | 203 result = Handle<CompilationCacheTable>(table); |
202 } | 204 } |
203 return result; | 205 return result; |
204 } | 206 } |
205 | 207 |
206 | 208 |
| 209 bool CompilationSubCache::HasFunction(SharedFunctionInfo* function_info) { |
| 210 if (function_info->script()->IsUndefined() || |
| 211 Script::cast(function_info->script())->source()->IsUndefined()) { |
| 212 return false; |
| 213 } |
| 214 |
| 215 String* source = |
| 216 String::cast(Script::cast(function_info->script())->source()); |
| 217 // Check all generations. |
| 218 for (int generation = 0; generation < generations(); generation++) { |
| 219 if (tables_[generation]->IsUndefined()) continue; |
| 220 |
| 221 CompilationCacheTable* table = |
| 222 CompilationCacheTable::cast(tables_[generation]); |
| 223 Object* object = table->Lookup(source); |
| 224 if (object->IsSharedFunctionInfo()) return true; |
| 225 } |
| 226 return false; |
| 227 } |
| 228 |
| 229 |
207 void CompilationSubCache::Age() { | 230 void CompilationSubCache::Age() { |
208 // Age the generations implicitly killing off the oldest. | 231 // Age the generations implicitly killing off the oldest. |
209 for (int i = generations_ - 1; i > 0; i--) { | 232 for (int i = generations_ - 1; i > 0; i--) { |
210 tables_[i] = tables_[i - 1]; | 233 tables_[i] = tables_[i - 1]; |
211 } | 234 } |
212 | 235 |
213 // Set the first generation as unborn. | 236 // Set the first generation as unborn. |
214 tables_[0] = Heap::undefined_value(); | 237 tables_[0] = Heap::undefined_value(); |
215 } | 238 } |
216 | 239 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 } | 522 } |
500 | 523 |
501 | 524 |
502 void CompilationCache::Clear() { | 525 void CompilationCache::Clear() { |
503 for (int i = 0; i < kSubCacheCount; i++) { | 526 for (int i = 0; i < kSubCacheCount; i++) { |
504 subcaches[i]->Clear(); | 527 subcaches[i]->Clear(); |
505 } | 528 } |
506 } | 529 } |
507 | 530 |
508 | 531 |
| 532 bool CompilationCache::HasFunction(SharedFunctionInfo* function_info) { |
| 533 return script.HasFunction(function_info); |
| 534 } |
| 535 |
| 536 |
509 void CompilationCache::Iterate(ObjectVisitor* v) { | 537 void CompilationCache::Iterate(ObjectVisitor* v) { |
510 for (int i = 0; i < kSubCacheCount; i++) { | 538 for (int i = 0; i < kSubCacheCount; i++) { |
511 subcaches[i]->Iterate(v); | 539 subcaches[i]->Iterate(v); |
512 } | 540 } |
513 } | 541 } |
514 | 542 |
515 | 543 |
516 void CompilationCache::MarkCompactPrologue() { | 544 void CompilationCache::MarkCompactPrologue() { |
517 for (int i = 0; i < kSubCacheCount; i++) { | 545 for (int i = 0; i < kSubCacheCount; i++) { |
518 subcaches[i]->Age(); | 546 subcaches[i]->Age(); |
519 } | 547 } |
520 } | 548 } |
521 | 549 |
522 | 550 |
523 void CompilationCache::Enable() { | 551 void CompilationCache::Enable() { |
524 enabled = true; | 552 enabled = true; |
525 } | 553 } |
526 | 554 |
527 | 555 |
528 void CompilationCache::Disable() { | 556 void CompilationCache::Disable() { |
529 enabled = false; | 557 enabled = false; |
530 Clear(); | 558 Clear(); |
531 } | 559 } |
532 | 560 |
533 | 561 |
534 } } // namespace v8::internal | 562 } } // namespace v8::internal |
OLD | NEW |