| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 23 matching lines...) Expand all Loading... |
| 34 #include "debug.h" | 34 #include "debug.h" |
| 35 #include "fast-codegen.h" | 35 #include "fast-codegen.h" |
| 36 #include "oprofile-agent.h" | 36 #include "oprofile-agent.h" |
| 37 #include "rewriter.h" | 37 #include "rewriter.h" |
| 38 #include "scopes.h" | 38 #include "scopes.h" |
| 39 #include "usage-analyzer.h" | 39 #include "usage-analyzer.h" |
| 40 | 40 |
| 41 namespace v8 { | 41 namespace v8 { |
| 42 namespace internal { | 42 namespace internal { |
| 43 | 43 |
| 44 CompilerData::CompilerData() {} |
| 44 | 45 |
| 45 class CodeGenSelector: public AstVisitor { | 46 class CodeGenSelector: public AstVisitor { |
| 46 public: | 47 public: |
| 47 enum CodeGenTag { NORMAL, FAST }; | 48 enum CodeGenTag { NORMAL, FAST }; |
| 48 | 49 |
| 49 CodeGenSelector() | 50 CodeGenSelector() |
| 50 : has_supported_syntax_(true), | 51 : has_supported_syntax_(true), |
| 51 context_(Expression::kUninitialized) { | 52 context_(Expression::kUninitialized) { |
| 52 } | 53 } |
| 53 | 54 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 if (!Rewriter::Process(literal) || !AnalyzeVariableUsage(literal)) { | 92 if (!Rewriter::Process(literal) || !AnalyzeVariableUsage(literal)) { |
| 92 // Signal a stack overflow by returning a null handle. The stack | 93 // Signal a stack overflow by returning a null handle. The stack |
| 93 // overflow exception will be thrown by the caller. | 94 // overflow exception will be thrown by the caller. |
| 94 return Handle<Code>::null(); | 95 return Handle<Code>::null(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 { | 98 { |
| 98 // Compute top scope and allocate variables. For lazy compilation | 99 // Compute top scope and allocate variables. For lazy compilation |
| 99 // the top scope only contains the single lazily compiled function, | 100 // the top scope only contains the single lazily compiled function, |
| 100 // so this doesn't re-allocate variables repeatedly. | 101 // so this doesn't re-allocate variables repeatedly. |
| 101 HistogramTimerScope timer(&Counters::variable_allocation); | 102 HistogramTimerScope timer(&COUNTER(variable_allocation)); |
| 102 Scope* top = literal->scope(); | 103 Scope* top = literal->scope(); |
| 103 while (top->outer_scope() != NULL) top = top->outer_scope(); | 104 while (top->outer_scope() != NULL) top = top->outer_scope(); |
| 104 top->AllocateVariables(context); | 105 top->AllocateVariables(context); |
| 105 } | 106 } |
| 106 | 107 |
| 107 #ifdef DEBUG | 108 #ifdef DEBUG |
| 108 if (Bootstrapper::IsActive() ? | 109 if (Bootstrapper::IsActive() ? |
| 109 FLAG_print_builtin_scopes : | 110 FLAG_print_builtin_scopes : |
| 110 FLAG_print_scopes) { | 111 FLAG_print_scopes) { |
| 111 literal->scope()->Print(); | 112 literal->scope()->Print(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 SetElement(args, 0, source); | 214 SetElement(args, 0, source); |
| 214 Handle<Object> result = Factory::NewSyntaxError("invalid_json", args); | 215 Handle<Object> result = Factory::NewSyntaxError("invalid_json", args); |
| 215 Top::Throw(*result, NULL); | 216 Top::Throw(*result, NULL); |
| 216 return Handle<JSFunction>::null(); | 217 return Handle<JSFunction>::null(); |
| 217 } | 218 } |
| 218 | 219 |
| 219 // Measure how long it takes to do the compilation; only take the | 220 // Measure how long it takes to do the compilation; only take the |
| 220 // rest of the function into account to avoid overlap with the | 221 // rest of the function into account to avoid overlap with the |
| 221 // parsing statistics. | 222 // parsing statistics. |
| 222 HistogramTimer* rate = is_eval | 223 HistogramTimer* rate = is_eval |
| 223 ? &Counters::compile_eval | 224 ? &COUNTER(compile_eval) |
| 224 : &Counters::compile; | 225 : &COUNTER(compile); |
| 225 HistogramTimerScope timer(rate); | 226 HistogramTimerScope timer(rate); |
| 226 | 227 |
| 227 // Compile the code. | 228 // Compile the code. |
| 228 Handle<Code> code = MakeCode(lit, script, context, is_eval, | 229 Handle<Code> code = MakeCode(lit, script, context, is_eval, |
| 229 Handle<SharedFunctionInfo>::null()); | 230 Handle<SharedFunctionInfo>::null()); |
| 230 | 231 |
| 231 // Check for stack-overflow exceptions. | 232 // Check for stack-overflow exceptions. |
| 232 if (code.is_null()) { | 233 if (code.is_null()) { |
| 233 Top::StackOverflow(); | 234 Top::StackOverflow(); |
| 234 return Handle<JSFunction>::null(); | 235 return Handle<JSFunction>::null(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 SetExpectedNofPropertiesFromEstimate(fun, lit->expected_property_count()); | 272 SetExpectedNofPropertiesFromEstimate(fun, lit->expected_property_count()); |
| 272 | 273 |
| 273 #ifdef ENABLE_DEBUGGER_SUPPORT | 274 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 274 // Notify debugger | 275 // Notify debugger |
| 275 Debugger::OnAfterCompile(script, fun); | 276 Debugger::OnAfterCompile(script, fun); |
| 276 #endif | 277 #endif |
| 277 | 278 |
| 278 return fun; | 279 return fun; |
| 279 } | 280 } |
| 280 | 281 |
| 281 | |
| 282 static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; | |
| 283 | |
| 284 | |
| 285 Handle<JSFunction> Compiler::Compile(Handle<String> source, | 282 Handle<JSFunction> Compiler::Compile(Handle<String> source, |
| 286 Handle<Object> script_name, | 283 Handle<Object> script_name, |
| 287 int line_offset, int column_offset, | 284 int line_offset, int column_offset, |
| 288 v8::Extension* extension, | 285 v8::Extension* extension, |
| 289 ScriptDataImpl* input_pre_data) { | 286 ScriptDataImpl* input_pre_data) { |
| 290 int source_length = source->length(); | 287 int source_length = source->length(); |
| 291 Counters::total_load_size.Increment(source_length); | 288 INCREMENT_COUNTER(total_load_size, source_length); |
| 292 Counters::total_compile_size.Increment(source_length); | 289 INCREMENT_COUNTER(total_compile_size, source_length); |
| 293 | 290 |
| 294 // The VM is in the COMPILER state until exiting this function. | 291 // The VM is in the COMPILER state until exiting this function. |
| 295 VMState state(COMPILER); | 292 VMState state(COMPILER); |
| 296 | 293 |
| 297 // Do a lookup in the compilation cache but not for extensions. | 294 // Do a lookup in the compilation cache but not for extensions. |
| 298 Handle<JSFunction> result; | 295 Handle<JSFunction> result; |
| 299 if (extension == NULL) { | 296 if (extension == NULL) { |
| 300 result = CompilationCache::LookupScript(source, | 297 result = CompilationCache::LookupScript(source, |
| 301 script_name, | 298 script_name, |
| 302 line_offset, | 299 line_offset, |
| 303 column_offset); | 300 column_offset); |
| 304 } | 301 } |
| 305 | 302 |
| 306 if (result.is_null()) { | 303 if (result.is_null()) { |
| 307 // No cache entry found. Do pre-parsing and compile the script. | 304 // No cache entry found. Do pre-parsing and compile the script. |
| 308 ScriptDataImpl* pre_data = input_pre_data; | 305 ScriptDataImpl* pre_data = input_pre_data; |
| 309 if (pre_data == NULL && source_length >= FLAG_min_preparse_length) { | 306 if (pre_data == NULL && source_length >= FLAG_min_preparse_length) { |
| 310 Access<SafeStringInputBuffer> buf(&safe_string_input_buffer); | 307 Access<SafeStringInputBuffer> buf( |
| 308 &v8_context()->compiler_data_.safe_string_input_buffer_); |
| 311 buf->Reset(source.location()); | 309 buf->Reset(source.location()); |
| 312 pre_data = PreParse(source, buf.value(), extension); | 310 pre_data = PreParse(source, buf.value(), extension); |
| 313 } | 311 } |
| 314 | 312 |
| 315 // Create a script object describing the script to be compiled. | 313 // Create a script object describing the script to be compiled. |
| 316 Handle<Script> script = Factory::NewScript(source); | 314 Handle<Script> script = Factory::NewScript(source); |
| 317 if (!script_name.is_null()) { | 315 if (!script_name.is_null()) { |
| 318 script->set_name(*script_name); | 316 script->set_name(*script_name); |
| 319 script->set_line_offset(Smi::FromInt(line_offset)); | 317 script->set_line_offset(Smi::FromInt(line_offset)); |
| 320 script->set_column_offset(Smi::FromInt(column_offset)); | 318 script->set_column_offset(Smi::FromInt(column_offset)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 345 | 343 |
| 346 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, | 344 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, |
| 347 Handle<Context> context, | 345 Handle<Context> context, |
| 348 bool is_global, | 346 bool is_global, |
| 349 ValidationState validate) { | 347 ValidationState validate) { |
| 350 // Note that if validation is required then no path through this | 348 // Note that if validation is required then no path through this |
| 351 // function is allowed to return a value without validating that | 349 // function is allowed to return a value without validating that |
| 352 // the input is legal json. | 350 // the input is legal json. |
| 353 | 351 |
| 354 int source_length = source->length(); | 352 int source_length = source->length(); |
| 355 Counters::total_eval_size.Increment(source_length); | 353 INCREMENT_COUNTER(total_eval_size, source_length); |
| 356 Counters::total_compile_size.Increment(source_length); | 354 INCREMENT_COUNTER(total_compile_size, source_length); |
| 357 | 355 |
| 358 // The VM is in the COMPILER state until exiting this function. | 356 // The VM is in the COMPILER state until exiting this function. |
| 359 VMState state(COMPILER); | 357 VMState state(COMPILER); |
| 360 | 358 |
| 361 // Do a lookup in the compilation cache; if the entry is not there, | 359 // Do a lookup in the compilation cache; if the entry is not there, |
| 362 // invoke the compiler and add the result to the cache. If we're | 360 // invoke the compiler and add the result to the cache. If we're |
| 363 // evaluating json we bypass the cache since we can't be sure a | 361 // evaluating json we bypass the cache since we can't be sure a |
| 364 // potential value in the cache has been validated. | 362 // potential value in the cache has been validated. |
| 365 Handle<JSFunction> result; | 363 Handle<JSFunction> result; |
| 366 if (validate == DONT_VALIDATE_JSON) | 364 if (validate == DONT_VALIDATE_JSON) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 396 | 394 |
| 397 PostponeInterruptsScope postpone; | 395 PostponeInterruptsScope postpone; |
| 398 | 396 |
| 399 // Compute name, source code and script data. | 397 // Compute name, source code and script data. |
| 400 Handle<String> name(String::cast(shared->name())); | 398 Handle<String> name(String::cast(shared->name())); |
| 401 Handle<Script> script(Script::cast(shared->script())); | 399 Handle<Script> script(Script::cast(shared->script())); |
| 402 | 400 |
| 403 int start_position = shared->start_position(); | 401 int start_position = shared->start_position(); |
| 404 int end_position = shared->end_position(); | 402 int end_position = shared->end_position(); |
| 405 bool is_expression = shared->is_expression(); | 403 bool is_expression = shared->is_expression(); |
| 406 Counters::total_compile_size.Increment(end_position - start_position); | 404 INCREMENT_COUNTER(total_compile_size, end_position - start_position); |
| 407 | 405 |
| 408 // Generate the AST for the lazily compiled function. The AST may be | 406 // Generate the AST for the lazily compiled function. The AST may be |
| 409 // NULL in case of parser stack overflow. | 407 // NULL in case of parser stack overflow. |
| 410 FunctionLiteral* lit = MakeLazyAST(script, name, | 408 FunctionLiteral* lit = MakeLazyAST(script, name, |
| 411 start_position, | 409 start_position, |
| 412 end_position, | 410 end_position, |
| 413 is_expression); | 411 is_expression); |
| 414 | 412 |
| 415 // Check for parse errors. | 413 // Check for parse errors. |
| 416 if (lit == NULL) { | 414 if (lit == NULL) { |
| 417 ASSERT(Top::has_pending_exception()); | 415 ASSERT(Top::has_pending_exception()); |
| 418 return false; | 416 return false; |
| 419 } | 417 } |
| 420 | 418 |
| 421 // Update the loop nesting in the function literal. | 419 // Update the loop nesting in the function literal. |
| 422 lit->set_loop_nesting(loop_nesting); | 420 lit->set_loop_nesting(loop_nesting); |
| 423 | 421 |
| 424 // Measure how long it takes to do the lazy compilation; only take | 422 // Measure how long it takes to do the lazy compilation; only take |
| 425 // the rest of the function into account to avoid overlap with the | 423 // the rest of the function into account to avoid overlap with the |
| 426 // lazy parsing statistics. | 424 // lazy parsing statistics. |
| 427 HistogramTimerScope timer(&Counters::compile_lazy); | 425 HistogramTimerScope timer(&COUNTER(compile_lazy)); |
| 428 | 426 |
| 429 // Compile the code. | 427 // Compile the code. |
| 430 Handle<Code> code = MakeCode(lit, script, Handle<Context>::null(), false, | 428 Handle<Code> code = MakeCode(lit, script, Handle<Context>::null(), false, |
| 431 shared); | 429 shared); |
| 432 | 430 |
| 433 // Check for stack-overflow exception. | 431 // Check for stack-overflow exception. |
| 434 if (code.is_null()) { | 432 if (code.is_null()) { |
| 435 Top::StackOverflow(); | 433 Top::StackOverflow(); |
| 436 return false; | 434 return false; |
| 437 } | 435 } |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 | 1110 |
| 1113 void CodeGenSelector::VisitThisFunction(ThisFunction* expr) { | 1111 void CodeGenSelector::VisitThisFunction(ThisFunction* expr) { |
| 1114 BAILOUT("ThisFunction"); | 1112 BAILOUT("ThisFunction"); |
| 1115 } | 1113 } |
| 1116 | 1114 |
| 1117 #undef BAILOUT | 1115 #undef BAILOUT |
| 1118 #undef CHECK_BAILOUT | 1116 #undef CHECK_BAILOUT |
| 1119 | 1117 |
| 1120 | 1118 |
| 1121 } } // namespace v8::internal | 1119 } } // namespace v8::internal |
| OLD | NEW |