OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "bootstrapper.h" | 30 #include "bootstrapper.h" |
31 #include "codegen-inl.h" | 31 #include "codegen-inl.h" |
| 32 #include "compilation-cache.h" |
32 #include "compiler.h" | 33 #include "compiler.h" |
33 #include "debug.h" | 34 #include "debug.h" |
34 #include "scopes.h" | 35 #include "scopes.h" |
35 #include "rewriter.h" | 36 #include "rewriter.h" |
36 #include "usage-analyzer.h" | 37 #include "usage-analyzer.h" |
37 | 38 |
38 namespace v8 { namespace internal { | 39 namespace v8 { namespace internal { |
39 | 40 |
40 DEFINE_bool(strict, false, "strict error checking"); | 41 DEFINE_bool(strict, false, "strict error checking"); |
41 DEFINE_int(min_preparse_length, 1024, | 42 DEFINE_int(min_preparse_length, 1024, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 Handle<Object> script_name, | 164 Handle<Object> script_name, |
164 int line_offset, int column_offset, | 165 int line_offset, int column_offset, |
165 v8::Extension* extension, | 166 v8::Extension* extension, |
166 ScriptDataImpl* input_pre_data) { | 167 ScriptDataImpl* input_pre_data) { |
167 Counters::total_load_size.Increment(source->length()); | 168 Counters::total_load_size.Increment(source->length()); |
168 Counters::total_compile_size.Increment(source->length()); | 169 Counters::total_compile_size.Increment(source->length()); |
169 | 170 |
170 // The VM is in the COMPILER state until exiting this function. | 171 // The VM is in the COMPILER state until exiting this function. |
171 VMState state(COMPILER); | 172 VMState state(COMPILER); |
172 | 173 |
173 ScriptDataImpl* pre_data = input_pre_data; | 174 // Do a lookup in the compilation cache but not for extensions. |
174 if (pre_data == NULL && source->length() >= FLAG_min_preparse_length) { | 175 Handle<JSFunction> result; |
175 Access<SafeStringInputBuffer> buf(&safe_string_input_buffer); | 176 if (extension == NULL) { |
176 buf->Reset(source.location()); | 177 result = CompilationCache::LookupScript(source, |
177 pre_data = PreParse(buf.value(), extension); | 178 script_name, |
| 179 line_offset, |
| 180 column_offset); |
178 } | 181 } |
179 | 182 |
180 // Create a script object describing the script to be compiled. | 183 if (result.is_null()) { |
181 Handle<Script> script = Factory::NewScript(source); | 184 // No cache entry found. Do pre-parsing and compile the script. |
182 if (!script_name.is_null()) { | 185 ScriptDataImpl* pre_data = input_pre_data; |
183 script->set_name(*script_name); | 186 if (pre_data == NULL && source->length() >= FLAG_min_preparse_length) { |
184 script->set_line_offset(Smi::FromInt(line_offset)); | 187 Access<SafeStringInputBuffer> buf(&safe_string_input_buffer); |
185 script->set_column_offset(Smi::FromInt(column_offset)); | 188 buf->Reset(source.location()); |
| 189 pre_data = PreParse(buf.value(), extension); |
| 190 } |
| 191 |
| 192 // Create a script object describing the script to be compiled. |
| 193 Handle<Script> script = Factory::NewScript(source); |
| 194 if (!script_name.is_null()) { |
| 195 script->set_name(*script_name); |
| 196 script->set_line_offset(Smi::FromInt(line_offset)); |
| 197 script->set_column_offset(Smi::FromInt(column_offset)); |
| 198 } |
| 199 |
| 200 // Compile the function and add it to the cache. |
| 201 result = MakeFunction(true, false, script, extension, pre_data); |
| 202 if (extension == NULL && !result.is_null()) { |
| 203 CompilationCache::Associate(source, CompilationCache::SCRIPT, result); |
| 204 } |
| 205 |
| 206 // Get rid of the pre-parsing data (if necessary). |
| 207 if (input_pre_data == NULL && pre_data != NULL) { |
| 208 delete pre_data; |
| 209 } |
186 } | 210 } |
187 | 211 |
188 Handle<JSFunction> result = | |
189 MakeFunction(true, false, script, extension, pre_data); | |
190 | |
191 if (input_pre_data == NULL && pre_data != NULL) | |
192 delete pre_data; | |
193 | |
194 return result; | 212 return result; |
195 } | 213 } |
196 | 214 |
197 | 215 |
198 Handle<JSFunction> Compiler::CompileEval(bool is_global, | 216 Handle<JSFunction> Compiler::CompileEval(bool is_global, |
199 Handle<String> source) { | 217 Handle<String> source) { |
200 Counters::total_eval_size.Increment(source->length()); | 218 Counters::total_eval_size.Increment(source->length()); |
201 Counters::total_compile_size.Increment(source->length()); | 219 Counters::total_compile_size.Increment(source->length()); |
202 | 220 |
203 // The VM is in the COMPILER state until exiting this function. | 221 // The VM is in the COMPILER state until exiting this function. |
204 VMState state(COMPILER); | 222 VMState state(COMPILER); |
| 223 CompilationCache::Entry entry = is_global |
| 224 ? CompilationCache::EVAL_GLOBAL |
| 225 : CompilationCache::EVAL_CONTEXTUAL; |
205 | 226 |
206 // Create a script object describing the script to be compiled. | 227 // Do a lookup in the compilation cache; if the entry is not there, |
207 Handle<Script> script = Factory::NewScript(source); | 228 // invoke the compiler and add the result to the cache. |
208 return MakeFunction(is_global, true, script, NULL, NULL); | 229 Handle<JSFunction> result = CompilationCache::LookupEval(source, entry); |
| 230 if (result.is_null()) { |
| 231 // Create a script object describing the script to be compiled. |
| 232 Handle<Script> script = Factory::NewScript(source); |
| 233 result = MakeFunction(is_global, true, script, NULL, NULL); |
| 234 if (!result.is_null()) { |
| 235 CompilationCache::Associate(source, entry, result); |
| 236 } |
| 237 } |
| 238 return result; |
209 } | 239 } |
210 | 240 |
211 | 241 |
212 bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared) { | 242 bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared) { |
213 ZoneScope zone_scope(DELETE_ON_EXIT); | 243 ZoneScope zone_scope(DELETE_ON_EXIT); |
214 | 244 |
215 // The VM is in the COMPILER state until exiting this function. | 245 // The VM is in the COMPILER state until exiting this function. |
216 VMState state(COMPILER); | 246 VMState state(COMPILER); |
217 | 247 |
218 // Make sure we have an initial stack limit. | 248 // Make sure we have an initial stack limit. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // Set the expected number of properties for instances. | 294 // Set the expected number of properties for instances. |
265 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 295 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
266 | 296 |
267 // Check the function has compiled code. | 297 // Check the function has compiled code. |
268 ASSERT(shared->is_compiled()); | 298 ASSERT(shared->is_compiled()); |
269 return true; | 299 return true; |
270 } | 300 } |
271 | 301 |
272 | 302 |
273 } } // namespace v8::internal | 303 } } // namespace v8::internal |
OLD | NEW |