Index: src/compiler.cc |
diff --git a/src/compiler.cc b/src/compiler.cc |
index 7fbbfb17ff5daf7b809e94144a3b35a3f45ba633..9e45531a4b22124d09e2485a80a08d9296e96b8d 100644 |
--- a/src/compiler.cc |
+++ b/src/compiler.cc |
@@ -130,8 +130,8 @@ CompilationInfo::CompilationInfo(ParseInfo* parse_info) |
if (shared_info()->is_compiled()) { |
// We should initialize the CompilationInfo feedback vector from the |
// passed in shared info, rather than creating a new one. |
- feedback_vector_ = Handle<TypeFeedbackVector>( |
- shared_info()->feedback_vector(), parse_info->isolate()); |
+ feedback_metadata_ = Handle<TypeFeedbackMetadata>( |
+ shared_info()->feedback_metadata(), parse_info->isolate()); |
} |
if (shared_info()->never_compiled()) MarkAsFirstCompile(); |
} |
@@ -205,18 +205,16 @@ bool CompilationInfo::ShouldSelfOptimize() { |
(!has_shared_info() || !shared_info()->optimization_disabled()); |
} |
- |
-void CompilationInfo::EnsureFeedbackVector() { |
- if (feedback_vector_.is_null()) { |
- Handle<TypeFeedbackMetadata> feedback_metadata = |
+void CompilationInfo::EnsureFeedbackMetadata() { |
+ if (feedback_metadata_.is_null()) { |
+ feedback_metadata_ = |
TypeFeedbackMetadata::New(isolate(), literal()->feedback_vector_spec()); |
- feedback_vector_ = TypeFeedbackVector::New(isolate(), feedback_metadata); |
} |
// It's very important that recompiles do not alter the structure of the |
// type feedback vector. |
- CHECK(!feedback_vector_->metadata()->SpecDiffersFrom( |
- literal()->feedback_vector_spec())); |
+ CHECK( |
+ !feedback_metadata_->SpecDiffersFrom(literal()->feedback_vector_spec())); |
} |
@@ -383,6 +381,11 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() { |
DCHECK(info()->shared_info()->has_deoptimization_support()); |
DCHECK(!info()->is_first_compile()); |
+ // If we have a closure make sure it has the literals array at this point. |
+ if (!info()->closure().is_null()) { |
+ JSFunction::EnsureLiterals(info()->closure()); |
+ } |
+ |
bool optimization_disabled = info()->shared_info()->optimization_disabled(); |
bool dont_crankshaft = info()->shared_info()->dont_crankshaft(); |
@@ -787,6 +790,7 @@ MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( |
Handle<SharedFunctionInfo> shared = info->shared_info(); |
FunctionLiteral* lit = info->literal(); |
DCHECK_EQ(shared->language_mode(), lit->language_mode()); |
+ shared->set_num_literals(lit->materialized_literal_count()); |
SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
MaybeDisableOptimization(shared, lit->dont_optimize_reason()); |
@@ -804,7 +808,7 @@ MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( |
// Update the code and feedback vector for the shared function info. |
shared->ReplaceCode(*info->code()); |
- shared->set_feedback_vector(*info->feedback_vector()); |
+ shared->set_feedback_metadata(*info->feedback_metadata()); |
if (info->has_bytecode_array()) { |
DCHECK(shared->function_data()->IsUndefined()); |
shared->set_function_data(*info->bytecode_array()); |
@@ -1018,6 +1022,7 @@ MaybeHandle<Code> Compiler::GetLazyCode(Handle<JSFunction> function) { |
if (FLAG_always_opt) { |
Handle<Code> opt_code; |
+ JSFunction::EnsureLiterals(function); |
if (Compiler::GetOptimizedCode(function, Compiler::NOT_CONCURRENT) |
.ToHandle(&opt_code)) { |
result = opt_code; |
@@ -1032,14 +1037,16 @@ bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { |
if (function->is_compiled()) return true; |
MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function); |
Handle<Code> code; |
+ Isolate* isolate = function->GetIsolate(); |
if (!maybe_code.ToHandle(&code)) { |
if (flag == CLEAR_EXCEPTION) { |
- function->GetIsolate()->clear_pending_exception(); |
+ isolate->clear_pending_exception(); |
} |
return false; |
} |
function->ReplaceCode(*code); |
DCHECK(function->is_compiled()); |
+ JSFunction::EnsureLiterals(function); |
return true; |
} |
@@ -1070,7 +1077,7 @@ bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { |
if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; |
shared->EnableDeoptimizationSupport(*unoptimized.code()); |
- shared->set_feedback_vector(*unoptimized.feedback_vector()); |
+ shared->set_feedback_metadata(*unoptimized.feedback_metadata()); |
info->MarkAsCompiled(); |
@@ -1146,12 +1153,15 @@ static inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) { |
bool Compiler::CompileDebugCode(Handle<JSFunction> function) { |
Handle<SharedFunctionInfo> shared(function->shared()); |
+ bool result; |
if (IsEvalToplevel(shared)) { |
- return CompileEvalForDebugging(function, shared); |
+ result = CompileEvalForDebugging(function, shared); |
} else { |
CompilationInfoWithZone info(function); |
- return CompileForDebugging(&info); |
+ result = CompileForDebugging(&info); |
} |
+ JSFunction::EnsureLiterals(function); |
+ return result; |
} |
@@ -1263,7 +1273,7 @@ static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { |
lit->name(), lit->materialized_literal_count(), lit->kind(), |
info->code(), |
ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), |
- info->feedback_vector()); |
+ info->feedback_metadata()); |
if (info->has_bytecode_array()) { |
DCHECK(result->function_data()->IsUndefined()); |
result->set_function_data(*info->bytecode_array()); |
@@ -1590,14 +1600,10 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( |
if (lazy) { |
Handle<Code> code = isolate->builtins()->CompileLazy(); |
info.SetCode(code); |
- // There's no need in theory for a lazy-compiled function to have a type |
- // feedback vector, but some parts of the system expect all |
- // SharedFunctionInfo instances to have one. The size of the vector depends |
- // on how many feedback-needing nodes are in the tree, and when lazily |
- // parsing we might not know that, if this function was never parsed before. |
- // In that case the vector will be replaced the next time MakeCode is |
- // called. |
- info.EnsureFeedbackVector(); |
+ // There's no need in theory for a lazy-compiled function to have type |
+ // feedback metadata, but some parts of the system expect all |
+ // SharedFunctionInfo instances to have one. |
+ info.EnsureFeedbackMetadata(); |
scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); |
} else if (Renumber(info.parse_info()) && GenerateBaselineCode(&info)) { |
// Code generation will ensure that the feedback vector is present and |
@@ -1617,7 +1623,7 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( |
Handle<SharedFunctionInfo> result = |
isolate->factory()->NewSharedFunctionInfo( |
literal->name(), literal->materialized_literal_count(), |
- literal->kind(), info.code(), scope_info, info.feedback_vector()); |
+ literal->kind(), info.code(), scope_info, info.feedback_metadata()); |
if (info.has_bytecode_array()) { |
DCHECK(result->function_data()->IsUndefined()); |
result->set_function_data(*info.bytecode_array()); |
@@ -1646,7 +1652,7 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( |
DCHECK(!existing->HasDebugCode()); |
existing->ReplaceCode(*info.code()); |
existing->set_scope_info(*scope_info); |
- existing->set_feedback_vector(*info.feedback_vector()); |
+ existing->set_feedback_metadata(*info.feedback_metadata()); |
} |
return existing; |
} |
@@ -1672,7 +1678,7 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( |
Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo( |
name, literals, FunctionKind::kNormalFunction, code, |
Handle<ScopeInfo>(fun->shared()->scope_info()), |
- Handle<TypeFeedbackVector>(fun->shared()->feedback_vector())); |
+ Handle<TypeFeedbackMetadata>(fun->shared()->feedback_metadata())); |
shared->set_construct_stub(*construct_stub); |
// Copy the function data to the shared function info. |
@@ -1720,6 +1726,10 @@ MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function, |
shared->ReplaceCode(*current_code); |
} |
+ // At this point we know we've compiled the function, so make sure the closure |
+ // points to valid literals and type-feedback-vector. |
+ JSFunction::EnsureLiterals(function); |
+ |
current_code->set_profiler_ticks(0); |
// TODO(mstarzinger): We cannot properly deserialize a scope chain containing |