Commit b527ec11 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[compiler] Ensure feedback vector before compiling.

This makes sure the type feedback vector is allocated and installed on
the SharedFunctionInfo before any of the compilers are being called.
Note that this now allows for an object state where a function is not
compiled but has a valid feedback vector is installed. This is working
as intended and supported by the rest of the system.

R=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/1857203002

Cr-Commit-Position: refs/heads/master@{#35265}
parent e1674a24
...@@ -143,12 +143,6 @@ CompilationInfo::CompilationInfo(ParseInfo* parse_info) ...@@ -143,12 +143,6 @@ CompilationInfo::CompilationInfo(ParseInfo* parse_info)
if (FLAG_turbo_types) MarkAsTypingEnabled(); if (FLAG_turbo_types) MarkAsTypingEnabled();
if (has_shared_info()) { if (has_shared_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());
}
if (shared_info()->never_compiled()) MarkAsFirstCompile(); if (shared_info()->never_compiled()) MarkAsFirstCompile();
} }
} }
...@@ -222,20 +216,6 @@ bool CompilationInfo::ShouldSelfOptimize() { ...@@ -222,20 +216,6 @@ bool CompilationInfo::ShouldSelfOptimize() {
} }
void CompilationInfo::EnsureFeedbackVector() {
if (feedback_vector_.is_null()) {
Handle<TypeFeedbackMetadata> 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()));
}
bool CompilationInfo::has_simple_parameters() { bool CompilationInfo::has_simple_parameters() {
return scope()->has_simple_parameters(); return scope()->has_simple_parameters();
} }
...@@ -784,10 +764,30 @@ void RecordFunctionCompilation(Logger::LogEventsAndTags tag, ...@@ -784,10 +764,30 @@ void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
} }
} }
void EnsureFeedbackVector(CompilationInfo* info) {
if (!info->has_shared_info()) return;
// If no type feedback vector exists, we create one now. At this point the
// AstNumbering pass has already run. Note that we should reuse any existing
// feedback vector rather than creating a new one.
if (info->shared_info()->feedback_vector()->is_empty()) {
Handle<TypeFeedbackMetadata> feedback_metadata = TypeFeedbackMetadata::New(
info->isolate(), info->literal()->feedback_vector_spec());
Handle<TypeFeedbackVector> feedback_vector =
TypeFeedbackVector::New(info->isolate(), feedback_metadata);
info->shared_info()->set_feedback_vector(*feedback_vector);
}
// It's very important that recompiles do not alter the structure of the type
// feedback vector. Verify that the structure fits the function literal.
CHECK(!info->shared_info()->feedback_vector()->metadata()->SpecDiffersFrom(
info->literal()->feedback_vector_spec()));
}
bool CompileUnoptimizedCode(CompilationInfo* info) { bool CompileUnoptimizedCode(CompilationInfo* info) {
DCHECK(AllowCompilation::IsAllowed(info->isolate())); DCHECK(AllowCompilation::IsAllowed(info->isolate()));
if (!Compiler::Analyze(info->parse_info()) || if (!Compiler::Analyze(info->parse_info()) ||
!(info->EnsureFeedbackVector(), FullCodeGenerator::MakeCode(info))) { !(EnsureFeedbackVector(info), FullCodeGenerator::MakeCode(info))) {
Isolate* isolate = info->isolate(); Isolate* isolate = info->isolate();
if (!isolate->has_pending_exception()) isolate->StackOverflow(); if (!isolate->has_pending_exception()) isolate->StackOverflow();
return false; return false;
...@@ -839,7 +839,7 @@ int CodeAndMetadataSize(CompilationInfo* info) { ...@@ -839,7 +839,7 @@ int CodeAndMetadataSize(CompilationInfo* info) {
bool GenerateBaselineCode(CompilationInfo* info) { bool GenerateBaselineCode(CompilationInfo* info) {
bool success; bool success;
info->EnsureFeedbackVector(); EnsureFeedbackVector(info);
if (FLAG_ignition && UseIgnition(info)) { if (FLAG_ignition && UseIgnition(info)) {
success = interpreter::Interpreter::MakeBytecode(info); success = interpreter::Interpreter::MakeBytecode(info);
} else { } else {
...@@ -872,7 +872,6 @@ void InstallBaselineCompilationResult(CompilationInfo* info, ...@@ -872,7 +872,6 @@ void InstallBaselineCompilationResult(CompilationInfo* info,
DCHECK(!info->code().is_null()); DCHECK(!info->code().is_null());
shared->ReplaceCode(*info->code()); shared->ReplaceCode(*info->code());
shared->set_scope_info(*scope_info); shared->set_scope_info(*scope_info);
shared->set_feedback_vector(*info->feedback_vector());
if (info->has_bytecode_array()) { if (info->has_bytecode_array()) {
DCHECK(!shared->HasBytecodeArray()); // Only compiled once. DCHECK(!shared->HasBytecodeArray()); // Only compiled once.
shared->set_bytecode_array(*info->bytecode_array()); shared->set_bytecode_array(*info->bytecode_array());
...@@ -1460,11 +1459,10 @@ bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { ...@@ -1460,11 +1459,10 @@ bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
shared->code()->has_reloc_info_for_serialization()) { shared->code()->has_reloc_info_for_serialization()) {
unoptimized.PrepareForSerializing(); unoptimized.PrepareForSerializing();
} }
unoptimized.EnsureFeedbackVector(); EnsureFeedbackVector(&unoptimized);
if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; if (!FullCodeGenerator::MakeCode(&unoptimized)) return false;
shared->EnableDeoptimizationSupport(*unoptimized.code()); shared->EnableDeoptimizationSupport(*unoptimized.code());
shared->set_feedback_vector(*unoptimized.feedback_vector());
info->MarkAsCompiled(); info->MarkAsCompiled();
...@@ -1498,11 +1496,6 @@ void Compiler::CompileForLiveEdit(Handle<Script> script) { ...@@ -1498,11 +1496,6 @@ void Compiler::CompileForLiveEdit(Handle<Script> script) {
LiveEditFunctionTracker tracker(info.isolate(), parse_info.literal()); LiveEditFunctionTracker tracker(info.isolate(), parse_info.literal());
if (!CompileUnoptimizedCode(&info)) return; if (!CompileUnoptimizedCode(&info)) return;
if (info.has_shared_info()) {
Handle<ScopeInfo> scope_info =
ScopeInfo::Create(info.isolate(), info.zone(), info.scope());
info.shared_info()->set_scope_info(*scope_info);
}
tracker.RecordRootFunctionInfo(info.code()); tracker.RecordRootFunctionInfo(info.code());
} }
......
...@@ -322,10 +322,6 @@ class CompilationInfo { ...@@ -322,10 +322,6 @@ class CompilationInfo {
output_code_kind() == Code::FUNCTION; output_code_kind() == Code::FUNCTION;
} }
void EnsureFeedbackVector();
Handle<TypeFeedbackVector> feedback_vector() const {
return feedback_vector_;
}
void SetCode(Handle<Code> code) { code_ = code; } void SetCode(Handle<Code> code) { code_ = code; }
void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) { void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) {
...@@ -534,9 +530,6 @@ class CompilationInfo { ...@@ -534,9 +530,6 @@ class CompilationInfo {
// The compiled code. // The compiled code.
Handle<Code> code_; Handle<Code> code_;
// Used by codegen, ultimately kept rooted by the SharedFunctionInfo.
Handle<TypeFeedbackVector> feedback_vector_;
// Compilation mode flag and whether deoptimization is allowed. // Compilation mode flag and whether deoptimization is allowed.
Mode mode_; Mode mode_;
BailoutId osr_ast_id_; BailoutId osr_ast_id_;
......
...@@ -3156,7 +3156,7 @@ LanguageMode BytecodeGenerator::language_mode() const { ...@@ -3156,7 +3156,7 @@ LanguageMode BytecodeGenerator::language_mode() const {
int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
return info()->feedback_vector()->GetIndex(slot); return info()->shared_info()->feedback_vector()->GetIndex(slot);
} }
} // namespace interpreter } // namespace interpreter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment