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 | |
84 // GC support. | 82 // GC support. |
85 void Iterate(ObjectVisitor* v); | 83 void Iterate(ObjectVisitor* v); |
| 84 void IterateFunctions(ObjectVisitor* v); |
86 | 85 |
87 // Clear this sub-cache evicting all its content. | 86 // Clear this sub-cache evicting all its content. |
88 void Clear(); | 87 void Clear(); |
89 | 88 |
90 // Number of generations in this sub-cache. | 89 // Number of generations in this sub-cache. |
91 inline int generations() { return generations_; } | 90 inline int generations() { return generations_; } |
92 | 91 |
93 private: | 92 private: |
94 int generations_; // Number of generations. | 93 int generations_; // Number of generations. |
95 Object** tables_; // Compilation cache tables - one for each generation. | 94 Object** tables_; // Compilation cache tables - one for each generation. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 tables_[generation] = *result; | 198 tables_[generation] = *result; |
200 } else { | 199 } else { |
201 CompilationCacheTable* table = | 200 CompilationCacheTable* table = |
202 CompilationCacheTable::cast(tables_[generation]); | 201 CompilationCacheTable::cast(tables_[generation]); |
203 result = Handle<CompilationCacheTable>(table); | 202 result = Handle<CompilationCacheTable>(table); |
204 } | 203 } |
205 return result; | 204 return result; |
206 } | 205 } |
207 | 206 |
208 | 207 |
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 | |
230 void CompilationSubCache::Age() { | 208 void CompilationSubCache::Age() { |
231 // Age the generations implicitly killing off the oldest. | 209 // Age the generations implicitly killing off the oldest. |
232 for (int i = generations_ - 1; i > 0; i--) { | 210 for (int i = generations_ - 1; i > 0; i--) { |
233 tables_[i] = tables_[i - 1]; | 211 tables_[i] = tables_[i - 1]; |
234 } | 212 } |
235 | 213 |
236 // Set the first generation as unborn. | 214 // Set the first generation as unborn. |
237 tables_[0] = Heap::undefined_value(); | 215 tables_[0] = Heap::undefined_value(); |
238 } | 216 } |
239 | 217 |
240 | 218 |
| 219 void CompilationSubCache::IterateFunctions(ObjectVisitor* v) { |
| 220 Object* undefined = Heap::raw_unchecked_undefined_value(); |
| 221 for (int i = 0; i < generations_; i++) { |
| 222 if (tables_[i] != undefined) { |
| 223 reinterpret_cast<CompilationCacheTable*>(tables_[i])->IterateElements(v); |
| 224 } |
| 225 } |
| 226 } |
| 227 |
| 228 |
241 void CompilationSubCache::Iterate(ObjectVisitor* v) { | 229 void CompilationSubCache::Iterate(ObjectVisitor* v) { |
242 v->VisitPointers(&tables_[0], &tables_[generations_]); | 230 v->VisitPointers(&tables_[0], &tables_[generations_]); |
243 } | 231 } |
244 | 232 |
245 | 233 |
246 void CompilationSubCache::Clear() { | 234 void CompilationSubCache::Clear() { |
247 MemsetPointer(tables_, Heap::undefined_value(), generations_); | 235 MemsetPointer(tables_, Heap::undefined_value(), generations_); |
248 } | 236 } |
249 | 237 |
250 | 238 |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 reg_exp.Put(source, flags, data); | 509 reg_exp.Put(source, flags, data); |
522 } | 510 } |
523 | 511 |
524 | 512 |
525 void CompilationCache::Clear() { | 513 void CompilationCache::Clear() { |
526 for (int i = 0; i < kSubCacheCount; i++) { | 514 for (int i = 0; i < kSubCacheCount; i++) { |
527 subcaches[i]->Clear(); | 515 subcaches[i]->Clear(); |
528 } | 516 } |
529 } | 517 } |
530 | 518 |
531 | |
532 bool CompilationCache::HasFunction(SharedFunctionInfo* function_info) { | |
533 return script.HasFunction(function_info); | |
534 } | |
535 | |
536 | |
537 void CompilationCache::Iterate(ObjectVisitor* v) { | 519 void CompilationCache::Iterate(ObjectVisitor* v) { |
538 for (int i = 0; i < kSubCacheCount; i++) { | 520 for (int i = 0; i < kSubCacheCount; i++) { |
539 subcaches[i]->Iterate(v); | 521 subcaches[i]->Iterate(v); |
540 } | 522 } |
541 } | 523 } |
542 | 524 |
| 525 |
| 526 void CompilationCache::IterateFunctions(ObjectVisitor* v) { |
| 527 for (int i = 0; i < kSubCacheCount; i++) { |
| 528 subcaches[i]->IterateFunctions(v); |
| 529 } |
| 530 } |
| 531 |
543 | 532 |
544 void CompilationCache::MarkCompactPrologue() { | 533 void CompilationCache::MarkCompactPrologue() { |
545 for (int i = 0; i < kSubCacheCount; i++) { | 534 for (int i = 0; i < kSubCacheCount; i++) { |
546 subcaches[i]->Age(); | 535 subcaches[i]->Age(); |
547 } | 536 } |
548 } | 537 } |
549 | 538 |
550 | 539 |
551 void CompilationCache::Enable() { | 540 void CompilationCache::Enable() { |
552 enabled = true; | 541 enabled = true; |
553 } | 542 } |
554 | 543 |
555 | 544 |
556 void CompilationCache::Disable() { | 545 void CompilationCache::Disable() { |
557 enabled = false; | 546 enabled = false; |
558 Clear(); | 547 Clear(); |
559 } | 548 } |
560 | 549 |
561 | 550 |
562 } } // namespace v8::internal | 551 } } // namespace v8::internal |
OLD | NEW |