| Index: src/compiler.cc
|
| diff --git a/src/compiler.cc b/src/compiler.cc
|
| index ef21f1f46f9e65ff227bdefb703fe4132101c59e..db92c2b20f4c86721aed29341bc6ecf4fd6dba68 100644
|
| --- a/src/compiler.cc
|
| +++ b/src/compiler.cc
|
| @@ -1013,6 +1013,9 @@ void Compiler::CompileForLiveEdit(Handle<Script> script) {
|
| PostponeInterruptsScope postpone(info.isolate());
|
| VMState<COMPILER> state(info.isolate());
|
|
|
| + // Get rid of old list of shared function infos.
|
| + script->set_shared_function_infos(Smi::FromInt(0));
|
| +
|
| info.parse_info()->set_global();
|
| if (!Parser::ParseStatic(info.parse_info())) return;
|
|
|
| @@ -1099,7 +1102,7 @@ static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
|
|
|
| DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position());
|
| SharedFunctionInfo::InitFromFunctionLiteral(result, lit);
|
| - result->set_script(*script);
|
| + SharedFunctionInfo::SetScript(result, script);
|
| result->set_is_toplevel(true);
|
|
|
| Handle<String> script_name = script->name()->IsString()
|
| @@ -1332,10 +1335,20 @@ Handle<SharedFunctionInfo> Compiler::CompileStreamedScript(
|
| }
|
|
|
|
|
| -Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(
|
| +Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
|
| FunctionLiteral* literal, Handle<Script> script,
|
| CompilationInfo* outer_info) {
|
| // Precondition: code has been parsed and scopes have been analyzed.
|
| + MaybeHandle<SharedFunctionInfo> maybe_existing =
|
| + script->FindSharedFunctionInfo(literal);
|
| + // We found an existing shared function info. If it's already compiled,
|
| + // don't worry about compiling it, and simply return it. If it's not yet
|
| + // compiled, continue to decide whether to eagerly compile.
|
| + Handle<SharedFunctionInfo> existing;
|
| + if (maybe_existing.ToHandle(&existing) && existing->is_compiled()) {
|
| + return existing;
|
| + }
|
| +
|
| Zone zone;
|
| ParseInfo parse_info(&zone, script);
|
| CompilationInfo info(&parse_info);
|
| @@ -1396,25 +1409,34 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(
|
| return Handle<SharedFunctionInfo>::null();
|
| }
|
|
|
| - // Create a shared function info object.
|
| - Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo(
|
| - literal->name(), literal->materialized_literal_count(), literal->kind(),
|
| - info.code(), scope_info, info.feedback_vector());
|
| + if (maybe_existing.is_null()) {
|
| + // Create a shared function info object.
|
| + Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo(
|
| + literal->name(), literal->materialized_literal_count(), literal->kind(),
|
| + info.code(), scope_info, info.feedback_vector());
|
|
|
| - SharedFunctionInfo::InitFromFunctionLiteral(result, literal);
|
| - result->set_script(*script);
|
| - result->set_is_toplevel(false);
|
| + SharedFunctionInfo::InitFromFunctionLiteral(result, literal);
|
| + SharedFunctionInfo::SetScript(result, script);
|
| + result->set_is_toplevel(false);
|
|
|
| - RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
|
| - result->set_allows_lazy_compilation(literal->AllowsLazyCompilation());
|
| - result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
|
| + RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
|
| + result->set_allows_lazy_compilation(literal->AllowsLazyCompilation());
|
| + result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
|
|
|
| - // Set the expected number of properties for instances and return
|
| - // the resulting function.
|
| - SetExpectedNofPropertiesFromEstimate(result,
|
| - literal->expected_property_count());
|
| - live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
|
| - return result;
|
| + // Set the expected number of properties for instances and return
|
| + // the resulting function.
|
| + SetExpectedNofPropertiesFromEstimate(result,
|
| + literal->expected_property_count());
|
| + live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
|
| + return result;
|
| + } else {
|
| + // We may have additional data from compilation now.
|
| + DCHECK(!existing->is_compiled());
|
| + existing->ReplaceCode(*info.code());
|
| + existing->set_scope_info(*scope_info);
|
| + existing->set_feedback_vector(*info.feedback_vector());
|
| + return existing;
|
| + }
|
| }
|
|
|
|
|
|
|