| 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 13 matching lines...) Expand all Loading... |
| 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 "compilation-cache.h" |
| 33 #include "compiler.h" | 33 #include "compiler.h" |
| 34 #include "data-flow.h" |
| 34 #include "debug.h" | 35 #include "debug.h" |
| 35 #include "fast-codegen.h" | 36 #include "fast-codegen.h" |
| 36 #include "full-codegen.h" | 37 #include "full-codegen.h" |
| 38 #include "liveedit.h" |
| 37 #include "oprofile-agent.h" | 39 #include "oprofile-agent.h" |
| 38 #include "rewriter.h" | 40 #include "rewriter.h" |
| 39 #include "scopes.h" | 41 #include "scopes.h" |
| 40 #include "usage-analyzer.h" | |
| 41 #include "liveedit.h" | |
| 42 | 42 |
| 43 namespace v8 { | 43 namespace v8 { |
| 44 namespace internal { | 44 namespace internal { |
| 45 | 45 |
| 46 | 46 |
| 47 static Handle<Code> MakeCode(Handle<Context> context, CompilationInfo* info) { | 47 static Handle<Code> MakeCode(Handle<Context> context, CompilationInfo* info) { |
| 48 FunctionLiteral* function = info->function(); | 48 FunctionLiteral* function = info->function(); |
| 49 ASSERT(function != NULL); | 49 ASSERT(function != NULL); |
| 50 // Rewrite the AST by introducing .result assignments where needed. | 50 // Rewrite the AST by introducing .result assignments where needed. |
| 51 if (!Rewriter::Process(function) || !AnalyzeVariableUsage(function)) { | 51 if (!Rewriter::Process(function)) { |
| 52 // Signal a stack overflow by returning a null handle. The stack | 52 // Signal a stack overflow by returning a null handle. The stack |
| 53 // overflow exception will be thrown by the caller. | 53 // overflow exception will be thrown by the caller. |
| 54 return Handle<Code>::null(); | 54 return Handle<Code>::null(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 { | 57 { |
| 58 // Compute top scope and allocate variables. For lazy compilation | 58 // Compute top scope and allocate variables. For lazy compilation |
| 59 // the top scope only contains the single lazily compiled function, | 59 // the top scope only contains the single lazily compiled function, |
| 60 // so this doesn't re-allocate variables repeatedly. | 60 // so this doesn't re-allocate variables repeatedly. |
| 61 HistogramTimerScope timer(&Counters::variable_allocation); | 61 HistogramTimerScope timer(&Counters::variable_allocation); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 72 } | 72 } |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 // Optimize the AST. | 75 // Optimize the AST. |
| 76 if (!Rewriter::Optimize(function)) { | 76 if (!Rewriter::Optimize(function)) { |
| 77 // Signal a stack overflow by returning a null handle. The stack | 77 // Signal a stack overflow by returning a null handle. The stack |
| 78 // overflow exception will be thrown by the caller. | 78 // overflow exception will be thrown by the caller. |
| 79 return Handle<Code>::null(); | 79 return Handle<Code>::null(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 if (FLAG_use_flow_graph) { |
| 83 FlowGraphBuilder builder; |
| 84 builder.Build(function); |
| 85 |
| 86 #ifdef DEBUG |
| 87 if (FLAG_print_graph_text) { |
| 88 builder.graph()->PrintText(builder.postorder()); |
| 89 } |
| 90 #endif |
| 91 } |
| 92 |
| 82 // Generate code and return it. Code generator selection is governed by | 93 // Generate code and return it. Code generator selection is governed by |
| 83 // which backends are enabled and whether the function is considered | 94 // which backends are enabled and whether the function is considered |
| 84 // run-once code or not: | 95 // run-once code or not: |
| 85 // | 96 // |
| 86 // --full-compiler enables the dedicated backend for code we expect to be | 97 // --full-compiler enables the dedicated backend for code we expect to be |
| 87 // run once | 98 // run once |
| 88 // --fast-compiler enables a speculative optimizing backend (for | 99 // --fast-compiler enables a speculative optimizing backend (for |
| 89 // non-run-once code) | 100 // non-run-once code) |
| 90 // | 101 // |
| 91 // The normal choice of backend can be overridden with the flags | 102 // The normal choice of backend can be overridden with the flags |
| (...skipping 18 matching lines...) Expand all Loading... |
| 110 checker.Check(info); | 121 checker.Check(info); |
| 111 if (checker.has_supported_syntax()) { | 122 if (checker.has_supported_syntax()) { |
| 112 return FastCodeGenerator::MakeCode(info); | 123 return FastCodeGenerator::MakeCode(info); |
| 113 } | 124 } |
| 114 } | 125 } |
| 115 | 126 |
| 116 return CodeGenerator::MakeCode(info); | 127 return CodeGenerator::MakeCode(info); |
| 117 } | 128 } |
| 118 | 129 |
| 119 | 130 |
| 131 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 132 Handle<Code> MakeCodeForLiveEdit(CompilationInfo* info) { |
| 133 Handle<Context> context = Handle<Context>::null(); |
| 134 return MakeCode(context, info); |
| 135 } |
| 136 #endif |
| 137 |
| 138 |
| 120 static Handle<JSFunction> MakeFunction(bool is_global, | 139 static Handle<JSFunction> MakeFunction(bool is_global, |
| 121 bool is_eval, | 140 bool is_eval, |
| 122 Compiler::ValidationState validate, | 141 Compiler::ValidationState validate, |
| 123 Handle<Script> script, | 142 Handle<Script> script, |
| 124 Handle<Context> context, | 143 Handle<Context> context, |
| 125 v8::Extension* extension, | 144 v8::Extension* extension, |
| 126 ScriptDataImpl* pre_data) { | 145 ScriptDataImpl* pre_data) { |
| 127 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 146 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
| 128 | 147 |
| 129 PostponeInterruptsScope postpone; | 148 PostponeInterruptsScope postpone; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | 236 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
| 218 Compiler::SetFunctionInfo(fun, lit, true, script); | 237 Compiler::SetFunctionInfo(fun, lit, true, script); |
| 219 | 238 |
| 220 // Hint to the runtime system used when allocating space for initial | 239 // Hint to the runtime system used when allocating space for initial |
| 221 // property space by setting the expected number of properties for | 240 // property space by setting the expected number of properties for |
| 222 // the instances of the function. | 241 // the instances of the function. |
| 223 SetExpectedNofPropertiesFromEstimate(fun, lit->expected_property_count()); | 242 SetExpectedNofPropertiesFromEstimate(fun, lit->expected_property_count()); |
| 224 | 243 |
| 225 #ifdef ENABLE_DEBUGGER_SUPPORT | 244 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 226 // Notify debugger | 245 // Notify debugger |
| 227 Debugger::OnAfterCompile(script, fun); | 246 Debugger::OnAfterCompile(script, Debugger::NO_AFTER_COMPILE_FLAGS); |
| 228 #endif | 247 #endif |
| 229 | 248 |
| 230 return fun; | 249 return fun; |
| 231 } | 250 } |
| 232 | 251 |
| 233 | 252 |
| 234 static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; | 253 static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; |
| 235 | 254 |
| 236 | 255 |
| 237 Handle<JSFunction> Compiler::Compile(Handle<String> source, | 256 Handle<JSFunction> Compiler::Compile(Handle<String> source, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 Handle<Code> code; | 460 Handle<Code> code; |
| 442 if (FLAG_lazy && allow_lazy) { | 461 if (FLAG_lazy && allow_lazy) { |
| 443 code = ComputeLazyCompile(literal->num_parameters()); | 462 code = ComputeLazyCompile(literal->num_parameters()); |
| 444 } else { | 463 } else { |
| 445 // The bodies of function literals have not yet been visited by | 464 // The bodies of function literals have not yet been visited by |
| 446 // the AST optimizer/analyzer. | 465 // the AST optimizer/analyzer. |
| 447 if (!Rewriter::Optimize(literal)) { | 466 if (!Rewriter::Optimize(literal)) { |
| 448 return Handle<JSFunction>::null(); | 467 return Handle<JSFunction>::null(); |
| 449 } | 468 } |
| 450 | 469 |
| 470 if (FLAG_use_flow_graph) { |
| 471 FlowGraphBuilder builder; |
| 472 builder.Build(literal); |
| 473 |
| 474 #ifdef DEBUG |
| 475 if (FLAG_print_graph_text) { |
| 476 builder.graph()->PrintText(builder.postorder()); |
| 477 } |
| 478 #endif |
| 479 } |
| 480 |
| 451 // Generate code and return it. The way that the compilation mode | 481 // Generate code and return it. The way that the compilation mode |
| 452 // is controlled by the command-line flags is described in | 482 // is controlled by the command-line flags is described in |
| 453 // the static helper function MakeCode. | 483 // the static helper function MakeCode. |
| 454 CompilationInfo info(literal, script, false); | 484 CompilationInfo info(literal, script, false); |
| 455 | 485 |
| 456 CHECK(!FLAG_always_full_compiler || !FLAG_always_fast_compiler); | 486 CHECK(!FLAG_always_full_compiler || !FLAG_always_fast_compiler); |
| 457 bool is_run_once = literal->try_full_codegen(); | 487 bool is_run_once = literal->try_full_codegen(); |
| 458 bool is_compiled = false; | 488 bool is_compiled = false; |
| 459 if (FLAG_always_full_compiler || (FLAG_full_compiler && is_run_once)) { | 489 if (FLAG_always_full_compiler || (FLAG_full_compiler && is_run_once)) { |
| 460 FullCodeGenSyntaxChecker checker; | 490 FullCodeGenSyntaxChecker checker; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 LOG(CodeCreateEvent(tag, *code, *func_name)); | 597 LOG(CodeCreateEvent(tag, *code, *func_name)); |
| 568 OProfileAgent::CreateNativeCodeRegion(*func_name, | 598 OProfileAgent::CreateNativeCodeRegion(*func_name, |
| 569 code->instruction_start(), | 599 code->instruction_start(), |
| 570 code->instruction_size()); | 600 code->instruction_size()); |
| 571 } | 601 } |
| 572 } | 602 } |
| 573 } | 603 } |
| 574 #endif | 604 #endif |
| 575 | 605 |
| 576 } } // namespace v8::internal | 606 } } // namespace v8::internal |
| OLD | NEW |