Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(867)

Side by Side Diff: src/compiler.cc

Issue 2632123006: Reland: [Parse] ParseInfo owns the parsing Zone. (Closed)
Patch Set: Rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/background-parsing-task.cc ('k') | src/compiler-dispatcher/compiler-dispatcher-job.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // Try to enqueue the eager function on the compiler dispatcher. 530 // Try to enqueue the eager function on the compiler dispatcher.
531 CompilerDispatcher* dispatcher = isolate->compiler_dispatcher(); 531 CompilerDispatcher* dispatcher = isolate->compiler_dispatcher();
532 if (UseCompilerDispatcher(dispatcher, literal->scope(), shared, is_debug, 532 if (UseCompilerDispatcher(dispatcher, literal->scope(), shared, is_debug,
533 will_serialize) && 533 will_serialize) &&
534 dispatcher->EnqueueAndStep(shared, literal)) { 534 dispatcher->EnqueueAndStep(shared, literal)) {
535 // If we have successfully queued up the function for compilation on the 535 // If we have successfully queued up the function for compilation on the
536 // compiler dispatcher then we are done. 536 // compiler dispatcher then we are done.
537 continue; 537 continue;
538 } else { 538 } else {
539 // Otherwise generate unoptimized code now. 539 // Otherwise generate unoptimized code now.
540 Zone zone(isolate->allocator(), ZONE_NAME); 540 ParseInfo parse_info(script);
541 ParseInfo parse_info(&zone, script);
542 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); 541 CompilationInfo info(&parse_info, Handle<JSFunction>::null());
543 542
544 parse_info.set_literal(literal); 543 parse_info.set_literal(literal);
545 parse_info.set_shared_info(shared); 544 parse_info.set_shared_info(shared);
546 parse_info.set_function_literal_id(shared->function_literal_id()); 545 parse_info.set_function_literal_id(shared->function_literal_id());
547 parse_info.set_language_mode(literal->scope()->language_mode()); 546 parse_info.set_language_mode(literal->scope()->language_mode());
548 parse_info.set_ast_value_factory( 547 parse_info.set_ast_value_factory(
549 outer_info->parse_info()->ast_value_factory()); 548 outer_info->parse_info()->ast_value_factory());
550 parse_info.set_ast_value_factory_owned(false); 549 parse_info.set_ast_value_factory_owned(false);
551 550
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); 917 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason()));
919 } 918 }
920 info->closure()->ReplaceCode(shared->code()); 919 info->closure()->ReplaceCode(shared->code());
921 return CompilationJob::FAILED; 920 return CompilationJob::FAILED;
922 } 921 }
923 922
924 MaybeHandle<Code> GetBaselineCode(Handle<JSFunction> function) { 923 MaybeHandle<Code> GetBaselineCode(Handle<JSFunction> function) {
925 Isolate* isolate = function->GetIsolate(); 924 Isolate* isolate = function->GetIsolate();
926 VMState<COMPILER> state(isolate); 925 VMState<COMPILER> state(isolate);
927 PostponeInterruptsScope postpone(isolate); 926 PostponeInterruptsScope postpone(isolate);
928 Zone zone(isolate->allocator(), ZONE_NAME); 927 ParseInfo parse_info(handle(function->shared()));
929 ParseInfo parse_info(&zone, handle(function->shared()));
930 CompilationInfo info(&parse_info, function); 928 CompilationInfo info(&parse_info, function);
931 929
932 DCHECK(function->shared()->is_compiled()); 930 DCHECK(function->shared()->is_compiled());
933 931
934 // Function no longer needs to be tiered up 932 // Function no longer needs to be tiered up
935 function->shared()->set_marked_for_tier_up(false); 933 function->shared()->set_marked_for_tier_up(false);
936 934
937 // Reset profiler ticks, function is no longer considered hot. 935 // Reset profiler ticks, function is no longer considered hot.
938 if (function->shared()->HasBytecodeArray()) { 936 if (function->shared()->HasBytecodeArray()) {
939 function->shared()->set_profiler_ticks(0); 937 function->shared()->set_profiler_ticks(0);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 if (function->shared()->is_compiled()) { 1050 if (function->shared()->is_compiled()) {
1053 return Handle<Code>(function->shared()->code()); 1051 return Handle<Code>(function->shared()->code());
1054 } 1052 }
1055 1053
1056 if (function->shared()->HasBytecodeArray()) { 1054 if (function->shared()->HasBytecodeArray()) {
1057 Handle<Code> entry = isolate->builtins()->InterpreterEntryTrampoline(); 1055 Handle<Code> entry = isolate->builtins()->InterpreterEntryTrampoline();
1058 function->shared()->ReplaceCode(*entry); 1056 function->shared()->ReplaceCode(*entry);
1059 return entry; 1057 return entry;
1060 } 1058 }
1061 1059
1062 Zone zone(isolate->allocator(), ZONE_NAME); 1060 ParseInfo parse_info(handle(function->shared()));
1063 ParseInfo parse_info(&zone, handle(function->shared()));
1064 CompilationInfo info(&parse_info, function); 1061 CompilationInfo info(&parse_info, function);
1065 Handle<Code> result; 1062 Handle<Code> result;
1066 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code); 1063 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code);
1067 1064
1068 if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) { 1065 if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) {
1069 Handle<Code> opt_code; 1066 Handle<Code> opt_code;
1070 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT) 1067 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT)
1071 .ToHandle(&opt_code)) { 1068 .ToHandle(&opt_code)) {
1072 result = opt_code; 1069 result = opt_code;
1073 } 1070 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 Handle<Code> code; 1231 Handle<Code> code;
1235 if (!GetOptimizedCode(function, mode).ToHandle(&code)) { 1232 if (!GetOptimizedCode(function, mode).ToHandle(&code)) {
1236 // Optimization failed, get unoptimized code. 1233 // Optimization failed, get unoptimized code.
1237 DCHECK(!isolate->has_pending_exception()); 1234 DCHECK(!isolate->has_pending_exception());
1238 if (function->shared()->is_compiled()) { 1235 if (function->shared()->is_compiled()) {
1239 code = handle(function->shared()->code(), isolate); 1236 code = handle(function->shared()->code(), isolate);
1240 } else if (function->shared()->HasBytecodeArray()) { 1237 } else if (function->shared()->HasBytecodeArray()) {
1241 code = isolate->builtins()->InterpreterEntryTrampoline(); 1238 code = isolate->builtins()->InterpreterEntryTrampoline();
1242 function->shared()->ReplaceCode(*code); 1239 function->shared()->ReplaceCode(*code);
1243 } else { 1240 } else {
1244 Zone zone(isolate->allocator(), ZONE_NAME); 1241 ParseInfo parse_info(handle(function->shared()));
1245 ParseInfo parse_info(&zone, handle(function->shared()));
1246 CompilationInfo info(&parse_info, function); 1242 CompilationInfo info(&parse_info, function);
1247 if (!GetUnoptimizedCode(&info).ToHandle(&code)) { 1243 if (!GetUnoptimizedCode(&info).ToHandle(&code)) {
1248 return false; 1244 return false;
1249 } 1245 }
1250 } 1246 }
1251 } 1247 }
1252 1248
1253 // Install code on closure. 1249 // Install code on closure.
1254 function->ReplaceCode(*code); 1250 function->ReplaceCode(*code);
1255 JSFunction::EnsureLiterals(function); 1251 JSFunction::EnsureLiterals(function);
1256 1252
1257 // Check postconditions on success. 1253 // Check postconditions on success.
1258 DCHECK(!isolate->has_pending_exception()); 1254 DCHECK(!isolate->has_pending_exception());
1259 DCHECK(function->shared()->is_compiled()); 1255 DCHECK(function->shared()->is_compiled());
1260 DCHECK(function->is_compiled()); 1256 DCHECK(function->is_compiled());
1261 return true; 1257 return true;
1262 } 1258 }
1263 1259
1264 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { 1260 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) {
1265 Isolate* isolate = shared->GetIsolate(); 1261 Isolate* isolate = shared->GetIsolate();
1266 DCHECK(AllowCompilation::IsAllowed(isolate)); 1262 DCHECK(AllowCompilation::IsAllowed(isolate));
1267 1263
1268 // Start a compilation. 1264 // Start a compilation.
1269 Zone zone(isolate->allocator(), ZONE_NAME); 1265 ParseInfo parse_info(shared);
1270 ParseInfo parse_info(&zone, shared);
1271 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); 1266 CompilationInfo info(&parse_info, Handle<JSFunction>::null());
1272 info.MarkAsDebug(); 1267 info.MarkAsDebug();
1273 if (GetUnoptimizedCode(&info).is_null()) { 1268 if (GetUnoptimizedCode(&info).is_null()) {
1274 isolate->clear_pending_exception(); 1269 isolate->clear_pending_exception();
1275 return false; 1270 return false;
1276 } 1271 }
1277 1272
1278 // Check postconditions on success. 1273 // Check postconditions on success.
1279 DCHECK(!isolate->has_pending_exception()); 1274 DCHECK(!isolate->has_pending_exception());
1280 DCHECK(shared->is_compiled()); 1275 DCHECK(shared->is_compiled());
1281 DCHECK(shared->HasDebugCode()); 1276 DCHECK(shared->HasDebugCode());
1282 return true; 1277 return true;
1283 } 1278 }
1284 1279
1285 MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) { 1280 MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) {
1286 Isolate* isolate = script->GetIsolate(); 1281 Isolate* isolate = script->GetIsolate();
1287 DCHECK(AllowCompilation::IsAllowed(isolate)); 1282 DCHECK(AllowCompilation::IsAllowed(isolate));
1288 1283
1289 // In order to ensure that live edit function info collection finds the newly 1284 // In order to ensure that live edit function info collection finds the newly
1290 // generated shared function infos, clear the script's list temporarily 1285 // generated shared function infos, clear the script's list temporarily
1291 // and restore it at the end of this method. 1286 // and restore it at the end of this method.
1292 Handle<FixedArray> old_function_infos(script->shared_function_infos(), 1287 Handle<FixedArray> old_function_infos(script->shared_function_infos(),
1293 isolate); 1288 isolate);
1294 script->set_shared_function_infos(isolate->heap()->empty_fixed_array()); 1289 script->set_shared_function_infos(isolate->heap()->empty_fixed_array());
1295 1290
1296 // Start a compilation. 1291 // Start a compilation.
1297 Zone zone(isolate->allocator(), ZONE_NAME); 1292 ParseInfo parse_info(script);
1298 ParseInfo parse_info(&zone, script);
1299 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); 1293 CompilationInfo info(&parse_info, Handle<JSFunction>::null());
1300 info.MarkAsDebug(); 1294 info.MarkAsDebug();
1301 1295
1302 // TODO(635): support extensions. 1296 // TODO(635): support extensions.
1303 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); 1297 const bool compilation_succeeded = !CompileToplevel(&info).is_null();
1304 Handle<JSArray> infos; 1298 Handle<JSArray> infos;
1305 if (compilation_succeeded) { 1299 if (compilation_succeeded) {
1306 // Check postconditions on success. 1300 // Check postconditions on success.
1307 DCHECK(!isolate->has_pending_exception()); 1301 DCHECK(!isolate->has_pending_exception());
1308 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script, 1302 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script,
1309 &zone, isolate); 1303 parse_info.zone(), isolate);
1310 } 1304 }
1311 1305
1312 // Restore the original function info list in order to remain side-effect 1306 // Restore the original function info list in order to remain side-effect
1313 // free as much as possible, since some code expects the old shared function 1307 // free as much as possible, since some code expects the old shared function
1314 // infos to stick around. 1308 // infos to stick around.
1315 script->set_shared_function_infos(*old_function_infos); 1309 script->set_shared_function_infos(*old_function_infos);
1316 1310
1317 return infos; 1311 return infos;
1318 } 1312 }
1319 1313
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 } 1423 }
1430 if (!script_name.is_null()) { 1424 if (!script_name.is_null()) {
1431 script->set_name(*script_name); 1425 script->set_name(*script_name);
1432 script->set_line_offset(line_offset); 1426 script->set_line_offset(line_offset);
1433 script->set_column_offset(column_offset); 1427 script->set_column_offset(column_offset);
1434 } 1428 }
1435 script->set_origin_options(options); 1429 script->set_origin_options(options);
1436 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); 1430 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL);
1437 Script::SetEvalOrigin(script, outer_info, eval_position); 1431 Script::SetEvalOrigin(script, outer_info, eval_position);
1438 1432
1439 Zone zone(isolate->allocator(), ZONE_NAME); 1433 ParseInfo parse_info(script);
1440 ParseInfo parse_info(&zone, script);
1441 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); 1434 CompilationInfo info(&parse_info, Handle<JSFunction>::null());
1442 parse_info.set_eval(); 1435 parse_info.set_eval();
1443 parse_info.set_language_mode(language_mode); 1436 parse_info.set_language_mode(language_mode);
1444 parse_info.set_parse_restriction(restriction); 1437 parse_info.set_parse_restriction(restriction);
1445 if (!context->IsNativeContext()) { 1438 if (!context->IsNativeContext()) {
1446 parse_info.set_outer_scope_info(handle(context->scope_info())); 1439 parse_info.set_outer_scope_info(handle(context->scope_info()));
1447 } 1440 }
1448 1441
1449 shared_info = CompileToplevel(&info); 1442 shared_info = CompileToplevel(&info);
1450 if (shared_info.is_null()) { 1443 if (shared_info.is_null()) {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 script->set_name(*script_name); 1632 script->set_name(*script_name);
1640 script->set_line_offset(line_offset); 1633 script->set_line_offset(line_offset);
1641 script->set_column_offset(column_offset); 1634 script->set_column_offset(column_offset);
1642 } 1635 }
1643 script->set_origin_options(resource_options); 1636 script->set_origin_options(resource_options);
1644 if (!source_map_url.is_null()) { 1637 if (!source_map_url.is_null()) {
1645 script->set_source_mapping_url(*source_map_url); 1638 script->set_source_mapping_url(*source_map_url);
1646 } 1639 }
1647 1640
1648 // Compile the function and add it to the cache. 1641 // Compile the function and add it to the cache.
1649 Zone zone(isolate->allocator(), ZONE_NAME); 1642 ParseInfo parse_info(script);
1650 ParseInfo parse_info(&zone, script);
1651 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); 1643 CompilationInfo info(&parse_info, Handle<JSFunction>::null());
1652 if (resource_options.IsModule()) parse_info.set_module(); 1644 if (resource_options.IsModule()) parse_info.set_module();
1653 if (compile_options != ScriptCompiler::kNoCompileOptions) { 1645 if (compile_options != ScriptCompiler::kNoCompileOptions) {
1654 parse_info.set_cached_data(cached_data); 1646 parse_info.set_cached_data(cached_data);
1655 } 1647 }
1656 parse_info.set_compile_options(compile_options); 1648 parse_info.set_compile_options(compile_options);
1657 parse_info.set_extension(extension); 1649 parse_info.set_extension(extension);
1658 if (!context->IsNativeContext()) { 1650 if (!context->IsNativeContext()) {
1659 parse_info.set_outer_scope_info(handle(context->scope_info())); 1651 parse_info.set_outer_scope_info(handle(context->scope_info()));
1660 } 1652 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 } 1829 }
1838 1830
1839 if (shared->is_compiled()) { 1831 if (shared->is_compiled()) {
1840 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. 1832 // TODO(mvstanton): pass pretenure flag to EnsureLiterals.
1841 JSFunction::EnsureLiterals(function); 1833 JSFunction::EnsureLiterals(function);
1842 } 1834 }
1843 } 1835 }
1844 1836
1845 } // namespace internal 1837 } // namespace internal
1846 } // namespace v8 1838 } // namespace v8
OLDNEW
« no previous file with comments | « src/background-parsing-task.cc ('k') | src/compiler-dispatcher/compiler-dispatcher-job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698