| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 15 matching lines...) Expand all Loading... |
| 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 "compiler.h" | 30 #include "compiler.h" |
| 31 | 31 |
| 32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
| 33 #include "codegen.h" | 33 #include "codegen.h" |
| 34 #include "compilation-cache.h" | 34 #include "compilation-cache.h" |
| 35 #include "debug.h" | 35 #include "debug.h" |
| 36 #include "deoptimizer.h" |
| 36 #include "full-codegen.h" | 37 #include "full-codegen.h" |
| 37 #include "gdb-jit.h" | 38 #include "gdb-jit.h" |
| 38 #include "hydrogen.h" | 39 #include "hydrogen.h" |
| 39 #include "isolate-inl.h" | 40 #include "isolate-inl.h" |
| 40 #include "lithium.h" | 41 #include "lithium.h" |
| 41 #include "liveedit.h" | 42 #include "liveedit.h" |
| 42 #include "parser.h" | 43 #include "parser.h" |
| 43 #include "rewriter.h" | 44 #include "rewriter.h" |
| 44 #include "runtime-profiler.h" | 45 #include "runtime-profiler.h" |
| 45 #include "scanner-character-streams.h" | 46 #include "scanner-character-streams.h" |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 } | 894 } |
| 894 } | 895 } |
| 895 } | 896 } |
| 896 | 897 |
| 897 ASSERT(info->code().is_null()); | 898 ASSERT(info->code().is_null()); |
| 898 return false; | 899 return false; |
| 899 } | 900 } |
| 900 | 901 |
| 901 | 902 |
| 902 void Compiler::RecompileParallel(Handle<JSFunction> closure) { | 903 void Compiler::RecompileParallel(Handle<JSFunction> closure) { |
| 903 if (closure->IsInRecompileQueue()) return; | |
| 904 ASSERT(closure->IsMarkedForParallelRecompilation()); | 904 ASSERT(closure->IsMarkedForParallelRecompilation()); |
| 905 | 905 |
| 906 Isolate* isolate = closure->GetIsolate(); | 906 Isolate* isolate = closure->GetIsolate(); |
| 907 // Here we prepare compile data for the parallel recompilation thread, but | 907 // Here we prepare compile data for the parallel recompilation thread, but |
| 908 // this still happens synchronously and interrupts execution. | 908 // this still happens synchronously and interrupts execution. |
| 909 Logger::TimerEventScope timer( | 909 Logger::TimerEventScope timer( |
| 910 isolate, Logger::TimerEventScope::v8_recompile_synchronous); | 910 isolate, Logger::TimerEventScope::v8_recompile_synchronous); |
| 911 | 911 |
| 912 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { | 912 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { |
| 913 if (FLAG_trace_parallel_recompilation) { | 913 if (FLAG_trace_parallel_recompilation) { |
| 914 PrintF(" ** Compilation queue, will retry opting on next run.\n"); | 914 PrintF(" ** Compilation queue, will retry opting on next run.\n"); |
| 915 } | 915 } |
| 916 return; | 916 return; |
| 917 } | 917 } |
| 918 | 918 |
| 919 SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(closure)); | 919 SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(closure)); |
| 920 VMState state(isolate, PARALLEL_COMPILER); | 920 VMState state(isolate, PARALLEL_COMPILER); |
| 921 PostponeInterruptsScope postpone(isolate); | 921 PostponeInterruptsScope postpone(isolate); |
| 922 | 922 |
| 923 Handle<SharedFunctionInfo> shared = info->shared_info(); | 923 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 924 int compiled_size = shared->end_position() - shared->start_position(); | 924 int compiled_size = shared->end_position() - shared->start_position(); |
| 925 isolate->counters()->total_compile_size()->Increment(compiled_size); | 925 isolate->counters()->total_compile_size()->Increment(compiled_size); |
| 926 info->SetOptimizing(BailoutId::None()); | 926 info->SetOptimizing(BailoutId::None()); |
| 927 | 927 |
| 928 { | 928 { |
| 929 CompilationHandleScope handle_scope(*info); | 929 CompilationHandleScope handle_scope(*info); |
| 930 | 930 |
| 931 if (!FLAG_manual_parallel_recompilation && | 931 if (InstallCodeFromOptimizedCodeMap(*info)) { |
| 932 InstallCodeFromOptimizedCodeMap(*info)) { | |
| 933 return; | 932 return; |
| 934 } | 933 } |
| 935 | 934 |
| 936 if (ParserApi::Parse(*info, kNoParsingFlags)) { | 935 if (ParserApi::Parse(*info, kNoParsingFlags)) { |
| 937 LanguageMode language_mode = info->function()->language_mode(); | 936 LanguageMode language_mode = info->function()->language_mode(); |
| 938 info->SetLanguageMode(language_mode); | 937 info->SetLanguageMode(language_mode); |
| 939 shared->set_language_mode(language_mode); | 938 shared->set_language_mode(language_mode); |
| 940 info->SaveHandles(); | 939 info->SaveHandles(); |
| 941 | 940 |
| 942 if (Rewriter::Rewrite(*info) && Scope::Analyze(*info)) { | 941 if (Rewriter::Rewrite(*info) && Scope::Analyze(*info)) { |
| 943 OptimizingCompiler* compiler = | 942 OptimizingCompiler* compiler = |
| 944 new(info->zone()) OptimizingCompiler(*info); | 943 new(info->zone()) OptimizingCompiler(*info); |
| 945 OptimizingCompiler::Status status = compiler->CreateGraph(); | 944 OptimizingCompiler::Status status = compiler->CreateGraph(); |
| 946 if (status == OptimizingCompiler::SUCCEEDED) { | 945 if (status == OptimizingCompiler::SUCCEEDED) { |
| 946 closure->MarkInRecompileQueue(); |
| 947 shared->code()->set_profiler_ticks(0); |
| 948 info.Detach(); |
| 947 isolate->optimizing_compiler_thread()->QueueForOptimization(compiler); | 949 isolate->optimizing_compiler_thread()->QueueForOptimization(compiler); |
| 948 shared->code()->set_profiler_ticks(0); | |
| 949 closure->ReplaceCode(isolate->builtins()->builtin( | |
| 950 Builtins::kInRecompileQueue)); | |
| 951 info.Detach(); | |
| 952 } else if (status == OptimizingCompiler::BAILED_OUT) { | 950 } else if (status == OptimizingCompiler::BAILED_OUT) { |
| 953 isolate->clear_pending_exception(); | 951 isolate->clear_pending_exception(); |
| 954 InstallFullCode(*info); | 952 InstallFullCode(*info); |
| 955 } | 953 } |
| 956 } | 954 } |
| 957 } | 955 } |
| 958 } | 956 } |
| 959 | 957 |
| 960 if (isolate->has_pending_exception()) { | 958 if (shared->code()->stack_check_patched_for_osr()) { |
| 961 isolate->clear_pending_exception(); | 959 // At this point we either put the function on recompilation queue or |
| 960 // aborted optimization. In either case we want to continue executing |
| 961 // the unoptimized code without running into OSR. If the unoptimized |
| 962 // code has been patched for OSR, unpatch it. |
| 963 InterruptStub interrupt_stub; |
| 964 Handle<Code> check_code = interrupt_stub.GetCode(isolate); |
| 965 Handle<Code> replacement_code = |
| 966 isolate->builtins()->OnStackReplacement(); |
| 967 Deoptimizer::RevertStackCheckCode(shared->code(), |
| 968 *check_code, |
| 969 *replacement_code); |
| 962 } | 970 } |
| 971 |
| 972 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); |
| 963 } | 973 } |
| 964 | 974 |
| 965 | 975 |
| 966 void Compiler::InstallOptimizedCode(OptimizingCompiler* optimizing_compiler) { | 976 void Compiler::InstallOptimizedCode(OptimizingCompiler* optimizing_compiler) { |
| 967 SmartPointer<CompilationInfo> info(optimizing_compiler->info()); | 977 SmartPointer<CompilationInfo> info(optimizing_compiler->info()); |
| 968 // Function may have been optimized meanwhile by OSR. | 978 ASSERT(info->closure()->IsMarkedForInstallingRecompiledCode()); |
| 969 if (FLAG_use_osr) { | |
| 970 // Function may have already been optimized meanwhile by OSR. | |
| 971 if (!info->code().is_null() && | |
| 972 info->code()->kind() == Code::OPTIMIZED_FUNCTION) { | |
| 973 return; | |
| 974 } | |
| 975 // OSR may also have caused optimization to be disabled. | |
| 976 if (info->shared_info()->optimization_disabled()) return; | |
| 977 } | |
| 978 | 979 |
| 979 Isolate* isolate = info->isolate(); | 980 Isolate* isolate = info->isolate(); |
| 980 VMState state(isolate, PARALLEL_COMPILER); | 981 VMState state(isolate, PARALLEL_COMPILER); |
| 981 Logger::TimerEventScope timer( | 982 Logger::TimerEventScope timer( |
| 982 isolate, Logger::TimerEventScope::v8_recompile_synchronous); | 983 isolate, Logger::TimerEventScope::v8_recompile_synchronous); |
| 983 // If crankshaft succeeded, install the optimized code else install | 984 // If crankshaft succeeded, install the optimized code else install |
| 984 // the unoptimized code. | 985 // the unoptimized code. |
| 985 OptimizingCompiler::Status status = optimizing_compiler->last_status(); | 986 OptimizingCompiler::Status status = optimizing_compiler->last_status(); |
| 986 if (status != OptimizingCompiler::SUCCEEDED) { | 987 if (status != OptimizingCompiler::SUCCEEDED) { |
| 987 optimizing_compiler->info()->set_bailout_reason( | 988 optimizing_compiler->info()->set_bailout_reason( |
| 988 "failed/bailed out last time"); | 989 "failed/bailed out last time"); |
| 989 status = optimizing_compiler->AbortOptimization(); | 990 status = optimizing_compiler->AbortOptimization(); |
| 990 } else { | 991 } else { |
| 991 status = optimizing_compiler->GenerateAndInstallCode(); | 992 status = optimizing_compiler->GenerateAndInstallCode(); |
| 992 ASSERT(status == OptimizingCompiler::SUCCEEDED || | 993 ASSERT(status == OptimizingCompiler::SUCCEEDED || |
| 993 status == OptimizingCompiler::BAILED_OUT); | 994 status == OptimizingCompiler::BAILED_OUT); |
| 994 } | 995 } |
| 995 | 996 |
| 996 InstallCodeCommon(*info); | 997 InstallCodeCommon(*info); |
| 997 if (status == OptimizingCompiler::SUCCEEDED) { | 998 if (status == OptimizingCompiler::SUCCEEDED) { |
| 998 Handle<Code> code = info->code(); | 999 Handle<Code> code = info->code(); |
| 999 ASSERT(info->shared_info()->scope_info() != ScopeInfo::Empty(isolate)); | 1000 ASSERT(info->shared_info()->scope_info() != ScopeInfo::Empty(isolate)); |
| 1000 info->closure()->ReplaceCode(*code); | 1001 info->closure()->ReplaceCode(*code); |
| 1001 if (info->shared_info()->SearchOptimizedCodeMap( | 1002 if (info->shared_info()->SearchOptimizedCodeMap( |
| 1002 info->closure()->context()->native_context()) == -1) { | 1003 info->closure()->context()->native_context()) == -1) { |
| 1003 InsertCodeIntoOptimizedCodeMap(*info); | 1004 InsertCodeIntoOptimizedCodeMap(*info); |
| 1004 } | 1005 } |
| 1006 if (FLAG_trace_parallel_recompilation) { |
| 1007 PrintF(" ** Optimized code for "); |
| 1008 info->closure()->PrintName(); |
| 1009 PrintF(" installed.\n"); |
| 1010 } |
| 1005 } else { | 1011 } else { |
| 1006 info->SetCode(Handle<Code>(info->shared_info()->code())); | 1012 info->SetCode(Handle<Code>(info->shared_info()->code())); |
| 1007 InstallFullCode(*info); | 1013 InstallFullCode(*info); |
| 1008 } | 1014 } |
| 1015 // Optimized code is finally replacing unoptimized code. Reset the latter's |
| 1016 // profiler ticks to prevent too soon re-opt after a deopt. |
| 1017 info->shared_info()->code()->set_profiler_ticks(0); |
| 1009 } | 1018 } |
| 1010 | 1019 |
| 1011 | 1020 |
| 1012 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, | 1021 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
| 1013 Handle<Script> script) { | 1022 Handle<Script> script) { |
| 1014 // Precondition: code has been parsed and scopes have been analyzed. | 1023 // Precondition: code has been parsed and scopes have been analyzed. |
| 1015 CompilationInfoWithZone info(script); | 1024 CompilationInfoWithZone info(script); |
| 1016 info.SetFunction(literal); | 1025 info.SetFunction(literal); |
| 1017 info.SetScope(literal->scope()); | 1026 info.SetScope(literal->scope()); |
| 1018 info.SetLanguageMode(literal->scope()->language_mode()); | 1027 info.SetLanguageMode(literal->scope()->language_mode()); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 } | 1142 } |
| 1134 } | 1143 } |
| 1135 | 1144 |
| 1136 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 1145 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
| 1137 Handle<Script>(info->script()), | 1146 Handle<Script>(info->script()), |
| 1138 Handle<Code>(info->code()), | 1147 Handle<Code>(info->code()), |
| 1139 info)); | 1148 info)); |
| 1140 } | 1149 } |
| 1141 | 1150 |
| 1142 } } // namespace v8::internal | 1151 } } // namespace v8::internal |
| OLD | NEW |