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

Unified Diff: src/compiler.cc

Issue 1668103002: Type Feedback Vector lives in the closure (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler.h ('k') | src/compiler/access-builder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index 354542d56e3f44ff14420659726a56a493499aee..ae9d3f262556a431ebda83a927e5ace4b8480eb6 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();
@@ -812,6 +815,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());
@@ -829,7 +833,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());
@@ -1043,6 +1047,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;
@@ -1057,14 +1062,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;
}
@@ -1095,7 +1102,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();
@@ -1171,12 +1178,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;
}
@@ -1288,7 +1298,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());
@@ -1615,14 +1625,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
@@ -1642,7 +1648,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());
@@ -1671,7 +1677,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;
}
@@ -1697,7 +1703,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.
@@ -1745,6 +1751,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
« no previous file with comments | « src/compiler.h ('k') | src/compiler/access-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698