Index: src/full-codegen.cc |
diff --git a/src/full-codegen.cc b/src/full-codegen.cc |
index cbf013e0bc8dcf9be468b0e509baa26539202d34..fb31f3aecb14990597657e3e152385a57042d3c2 100644 |
--- a/src/full-codegen.cc |
+++ b/src/full-codegen.cc |
@@ -345,7 +345,6 @@ bool FullCodeGenerator::MakeCode(CompilationInfo* info) { |
info->function()->scope()->AllowsLazyCompilation()); |
cgen.PopulateDeoptimizationData(code); |
cgen.PopulateTypeFeedbackInfo(code); |
- cgen.PopulateTypeFeedbackCells(code); |
code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); |
code->set_handler_table(*cgen.handler_table()); |
#ifdef ENABLE_DEBUGGER_SUPPORT |
@@ -387,6 +386,82 @@ unsigned FullCodeGenerator::EmitBackEdgeTable() { |
} |
+void FullCodeGenerator::FeedbackVectorWrapper::Initialize( |
+ Isolate* isolate, |
+ int minimum_length, |
+ int maximum_length) { |
+ ASSERT_EQ(isolate->heap()->the_hole_value(), |
+ *TypeFeedbackInfo::UninitializedSentinel(isolate)); |
+ feedback_vector_ = isolate->factory()->NewFixedArrayWithHoles(minimum_length, |
Benedikt Meurer
2014/01/24 11:29:54
As discussed offline: Please add an explanation he
mvstanton
2014/01/30 15:13:41
Changed to a new approach.
|
+ TENURED); |
+ maximum_length_ = maximum_length; |
+ used_ = 0; |
+} |
+ |
+ |
+void FullCodeGenerator::FeedbackVectorWrapper::Visit( |
+ Isolate* isolate, |
+ AstNode* node) { |
+ int new_used = node->ConsumeFeedbackSlots(isolate, used_); |
+ if (new_used > used_) { |
+ int old_vector_length = feedback_vector_->length(); |
+ if (new_used > old_vector_length) { |
+ int min_extra = new_used - old_vector_length; |
+ int max_extra = maximum_length_ - old_vector_length; |
+ int extra = Min(min_extra * 4, max_extra); |
+ |
+ if (FLAG_trace_type_feedback) { |
+ PrintF("Growing vector (min, max, chosen) (%d, %d, %d)\n", |
+ min_extra, max_extra, extra); |
+ } |
+ |
+ // We must grow the vector, somewhere between [new_used, maximum_length_]. |
+ Handle<FixedArray> new_array = isolate->factory()->CopySizeFixedArray( |
+ feedback_vector_, |
+ feedback_vector_->length() + extra, |
+ TENURED); |
+ *(feedback_vector_.location()) = *new_array; |
+ |
+ // Initialize the slots to undefined |
+ for (int i = Max(0, old_vector_length - 1); |
+ i < feedback_vector_->length(); |
+ i++) { |
+ feedback_vector_->set( |
+ i, |
+ *TypeFeedbackInfo::UninitializedSentinel(isolate), |
+ SKIP_WRITE_BARRIER); |
+ } |
+ } |
+ |
+ used_ = new_used; |
+ ASSERT(used_ <= feedback_vector_->length()); |
+ } |
+} |
+ |
+ |
+void FullCodeGenerator::FeedbackVectorWrapper::Set( |
+ int slot, |
+ Handle<Object> object) { |
+ ASSERT(feedback_vector_->length() > slot); |
+ feedback_vector_->set(slot, *object); |
+} |
+ |
+ |
+void FullCodeGenerator::FeedbackVectorWrapper::Finalize(Isolate* isolate) { |
+ ASSERT(used_ <= feedback_vector_->length()); |
+ if (used_ < feedback_vector_->length()) { |
+ if (FLAG_trace_type_feedback) { |
+ PrintF("Allocated feedback vector: shrank %d to %d slots.\n", |
+ feedback_vector_->length(), used_); |
+ } |
+ |
+ if (used_ > 0) { |
+ feedback_vector_->Shrink(used_); |
+ } |
+ } |
+} |
+ |
+ |
void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { |
// Fill in the deoptimization information. |
ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); |
@@ -405,6 +480,7 @@ void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { |
void FullCodeGenerator::PopulateTypeFeedbackInfo(Handle<Code> code) { |
Handle<TypeFeedbackInfo> info = isolate()->factory()->NewTypeFeedbackInfo(); |
info->set_ic_total_count(ic_total_count_); |
+ info->set_feedback_vector(*FeedbackVector()); |
ASSERT(!isolate()->heap()->InNewSpace(*info)); |
code->set_type_feedback_info(*info); |
} |
@@ -425,21 +501,6 @@ void FullCodeGenerator::Initialize() { |
} |
-void FullCodeGenerator::PopulateTypeFeedbackCells(Handle<Code> code) { |
- if (type_feedback_cells_.is_empty()) return; |
- int length = type_feedback_cells_.length(); |
- int array_size = TypeFeedbackCells::LengthOfFixedArray(length); |
- Handle<TypeFeedbackCells> cache = Handle<TypeFeedbackCells>::cast( |
- isolate()->factory()->NewFixedArray(array_size, TENURED)); |
- for (int i = 0; i < length; i++) { |
- cache->SetAstId(i, type_feedback_cells_[i].ast_id); |
- cache->SetCell(i, *type_feedback_cells_[i].cell); |
- } |
- TypeFeedbackInfo::cast(code->type_feedback_info())->set_type_feedback_cells( |
- *cache); |
-} |
- |
- |
void FullCodeGenerator::PrepareForBailout(Expression* node, State state) { |
PrepareForBailoutForId(node->id(), state); |
} |
@@ -488,13 +549,6 @@ void FullCodeGenerator::PrepareForBailoutForId(BailoutId id, State state) { |
} |
-void FullCodeGenerator::RecordTypeFeedbackCell( |
- TypeFeedbackId id, Handle<Cell> cell) { |
- TypeFeedbackCellEntry entry = { id, cell }; |
- type_feedback_cells_.Add(entry, zone()); |
-} |
- |
- |
void FullCodeGenerator::RecordBackEdge(BailoutId ast_id) { |
// The pc offset does not need to be encoded and packed together with a state. |
ASSERT(masm_->pc_offset() > 0); |