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 | 8 |
9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 | 1006 |
1007 | 1007 |
1008 void Compiler::CompileForLiveEdit(Handle<Script> script) { | 1008 void Compiler::CompileForLiveEdit(Handle<Script> script) { |
1009 // TODO(635): support extensions. | 1009 // TODO(635): support extensions. |
1010 Zone zone; | 1010 Zone zone; |
1011 ParseInfo parse_info(&zone, script); | 1011 ParseInfo parse_info(&zone, script); |
1012 CompilationInfo info(&parse_info); | 1012 CompilationInfo info(&parse_info); |
1013 PostponeInterruptsScope postpone(info.isolate()); | 1013 PostponeInterruptsScope postpone(info.isolate()); |
1014 VMState<COMPILER> state(info.isolate()); | 1014 VMState<COMPILER> state(info.isolate()); |
1015 | 1015 |
| 1016 // Get rid of old list of shared function infos. |
| 1017 script->set_shared_function_infos(Smi::FromInt(0)); |
| 1018 |
1016 info.parse_info()->set_global(); | 1019 info.parse_info()->set_global(); |
1017 if (!Parser::ParseStatic(info.parse_info())) return; | 1020 if (!Parser::ParseStatic(info.parse_info())) return; |
1018 | 1021 |
1019 LiveEditFunctionTracker tracker(info.isolate(), info.function()); | 1022 LiveEditFunctionTracker tracker(info.isolate(), info.function()); |
1020 if (!CompileUnoptimizedCode(&info)) return; | 1023 if (!CompileUnoptimizedCode(&info)) return; |
1021 if (info.has_shared_info()) { | 1024 if (info.has_shared_info()) { |
1022 Handle<ScopeInfo> scope_info = | 1025 Handle<ScopeInfo> scope_info = |
1023 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | 1026 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); |
1024 info.shared_info()->set_scope_info(*scope_info); | 1027 info.shared_info()->set_scope_info(*scope_info); |
1025 } | 1028 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 // Allocate function. | 1095 // Allocate function. |
1093 DCHECK(!info->code().is_null()); | 1096 DCHECK(!info->code().is_null()); |
1094 result = isolate->factory()->NewSharedFunctionInfo( | 1097 result = isolate->factory()->NewSharedFunctionInfo( |
1095 lit->name(), lit->materialized_literal_count(), lit->kind(), | 1098 lit->name(), lit->materialized_literal_count(), lit->kind(), |
1096 info->code(), | 1099 info->code(), |
1097 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), | 1100 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), |
1098 info->feedback_vector()); | 1101 info->feedback_vector()); |
1099 | 1102 |
1100 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | 1103 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
1101 SharedFunctionInfo::InitFromFunctionLiteral(result, lit); | 1104 SharedFunctionInfo::InitFromFunctionLiteral(result, lit); |
1102 result->set_script(*script); | 1105 SharedFunctionInfo::SetScript(result, script); |
1103 result->set_is_toplevel(true); | 1106 result->set_is_toplevel(true); |
1104 | 1107 |
1105 Handle<String> script_name = script->name()->IsString() | 1108 Handle<String> script_name = script->name()->IsString() |
1106 ? Handle<String>(String::cast(script->name())) | 1109 ? Handle<String>(String::cast(script->name())) |
1107 : isolate->factory()->empty_string(); | 1110 : isolate->factory()->empty_string(); |
1108 Logger::LogEventsAndTags log_tag = info->is_eval() | 1111 Logger::LogEventsAndTags log_tag = info->is_eval() |
1109 ? Logger::EVAL_TAG | 1112 ? Logger::EVAL_TAG |
1110 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); | 1113 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); |
1111 | 1114 |
1112 PROFILE(isolate, CodeCreateEvent( | 1115 PROFILE(isolate, CodeCreateEvent( |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 parse_info->set_language_mode( | 1328 parse_info->set_language_mode( |
1326 static_cast<LanguageMode>(parse_info->language_mode() | language_mode)); | 1329 static_cast<LanguageMode>(parse_info->language_mode() | language_mode)); |
1327 | 1330 |
1328 CompilationInfo compile_info(parse_info); | 1331 CompilationInfo compile_info(parse_info); |
1329 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the | 1332 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the |
1330 // real code caching lands, streaming needs to be adapted to use it. | 1333 // real code caching lands, streaming needs to be adapted to use it. |
1331 return CompileToplevel(&compile_info); | 1334 return CompileToplevel(&compile_info); |
1332 } | 1335 } |
1333 | 1336 |
1334 | 1337 |
1335 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( | 1338 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( |
1336 FunctionLiteral* literal, Handle<Script> script, | 1339 FunctionLiteral* literal, Handle<Script> script, |
1337 CompilationInfo* outer_info) { | 1340 CompilationInfo* outer_info) { |
1338 // Precondition: code has been parsed and scopes have been analyzed. | 1341 // Precondition: code has been parsed and scopes have been analyzed. |
| 1342 MaybeHandle<SharedFunctionInfo> maybe_existing = |
| 1343 script->FindSharedFunctionInfo(literal); |
| 1344 // We found an existing shared function info. If it's already compiled, |
| 1345 // don't worry about compiling it, and simply return it. If it's not yet |
| 1346 // compiled, continue to decide whether to eagerly compile. |
| 1347 Handle<SharedFunctionInfo> existing; |
| 1348 if (maybe_existing.ToHandle(&existing) && existing->is_compiled()) { |
| 1349 return existing; |
| 1350 } |
| 1351 |
1339 Zone zone; | 1352 Zone zone; |
1340 ParseInfo parse_info(&zone, script); | 1353 ParseInfo parse_info(&zone, script); |
1341 CompilationInfo info(&parse_info); | 1354 CompilationInfo info(&parse_info); |
1342 parse_info.set_literal(literal); | 1355 parse_info.set_literal(literal); |
1343 parse_info.set_scope(literal->scope()); | 1356 parse_info.set_scope(literal->scope()); |
1344 parse_info.set_language_mode(literal->scope()->language_mode()); | 1357 parse_info.set_language_mode(literal->scope()->language_mode()); |
1345 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1358 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
1346 | 1359 |
1347 Isolate* isolate = info.isolate(); | 1360 Isolate* isolate = info.isolate(); |
1348 Factory* factory = isolate->factory(); | 1361 Factory* factory = isolate->factory(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 DCHECK(!info.code().is_null()); | 1402 DCHECK(!info.code().is_null()); |
1390 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | 1403 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); |
1391 if (literal->should_eager_compile() && | 1404 if (literal->should_eager_compile() && |
1392 literal->should_be_used_once_hint()) { | 1405 literal->should_be_used_once_hint()) { |
1393 info.code()->MarkToBeExecutedOnce(isolate); | 1406 info.code()->MarkToBeExecutedOnce(isolate); |
1394 } | 1407 } |
1395 } else { | 1408 } else { |
1396 return Handle<SharedFunctionInfo>::null(); | 1409 return Handle<SharedFunctionInfo>::null(); |
1397 } | 1410 } |
1398 | 1411 |
1399 // Create a shared function info object. | 1412 if (maybe_existing.is_null()) { |
1400 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( | 1413 // Create a shared function info object. |
1401 literal->name(), literal->materialized_literal_count(), literal->kind(), | 1414 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( |
1402 info.code(), scope_info, info.feedback_vector()); | 1415 literal->name(), literal->materialized_literal_count(), literal->kind(), |
| 1416 info.code(), scope_info, info.feedback_vector()); |
1403 | 1417 |
1404 SharedFunctionInfo::InitFromFunctionLiteral(result, literal); | 1418 SharedFunctionInfo::InitFromFunctionLiteral(result, literal); |
1405 result->set_script(*script); | 1419 SharedFunctionInfo::SetScript(result, script); |
1406 result->set_is_toplevel(false); | 1420 result->set_is_toplevel(false); |
1407 | 1421 |
1408 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); | 1422 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
1409 result->set_allows_lazy_compilation(literal->AllowsLazyCompilation()); | 1423 result->set_allows_lazy_compilation(literal->AllowsLazyCompilation()); |
1410 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); | 1424 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); |
1411 | 1425 |
1412 // Set the expected number of properties for instances and return | 1426 // Set the expected number of properties for instances and return |
1413 // the resulting function. | 1427 // the resulting function. |
1414 SetExpectedNofPropertiesFromEstimate(result, | 1428 SetExpectedNofPropertiesFromEstimate(result, |
1415 literal->expected_property_count()); | 1429 literal->expected_property_count()); |
1416 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); | 1430 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); |
1417 return result; | 1431 return result; |
| 1432 } else { |
| 1433 // We may have additional data from compilation now. |
| 1434 DCHECK(!existing->is_compiled()); |
| 1435 existing->ReplaceCode(*info.code()); |
| 1436 existing->set_scope_info(*scope_info); |
| 1437 existing->set_feedback_vector(*info.feedback_vector()); |
| 1438 return existing; |
| 1439 } |
1418 } | 1440 } |
1419 | 1441 |
1420 | 1442 |
1421 MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function, | 1443 MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function, |
1422 Handle<Code> current_code, | 1444 Handle<Code> current_code, |
1423 ConcurrencyMode mode, | 1445 ConcurrencyMode mode, |
1424 BailoutId osr_ast_id) { | 1446 BailoutId osr_ast_id) { |
1425 Handle<Code> cached_code; | 1447 Handle<Code> cached_code; |
1426 if (GetCodeFromOptimizedCodeMap( | 1448 if (GetCodeFromOptimizedCodeMap( |
1427 function, osr_ast_id).ToHandle(&cached_code)) { | 1449 function, osr_ast_id).ToHandle(&cached_code)) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 | 1590 |
1569 | 1591 |
1570 #if DEBUG | 1592 #if DEBUG |
1571 void CompilationInfo::PrintAstForTesting() { | 1593 void CompilationInfo::PrintAstForTesting() { |
1572 PrintF("--- Source from AST ---\n%s\n", | 1594 PrintF("--- Source from AST ---\n%s\n", |
1573 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1595 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1574 } | 1596 } |
1575 #endif | 1597 #endif |
1576 } // namespace internal | 1598 } // namespace internal |
1577 } // namespace v8 | 1599 } // namespace v8 |
OLD | NEW |