| 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 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 | 1012 |
| 1013 void Compiler::CompileForLiveEdit(Handle<Script> script) { | 1013 void Compiler::CompileForLiveEdit(Handle<Script> script) { |
| 1014 // TODO(635): support extensions. | 1014 // TODO(635): support extensions. |
| 1015 Zone zone; | 1015 Zone zone; |
| 1016 ParseInfo parse_info(&zone, script); | 1016 ParseInfo parse_info(&zone, script); |
| 1017 CompilationInfo info(&parse_info); | 1017 CompilationInfo info(&parse_info); |
| 1018 PostponeInterruptsScope postpone(info.isolate()); | 1018 PostponeInterruptsScope postpone(info.isolate()); |
| 1019 VMState<COMPILER> state(info.isolate()); | 1019 VMState<COMPILER> state(info.isolate()); |
| 1020 | 1020 |
| 1021 // Get rid of old list of shared function infos. | 1021 // Get rid of old list of shared function infos. |
| 1022 script->set_shared_function_infos(Smi::FromInt(0)); | 1022 info.MarkAsFirstCompile(); |
| 1023 | |
| 1024 info.parse_info()->set_global(); | 1023 info.parse_info()->set_global(); |
| 1025 if (!Parser::ParseStatic(info.parse_info())) return; | 1024 if (!Parser::ParseStatic(info.parse_info())) return; |
| 1026 | 1025 |
| 1027 LiveEditFunctionTracker tracker(info.isolate(), info.function()); | 1026 LiveEditFunctionTracker tracker(info.isolate(), info.function()); |
| 1028 if (!CompileUnoptimizedCode(&info)) return; | 1027 if (!CompileUnoptimizedCode(&info)) return; |
| 1029 if (info.has_shared_info()) { | 1028 if (info.has_shared_info()) { |
| 1030 Handle<ScopeInfo> scope_info = | 1029 Handle<ScopeInfo> scope_info = |
| 1031 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | 1030 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); |
| 1032 info.shared_info()->set_scope_info(*scope_info); | 1031 info.shared_info()->set_scope_info(*scope_info); |
| 1033 } | 1032 } |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the | 1335 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the |
| 1337 // real code caching lands, streaming needs to be adapted to use it. | 1336 // real code caching lands, streaming needs to be adapted to use it. |
| 1338 return CompileToplevel(&compile_info); | 1337 return CompileToplevel(&compile_info); |
| 1339 } | 1338 } |
| 1340 | 1339 |
| 1341 | 1340 |
| 1342 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( | 1341 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( |
| 1343 FunctionLiteral* literal, Handle<Script> script, | 1342 FunctionLiteral* literal, Handle<Script> script, |
| 1344 CompilationInfo* outer_info) { | 1343 CompilationInfo* outer_info) { |
| 1345 // Precondition: code has been parsed and scopes have been analyzed. | 1344 // Precondition: code has been parsed and scopes have been analyzed. |
| 1345 Isolate* isolate = outer_info->isolate(); |
| 1346 MaybeHandle<SharedFunctionInfo> maybe_existing; | 1346 MaybeHandle<SharedFunctionInfo> maybe_existing; |
| 1347 if (outer_info->is_first_compile()) { | 1347 if (outer_info->is_first_compile()) { |
| 1348 // On the first compile, there are no existing shared function info for | 1348 // On the first compile, there are no existing shared function info for |
| 1349 // inner functions yet, so do not try to find them. | 1349 // inner functions yet, so do not try to find them. All bets are off for |
| 1350 DCHECK(script->FindSharedFunctionInfo(literal).is_null()); | 1350 // live edit though. |
| 1351 DCHECK(script->FindSharedFunctionInfo(literal).is_null() || |
| 1352 isolate->debug()->live_edit_enabled()); |
| 1351 } else { | 1353 } else { |
| 1352 maybe_existing = script->FindSharedFunctionInfo(literal); | 1354 maybe_existing = script->FindSharedFunctionInfo(literal); |
| 1353 } | 1355 } |
| 1354 // We found an existing shared function info. If it's already compiled, | 1356 // We found an existing shared function info. If it's already compiled, |
| 1355 // don't worry about compiling it, and simply return it. If it's not yet | 1357 // don't worry about compiling it, and simply return it. If it's not yet |
| 1356 // compiled, continue to decide whether to eagerly compile. | 1358 // compiled, continue to decide whether to eagerly compile. |
| 1357 Handle<SharedFunctionInfo> existing; | 1359 Handle<SharedFunctionInfo> existing; |
| 1358 if (maybe_existing.ToHandle(&existing) && existing->is_compiled()) { | 1360 if (maybe_existing.ToHandle(&existing) && existing->is_compiled()) { |
| 1359 return existing; | 1361 return existing; |
| 1360 } | 1362 } |
| 1361 | 1363 |
| 1362 Zone zone; | 1364 Zone zone; |
| 1363 ParseInfo parse_info(&zone, script); | 1365 ParseInfo parse_info(&zone, script); |
| 1364 CompilationInfo info(&parse_info); | 1366 CompilationInfo info(&parse_info); |
| 1365 parse_info.set_literal(literal); | 1367 parse_info.set_literal(literal); |
| 1366 parse_info.set_scope(literal->scope()); | 1368 parse_info.set_scope(literal->scope()); |
| 1367 parse_info.set_language_mode(literal->scope()->language_mode()); | 1369 parse_info.set_language_mode(literal->scope()->language_mode()); |
| 1368 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1370 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
| 1369 if (outer_info->is_first_compile()) info.MarkAsFirstCompile(); | 1371 if (outer_info->is_first_compile()) info.MarkAsFirstCompile(); |
| 1370 | 1372 |
| 1371 Isolate* isolate = info.isolate(); | |
| 1372 Factory* factory = isolate->factory(); | |
| 1373 LiveEditFunctionTracker live_edit_tracker(isolate, literal); | 1373 LiveEditFunctionTracker live_edit_tracker(isolate, literal); |
| 1374 // Determine if the function can be lazily compiled. This is necessary to | 1374 // Determine if the function can be lazily compiled. This is necessary to |
| 1375 // allow some of our builtin JS files to be lazily compiled. These | 1375 // allow some of our builtin JS files to be lazily compiled. These |
| 1376 // builtins cannot be handled lazily by the parser, since we have to know | 1376 // builtins cannot be handled lazily by the parser, since we have to know |
| 1377 // if a function uses the special natives syntax, which is something the | 1377 // if a function uses the special natives syntax, which is something the |
| 1378 // parser records. | 1378 // parser records. |
| 1379 // If the debugger requests compilation for break points, we cannot be | 1379 // If the debugger requests compilation for break points, we cannot be |
| 1380 // aggressive about lazy compilation, because it might trigger compilation | 1380 // aggressive about lazy compilation, because it might trigger compilation |
| 1381 // of functions without an outer context when setting a breakpoint through | 1381 // of functions without an outer context when setting a breakpoint through |
| 1382 // Debug::FindSharedFunctionInfoInScript. | 1382 // Debug::FindSharedFunctionInfoInScript. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 if (literal->should_eager_compile() && | 1417 if (literal->should_eager_compile() && |
| 1418 literal->should_be_used_once_hint()) { | 1418 literal->should_be_used_once_hint()) { |
| 1419 info.code()->MarkToBeExecutedOnce(isolate); | 1419 info.code()->MarkToBeExecutedOnce(isolate); |
| 1420 } | 1420 } |
| 1421 } else { | 1421 } else { |
| 1422 return Handle<SharedFunctionInfo>::null(); | 1422 return Handle<SharedFunctionInfo>::null(); |
| 1423 } | 1423 } |
| 1424 | 1424 |
| 1425 if (maybe_existing.is_null()) { | 1425 if (maybe_existing.is_null()) { |
| 1426 // Create a shared function info object. | 1426 // Create a shared function info object. |
| 1427 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( | 1427 Handle<SharedFunctionInfo> result = |
| 1428 literal->name(), literal->materialized_literal_count(), literal->kind(), | 1428 isolate->factory()->NewSharedFunctionInfo( |
| 1429 info.code(), scope_info, info.feedback_vector()); | 1429 literal->name(), literal->materialized_literal_count(), |
| 1430 literal->kind(), info.code(), scope_info, info.feedback_vector()); |
| 1430 | 1431 |
| 1431 SharedFunctionInfo::InitFromFunctionLiteral(result, literal); | 1432 SharedFunctionInfo::InitFromFunctionLiteral(result, literal); |
| 1432 SharedFunctionInfo::SetScript(result, script); | 1433 SharedFunctionInfo::SetScript(result, script); |
| 1433 result->set_is_toplevel(false); | 1434 result->set_is_toplevel(false); |
| 1434 // If the outer function has been compiled before, we cannot be sure that | 1435 // If the outer function has been compiled before, we cannot be sure that |
| 1435 // shared function info for this function literal has been created for the | 1436 // shared function info for this function literal has been created for the |
| 1436 // first time. It may have already been compiled previously. | 1437 // first time. It may have already been compiled previously. |
| 1437 result->set_never_compiled(outer_info->is_first_compile() && lazy); | 1438 result->set_never_compiled(outer_info->is_first_compile() && lazy); |
| 1438 | 1439 |
| 1439 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); | 1440 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 | 1618 |
| 1618 | 1619 |
| 1619 #if DEBUG | 1620 #if DEBUG |
| 1620 void CompilationInfo::PrintAstForTesting() { | 1621 void CompilationInfo::PrintAstForTesting() { |
| 1621 PrintF("--- Source from AST ---\n%s\n", | 1622 PrintF("--- Source from AST ---\n%s\n", |
| 1622 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1623 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
| 1623 } | 1624 } |
| 1624 #endif | 1625 #endif |
| 1625 } // namespace internal | 1626 } // namespace internal |
| 1626 } // namespace v8 | 1627 } // namespace v8 |
| OLD | NEW |