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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 DCHECK(!shared->is_toplevel()); | 500 DCHECK(!shared->is_toplevel()); |
501 // If we found an existing shared function info with compiled code, | 501 // If we found an existing shared function info with compiled code, |
502 // we are done. | 502 // we are done. |
503 if (shared->is_compiled()) continue; | 503 if (shared->is_compiled()) continue; |
504 } else { | 504 } else { |
505 shared = | 505 shared = |
506 isolate->factory()->NewSharedFunctionInfoForLiteral(literal, script); | 506 isolate->factory()->NewSharedFunctionInfoForLiteral(literal, script); |
507 shared->set_is_toplevel(false); | 507 shared->set_is_toplevel(false); |
508 } | 508 } |
509 | 509 |
510 ParseInfo parse_info(script); | 510 Zone zone(isolate->allocator(), ZONE_NAME); |
| 511 ParseInfo parse_info(&zone, script); |
511 parse_info.set_literal(literal); | 512 parse_info.set_literal(literal); |
512 parse_info.set_shared_info(shared); | 513 parse_info.set_shared_info(shared); |
513 parse_info.set_function_literal_id(shared->function_literal_id()); | 514 parse_info.set_function_literal_id(shared->function_literal_id()); |
514 parse_info.set_language_mode(literal->scope()->language_mode()); | 515 parse_info.set_language_mode(literal->scope()->language_mode()); |
515 parse_info.set_ast_value_factory( | 516 parse_info.set_ast_value_factory( |
516 outer_info->parse_info()->ast_value_factory()); | 517 outer_info->parse_info()->ast_value_factory()); |
517 parse_info.set_ast_value_factory_owned(false); | 518 parse_info.set_ast_value_factory_owned(false); |
518 | 519 |
519 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 520 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
520 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 521 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); | 889 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); |
889 } | 890 } |
890 info->closure()->ReplaceCode(shared->code()); | 891 info->closure()->ReplaceCode(shared->code()); |
891 return CompilationJob::FAILED; | 892 return CompilationJob::FAILED; |
892 } | 893 } |
893 | 894 |
894 MaybeHandle<Code> GetBaselineCode(Handle<JSFunction> function) { | 895 MaybeHandle<Code> GetBaselineCode(Handle<JSFunction> function) { |
895 Isolate* isolate = function->GetIsolate(); | 896 Isolate* isolate = function->GetIsolate(); |
896 VMState<COMPILER> state(isolate); | 897 VMState<COMPILER> state(isolate); |
897 PostponeInterruptsScope postpone(isolate); | 898 PostponeInterruptsScope postpone(isolate); |
898 ParseInfo parse_info(handle(function->shared())); | 899 Zone zone(isolate->allocator(), ZONE_NAME); |
| 900 ParseInfo parse_info(&zone, handle(function->shared())); |
899 CompilationInfo info(&parse_info, function); | 901 CompilationInfo info(&parse_info, function); |
900 | 902 |
901 DCHECK(function->shared()->is_compiled()); | 903 DCHECK(function->shared()->is_compiled()); |
902 | 904 |
903 // Function no longer needs to be tiered up | 905 // Function no longer needs to be tiered up |
904 function->shared()->set_marked_for_tier_up(false); | 906 function->shared()->set_marked_for_tier_up(false); |
905 | 907 |
906 // Reset profiler ticks, function is no longer considered hot. | 908 // Reset profiler ticks, function is no longer considered hot. |
907 if (function->shared()->HasBytecodeArray()) { | 909 if (function->shared()->HasBytecodeArray()) { |
908 function->shared()->set_profiler_ticks(0); | 910 function->shared()->set_profiler_ticks(0); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 if (function->shared()->is_compiled()) { | 1023 if (function->shared()->is_compiled()) { |
1022 return Handle<Code>(function->shared()->code()); | 1024 return Handle<Code>(function->shared()->code()); |
1023 } | 1025 } |
1024 | 1026 |
1025 if (function->shared()->HasBytecodeArray()) { | 1027 if (function->shared()->HasBytecodeArray()) { |
1026 Handle<Code> entry = isolate->builtins()->InterpreterEntryTrampoline(); | 1028 Handle<Code> entry = isolate->builtins()->InterpreterEntryTrampoline(); |
1027 function->shared()->ReplaceCode(*entry); | 1029 function->shared()->ReplaceCode(*entry); |
1028 return entry; | 1030 return entry; |
1029 } | 1031 } |
1030 | 1032 |
1031 ParseInfo parse_info(handle(function->shared())); | 1033 Zone zone(isolate->allocator(), ZONE_NAME); |
| 1034 ParseInfo parse_info(&zone, handle(function->shared())); |
1032 CompilationInfo info(&parse_info, function); | 1035 CompilationInfo info(&parse_info, function); |
1033 Handle<Code> result; | 1036 Handle<Code> result; |
1034 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code); | 1037 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code); |
1035 | 1038 |
1036 if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) { | 1039 if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) { |
1037 Handle<Code> opt_code; | 1040 Handle<Code> opt_code; |
1038 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT) | 1041 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT) |
1039 .ToHandle(&opt_code)) { | 1042 .ToHandle(&opt_code)) { |
1040 result = opt_code; | 1043 result = opt_code; |
1041 } | 1044 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 Handle<Code> code; | 1203 Handle<Code> code; |
1201 if (!GetOptimizedCode(function, mode).ToHandle(&code)) { | 1204 if (!GetOptimizedCode(function, mode).ToHandle(&code)) { |
1202 // Optimization failed, get unoptimized code. | 1205 // Optimization failed, get unoptimized code. |
1203 DCHECK(!isolate->has_pending_exception()); | 1206 DCHECK(!isolate->has_pending_exception()); |
1204 if (function->shared()->is_compiled()) { | 1207 if (function->shared()->is_compiled()) { |
1205 code = handle(function->shared()->code(), isolate); | 1208 code = handle(function->shared()->code(), isolate); |
1206 } else if (function->shared()->HasBytecodeArray()) { | 1209 } else if (function->shared()->HasBytecodeArray()) { |
1207 code = isolate->builtins()->InterpreterEntryTrampoline(); | 1210 code = isolate->builtins()->InterpreterEntryTrampoline(); |
1208 function->shared()->ReplaceCode(*code); | 1211 function->shared()->ReplaceCode(*code); |
1209 } else { | 1212 } else { |
1210 ParseInfo parse_info(handle(function->shared())); | 1213 Zone zone(isolate->allocator(), ZONE_NAME); |
| 1214 ParseInfo parse_info(&zone, handle(function->shared())); |
1211 CompilationInfo info(&parse_info, function); | 1215 CompilationInfo info(&parse_info, function); |
1212 if (!GetUnoptimizedCode(&info).ToHandle(&code)) { | 1216 if (!GetUnoptimizedCode(&info).ToHandle(&code)) { |
1213 return false; | 1217 return false; |
1214 } | 1218 } |
1215 } | 1219 } |
1216 } | 1220 } |
1217 | 1221 |
1218 // Install code on closure. | 1222 // Install code on closure. |
1219 function->ReplaceCode(*code); | 1223 function->ReplaceCode(*code); |
1220 JSFunction::EnsureLiterals(function); | 1224 JSFunction::EnsureLiterals(function); |
1221 | 1225 |
1222 // Check postconditions on success. | 1226 // Check postconditions on success. |
1223 DCHECK(!isolate->has_pending_exception()); | 1227 DCHECK(!isolate->has_pending_exception()); |
1224 DCHECK(function->shared()->is_compiled()); | 1228 DCHECK(function->shared()->is_compiled()); |
1225 DCHECK(function->is_compiled()); | 1229 DCHECK(function->is_compiled()); |
1226 return true; | 1230 return true; |
1227 } | 1231 } |
1228 | 1232 |
1229 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { | 1233 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { |
1230 Isolate* isolate = shared->GetIsolate(); | 1234 Isolate* isolate = shared->GetIsolate(); |
1231 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1235 DCHECK(AllowCompilation::IsAllowed(isolate)); |
1232 | 1236 |
1233 // Start a compilation. | 1237 // Start a compilation. |
1234 ParseInfo parse_info(shared); | 1238 Zone zone(isolate->allocator(), ZONE_NAME); |
| 1239 ParseInfo parse_info(&zone, shared); |
1235 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1240 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1236 info.MarkAsDebug(); | 1241 info.MarkAsDebug(); |
1237 if (GetUnoptimizedCode(&info).is_null()) { | 1242 if (GetUnoptimizedCode(&info).is_null()) { |
1238 isolate->clear_pending_exception(); | 1243 isolate->clear_pending_exception(); |
1239 return false; | 1244 return false; |
1240 } | 1245 } |
1241 | 1246 |
1242 // Check postconditions on success. | 1247 // Check postconditions on success. |
1243 DCHECK(!isolate->has_pending_exception()); | 1248 DCHECK(!isolate->has_pending_exception()); |
1244 DCHECK(shared->is_compiled()); | 1249 DCHECK(shared->is_compiled()); |
1245 DCHECK(shared->HasDebugCode()); | 1250 DCHECK(shared->HasDebugCode()); |
1246 return true; | 1251 return true; |
1247 } | 1252 } |
1248 | 1253 |
1249 MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) { | 1254 MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) { |
1250 Isolate* isolate = script->GetIsolate(); | 1255 Isolate* isolate = script->GetIsolate(); |
1251 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1256 DCHECK(AllowCompilation::IsAllowed(isolate)); |
1252 | 1257 |
1253 // In order to ensure that live edit function info collection finds the newly | 1258 // In order to ensure that live edit function info collection finds the newly |
1254 // generated shared function infos, clear the script's list temporarily | 1259 // generated shared function infos, clear the script's list temporarily |
1255 // and restore it at the end of this method. | 1260 // and restore it at the end of this method. |
1256 Handle<FixedArray> old_function_infos(script->shared_function_infos(), | 1261 Handle<FixedArray> old_function_infos(script->shared_function_infos(), |
1257 isolate); | 1262 isolate); |
1258 script->set_shared_function_infos(isolate->heap()->empty_fixed_array()); | 1263 script->set_shared_function_infos(isolate->heap()->empty_fixed_array()); |
1259 | 1264 |
1260 // Start a compilation. | 1265 // Start a compilation. |
1261 ParseInfo parse_info(script); | 1266 Zone zone(isolate->allocator(), ZONE_NAME); |
| 1267 ParseInfo parse_info(&zone, script); |
1262 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1268 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1263 info.MarkAsDebug(); | 1269 info.MarkAsDebug(); |
1264 | 1270 |
1265 // TODO(635): support extensions. | 1271 // TODO(635): support extensions. |
1266 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); | 1272 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); |
1267 Handle<JSArray> infos; | 1273 Handle<JSArray> infos; |
1268 if (compilation_succeeded) { | 1274 if (compilation_succeeded) { |
1269 // Check postconditions on success. | 1275 // Check postconditions on success. |
1270 DCHECK(!isolate->has_pending_exception()); | 1276 DCHECK(!isolate->has_pending_exception()); |
1271 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script, | 1277 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script, |
1272 parse_info.zone(), isolate); | 1278 &zone, isolate); |
1273 } | 1279 } |
1274 | 1280 |
1275 // Restore the original function info list in order to remain side-effect | 1281 // Restore the original function info list in order to remain side-effect |
1276 // free as much as possible, since some code expects the old shared function | 1282 // free as much as possible, since some code expects the old shared function |
1277 // infos to stick around. | 1283 // infos to stick around. |
1278 script->set_shared_function_infos(*old_function_infos); | 1284 script->set_shared_function_infos(*old_function_infos); |
1279 | 1285 |
1280 return infos; | 1286 return infos; |
1281 } | 1287 } |
1282 | 1288 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 } | 1392 } |
1387 if (!script_name.is_null()) { | 1393 if (!script_name.is_null()) { |
1388 script->set_name(*script_name); | 1394 script->set_name(*script_name); |
1389 script->set_line_offset(line_offset); | 1395 script->set_line_offset(line_offset); |
1390 script->set_column_offset(column_offset); | 1396 script->set_column_offset(column_offset); |
1391 } | 1397 } |
1392 script->set_origin_options(options); | 1398 script->set_origin_options(options); |
1393 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); | 1399 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); |
1394 Script::SetEvalOrigin(script, outer_info, eval_position); | 1400 Script::SetEvalOrigin(script, outer_info, eval_position); |
1395 | 1401 |
1396 ParseInfo parse_info(script); | 1402 Zone zone(isolate->allocator(), ZONE_NAME); |
| 1403 ParseInfo parse_info(&zone, script); |
1397 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1404 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1398 parse_info.set_eval(); | 1405 parse_info.set_eval(); |
1399 parse_info.set_language_mode(language_mode); | 1406 parse_info.set_language_mode(language_mode); |
1400 parse_info.set_parse_restriction(restriction); | 1407 parse_info.set_parse_restriction(restriction); |
1401 if (!context->IsNativeContext()) { | 1408 if (!context->IsNativeContext()) { |
1402 parse_info.set_outer_scope_info(handle(context->scope_info())); | 1409 parse_info.set_outer_scope_info(handle(context->scope_info())); |
1403 } | 1410 } |
1404 | 1411 |
1405 shared_info = CompileToplevel(&info); | 1412 shared_info = CompileToplevel(&info); |
1406 | 1413 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 script->set_name(*script_name); | 1571 script->set_name(*script_name); |
1565 script->set_line_offset(line_offset); | 1572 script->set_line_offset(line_offset); |
1566 script->set_column_offset(column_offset); | 1573 script->set_column_offset(column_offset); |
1567 } | 1574 } |
1568 script->set_origin_options(resource_options); | 1575 script->set_origin_options(resource_options); |
1569 if (!source_map_url.is_null()) { | 1576 if (!source_map_url.is_null()) { |
1570 script->set_source_mapping_url(*source_map_url); | 1577 script->set_source_mapping_url(*source_map_url); |
1571 } | 1578 } |
1572 | 1579 |
1573 // Compile the function and add it to the cache. | 1580 // Compile the function and add it to the cache. |
1574 ParseInfo parse_info(script); | 1581 Zone zone(isolate->allocator(), ZONE_NAME); |
| 1582 ParseInfo parse_info(&zone, script); |
1575 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1583 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1576 if (resource_options.IsModule()) parse_info.set_module(); | 1584 if (resource_options.IsModule()) parse_info.set_module(); |
1577 if (compile_options != ScriptCompiler::kNoCompileOptions) { | 1585 if (compile_options != ScriptCompiler::kNoCompileOptions) { |
1578 parse_info.set_cached_data(cached_data); | 1586 parse_info.set_cached_data(cached_data); |
1579 } | 1587 } |
1580 parse_info.set_compile_options(compile_options); | 1588 parse_info.set_compile_options(compile_options); |
1581 parse_info.set_extension(extension); | 1589 parse_info.set_extension(extension); |
1582 if (!context->IsNativeContext()) { | 1590 if (!context->IsNativeContext()) { |
1583 parse_info.set_outer_scope_info(handle(context->scope_info())); | 1591 parse_info.set_outer_scope_info(handle(context->scope_info())); |
1584 } | 1592 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 DCHECK(shared->is_compiled()); | 1769 DCHECK(shared->is_compiled()); |
1762 function->set_literals(cached.literals); | 1770 function->set_literals(cached.literals); |
1763 } else if (shared->is_compiled()) { | 1771 } else if (shared->is_compiled()) { |
1764 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1772 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
1765 JSFunction::EnsureLiterals(function); | 1773 JSFunction::EnsureLiterals(function); |
1766 } | 1774 } |
1767 } | 1775 } |
1768 | 1776 |
1769 } // namespace internal | 1777 } // namespace internal |
1770 } // namespace v8 | 1778 } // namespace v8 |
OLD | NEW |