| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler.h" | 5 #include "src/compiler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/asmjs/asm-js.h" | 10 #include "src/asmjs/asm-js.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "src/debug/debug.h" | 21 #include "src/debug/debug.h" |
| 22 #include "src/debug/liveedit.h" | 22 #include "src/debug/liveedit.h" |
| 23 #include "src/frames-inl.h" | 23 #include "src/frames-inl.h" |
| 24 #include "src/full-codegen/full-codegen.h" | 24 #include "src/full-codegen/full-codegen.h" |
| 25 #include "src/globals.h" | 25 #include "src/globals.h" |
| 26 #include "src/heap/heap.h" | 26 #include "src/heap/heap.h" |
| 27 #include "src/interpreter/interpreter.h" | 27 #include "src/interpreter/interpreter.h" |
| 28 #include "src/isolate-inl.h" | 28 #include "src/isolate-inl.h" |
| 29 #include "src/log-inl.h" | 29 #include "src/log-inl.h" |
| 30 #include "src/messages.h" | 30 #include "src/messages.h" |
| 31 #include "src/parsing/parser.h" | 31 #include "src/parsing/parsing.h" |
| 32 #include "src/parsing/rewriter.h" | 32 #include "src/parsing/rewriter.h" |
| 33 #include "src/parsing/scanner-character-streams.h" | 33 #include "src/parsing/scanner-character-streams.h" |
| 34 #include "src/runtime-profiler.h" | 34 #include "src/runtime-profiler.h" |
| 35 #include "src/snapshot/code-serializer.h" | 35 #include "src/snapshot/code-serializer.h" |
| 36 #include "src/vm-state-inl.h" | 36 #include "src/vm-state-inl.h" |
| 37 | 37 |
| 38 namespace v8 { | 38 namespace v8 { |
| 39 namespace internal { | 39 namespace internal { |
| 40 | 40 |
| 41 | 41 |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 return false; | 458 return false; |
| 459 } | 459 } |
| 460 return true; | 460 return true; |
| 461 } | 461 } |
| 462 | 462 |
| 463 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { | 463 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { |
| 464 VMState<COMPILER> state(info->isolate()); | 464 VMState<COMPILER> state(info->isolate()); |
| 465 PostponeInterruptsScope postpone(info->isolate()); | 465 PostponeInterruptsScope postpone(info->isolate()); |
| 466 | 466 |
| 467 // Parse and update CompilationInfo with the results. | 467 // Parse and update CompilationInfo with the results. |
| 468 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); | 468 if (!parsing::ParseAny(info->parse_info())) return MaybeHandle<Code>(); |
| 469 DCHECK_EQ(info->shared_info()->language_mode(), | 469 DCHECK_EQ(info->shared_info()->language_mode(), |
| 470 info->literal()->language_mode()); | 470 info->literal()->language_mode()); |
| 471 | 471 |
| 472 // Compile either unoptimized code or bytecode for the interpreter. | 472 // Compile either unoptimized code or bytecode for the interpreter. |
| 473 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 473 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
| 474 | 474 |
| 475 // Record the function compilation event. | 475 // Record the function compilation event. |
| 476 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 476 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
| 477 | 477 |
| 478 return info->code(); | 478 return info->code(); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 } | 828 } |
| 829 DCHECK(!IsResumableFunction(function->shared()->kind())); | 829 DCHECK(!IsResumableFunction(function->shared()->kind())); |
| 830 | 830 |
| 831 if (FLAG_trace_opt) { | 831 if (FLAG_trace_opt) { |
| 832 OFStream os(stdout); | 832 OFStream os(stdout); |
| 833 os << "[switching method " << Brief(*function) << " to baseline code]" | 833 os << "[switching method " << Brief(*function) << " to baseline code]" |
| 834 << std::endl; | 834 << std::endl; |
| 835 } | 835 } |
| 836 | 836 |
| 837 // Parse and update CompilationInfo with the results. | 837 // Parse and update CompilationInfo with the results. |
| 838 if (!Parser::ParseStatic(info.parse_info())) return MaybeHandle<Code>(); | 838 if (!parsing::ParseFunction(info.parse_info())) return MaybeHandle<Code>(); |
| 839 Handle<SharedFunctionInfo> shared = info.shared_info(); | 839 Handle<SharedFunctionInfo> shared = info.shared_info(); |
| 840 DCHECK_EQ(shared->language_mode(), info.literal()->language_mode()); | 840 DCHECK_EQ(shared->language_mode(), info.literal()->language_mode()); |
| 841 | 841 |
| 842 // Compile baseline code using the full code generator. | 842 // Compile baseline code using the full code generator. |
| 843 if (!Compiler::Analyze(info.parse_info()) || | 843 if (!Compiler::Analyze(info.parse_info()) || |
| 844 !FullCodeGenerator::MakeCode(&info)) { | 844 !FullCodeGenerator::MakeCode(&info)) { |
| 845 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 845 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
| 846 return MaybeHandle<Code>(); | 846 return MaybeHandle<Code>(); |
| 847 } | 847 } |
| 848 | 848 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 ParseInfo* parse_info = info->parse_info(); | 958 ParseInfo* parse_info = info->parse_info(); |
| 959 Handle<Script> script = parse_info->script(); | 959 Handle<Script> script = parse_info->script(); |
| 960 | 960 |
| 961 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 961 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
| 962 FixedArray* array = isolate->native_context()->embedder_data(); | 962 FixedArray* array = isolate->native_context()->embedder_data(); |
| 963 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); | 963 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); |
| 964 | 964 |
| 965 Handle<SharedFunctionInfo> result; | 965 Handle<SharedFunctionInfo> result; |
| 966 | 966 |
| 967 { VMState<COMPILER> state(info->isolate()); | 967 { VMState<COMPILER> state(info->isolate()); |
| 968 if (parse_info->literal() == nullptr && !Parser::ParseStatic(parse_info)) { | 968 if (parse_info->literal() == nullptr && |
| 969 !parsing::ParseProgram(parse_info)) { |
| 969 return Handle<SharedFunctionInfo>::null(); | 970 return Handle<SharedFunctionInfo>::null(); |
| 970 } | 971 } |
| 971 | 972 |
| 972 FunctionLiteral* lit = parse_info->literal(); | 973 FunctionLiteral* lit = parse_info->literal(); |
| 973 | 974 |
| 974 // Measure how long it takes to do the compilation; only take the | 975 // Measure how long it takes to do the compilation; only take the |
| 975 // rest of the function into account to avoid overlap with the | 976 // rest of the function into account to avoid overlap with the |
| 976 // parsing statistics. | 977 // parsing statistics. |
| 977 RuntimeCallTimerScope runtimeTimer( | 978 RuntimeCallTimerScope runtimeTimer( |
| 978 isolate, parse_info->is_eval() ? &RuntimeCallStats::CompileEval | 979 isolate, parse_info->is_eval() ? &RuntimeCallStats::CompileEval |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 bool Compiler::Analyze(ParseInfo* info) { | 1024 bool Compiler::Analyze(ParseInfo* info) { |
| 1024 DCHECK_NOT_NULL(info->literal()); | 1025 DCHECK_NOT_NULL(info->literal()); |
| 1025 if (!Rewriter::Rewrite(info)) return false; | 1026 if (!Rewriter::Rewrite(info)) return false; |
| 1026 DeclarationScope::Analyze(info, AnalyzeMode::kRegular); | 1027 DeclarationScope::Analyze(info, AnalyzeMode::kRegular); |
| 1027 if (!Renumber(info)) return false; | 1028 if (!Renumber(info)) return false; |
| 1028 DCHECK_NOT_NULL(info->scope()); | 1029 DCHECK_NOT_NULL(info->scope()); |
| 1029 return true; | 1030 return true; |
| 1030 } | 1031 } |
| 1031 | 1032 |
| 1032 bool Compiler::ParseAndAnalyze(ParseInfo* info) { | 1033 bool Compiler::ParseAndAnalyze(ParseInfo* info) { |
| 1033 if (!Parser::ParseStatic(info)) return false; | 1034 if (!parsing::ParseAny(info)) return false; |
| 1034 if (!Compiler::Analyze(info)) return false; | 1035 if (!Compiler::Analyze(info)) return false; |
| 1035 DCHECK_NOT_NULL(info->literal()); | 1036 DCHECK_NOT_NULL(info->literal()); |
| 1036 DCHECK_NOT_NULL(info->scope()); | 1037 DCHECK_NOT_NULL(info->scope()); |
| 1037 return true; | 1038 return true; |
| 1038 } | 1039 } |
| 1039 | 1040 |
| 1040 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { | 1041 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { |
| 1041 if (function->is_compiled()) return true; | 1042 if (function->is_compiled()) return true; |
| 1042 Isolate* isolate = function->GetIsolate(); | 1043 Isolate* isolate = function->GetIsolate(); |
| 1043 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1044 DCHECK(AllowCompilation::IsAllowed(isolate)); |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 DCHECK(shared->is_compiled()); | 1721 DCHECK(shared->is_compiled()); |
| 1721 function->set_literals(cached.literals); | 1722 function->set_literals(cached.literals); |
| 1722 } else if (shared->is_compiled()) { | 1723 } else if (shared->is_compiled()) { |
| 1723 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1724 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
| 1724 JSFunction::EnsureLiterals(function); | 1725 JSFunction::EnsureLiterals(function); |
| 1725 } | 1726 } |
| 1726 } | 1727 } |
| 1727 | 1728 |
| 1728 } // namespace internal | 1729 } // namespace internal |
| 1729 } // namespace v8 | 1730 } // namespace v8 |
| OLD | NEW |