OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <iomanip> | 5 #include <iomanip> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
11 #include "src/allocation-site-scopes.h" | 11 #include "src/allocation-site-scopes.h" |
12 #include "src/api.h" | 12 #include "src/api.h" |
13 #include "src/arguments.h" | 13 #include "src/arguments.h" |
14 #include "src/base/bits.h" | 14 #include "src/base/bits.h" |
15 #include "src/bootstrapper.h" | 15 #include "src/bootstrapper.h" |
16 #include "src/code-stubs.h" | 16 #include "src/code-stubs.h" |
17 #include "src/codegen.h" | 17 #include "src/codegen.h" |
18 #include "src/compilation-dependencies.h" | |
19 #include "src/compiler.h" | 18 #include "src/compiler.h" |
20 #include "src/cpu-profiler.h" | 19 #include "src/cpu-profiler.h" |
21 #include "src/date.h" | 20 #include "src/date.h" |
22 #include "src/debug.h" | 21 #include "src/debug.h" |
23 #include "src/deoptimizer.h" | 22 #include "src/deoptimizer.h" |
24 #include "src/elements.h" | 23 #include "src/elements.h" |
25 #include "src/execution.h" | 24 #include "src/execution.h" |
26 #include "src/field-index-inl.h" | 25 #include "src/field-index-inl.h" |
27 #include "src/field-index.h" | 26 #include "src/field-index.h" |
28 #include "src/full-codegen.h" | 27 #include "src/full-codegen.h" |
(...skipping 12102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12131 } | 12130 } |
12132 | 12131 |
12133 RETURN_ON_EXCEPTION( | 12132 RETURN_ON_EXCEPTION( |
12134 isolate, EnqueueSpliceRecord(array, index, deleted, add_count), Object); | 12133 isolate, EnqueueSpliceRecord(array, index, deleted, add_count), Object); |
12135 | 12134 |
12136 return hresult; | 12135 return hresult; |
12137 } | 12136 } |
12138 | 12137 |
12139 | 12138 |
12140 // static | 12139 // static |
| 12140 void Map::AddDependentCompilationInfo(Handle<Map> map, |
| 12141 DependentCode::DependencyGroup group, |
| 12142 CompilationInfo* info) { |
| 12143 Handle<DependentCode> codes = DependentCode::InsertCompilationInfo( |
| 12144 handle(map->dependent_code(), info->isolate()), group, |
| 12145 info->object_wrapper()); |
| 12146 if (*codes != map->dependent_code()) map->set_dependent_code(*codes); |
| 12147 info->dependencies(group)->Add(map, info->zone()); |
| 12148 } |
| 12149 |
| 12150 |
| 12151 // static |
12141 void Map::AddDependentCode(Handle<Map> map, | 12152 void Map::AddDependentCode(Handle<Map> map, |
12142 DependentCode::DependencyGroup group, | 12153 DependentCode::DependencyGroup group, |
12143 Handle<Code> code) { | 12154 Handle<Code> code) { |
12144 Handle<WeakCell> cell = Code::WeakCellFor(code); | 12155 Handle<WeakCell> cell = Code::WeakCellFor(code); |
12145 Handle<DependentCode> codes = DependentCode::InsertWeakCode( | 12156 Handle<DependentCode> codes = DependentCode::InsertWeakCode( |
12146 Handle<DependentCode>(map->dependent_code()), group, cell); | 12157 Handle<DependentCode>(map->dependent_code()), group, cell); |
12147 if (*codes != map->dependent_code()) map->set_dependent_code(*codes); | 12158 if (*codes != map->dependent_code()) map->set_dependent_code(*codes); |
12148 } | 12159 } |
12149 | 12160 |
12150 | 12161 |
12151 DependentCode::GroupStartIndexes::GroupStartIndexes(DependentCode* entries) { | 12162 DependentCode::GroupStartIndexes::GroupStartIndexes(DependentCode* entries) { |
12152 Recompute(entries); | 12163 Recompute(entries); |
12153 } | 12164 } |
12154 | 12165 |
12155 | 12166 |
12156 void DependentCode::GroupStartIndexes::Recompute(DependentCode* entries) { | 12167 void DependentCode::GroupStartIndexes::Recompute(DependentCode* entries) { |
12157 start_indexes_[0] = 0; | 12168 start_indexes_[0] = 0; |
12158 for (int g = 1; g <= kGroupCount; g++) { | 12169 for (int g = 1; g <= kGroupCount; g++) { |
12159 int count = entries->number_of_entries(static_cast<DependencyGroup>(g - 1)); | 12170 int count = entries->number_of_entries(static_cast<DependencyGroup>(g - 1)); |
12160 start_indexes_[g] = start_indexes_[g - 1] + count; | 12171 start_indexes_[g] = start_indexes_[g - 1] + count; |
12161 } | 12172 } |
12162 } | 12173 } |
12163 | 12174 |
12164 | 12175 |
12165 Handle<DependentCode> DependentCode::InsertCompilationDependencies( | 12176 DependentCode* DependentCode::ForObject(Handle<HeapObject> object, |
| 12177 DependencyGroup group) { |
| 12178 AllowDeferredHandleDereference dependencies_are_safe; |
| 12179 if (group == DependentCode::kPropertyCellChangedGroup) { |
| 12180 return Handle<PropertyCell>::cast(object)->dependent_code(); |
| 12181 } else if (group == DependentCode::kAllocationSiteTenuringChangedGroup || |
| 12182 group == DependentCode::kAllocationSiteTransitionChangedGroup) { |
| 12183 return Handle<AllocationSite>::cast(object)->dependent_code(); |
| 12184 } |
| 12185 return Handle<Map>::cast(object)->dependent_code(); |
| 12186 } |
| 12187 |
| 12188 |
| 12189 Handle<DependentCode> DependentCode::InsertCompilationInfo( |
12166 Handle<DependentCode> entries, DependencyGroup group, | 12190 Handle<DependentCode> entries, DependencyGroup group, |
12167 Handle<Foreign> info) { | 12191 Handle<Foreign> info) { |
12168 return Insert(entries, group, info); | 12192 return Insert(entries, group, info); |
12169 } | 12193 } |
12170 | 12194 |
12171 | 12195 |
12172 Handle<DependentCode> DependentCode::InsertWeakCode( | 12196 Handle<DependentCode> DependentCode::InsertWeakCode( |
12173 Handle<DependentCode> entries, DependencyGroup group, | 12197 Handle<DependentCode> entries, DependencyGroup group, |
12174 Handle<WeakCell> code_cell) { | 12198 Handle<WeakCell> code_cell) { |
12175 return Insert(entries, group, code_cell); | 12199 return Insert(entries, group, code_cell); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12261 } | 12285 } |
12262 | 12286 |
12263 #ifdef DEBUG | 12287 #ifdef DEBUG |
12264 for (int i = start; i < end; i++) { | 12288 for (int i = start; i < end; i++) { |
12265 DCHECK(object_at(i) != info); | 12289 DCHECK(object_at(i) != info); |
12266 } | 12290 } |
12267 #endif | 12291 #endif |
12268 } | 12292 } |
12269 | 12293 |
12270 | 12294 |
12271 void DependentCode::RemoveCompilationDependencies( | 12295 void DependentCode::RemoveCompilationInfo(DependentCode::DependencyGroup group, |
12272 DependentCode::DependencyGroup group, Foreign* info) { | 12296 Foreign* info) { |
12273 DisallowHeapAllocation no_allocation; | 12297 DisallowHeapAllocation no_allocation; |
12274 GroupStartIndexes starts(this); | 12298 GroupStartIndexes starts(this); |
12275 int start = starts.at(group); | 12299 int start = starts.at(group); |
12276 int end = starts.at(group + 1); | 12300 int end = starts.at(group + 1); |
12277 // Find compilation info wrapper. | 12301 // Find compilation info wrapper. |
12278 int info_pos = -1; | 12302 int info_pos = -1; |
12279 for (int i = start; i < end; i++) { | 12303 for (int i = start; i < end; i++) { |
12280 if (object_at(i) == info) { | 12304 if (object_at(i) == info) { |
12281 info_pos = i; | 12305 info_pos = i; |
12282 break; | 12306 break; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12336 Code* code = Code::cast(cell->value()); | 12360 Code* code = Code::cast(cell->value()); |
12337 if (!code->marked_for_deoptimization()) { | 12361 if (!code->marked_for_deoptimization()) { |
12338 SetMarkedForDeoptimization(code, group); | 12362 SetMarkedForDeoptimization(code, group); |
12339 if (invalidate_embedded_objects) { | 12363 if (invalidate_embedded_objects) { |
12340 code->InvalidateEmbeddedObjects(); | 12364 code->InvalidateEmbeddedObjects(); |
12341 } | 12365 } |
12342 marked = true; | 12366 marked = true; |
12343 } | 12367 } |
12344 } else { | 12368 } else { |
12345 DCHECK(obj->IsForeign()); | 12369 DCHECK(obj->IsForeign()); |
12346 CompilationDependencies* info = | 12370 CompilationInfo* info = reinterpret_cast<CompilationInfo*>( |
12347 reinterpret_cast<CompilationDependencies*>( | 12371 Foreign::cast(obj)->foreign_address()); |
12348 Foreign::cast(obj)->foreign_address()); | 12372 info->AbortDueToDependencyChange(); |
12349 info->Abort(); | |
12350 } | 12373 } |
12351 } | 12374 } |
12352 // Compact the array by moving all subsequent groups to fill in the new holes. | 12375 // Compact the array by moving all subsequent groups to fill in the new holes. |
12353 for (int src = end, dst = start; src < code_entries; src++, dst++) { | 12376 for (int src = end, dst = start; src < code_entries; src++, dst++) { |
12354 copy(src, dst); | 12377 copy(src, dst); |
12355 } | 12378 } |
12356 // Now the holes are at the end of the array, zap them for heap-verifier. | 12379 // Now the holes are at the end of the array, zap them for heap-verifier. |
12357 int removed = end - start; | 12380 int removed = end - start; |
12358 for (int i = code_entries - removed; i < code_entries; i++) { | 12381 for (int i = code_entries - removed; i < code_entries; i++) { |
12359 clear_at(i); | 12382 clear_at(i); |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13419 ElementsKindToString(to_kind)); | 13442 ElementsKindToString(to_kind)); |
13420 } | 13443 } |
13421 site->SetElementsKind(to_kind); | 13444 site->SetElementsKind(to_kind); |
13422 site->dependent_code()->DeoptimizeDependentCodeGroup( | 13445 site->dependent_code()->DeoptimizeDependentCodeGroup( |
13423 isolate, DependentCode::kAllocationSiteTransitionChangedGroup); | 13446 isolate, DependentCode::kAllocationSiteTransitionChangedGroup); |
13424 } | 13447 } |
13425 } | 13448 } |
13426 } | 13449 } |
13427 | 13450 |
13428 | 13451 |
| 13452 // static |
| 13453 void AllocationSite::RegisterForDeoptOnTenureChange(Handle<AllocationSite> site, |
| 13454 CompilationInfo* info) { |
| 13455 AddDependentCompilationInfo( |
| 13456 site, DependentCode::kAllocationSiteTenuringChangedGroup, info); |
| 13457 } |
| 13458 |
| 13459 |
| 13460 // static |
| 13461 void AllocationSite::RegisterForDeoptOnTransitionChange( |
| 13462 Handle<AllocationSite> site, CompilationInfo* info) { |
| 13463 // Do nothing if the object doesn't have any useful element transitions left. |
| 13464 ElementsKind kind = |
| 13465 site->SitePointsToLiteral() |
| 13466 ? JSObject::cast(site->transition_info())->GetElementsKind() |
| 13467 : site->GetElementsKind(); |
| 13468 if (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) { |
| 13469 AddDependentCompilationInfo( |
| 13470 site, DependentCode::kAllocationSiteTransitionChangedGroup, info); |
| 13471 } |
| 13472 } |
| 13473 |
| 13474 |
| 13475 // static |
| 13476 void AllocationSite::AddDependentCompilationInfo( |
| 13477 Handle<AllocationSite> site, DependentCode::DependencyGroup group, |
| 13478 CompilationInfo* info) { |
| 13479 Handle<DependentCode> dep(site->dependent_code()); |
| 13480 Handle<DependentCode> codes = |
| 13481 DependentCode::InsertCompilationInfo(dep, group, info->object_wrapper()); |
| 13482 if (*codes != site->dependent_code()) site->set_dependent_code(*codes); |
| 13483 info->dependencies(group)->Add(Handle<HeapObject>(*site), info->zone()); |
| 13484 } |
| 13485 |
| 13486 |
13429 const char* AllocationSite::PretenureDecisionName(PretenureDecision decision) { | 13487 const char* AllocationSite::PretenureDecisionName(PretenureDecision decision) { |
13430 switch (decision) { | 13488 switch (decision) { |
13431 case kUndecided: return "undecided"; | 13489 case kUndecided: return "undecided"; |
13432 case kDontTenure: return "don't tenure"; | 13490 case kDontTenure: return "don't tenure"; |
13433 case kMaybeTenure: return "maybe tenure"; | 13491 case kMaybeTenure: return "maybe tenure"; |
13434 case kTenure: return "tenure"; | 13492 case kTenure: return "tenure"; |
13435 case kZombie: return "zombie"; | 13493 case kZombie: return "zombie"; |
13436 default: UNREACHABLE(); | 13494 default: UNREACHABLE(); |
13437 } | 13495 } |
13438 return NULL; | 13496 return NULL; |
(...skipping 3633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17072 // Deopt when transitioning from a constant type. | 17130 // Deopt when transitioning from a constant type. |
17073 if (!invalidate && old_type == PropertyCellType::kConstant && | 17131 if (!invalidate && old_type == PropertyCellType::kConstant && |
17074 new_type != PropertyCellType::kConstant) { | 17132 new_type != PropertyCellType::kConstant) { |
17075 auto isolate = dictionary->GetIsolate(); | 17133 auto isolate = dictionary->GetIsolate(); |
17076 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 17134 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
17077 isolate, DependentCode::kPropertyCellChangedGroup); | 17135 isolate, DependentCode::kPropertyCellChangedGroup); |
17078 } | 17136 } |
17079 return value; | 17137 return value; |
17080 } | 17138 } |
17081 | 17139 |
| 17140 |
| 17141 // static |
| 17142 void PropertyCell::AddDependentCompilationInfo(Handle<PropertyCell> cell, |
| 17143 CompilationInfo* info) { |
| 17144 Handle<DependentCode> codes = DependentCode::InsertCompilationInfo( |
| 17145 handle(cell->dependent_code(), info->isolate()), |
| 17146 DependentCode::kPropertyCellChangedGroup, info->object_wrapper()); |
| 17147 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); |
| 17148 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( |
| 17149 cell, info->zone()); |
| 17150 } |
| 17151 |
17082 } } // namespace v8::internal | 17152 } } // namespace v8::internal |
OLD | NEW |