| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 namespace v8 { | 53 namespace v8 { |
| 54 namespace internal { | 54 namespace internal { |
| 55 | 55 |
| 56 | 56 |
| 57 CompilationInfo::CompilationInfo(Handle<Script> script, | 57 CompilationInfo::CompilationInfo(Handle<Script> script, |
| 58 Zone* zone) | 58 Zone* zone) |
| 59 : flags_(LanguageModeField::encode(CLASSIC_MODE)), | 59 : flags_(LanguageModeField::encode(CLASSIC_MODE)), |
| 60 script_(script), | 60 script_(script), |
| 61 osr_ast_id_(BailoutId::None()), | 61 osr_ast_id_(BailoutId::None()), |
| 62 osr_pc_offset_(0), | |
| 63 parameter_count_(0) { | 62 parameter_count_(0) { |
| 64 Initialize(script->GetIsolate(), BASE, zone); | 63 Initialize(script->GetIsolate(), BASE, zone); |
| 65 } | 64 } |
| 66 | 65 |
| 67 | 66 |
| 68 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, | 67 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
| 69 Zone* zone) | 68 Zone* zone) |
| 70 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), | 69 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
| 71 shared_info_(shared_info), | 70 shared_info_(shared_info), |
| 72 script_(Handle<Script>(Script::cast(shared_info->script()))), | 71 script_(Handle<Script>(Script::cast(shared_info->script()))), |
| 73 osr_ast_id_(BailoutId::None()), | 72 osr_ast_id_(BailoutId::None()), |
| 74 osr_pc_offset_(0), | |
| 75 parameter_count_(0) { | 73 parameter_count_(0) { |
| 76 Initialize(script_->GetIsolate(), BASE, zone); | 74 Initialize(script_->GetIsolate(), BASE, zone); |
| 77 } | 75 } |
| 78 | 76 |
| 79 | 77 |
| 80 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, | 78 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, |
| 81 Zone* zone) | 79 Zone* zone) |
| 82 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), | 80 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
| 83 closure_(closure), | 81 closure_(closure), |
| 84 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | 82 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
| 85 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 83 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
| 86 context_(closure->context()), | 84 context_(closure->context()), |
| 87 osr_ast_id_(BailoutId::None()), | 85 osr_ast_id_(BailoutId::None()), |
| 88 osr_pc_offset_(0), | |
| 89 parameter_count_(0) { | 86 parameter_count_(0) { |
| 90 Initialize(script_->GetIsolate(), BASE, zone); | 87 Initialize(script_->GetIsolate(), BASE, zone); |
| 91 } | 88 } |
| 92 | 89 |
| 93 | 90 |
| 94 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, | 91 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, |
| 95 Isolate* isolate, | 92 Isolate* isolate, |
| 96 Zone* zone) | 93 Zone* zone) |
| 97 : flags_(LanguageModeField::encode(CLASSIC_MODE) | | 94 : flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| 98 IsLazy::encode(true)), | 95 IsLazy::encode(true)), |
| 99 osr_ast_id_(BailoutId::None()), | 96 osr_ast_id_(BailoutId::None()), |
| 100 osr_pc_offset_(0), | |
| 101 parameter_count_(0) { | 97 parameter_count_(0) { |
| 102 Initialize(isolate, STUB, zone); | 98 Initialize(isolate, STUB, zone); |
| 103 code_stub_ = stub; | 99 code_stub_ = stub; |
| 104 } | 100 } |
| 105 | 101 |
| 106 | 102 |
| 107 void CompilationInfo::Initialize(Isolate* isolate, | 103 void CompilationInfo::Initialize(Isolate* isolate, |
| 108 Mode mode, | 104 Mode mode, |
| 109 Zone* zone) { | 105 Zone* zone) { |
| 110 isolate_ = isolate; | 106 isolate_ = isolate; |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 return; | 953 return; |
| 958 } | 954 } |
| 959 Compiler::RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 955 Compiler::RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
| 960 } | 956 } |
| 961 | 957 |
| 962 | 958 |
| 963 static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { | 959 static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { |
| 964 Handle<Code> code = info->code(); | 960 Handle<Code> code = info->code(); |
| 965 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. | 961 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. |
| 966 | 962 |
| 967 // Cache non-OSR optimized code. | 963 // Cache optimized code. |
| 968 if (FLAG_cache_optimized_code && !info->is_osr()) { | 964 if (FLAG_cache_optimized_code) { |
| 969 Handle<JSFunction> function = info->closure(); | 965 Handle<JSFunction> function = info->closure(); |
| 970 Handle<SharedFunctionInfo> shared(function->shared()); | 966 Handle<SharedFunctionInfo> shared(function->shared()); |
| 971 Handle<FixedArray> literals(function->literals()); | 967 Handle<FixedArray> literals(function->literals()); |
| 972 Handle<Context> native_context(function->context()->native_context()); | 968 Handle<Context> native_context(function->context()->native_context()); |
| 973 SharedFunctionInfo::AddToOptimizedCodeMap( | 969 SharedFunctionInfo::AddToOptimizedCodeMap( |
| 974 shared, native_context, code, literals); | 970 shared, native_context, code, literals, info->osr_ast_id()); |
| 975 } | 971 } |
| 976 } | 972 } |
| 977 | 973 |
| 978 | 974 |
| 979 static bool InstallCodeFromOptimizedCodeMap(CompilationInfo* info) { | 975 static bool InstallCodeFromOptimizedCodeMap(CompilationInfo* info) { |
| 980 if (!info->IsOptimizing()) return false; // Nothing to look up. | 976 if (!info->IsOptimizing()) return false; // Nothing to look up. |
| 981 | 977 |
| 982 // Lookup non-OSR optimized code. | 978 // Lookup optimized code. |
| 983 if (FLAG_cache_optimized_code && !info->is_osr()) { | 979 if (FLAG_cache_optimized_code) { |
| 984 Handle<SharedFunctionInfo> shared = info->shared_info(); | 980 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 985 Handle<JSFunction> function = info->closure(); | 981 Handle<JSFunction> function = info->closure(); |
| 986 ASSERT(!function.is_null()); | 982 ASSERT(!function.is_null()); |
| 987 Handle<Context> native_context(function->context()->native_context()); | 983 Handle<Context> native_context(function->context()->native_context()); |
| 988 int index = shared->SearchOptimizedCodeMap(*native_context); | 984 int index = shared->SearchOptimizedCodeMap(*native_context, |
| 985 info->osr_ast_id()); |
| 989 if (index > 0) { | 986 if (index > 0) { |
| 990 if (FLAG_trace_opt) { | 987 if (FLAG_trace_opt) { |
| 991 PrintF("[found optimized code for "); | 988 PrintF("[found optimized code for "); |
| 992 function->ShortPrint(); | 989 function->ShortPrint(); |
| 990 if (info->is_osr()) { |
| 991 PrintF(" with osr ast id %d ", info->osr_ast_id().ToInt()); |
| 992 } |
| 993 PrintF("]\n"); | 993 PrintF("]\n"); |
| 994 } | 994 } |
| 995 // Caching of optimized code enabled and optimized code found. | 995 // Caching of optimized code enabled and optimized code found. |
| 996 shared->InstallFromOptimizedCodeMap(*function, index); | 996 shared->InstallFromOptimizedCodeMap(*function, index); |
| 997 return true; | 997 return true; |
| 998 } | 998 } |
| 999 } | 999 } |
| 1000 return false; | 1000 return false; |
| 1001 } | 1001 } |
| 1002 | 1002 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 } | 1049 } |
| 1050 } | 1050 } |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 ASSERT(info->code().is_null()); | 1053 ASSERT(info->code().is_null()); |
| 1054 return false; | 1054 return false; |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 | 1057 |
| 1058 bool Compiler::RecompileConcurrent(Handle<JSFunction> closure, | 1058 bool Compiler::RecompileConcurrent(Handle<JSFunction> closure, |
| 1059 uint32_t osr_pc_offset) { | 1059 BailoutId osr_ast_id) { |
| 1060 bool compiling_for_osr = (osr_pc_offset != 0); | 1060 bool compiling_for_osr = !osr_ast_id.IsNone(); |
| 1061 | 1061 |
| 1062 Isolate* isolate = closure->GetIsolate(); | 1062 Isolate* isolate = closure->GetIsolate(); |
| 1063 // Here we prepare compile data for the concurrent recompilation thread, but | 1063 // Here we prepare compile data for the concurrent recompilation thread, but |
| 1064 // this still happens synchronously and interrupts execution. | 1064 // this still happens synchronously and interrupts execution. |
| 1065 Logger::TimerEventScope timer( | 1065 Logger::TimerEventScope timer( |
| 1066 isolate, Logger::TimerEventScope::v8_recompile_synchronous); | 1066 isolate, Logger::TimerEventScope::v8_recompile_synchronous); |
| 1067 | 1067 |
| 1068 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { | 1068 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { |
| 1069 if (FLAG_trace_concurrent_recompilation) { | 1069 if (FLAG_trace_concurrent_recompilation) { |
| 1070 PrintF(" ** Compilation queue full, will retry optimizing "); | 1070 PrintF(" ** Compilation queue full, will retry optimizing "); |
| 1071 closure->PrintName(); | 1071 closure->PrintName(); |
| 1072 PrintF(" on next run.\n"); | 1072 PrintF(" on next run.\n"); |
| 1073 } | 1073 } |
| 1074 return false; | 1074 return false; |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(closure)); | 1077 SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(closure)); |
| 1078 Handle<SharedFunctionInfo> shared = info->shared_info(); | 1078 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 1079 | 1079 |
| 1080 if (compiling_for_osr) { | 1080 if (compiling_for_osr) { |
| 1081 BailoutId osr_ast_id = | |
| 1082 shared->code()->TranslatePcOffsetToAstId(osr_pc_offset); | |
| 1083 ASSERT(!osr_ast_id.IsNone()); | |
| 1084 info->SetOptimizing(osr_ast_id); | 1081 info->SetOptimizing(osr_ast_id); |
| 1085 info->set_osr_pc_offset(osr_pc_offset); | |
| 1086 | 1082 |
| 1087 if (FLAG_trace_osr) { | 1083 if (FLAG_trace_osr) { |
| 1088 PrintF("[COSR - attempt to queue "); | 1084 PrintF("[COSR - attempt to queue "); |
| 1089 closure->PrintName(); | 1085 closure->PrintName(); |
| 1090 PrintF(" at AST id %d]\n", osr_ast_id.ToInt()); | 1086 PrintF(" at AST id %d]\n", osr_ast_id.ToInt()); |
| 1091 } | 1087 } |
| 1092 } else { | 1088 } else { |
| 1093 info->SetOptimizing(BailoutId::None()); | 1089 info->SetOptimizing(BailoutId::None()); |
| 1094 } | 1090 } |
| 1095 | 1091 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 ASSERT(status == RecompileJob::SUCCEEDED || | 1167 ASSERT(status == RecompileJob::SUCCEEDED || |
| 1172 status == RecompileJob::BAILED_OUT); | 1168 status == RecompileJob::BAILED_OUT); |
| 1173 } | 1169 } |
| 1174 | 1170 |
| 1175 InstallCodeCommon(*info); | 1171 InstallCodeCommon(*info); |
| 1176 if (status == RecompileJob::SUCCEEDED) { | 1172 if (status == RecompileJob::SUCCEEDED) { |
| 1177 Handle<Code> code = info->code(); | 1173 Handle<Code> code = info->code(); |
| 1178 ASSERT(info->shared_info()->scope_info() != ScopeInfo::Empty(isolate)); | 1174 ASSERT(info->shared_info()->scope_info() != ScopeInfo::Empty(isolate)); |
| 1179 info->closure()->ReplaceCode(*code); | 1175 info->closure()->ReplaceCode(*code); |
| 1180 if (info->shared_info()->SearchOptimizedCodeMap( | 1176 if (info->shared_info()->SearchOptimizedCodeMap( |
| 1181 info->closure()->context()->native_context()) == -1) { | 1177 info->closure()->context()->native_context(), |
| 1178 info->osr_ast_id()) == -1) { |
| 1182 InsertCodeIntoOptimizedCodeMap(*info); | 1179 InsertCodeIntoOptimizedCodeMap(*info); |
| 1183 } | 1180 } |
| 1184 if (FLAG_trace_concurrent_recompilation) { | 1181 if (FLAG_trace_concurrent_recompilation) { |
| 1185 PrintF(" ** Optimized code for "); | 1182 PrintF(" ** Optimized code for "); |
| 1186 info->closure()->PrintName(); | 1183 info->closure()->PrintName(); |
| 1187 PrintF(" installed.\n"); | 1184 PrintF(" installed.\n"); |
| 1188 } | 1185 } |
| 1189 } else { | 1186 } else { |
| 1190 info->AbortOptimization(); | 1187 info->AbortOptimization(); |
| 1191 InstallFullCode(*info); | 1188 InstallFullCode(*info); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 AllowHandleDereference allow_deref; | 1358 AllowHandleDereference allow_deref; |
| 1362 bool tracing_on = info()->IsStub() | 1359 bool tracing_on = info()->IsStub() |
| 1363 ? FLAG_trace_hydrogen_stubs | 1360 ? FLAG_trace_hydrogen_stubs |
| 1364 : (FLAG_trace_hydrogen && | 1361 : (FLAG_trace_hydrogen && |
| 1365 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1362 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
| 1366 return (tracing_on && | 1363 return (tracing_on && |
| 1367 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1364 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
| 1368 } | 1365 } |
| 1369 | 1366 |
| 1370 } } // namespace v8::internal | 1367 } } // namespace v8::internal |
| OLD | NEW |