Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 46539311de9625d9c7ffccc54bd476ab5510a47b..3b93d61685ce89222ea9e923d3fa9fc26330b512 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -3624,6 +3624,7 @@ MaybeObject* JSObject::NormalizeProperties(PropertyNormalizationMode mode, |
} |
set_map(new_map); |
+ map_of_this->NotifyObjectLayoutChange(); |
set_properties(dictionary); |
@@ -5292,6 +5293,7 @@ MaybeObject* Map::CopyDropDescriptors() { |
result->set_pre_allocated_property_fields(pre_allocated_property_fields()); |
result->set_is_shared(false); |
result->ClearCodeCache(GetHeap()); |
+ NotifyObjectLayoutChange(); |
return result; |
} |
@@ -9501,43 +9503,102 @@ void Map::ZapPrototypeTransitions() { |
} |
-Handle<DependentCodes> DependentCodes::Append(Handle<DependentCodes> codes, |
+DependentCode::GroupStartIndexes::GroupStartIndexes(DependentCode* codes) { |
+ Recompute(codes); |
+} |
+ |
+ |
+void DependentCode::GroupStartIndexes::Recompute(DependentCode* codes) { |
+ start_indexes_[0] = 0; |
+ for (int g = 1; g <= kGroupCount; g++) { |
+ int count = codes->number_of_codes(static_cast<DependencyGroup>(g - 1)); |
+ start_indexes_[g] = start_indexes_[g - 1] + count; |
+ } |
+} |
+ |
+ |
+Handle<DependentCode> DependentCode::Insert(Handle<DependentCode> codes, |
+ DependencyGroup group, |
Handle<Code> value) { |
- int append_index = codes->number_of_codes(); |
- if (append_index > 0 && codes->code_at(append_index - 1) == *value) { |
+ GroupStartIndexes starts(*codes); |
+ int start = starts.at(group); |
+ int end = starts.at(group + 1); |
+ int number_of_codes = starts.at(kGroupCount); |
+ if (start < end && codes->code_at(end - 1) == *value) { |
// Do not append the code if it is already in the array. |
// It is sufficient to just check only the last element because |
// we process embedded maps of an optimized code in one batch. |
return codes; |
} |
- if (codes->length() < kCodesIndex + append_index + 1) { |
+ if (codes->length() < kCodesStartIndex + number_of_codes + 1) { |
Factory* factory = codes->GetIsolate()->factory(); |
- int capacity = kCodesIndex + append_index + 1; |
+ int capacity = kCodesStartIndex + number_of_codes + 1; |
if (capacity > 5) capacity = capacity * 5 / 4; |
- Handle<DependentCodes> new_codes = Handle<DependentCodes>::cast( |
+ Handle<DependentCode> new_codes = Handle<DependentCode>::cast( |
factory->CopySizeFixedArray(codes, capacity)); |
// The number of codes can change after GC. |
- append_index = codes->number_of_codes(); |
- for (int i = 0; i < append_index; i++) { |
+ starts.Recompute(*codes); |
+ start = starts.at(group); |
+ end = starts.at(group + 1); |
+ number_of_codes = starts.at(kGroupCount); |
+ for (int i = 0; i < number_of_codes; i++) { |
codes->clear_code_at(i); |
} |
+ // If the old fixed array was empty, we need to reset counters of the |
+ // new array. |
+ if (number_of_codes == 0) { |
+ for (int g = 0; g < kGroupCount; g++) { |
+ new_codes->set_number_of_codes(static_cast<DependencyGroup>(g), 0); |
+ } |
+ } |
codes = new_codes; |
} |
- codes->set_code_at(append_index, *value); |
- codes->set_number_of_codes(append_index + 1); |
+ codes->ExtendGroup(group); |
+ codes->set_code_at(end, *value); |
+ codes->set_number_of_codes(group, end + 1 - start); |
return codes; |
} |
-bool DependentCodes::Contains(Code* code) { |
- int limit = number_of_codes(); |
- for (int i = 0; i < limit; i++) { |
+bool DependentCode::Contains(DependencyGroup group, Code* code) { |
+ GroupStartIndexes starts(this); |
+ int number_of_codes = starts.at(kGroupCount); |
+ for (int i = 0; i < number_of_codes; i++) { |
if (code_at(i) == code) return true; |
} |
return false; |
} |
+class DeoptimizeDependentCodeFilter : public OptimizedFunctionFilter { |
+ public: |
+ virtual bool TakeFunction(JSFunction* function) { |
+ return function->code()->marked_for_deoptimization(); |
+ } |
+}; |
+ |
+ |
+void DependentCode::DeoptimizeDependentCodeGroup( |
+ DependentCode::DependencyGroup group) { |
+ AssertNoAllocation no_allocation_scope; |
+ DependentCode::GroupStartIndexes starts(this); |
+ int start = starts.at(group); |
+ int end = starts.at(group + 1); |
+ int number_of_codes = starts.at(DependentCode::kGroupCount); |
+ if (start == end) return; |
+ for (int i = start; i < end; i++) { |
+ Code* code = code_at(i); |
+ code->set_marked_for_deoptimization(true); |
+ } |
+ for (int src = end, dst = start; src < number_of_codes; src++, dst++) { |
+ set_code_at(dst, code_at(src)); |
+ } |
+ set_number_of_codes(group, 0); |
+ DeoptimizeDependentCodeFilter filter; |
+ Deoptimizer::DeoptimizeAllFunctionsWith(&filter); |
+} |
+ |
+ |
MaybeObject* JSReceiver::SetPrototype(Object* value, |
bool skip_hidden_prototypes) { |
#ifdef DEBUG |