OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 11073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11084 | 11084 |
11085 | 11085 |
11086 void Map::ZapPrototypeTransitions() { | 11086 void Map::ZapPrototypeTransitions() { |
11087 FixedArray* proto_transitions = GetPrototypeTransitions(); | 11087 FixedArray* proto_transitions = GetPrototypeTransitions(); |
11088 MemsetPointer(proto_transitions->data_start(), | 11088 MemsetPointer(proto_transitions->data_start(), |
11089 GetHeap()->the_hole_value(), | 11089 GetHeap()->the_hole_value(), |
11090 proto_transitions->length()); | 11090 proto_transitions->length()); |
11091 } | 11091 } |
11092 | 11092 |
11093 | 11093 |
11094 void Map::AddDependentCompilationInfo(DependentCode::DependencyGroup group, | |
11095 CompilationInfo* info) { | |
11096 Handle<DependentCode> dep(dependent_code()); | |
11097 Handle<DependentCode> codes = | |
11098 DependentCode::Insert(dep, group, info->object_wrapper()); | |
11099 if (*codes != dependent_code()) set_dependent_code(*codes); | |
11100 info->dependent_maps(group)->Add(Handle<Map>(this), info->zone()); | |
11101 } | |
11102 | |
11103 | |
11104 void Map::AddDependentCode(DependentCode::DependencyGroup group, | |
11105 Handle<Code> code) { | |
11106 Handle<DependentCode> codes = DependentCode::Insert( | |
11107 Handle<DependentCode>(dependent_code()), group, code); | |
11108 if (*codes != dependent_code()) set_dependent_code(*codes); | |
11109 } | |
11110 | |
11111 | |
11112 DependentCode::GroupStartIndexes::GroupStartIndexes(DependentCode* entries) { | 11094 DependentCode::GroupStartIndexes::GroupStartIndexes(DependentCode* entries) { |
11113 Recompute(entries); | 11095 Recompute(entries); |
11114 } | 11096 } |
11115 | 11097 |
11116 | 11098 |
11117 void DependentCode::GroupStartIndexes::Recompute(DependentCode* entries) { | 11099 void DependentCode::GroupStartIndexes::Recompute(DependentCode* entries) { |
11118 start_indexes_[0] = 0; | 11100 start_indexes_[0] = 0; |
11119 for (int g = 1; g <= kGroupCount; g++) { | 11101 for (int g = 1; g <= kGroupCount; g++) { |
11120 int count = entries->number_of_entries(static_cast<DependencyGroup>(g - 1)); | 11102 int count = entries->number_of_entries(static_cast<DependencyGroup>(g - 1)); |
11121 start_indexes_[g] = start_indexes_[g - 1] + count; | 11103 start_indexes_[g] = start_indexes_[g - 1] + count; |
11122 } | 11104 } |
11123 } | 11105 } |
11124 | 11106 |
11125 | 11107 |
11126 Handle<DependentCode> DependentCode::Insert(Handle<DependentCode> entries, | 11108 Handle<DependentCode> DependentCode::Insert(Handle<DependentCode> entries, |
11127 DependencyGroup group, | 11109 DependencyGroup group, |
11128 Handle<Object> object) { | 11110 Handle<Code> value) { |
11129 GroupStartIndexes starts(*entries); | 11111 GroupStartIndexes starts(*entries); |
11130 int start = starts.at(group); | 11112 int start = starts.at(group); |
11131 int end = starts.at(group + 1); | 11113 int end = starts.at(group + 1); |
11132 int number_of_entries = starts.number_of_entries(); | 11114 int number_of_entries = starts.number_of_entries(); |
11133 if (start < end && entries->object_at(end - 1) == *object) { | 11115 if (start < end && entries->code_at(end - 1) == *value) { |
11134 // Do not append the compilation info if it is already in the array. | 11116 // Do not append the code if it is already in the array. |
11135 // It is sufficient to just check only the last element because | 11117 // It is sufficient to just check only the last element because |
11136 // we process embedded maps of an optimized code in one batch. | 11118 // we process embedded maps of an optimized code in one batch. |
11137 return entries; | 11119 return entries; |
11138 } | 11120 } |
11139 if (entries->length() < kCodesStartIndex + number_of_entries + 1) { | 11121 if (entries->length() < kCodesStartIndex + number_of_entries + 1) { |
11140 Factory* factory = entries->GetIsolate()->factory(); | 11122 Factory* factory = entries->GetIsolate()->factory(); |
11141 int capacity = kCodesStartIndex + number_of_entries + 1; | 11123 int capacity = kCodesStartIndex + number_of_entries + 1; |
11142 if (capacity > 5) capacity = capacity * 5 / 4; | 11124 if (capacity > 5) capacity = capacity * 5 / 4; |
11143 Handle<DependentCode> new_entries = Handle<DependentCode>::cast( | 11125 Handle<DependentCode> new_entries = Handle<DependentCode>::cast( |
11144 factory->CopySizeFixedArray(entries, capacity)); | 11126 factory->CopySizeFixedArray(entries, capacity)); |
11145 // The number of codes can change after GC. | 11127 // The number of codes can change after GC. |
11146 starts.Recompute(*entries); | 11128 starts.Recompute(*entries); |
11147 start = starts.at(group); | 11129 start = starts.at(group); |
11148 end = starts.at(group + 1); | 11130 end = starts.at(group + 1); |
11149 number_of_entries = starts.number_of_entries(); | 11131 number_of_entries = starts.number_of_entries(); |
11150 for (int i = 0; i < number_of_entries; i++) { | 11132 for (int i = 0; i < number_of_entries; i++) { |
11151 entries->clear_at(i); | 11133 entries->clear_code_at(i); |
11152 } | 11134 } |
11153 // If the old fixed array was empty, we need to reset counters of the | 11135 // If the old fixed array was empty, we need to reset counters of the |
11154 // new array. | 11136 // new array. |
11155 if (number_of_entries == 0) { | 11137 if (number_of_entries == 0) { |
11156 for (int g = 0; g < kGroupCount; g++) { | 11138 for (int g = 0; g < kGroupCount; g++) { |
11157 new_entries->set_number_of_entries(static_cast<DependencyGroup>(g), 0); | 11139 new_entries->set_number_of_entries(static_cast<DependencyGroup>(g), 0); |
11158 } | 11140 } |
11159 } | 11141 } |
11160 entries = new_entries; | 11142 entries = new_entries; |
11161 } | 11143 } |
11162 entries->ExtendGroup(group); | 11144 entries->ExtendGroup(group); |
11163 entries->set_object_at(end, *object); | 11145 entries->set_code_at(end, *value); |
11164 entries->set_number_of_entries(group, end + 1 - start); | 11146 entries->set_number_of_entries(group, end + 1 - start); |
11165 return entries; | 11147 return entries; |
11166 } | 11148 } |
11167 | 11149 |
11168 | 11150 |
11169 void DependentCode::UpdateToFinishedCode(DependencyGroup group, | |
11170 CompilationInfo* info, | |
11171 Code* code) { | |
11172 DisallowHeapAllocation no_gc; | |
11173 AllowDeferredHandleDereference get_object_wrapper; | |
11174 Foreign* info_wrapper = *info->object_wrapper(); | |
11175 GroupStartIndexes starts(this); | |
11176 int start = starts.at(group); | |
11177 int end = starts.at(group + 1); | |
11178 for (int i = start; i < end; i++) { | |
11179 if (object_at(i) == info_wrapper) { | |
11180 set_object_at(i, code); | |
11181 break; | |
11182 } | |
11183 } | |
11184 | |
11185 #ifdef DEBUG | |
11186 for (int i = start; i < end; i++) { | |
11187 ASSERT(is_code_at(i) || compilation_info_at(i) != info); | |
11188 } | |
11189 #endif | |
11190 } | |
11191 | |
11192 | |
11193 void DependentCode::RemoveCompilationInfo(DependentCode::DependencyGroup group, | |
11194 CompilationInfo* info) { | |
11195 DisallowHeapAllocation no_allocation; | |
11196 AllowDeferredHandleDereference get_object_wrapper; | |
11197 Foreign* info_wrapper = *info->object_wrapper(); | |
11198 GroupStartIndexes starts(this); | |
11199 int start = starts.at(group); | |
11200 int end = starts.at(group + 1); | |
11201 // Find compilation info wrapper. | |
11202 int info_pos = -1; | |
11203 for (int i = start; i < end; i++) { | |
11204 if (object_at(i) == info_wrapper) { | |
11205 info_pos = i; | |
11206 break; | |
11207 } | |
11208 } | |
11209 if (info_pos == -1) return; // Not found. | |
11210 int gap = info_pos; | |
11211 // Use the last of each group to fill the gap in the previous group. | |
11212 for (int i = group; i < kGroupCount; i++) { | |
11213 int last_of_group = starts.at(group + 1) - 1; | |
11214 ASSERT(last_of_group >= gap); | |
11215 if (last_of_group == gap) continue; | |
11216 copy(last_of_group, gap); | |
11217 gap = last_of_group; | |
11218 } | |
11219 clear_at(gap); // Clear last gap. | |
11220 set_number_of_entries(group, end - start - 1); | |
11221 | |
11222 #ifdef DEBUG | |
11223 for (int i = start; i < end - 1; i++) { | |
11224 ASSERT(is_code_at(i) || compilation_info_at(i) != info); | |
11225 } | |
11226 #endif | |
11227 } | |
11228 | |
11229 | |
11230 bool DependentCode::Contains(DependencyGroup group, Code* code) { | 11151 bool DependentCode::Contains(DependencyGroup group, Code* code) { |
11231 GroupStartIndexes starts(this); | 11152 GroupStartIndexes starts(this); |
11232 int number_of_entries = starts.number_of_code_entries(); | 11153 int number_of_entries = starts.at(kGroupCount); |
11233 for (int i = 0; i < number_of_entries; i++) { | 11154 for (int i = 0; i < number_of_entries; i++) { |
11234 if (object_at(i) == code) return true; | 11155 if (code_at(i) == code) return true; |
11235 } | 11156 } |
11236 return false; | 11157 return false; |
11237 } | 11158 } |
11238 | 11159 |
11239 | 11160 |
11240 class DeoptimizeDependentCodeFilter : public OptimizedFunctionFilter { | 11161 class DeoptimizeDependentCodeFilter : public OptimizedFunctionFilter { |
11241 public: | 11162 public: |
11242 virtual bool TakeFunction(JSFunction* function) { | 11163 virtual bool TakeFunction(JSFunction* function) { |
11243 return function->code()->marked_for_deoptimization(); | 11164 return function->code()->marked_for_deoptimization(); |
11244 } | 11165 } |
11245 }; | 11166 }; |
11246 | 11167 |
11247 | 11168 |
11248 void DependentCode::DeoptimizeDependentCodeGroup( | 11169 void DependentCode::DeoptimizeDependentCodeGroup( |
11249 Isolate* isolate, | 11170 Isolate* isolate, |
11250 DependentCode::DependencyGroup group) { | 11171 DependentCode::DependencyGroup group) { |
11251 DisallowHeapAllocation no_allocation_scope; | 11172 DisallowHeapAllocation no_allocation_scope; |
11252 DependentCode::GroupStartIndexes starts(this); | 11173 DependentCode::GroupStartIndexes starts(this); |
11253 int start = starts.at(group); | 11174 int start = starts.at(group); |
11254 int end = starts.at(group + 1); | 11175 int end = starts.at(group + 1); |
11255 int code_entries = starts.number_of_code_entries(); | 11176 int number_of_entries = starts.at(DependentCode::kGroupCount); |
11256 if (start == end) return; | 11177 if (start == end) return; |
11257 for (int i = start; i < end; i++) { | 11178 for (int i = start; i < end; i++) { |
11258 if (is_code_at(i)) { | 11179 Code* code = code_at(i); |
11259 Code* code = code_at(i); | 11180 code->set_marked_for_deoptimization(true); |
11260 code->set_marked_for_deoptimization(true); | |
11261 } else { | |
11262 CompilationInfo* info = compilation_info_at(i); | |
11263 info->AbortDueToDependentMap(); | |
11264 } | |
11265 } | 11181 } |
11266 // Compact the array by moving all subsequent groups to fill in the new holes. | 11182 // Compact the array by moving all subsequent groups to fill in the new holes. |
11267 for (int src = end, dst = start; src < code_entries; src++, dst++) { | 11183 for (int src = end, dst = start; src < number_of_entries; src++, dst++) { |
11268 copy(src, dst); | 11184 set_code_at(dst, code_at(src)); |
11269 } | 11185 } |
11270 // Now the holes are at the end of the array, zap them for heap-verifier. | 11186 // Now the holes are at the end of the array, zap them for heap-verifier. |
11271 int removed = end - start; | 11187 int removed = end - start; |
11272 for (int i = code_entries - removed; i < code_entries; i++) { | 11188 for (int i = number_of_entries - removed; i < number_of_entries; i++) { |
11273 clear_at(i); | 11189 clear_code_at(i); |
11274 } | 11190 } |
11275 set_number_of_entries(group, 0); | 11191 set_number_of_entries(group, 0); |
11276 DeoptimizeDependentCodeFilter filter; | 11192 DeoptimizeDependentCodeFilter filter; |
11277 Deoptimizer::DeoptimizeAllFunctionsWith(isolate, &filter); | 11193 Deoptimizer::DeoptimizeAllFunctionsWith(isolate, &filter); |
11278 } | 11194 } |
11279 | 11195 |
11280 | 11196 |
11281 MaybeObject* JSReceiver::SetPrototype(Object* value, | 11197 MaybeObject* JSReceiver::SetPrototype(Object* value, |
11282 bool skip_hidden_prototypes) { | 11198 bool skip_hidden_prototypes) { |
11283 #ifdef DEBUG | 11199 #ifdef DEBUG |
(...skipping 4504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15788 | 15704 |
15789 | 15705 |
15790 void JSTypedArray::Neuter() { | 15706 void JSTypedArray::Neuter() { |
15791 set_byte_offset(Smi::FromInt(0)); | 15707 set_byte_offset(Smi::FromInt(0)); |
15792 set_byte_length(Smi::FromInt(0)); | 15708 set_byte_length(Smi::FromInt(0)); |
15793 set_length(Smi::FromInt(0)); | 15709 set_length(Smi::FromInt(0)); |
15794 set_elements(GetHeap()->EmptyExternalArrayForMap(map())); | 15710 set_elements(GetHeap()->EmptyExternalArrayForMap(map())); |
15795 } | 15711 } |
15796 | 15712 |
15797 } } // namespace v8::internal | 15713 } } // namespace v8::internal |
OLD | NEW |