| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 result = table->Lookup(*source); | 95 result = table->Lookup(*source); |
| 96 } | 96 } |
| 97 if (result->IsJSFunction()) { | 97 if (result->IsJSFunction()) { |
| 98 return Handle<JSFunction>(JSFunction::cast(result)); | 98 return Handle<JSFunction>(JSFunction::cast(result)); |
| 99 } else { | 99 } else { |
| 100 return Handle<JSFunction>::null(); | 100 return Handle<JSFunction>::null(); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 static Handle<JSFunction> Lookup(Handle<String> source, |
| 106 Handle<Context> context, |
| 107 CompilationCache::Entry entry) { |
| 108 // Make sure not to leak the table into the surrounding handle |
| 109 // scope. Otherwise, we risk keeping old tables around even after |
| 110 // having cleared the cache. |
| 111 Object* result; |
| 112 { HandleScope scope; |
| 113 Handle<CompilationCacheTable> table = GetTable(entry); |
| 114 result = table->LookupEval(*source, *context); |
| 115 } |
| 116 if (result->IsJSFunction()) { |
| 117 return Handle<JSFunction>(JSFunction::cast(result)); |
| 118 } else { |
| 119 return Handle<JSFunction>::null(); |
| 120 } |
| 121 } |
| 122 |
| 123 |
| 105 Handle<JSFunction> CompilationCache::LookupScript(Handle<String> source, | 124 Handle<JSFunction> CompilationCache::LookupScript(Handle<String> source, |
| 106 Handle<Object> name, | 125 Handle<Object> name, |
| 107 int line_offset, | 126 int line_offset, |
| 108 int column_offset) { | 127 int column_offset) { |
| 109 Handle<JSFunction> result = Lookup(source, SCRIPT); | 128 Handle<JSFunction> result = Lookup(source, SCRIPT); |
| 110 if (result.is_null()) { | 129 if (result.is_null()) { |
| 111 Counters::compilation_cache_misses.Increment(); | 130 Counters::compilation_cache_misses.Increment(); |
| 112 } else if (HasOrigin(result, name, line_offset, column_offset)) { | 131 } else if (HasOrigin(result, name, line_offset, column_offset)) { |
| 113 Counters::compilation_cache_hits.Increment(); | 132 Counters::compilation_cache_hits.Increment(); |
| 114 } else { | 133 } else { |
| 115 result = Handle<JSFunction>::null(); | 134 result = Handle<JSFunction>::null(); |
| 116 Counters::compilation_cache_misses.Increment(); | 135 Counters::compilation_cache_misses.Increment(); |
| 117 } | 136 } |
| 118 return result; | 137 return result; |
| 119 } | 138 } |
| 120 | 139 |
| 121 | 140 |
| 122 Handle<JSFunction> CompilationCache::LookupEval(Handle<String> source, | 141 Handle<JSFunction> CompilationCache::LookupEval(Handle<String> source, |
| 142 Handle<Context> context, |
| 123 Entry entry) { | 143 Entry entry) { |
| 124 ASSERT(entry == EVAL_GLOBAL || entry == EVAL_CONTEXTUAL); | 144 ASSERT(entry == EVAL_GLOBAL || entry == EVAL_CONTEXTUAL); |
| 125 Handle<JSFunction> result = Lookup(source, entry); | 145 Handle<JSFunction> result = Lookup(source, context, entry); |
| 126 if (result.is_null()) { | 146 if (result.is_null()) { |
| 127 Counters::compilation_cache_misses.Increment(); | 147 Counters::compilation_cache_misses.Increment(); |
| 128 } else { | 148 } else { |
| 129 Counters::compilation_cache_hits.Increment(); | 149 Counters::compilation_cache_hits.Increment(); |
| 130 } | 150 } |
| 131 return result; | 151 return result; |
| 132 } | 152 } |
| 133 | 153 |
| 134 | 154 |
| 135 void CompilationCache::PutFunction(Handle<String> source, | 155 void CompilationCache::PutFunction(Handle<String> source, |
| 136 Entry entry, | 156 Entry entry, |
| 137 Handle<JSFunction> boilerplate) { | 157 Handle<JSFunction> boilerplate) { |
| 138 HandleScope scope; | 158 HandleScope scope; |
| 139 ASSERT(boilerplate->IsBoilerplate()); | 159 ASSERT(boilerplate->IsBoilerplate()); |
| 140 Handle<CompilationCacheTable> table = GetTable(entry); | 160 Handle<CompilationCacheTable> table = GetTable(entry); |
| 141 CALL_HEAP_FUNCTION_VOID(table->Put(*source, *boilerplate)); | 161 CALL_HEAP_FUNCTION_VOID(table->Put(*source, *boilerplate)); |
| 142 } | 162 } |
| 143 | 163 |
| 144 | 164 |
| 165 void CompilationCache::PutEvalFunction(Handle<String> source, |
| 166 Handle<Context> context, |
| 167 Entry entry, |
| 168 Handle<JSFunction> boilerplate) { |
| 169 HandleScope scope; |
| 170 ASSERT(boilerplate->IsBoilerplate()); |
| 171 Handle<CompilationCacheTable> table = GetTable(entry); |
| 172 CALL_HEAP_FUNCTION_VOID(table->PutEval(*source, *context, *boilerplate)); |
| 173 } |
| 174 |
| 175 |
| 145 Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, | 176 Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, |
| 146 JSRegExp::Flags flags) { | 177 JSRegExp::Flags flags) { |
| 147 Handle<CompilationCacheTable> table = GetTable(REGEXP); | 178 Handle<CompilationCacheTable> table = GetTable(REGEXP); |
| 148 Object* result = table->LookupRegExp(*source, flags); | 179 Object* result = table->LookupRegExp(*source, flags); |
| 149 if (result->IsFixedArray()) { | 180 if (result->IsFixedArray()) { |
| 150 Counters::regexp_cache_hits.Increment(); | 181 Counters::regexp_cache_hits.Increment(); |
| 151 return Handle<FixedArray>(FixedArray::cast(result)); | 182 return Handle<FixedArray>(FixedArray::cast(result)); |
| 152 } else { | 183 } else { |
| 153 Counters::regexp_cache_misses.Increment(); | 184 Counters::regexp_cache_misses.Increment(); |
| 154 return Handle<FixedArray>(); | 185 return Handle<FixedArray>(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 171 } | 202 } |
| 172 } | 203 } |
| 173 | 204 |
| 174 | 205 |
| 175 void CompilationCache::Iterate(ObjectVisitor* v) { | 206 void CompilationCache::Iterate(ObjectVisitor* v) { |
| 176 v->VisitPointers(&tables[0], &tables[NUMBER_OF_ENTRY_KINDS]); | 207 v->VisitPointers(&tables[0], &tables[NUMBER_OF_ENTRY_KINDS]); |
| 177 } | 208 } |
| 178 | 209 |
| 179 | 210 |
| 180 } } // namespace v8::internal | 211 } } // namespace v8::internal |
| OLD | NEW |