| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 | 8 |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 DCHECK(!function->is_compiled()); | 707 DCHECK(!function->is_compiled()); |
| 708 if (function->shared()->is_compiled()) { | 708 if (function->shared()->is_compiled()) { |
| 709 return Handle<Code>(function->shared()->code()); | 709 return Handle<Code>(function->shared()->code()); |
| 710 } | 710 } |
| 711 | 711 |
| 712 CompilationInfoWithZone info(function); | 712 CompilationInfoWithZone info(function); |
| 713 Handle<Code> result; | 713 Handle<Code> result; |
| 714 ASSIGN_RETURN_ON_EXCEPTION(info.isolate(), result, | 714 ASSIGN_RETURN_ON_EXCEPTION(info.isolate(), result, |
| 715 GetUnoptimizedCodeCommon(&info), | 715 GetUnoptimizedCodeCommon(&info), |
| 716 Code); | 716 Code); |
| 717 return result; |
| 718 } |
| 719 |
| 720 |
| 721 MaybeHandle<Code> Compiler::GetLazyCode(Handle<JSFunction> function) { |
| 722 DCHECK(!function->GetIsolate()->has_pending_exception()); |
| 723 DCHECK(!function->is_compiled()); |
| 724 if (function->shared()->is_compiled()) { |
| 725 return Handle<Code>(function->shared()->code()); |
| 726 } |
| 727 |
| 728 CompilationInfoWithZone info(function); |
| 729 Handle<Code> result; |
| 730 ASSIGN_RETURN_ON_EXCEPTION(info.isolate(), result, |
| 731 GetUnoptimizedCodeCommon(&info), Code); |
| 717 | 732 |
| 718 if (FLAG_always_opt && | 733 if (FLAG_always_opt && |
| 719 info.isolate()->use_crankshaft() && | 734 info.isolate()->use_crankshaft() && |
| 720 !info.shared_info()->optimization_disabled() && | 735 !info.shared_info()->optimization_disabled() && |
| 721 !info.isolate()->DebuggerHasBreakPoints()) { | 736 !info.isolate()->DebuggerHasBreakPoints()) { |
| 722 Handle<Code> opt_code; | 737 Handle<Code> opt_code; |
| 723 if (Compiler::GetOptimizedCode( | 738 if (Compiler::GetOptimizedCode( |
| 724 function, result, | 739 function, result, |
| 725 Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) { | 740 Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) { |
| 726 result = opt_code; | 741 result = opt_code; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 737 DCHECK(!shared->is_compiled()); | 752 DCHECK(!shared->is_compiled()); |
| 738 | 753 |
| 739 CompilationInfoWithZone info(shared); | 754 CompilationInfoWithZone info(shared); |
| 740 return GetUnoptimizedCodeCommon(&info); | 755 return GetUnoptimizedCodeCommon(&info); |
| 741 } | 756 } |
| 742 | 757 |
| 743 | 758 |
| 744 bool Compiler::EnsureCompiled(Handle<JSFunction> function, | 759 bool Compiler::EnsureCompiled(Handle<JSFunction> function, |
| 745 ClearExceptionFlag flag) { | 760 ClearExceptionFlag flag) { |
| 746 if (function->is_compiled()) return true; | 761 if (function->is_compiled()) return true; |
| 747 MaybeHandle<Code> maybe_code = Compiler::GetUnoptimizedCode(function); | 762 MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function); |
| 748 Handle<Code> code; | 763 Handle<Code> code; |
| 749 if (!maybe_code.ToHandle(&code)) { | 764 if (!maybe_code.ToHandle(&code)) { |
| 750 if (flag == CLEAR_EXCEPTION) { | 765 if (flag == CLEAR_EXCEPTION) { |
| 751 function->GetIsolate()->clear_pending_exception(); | 766 function->GetIsolate()->clear_pending_exception(); |
| 752 } | 767 } |
| 753 return false; | 768 return false; |
| 754 } | 769 } |
| 755 function->ReplaceCode(*code); | 770 function->ReplaceCode(*code); |
| 756 DCHECK(function->is_compiled()); | 771 DCHECK(function->is_compiled()); |
| 757 return true; | 772 return true; |
| 758 } | 773 } |
| 759 | 774 |
| 760 | 775 |
| 761 // Compile full code for debugging. This code will have debug break slots | 776 // Compile full code for debugging. This code will have debug break slots |
| 762 // and deoptimization information. Deoptimization information is required | 777 // and deoptimization information. Deoptimization information is required |
| 763 // in case that an optimized version of this function is still activated on | 778 // in case that an optimized version of this function is still activated on |
| 764 // the stack. It will also make sure that the full code is compiled with | 779 // the stack. It will also make sure that the full code is compiled with |
| 765 // the same flags as the previous version, that is flags which can change | 780 // the same flags as the previous version, that is flags which can change |
| 766 // the code generated. The current method of mapping from already compiled | 781 // the code generated. The current method of mapping from already compiled |
| 767 // full code without debug break slots to full code with debug break slots | 782 // full code without debug break slots to full code with debug break slots |
| 768 // depends on the generated code is otherwise exactly the same. | 783 // depends on the generated code is otherwise exactly the same. |
| 769 // If compilation fails, just keep the existing code. | 784 // If compilation fails, just keep the existing code. |
| 770 MaybeHandle<Code> Compiler::GetCodeForDebugging(Handle<JSFunction> function) { | 785 MaybeHandle<Code> Compiler::GetDebugCode(Handle<JSFunction> function) { |
| 771 CompilationInfoWithZone info(function); | 786 CompilationInfoWithZone info(function); |
| 772 Isolate* isolate = info.isolate(); | 787 Isolate* isolate = info.isolate(); |
| 773 VMState<COMPILER> state(isolate); | 788 VMState<COMPILER> state(isolate); |
| 774 | 789 |
| 775 info.MarkAsDebug(); | 790 info.MarkAsDebug(); |
| 776 | 791 |
| 777 DCHECK(!isolate->has_pending_exception()); | 792 DCHECK(!isolate->has_pending_exception()); |
| 778 Handle<Code> old_code(function->shared()->code()); | 793 Handle<Code> old_code(function->shared()->code()); |
| 779 DCHECK(old_code->kind() == Code::FUNCTION); | 794 DCHECK(old_code->kind() == Code::FUNCTION); |
| 780 DCHECK(!old_code->has_debug_break_slots()); | 795 DCHECK(!old_code->has_debug_break_slots()); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 // aggressive about lazy compilation, because it might trigger compilation | 1108 // aggressive about lazy compilation, because it might trigger compilation |
| 1094 // of functions without an outer context when setting a breakpoint through | 1109 // of functions without an outer context when setting a breakpoint through |
| 1095 // Debug::FindSharedFunctionInfoInScript. | 1110 // Debug::FindSharedFunctionInfoInScript. |
| 1096 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); | 1111 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); |
| 1097 bool allow_lazy = literal->AllowsLazyCompilation() && | 1112 bool allow_lazy = literal->AllowsLazyCompilation() && |
| 1098 !DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx); | 1113 !DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx); |
| 1099 | 1114 |
| 1100 // Generate code | 1115 // Generate code |
| 1101 Handle<ScopeInfo> scope_info; | 1116 Handle<ScopeInfo> scope_info; |
| 1102 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { | 1117 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { |
| 1103 Handle<Code> code = isolate->builtins()->CompileUnoptimized(); | 1118 Handle<Code> code = isolate->builtins()->CompileLazy(); |
| 1104 info.SetCode(code); | 1119 info.SetCode(code); |
| 1105 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); | 1120 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); |
| 1106 } else if (FullCodeGenerator::MakeCode(&info)) { | 1121 } else if (FullCodeGenerator::MakeCode(&info)) { |
| 1107 DCHECK(!info.code().is_null()); | 1122 DCHECK(!info.code().is_null()); |
| 1108 scope_info = ScopeInfo::Create(info.scope(), info.zone()); | 1123 scope_info = ScopeInfo::Create(info.scope(), info.zone()); |
| 1109 } else { | 1124 } else { |
| 1110 return Handle<SharedFunctionInfo>::null(); | 1125 return Handle<SharedFunctionInfo>::null(); |
| 1111 } | 1126 } |
| 1112 | 1127 |
| 1113 // Create a shared function info object. | 1128 // Create a shared function info object. |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 // SharedFunctionInfo is passed separately, because if CompilationInfo | 1362 // SharedFunctionInfo is passed separately, because if CompilationInfo |
| 1348 // was created using Script object, it will not have it. | 1363 // was created using Script object, it will not have it. |
| 1349 | 1364 |
| 1350 // Log the code generation. If source information is available include | 1365 // Log the code generation. If source information is available include |
| 1351 // script name and line number. Check explicitly whether logging is | 1366 // script name and line number. Check explicitly whether logging is |
| 1352 // enabled as finding the line number is not free. | 1367 // enabled as finding the line number is not free. |
| 1353 if (info->isolate()->logger()->is_logging_code_events() || | 1368 if (info->isolate()->logger()->is_logging_code_events() || |
| 1354 info->isolate()->cpu_profiler()->is_profiling()) { | 1369 info->isolate()->cpu_profiler()->is_profiling()) { |
| 1355 Handle<Script> script = info->script(); | 1370 Handle<Script> script = info->script(); |
| 1356 Handle<Code> code = info->code(); | 1371 Handle<Code> code = info->code(); |
| 1357 if (code.is_identical_to( | 1372 if (code.is_identical_to(info->isolate()->builtins()->CompileLazy())) { |
| 1358 info->isolate()->builtins()->CompileUnoptimized())) { | |
| 1359 return; | 1373 return; |
| 1360 } | 1374 } |
| 1361 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; | 1375 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; |
| 1362 int column_num = | 1376 int column_num = |
| 1363 Script::GetColumnNumber(script, shared->start_position()) + 1; | 1377 Script::GetColumnNumber(script, shared->start_position()) + 1; |
| 1364 String* script_name = script->name()->IsString() | 1378 String* script_name = script->name()->IsString() |
| 1365 ? String::cast(script->name()) | 1379 ? String::cast(script->name()) |
| 1366 : info->isolate()->heap()->empty_string(); | 1380 : info->isolate()->heap()->empty_string(); |
| 1367 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); | 1381 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); |
| 1368 PROFILE(info->isolate(), CodeCreateEvent( | 1382 PROFILE(info->isolate(), CodeCreateEvent( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 AllowHandleDereference allow_deref; | 1421 AllowHandleDereference allow_deref; |
| 1408 bool tracing_on = info()->IsStub() | 1422 bool tracing_on = info()->IsStub() |
| 1409 ? FLAG_trace_hydrogen_stubs | 1423 ? FLAG_trace_hydrogen_stubs |
| 1410 : (FLAG_trace_hydrogen && | 1424 : (FLAG_trace_hydrogen && |
| 1411 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1425 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
| 1412 return (tracing_on && | 1426 return (tracing_on && |
| 1413 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1427 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
| 1414 } | 1428 } |
| 1415 | 1429 |
| 1416 } } // namespace v8::internal | 1430 } } // namespace v8::internal |
| OLD | NEW |