| 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 // Try to enqueue the eager function on the compiler dispatcher. | 526 // Try to enqueue the eager function on the compiler dispatcher. |
| 527 CompilerDispatcher* dispatcher = isolate->compiler_dispatcher(); | 527 CompilerDispatcher* dispatcher = isolate->compiler_dispatcher(); |
| 528 if (UseCompilerDispatcher(dispatcher, literal->scope(), shared, is_debug, | 528 if (UseCompilerDispatcher(dispatcher, literal->scope(), shared, is_debug, |
| 529 will_serialize) && | 529 will_serialize) && |
| 530 dispatcher->EnqueueAndStep(shared, literal)) { | 530 dispatcher->EnqueueAndStep(shared, literal)) { |
| 531 // If we have successfully queued up the function for compilation on the | 531 // If we have successfully queued up the function for compilation on the |
| 532 // compiler dispatcher then we are done. | 532 // compiler dispatcher then we are done. |
| 533 continue; | 533 continue; |
| 534 } else { | 534 } else { |
| 535 // Otherwise generate unoptimized code now. | 535 // Otherwise generate unoptimized code now. |
| 536 Zone zone(isolate->allocator(), ZONE_NAME); | 536 ParseInfo parse_info(script); |
| 537 ParseInfo parse_info(&zone, script); | |
| 538 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 537 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 539 | 538 |
| 540 parse_info.set_literal(literal); | 539 parse_info.set_literal(literal); |
| 541 parse_info.set_shared_info(shared); | 540 parse_info.set_shared_info(shared); |
| 542 parse_info.set_function_literal_id(shared->function_literal_id()); | 541 parse_info.set_function_literal_id(shared->function_literal_id()); |
| 543 parse_info.set_language_mode(literal->scope()->language_mode()); | 542 parse_info.set_language_mode(literal->scope()->language_mode()); |
| 544 parse_info.set_ast_value_factory( | 543 parse_info.set_ast_value_factory( |
| 545 outer_info->parse_info()->ast_value_factory()); | 544 outer_info->parse_info()->ast_value_factory()); |
| 546 parse_info.set_ast_value_factory_owned(false); | 545 parse_info.set_ast_value_factory_owned(false); |
| 547 | 546 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); | 911 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); |
| 913 } | 912 } |
| 914 info->closure()->ReplaceCode(shared->code()); | 913 info->closure()->ReplaceCode(shared->code()); |
| 915 return CompilationJob::FAILED; | 914 return CompilationJob::FAILED; |
| 916 } | 915 } |
| 917 | 916 |
| 918 MaybeHandle<Code> GetBaselineCode(Handle<JSFunction> function) { | 917 MaybeHandle<Code> GetBaselineCode(Handle<JSFunction> function) { |
| 919 Isolate* isolate = function->GetIsolate(); | 918 Isolate* isolate = function->GetIsolate(); |
| 920 VMState<COMPILER> state(isolate); | 919 VMState<COMPILER> state(isolate); |
| 921 PostponeInterruptsScope postpone(isolate); | 920 PostponeInterruptsScope postpone(isolate); |
| 922 Zone zone(isolate->allocator(), ZONE_NAME); | 921 ParseInfo parse_info(handle(function->shared())); |
| 923 ParseInfo parse_info(&zone, handle(function->shared())); | |
| 924 CompilationInfo info(&parse_info, function); | 922 CompilationInfo info(&parse_info, function); |
| 925 | 923 |
| 926 DCHECK(function->shared()->is_compiled()); | 924 DCHECK(function->shared()->is_compiled()); |
| 927 | 925 |
| 928 // Function no longer needs to be tiered up | 926 // Function no longer needs to be tiered up |
| 929 function->shared()->set_marked_for_tier_up(false); | 927 function->shared()->set_marked_for_tier_up(false); |
| 930 | 928 |
| 931 // Reset profiler ticks, function is no longer considered hot. | 929 // Reset profiler ticks, function is no longer considered hot. |
| 932 if (function->shared()->HasBytecodeArray()) { | 930 if (function->shared()->HasBytecodeArray()) { |
| 933 function->shared()->set_profiler_ticks(0); | 931 function->shared()->set_profiler_ticks(0); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 if (function->shared()->is_compiled()) { | 1044 if (function->shared()->is_compiled()) { |
| 1047 return Handle<Code>(function->shared()->code()); | 1045 return Handle<Code>(function->shared()->code()); |
| 1048 } | 1046 } |
| 1049 | 1047 |
| 1050 if (function->shared()->HasBytecodeArray()) { | 1048 if (function->shared()->HasBytecodeArray()) { |
| 1051 Handle<Code> entry = isolate->builtins()->InterpreterEntryTrampoline(); | 1049 Handle<Code> entry = isolate->builtins()->InterpreterEntryTrampoline(); |
| 1052 function->shared()->ReplaceCode(*entry); | 1050 function->shared()->ReplaceCode(*entry); |
| 1053 return entry; | 1051 return entry; |
| 1054 } | 1052 } |
| 1055 | 1053 |
| 1056 Zone zone(isolate->allocator(), ZONE_NAME); | 1054 ParseInfo parse_info(handle(function->shared())); |
| 1057 ParseInfo parse_info(&zone, handle(function->shared())); | |
| 1058 CompilationInfo info(&parse_info, function); | 1055 CompilationInfo info(&parse_info, function); |
| 1059 Handle<Code> result; | 1056 Handle<Code> result; |
| 1060 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code); | 1057 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code); |
| 1061 | 1058 |
| 1062 if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) { | 1059 if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) { |
| 1063 Handle<Code> opt_code; | 1060 Handle<Code> opt_code; |
| 1064 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT) | 1061 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT) |
| 1065 .ToHandle(&opt_code)) { | 1062 .ToHandle(&opt_code)) { |
| 1066 result = opt_code; | 1063 result = opt_code; |
| 1067 } | 1064 } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 Handle<Code> code; | 1226 Handle<Code> code; |
| 1230 if (!GetOptimizedCode(function, mode).ToHandle(&code)) { | 1227 if (!GetOptimizedCode(function, mode).ToHandle(&code)) { |
| 1231 // Optimization failed, get unoptimized code. | 1228 // Optimization failed, get unoptimized code. |
| 1232 DCHECK(!isolate->has_pending_exception()); | 1229 DCHECK(!isolate->has_pending_exception()); |
| 1233 if (function->shared()->is_compiled()) { | 1230 if (function->shared()->is_compiled()) { |
| 1234 code = handle(function->shared()->code(), isolate); | 1231 code = handle(function->shared()->code(), isolate); |
| 1235 } else if (function->shared()->HasBytecodeArray()) { | 1232 } else if (function->shared()->HasBytecodeArray()) { |
| 1236 code = isolate->builtins()->InterpreterEntryTrampoline(); | 1233 code = isolate->builtins()->InterpreterEntryTrampoline(); |
| 1237 function->shared()->ReplaceCode(*code); | 1234 function->shared()->ReplaceCode(*code); |
| 1238 } else { | 1235 } else { |
| 1239 Zone zone(isolate->allocator(), ZONE_NAME); | 1236 ParseInfo parse_info(handle(function->shared())); |
| 1240 ParseInfo parse_info(&zone, handle(function->shared())); | |
| 1241 CompilationInfo info(&parse_info, function); | 1237 CompilationInfo info(&parse_info, function); |
| 1242 if (!GetUnoptimizedCode(&info).ToHandle(&code)) { | 1238 if (!GetUnoptimizedCode(&info).ToHandle(&code)) { |
| 1243 return false; | 1239 return false; |
| 1244 } | 1240 } |
| 1245 } | 1241 } |
| 1246 } | 1242 } |
| 1247 | 1243 |
| 1248 // Install code on closure. | 1244 // Install code on closure. |
| 1249 function->ReplaceCode(*code); | 1245 function->ReplaceCode(*code); |
| 1250 JSFunction::EnsureLiterals(function); | 1246 JSFunction::EnsureLiterals(function); |
| 1251 | 1247 |
| 1252 // Check postconditions on success. | 1248 // Check postconditions on success. |
| 1253 DCHECK(!isolate->has_pending_exception()); | 1249 DCHECK(!isolate->has_pending_exception()); |
| 1254 DCHECK(function->shared()->is_compiled()); | 1250 DCHECK(function->shared()->is_compiled()); |
| 1255 DCHECK(function->is_compiled()); | 1251 DCHECK(function->is_compiled()); |
| 1256 return true; | 1252 return true; |
| 1257 } | 1253 } |
| 1258 | 1254 |
| 1259 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { | 1255 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { |
| 1260 Isolate* isolate = shared->GetIsolate(); | 1256 Isolate* isolate = shared->GetIsolate(); |
| 1261 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1257 DCHECK(AllowCompilation::IsAllowed(isolate)); |
| 1262 | 1258 |
| 1263 // Start a compilation. | 1259 // Start a compilation. |
| 1264 Zone zone(isolate->allocator(), ZONE_NAME); | 1260 ParseInfo parse_info(shared); |
| 1265 ParseInfo parse_info(&zone, shared); | |
| 1266 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1261 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 1267 info.MarkAsDebug(); | 1262 info.MarkAsDebug(); |
| 1268 if (GetUnoptimizedCode(&info).is_null()) { | 1263 if (GetUnoptimizedCode(&info).is_null()) { |
| 1269 isolate->clear_pending_exception(); | 1264 isolate->clear_pending_exception(); |
| 1270 return false; | 1265 return false; |
| 1271 } | 1266 } |
| 1272 | 1267 |
| 1273 // Check postconditions on success. | 1268 // Check postconditions on success. |
| 1274 DCHECK(!isolate->has_pending_exception()); | 1269 DCHECK(!isolate->has_pending_exception()); |
| 1275 DCHECK(shared->is_compiled()); | 1270 DCHECK(shared->is_compiled()); |
| 1276 DCHECK(shared->HasDebugCode()); | 1271 DCHECK(shared->HasDebugCode()); |
| 1277 return true; | 1272 return true; |
| 1278 } | 1273 } |
| 1279 | 1274 |
| 1280 MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) { | 1275 MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) { |
| 1281 Isolate* isolate = script->GetIsolate(); | 1276 Isolate* isolate = script->GetIsolate(); |
| 1282 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1277 DCHECK(AllowCompilation::IsAllowed(isolate)); |
| 1283 | 1278 |
| 1284 // In order to ensure that live edit function info collection finds the newly | 1279 // In order to ensure that live edit function info collection finds the newly |
| 1285 // generated shared function infos, clear the script's list temporarily | 1280 // generated shared function infos, clear the script's list temporarily |
| 1286 // and restore it at the end of this method. | 1281 // and restore it at the end of this method. |
| 1287 Handle<FixedArray> old_function_infos(script->shared_function_infos(), | 1282 Handle<FixedArray> old_function_infos(script->shared_function_infos(), |
| 1288 isolate); | 1283 isolate); |
| 1289 script->set_shared_function_infos(isolate->heap()->empty_fixed_array()); | 1284 script->set_shared_function_infos(isolate->heap()->empty_fixed_array()); |
| 1290 | 1285 |
| 1291 // Start a compilation. | 1286 // Start a compilation. |
| 1292 Zone zone(isolate->allocator(), ZONE_NAME); | 1287 ParseInfo parse_info(script); |
| 1293 ParseInfo parse_info(&zone, script); | |
| 1294 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1288 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 1295 info.MarkAsDebug(); | 1289 info.MarkAsDebug(); |
| 1296 | 1290 |
| 1297 // TODO(635): support extensions. | 1291 // TODO(635): support extensions. |
| 1298 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); | 1292 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); |
| 1299 Handle<JSArray> infos; | 1293 Handle<JSArray> infos; |
| 1300 if (compilation_succeeded) { | 1294 if (compilation_succeeded) { |
| 1301 // Check postconditions on success. | 1295 // Check postconditions on success. |
| 1302 DCHECK(!isolate->has_pending_exception()); | 1296 DCHECK(!isolate->has_pending_exception()); |
| 1303 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script, | 1297 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script, |
| 1304 &zone, isolate); | 1298 parse_info.zone(), isolate); |
| 1305 } | 1299 } |
| 1306 | 1300 |
| 1307 // Restore the original function info list in order to remain side-effect | 1301 // Restore the original function info list in order to remain side-effect |
| 1308 // free as much as possible, since some code expects the old shared function | 1302 // free as much as possible, since some code expects the old shared function |
| 1309 // infos to stick around. | 1303 // infos to stick around. |
| 1310 script->set_shared_function_infos(*old_function_infos); | 1304 script->set_shared_function_infos(*old_function_infos); |
| 1311 | 1305 |
| 1312 return infos; | 1306 return infos; |
| 1313 } | 1307 } |
| 1314 | 1308 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1418 } | 1412 } |
| 1419 if (!script_name.is_null()) { | 1413 if (!script_name.is_null()) { |
| 1420 script->set_name(*script_name); | 1414 script->set_name(*script_name); |
| 1421 script->set_line_offset(line_offset); | 1415 script->set_line_offset(line_offset); |
| 1422 script->set_column_offset(column_offset); | 1416 script->set_column_offset(column_offset); |
| 1423 } | 1417 } |
| 1424 script->set_origin_options(options); | 1418 script->set_origin_options(options); |
| 1425 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); | 1419 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); |
| 1426 Script::SetEvalOrigin(script, outer_info, eval_position); | 1420 Script::SetEvalOrigin(script, outer_info, eval_position); |
| 1427 | 1421 |
| 1428 Zone zone(isolate->allocator(), ZONE_NAME); | 1422 ParseInfo parse_info(script); |
| 1429 ParseInfo parse_info(&zone, script); | |
| 1430 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1423 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 1431 parse_info.set_eval(); | 1424 parse_info.set_eval(); |
| 1432 parse_info.set_language_mode(language_mode); | 1425 parse_info.set_language_mode(language_mode); |
| 1433 parse_info.set_parse_restriction(restriction); | 1426 parse_info.set_parse_restriction(restriction); |
| 1434 if (!context->IsNativeContext()) { | 1427 if (!context->IsNativeContext()) { |
| 1435 parse_info.set_outer_scope_info(handle(context->scope_info())); | 1428 parse_info.set_outer_scope_info(handle(context->scope_info())); |
| 1436 } | 1429 } |
| 1437 | 1430 |
| 1438 shared_info = CompileToplevel(&info); | 1431 shared_info = CompileToplevel(&info); |
| 1439 | 1432 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 script->set_name(*script_name); | 1591 script->set_name(*script_name); |
| 1599 script->set_line_offset(line_offset); | 1592 script->set_line_offset(line_offset); |
| 1600 script->set_column_offset(column_offset); | 1593 script->set_column_offset(column_offset); |
| 1601 } | 1594 } |
| 1602 script->set_origin_options(resource_options); | 1595 script->set_origin_options(resource_options); |
| 1603 if (!source_map_url.is_null()) { | 1596 if (!source_map_url.is_null()) { |
| 1604 script->set_source_mapping_url(*source_map_url); | 1597 script->set_source_mapping_url(*source_map_url); |
| 1605 } | 1598 } |
| 1606 | 1599 |
| 1607 // Compile the function and add it to the cache. | 1600 // Compile the function and add it to the cache. |
| 1608 Zone zone(isolate->allocator(), ZONE_NAME); | 1601 ParseInfo parse_info(script); |
| 1609 ParseInfo parse_info(&zone, script); | |
| 1610 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1602 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 1611 if (is_module) parse_info.set_module(); | 1603 if (is_module) parse_info.set_module(); |
| 1612 if (compile_options != ScriptCompiler::kNoCompileOptions) { | 1604 if (compile_options != ScriptCompiler::kNoCompileOptions) { |
| 1613 parse_info.set_cached_data(cached_data); | 1605 parse_info.set_cached_data(cached_data); |
| 1614 } | 1606 } |
| 1615 parse_info.set_compile_options(compile_options); | 1607 parse_info.set_compile_options(compile_options); |
| 1616 parse_info.set_extension(extension); | 1608 parse_info.set_extension(extension); |
| 1617 if (!context->IsNativeContext()) { | 1609 if (!context->IsNativeContext()) { |
| 1618 parse_info.set_outer_scope_info(handle(context->scope_info())); | 1610 parse_info.set_outer_scope_info(handle(context->scope_info())); |
| 1619 } | 1611 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 } | 1780 } |
| 1789 | 1781 |
| 1790 if (shared->is_compiled()) { | 1782 if (shared->is_compiled()) { |
| 1791 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1783 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
| 1792 JSFunction::EnsureLiterals(function); | 1784 JSFunction::EnsureLiterals(function); |
| 1793 } | 1785 } |
| 1794 } | 1786 } |
| 1795 | 1787 |
| 1796 } // namespace internal | 1788 } // namespace internal |
| 1797 } // namespace v8 | 1789 } // namespace v8 |
| OLD | NEW |