| 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" |
| 18 #include "src/compiler.h" | 19 #include "src/compiler.h" |
| 19 #include "src/cpu-profiler.h" | 20 #include "src/cpu-profiler.h" |
| 20 #include "src/date.h" | 21 #include "src/date.h" |
| 21 #include "src/debug.h" | 22 #include "src/debug.h" |
| 22 #include "src/deoptimizer.h" | 23 #include "src/deoptimizer.h" |
| 23 #include "src/elements.h" | 24 #include "src/elements.h" |
| 24 #include "src/execution.h" | 25 #include "src/execution.h" |
| 25 #include "src/field-index-inl.h" | 26 #include "src/field-index-inl.h" |
| 26 #include "src/field-index.h" | 27 #include "src/field-index.h" |
| 27 #include "src/full-codegen.h" | 28 #include "src/full-codegen.h" |
| (...skipping 12120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12148 } | 12149 } |
| 12149 | 12150 |
| 12150 RETURN_ON_EXCEPTION( | 12151 RETURN_ON_EXCEPTION( |
| 12151 isolate, EnqueueSpliceRecord(array, index, deleted, add_count), Object); | 12152 isolate, EnqueueSpliceRecord(array, index, deleted, add_count), Object); |
| 12152 | 12153 |
| 12153 return hresult; | 12154 return hresult; |
| 12154 } | 12155 } |
| 12155 | 12156 |
| 12156 | 12157 |
| 12157 // static | 12158 // static |
| 12158 void Map::AddDependentCompilationInfo(Handle<Map> map, | |
| 12159 DependentCode::DependencyGroup group, | |
| 12160 CompilationInfo* info) { | |
| 12161 Handle<DependentCode> codes = DependentCode::InsertCompilationInfo( | |
| 12162 handle(map->dependent_code(), info->isolate()), group, | |
| 12163 info->object_wrapper()); | |
| 12164 if (*codes != map->dependent_code()) map->set_dependent_code(*codes); | |
| 12165 info->dependencies(group)->Add(map, info->zone()); | |
| 12166 } | |
| 12167 | |
| 12168 | |
| 12169 // static | |
| 12170 void Map::AddDependentCode(Handle<Map> map, | 12159 void Map::AddDependentCode(Handle<Map> map, |
| 12171 DependentCode::DependencyGroup group, | 12160 DependentCode::DependencyGroup group, |
| 12172 Handle<Code> code) { | 12161 Handle<Code> code) { |
| 12173 Handle<WeakCell> cell = Code::WeakCellFor(code); | 12162 Handle<WeakCell> cell = Code::WeakCellFor(code); |
| 12174 Handle<DependentCode> codes = DependentCode::InsertWeakCode( | 12163 Handle<DependentCode> codes = DependentCode::InsertWeakCode( |
| 12175 Handle<DependentCode>(map->dependent_code()), group, cell); | 12164 Handle<DependentCode>(map->dependent_code()), group, cell); |
| 12176 if (*codes != map->dependent_code()) map->set_dependent_code(*codes); | 12165 if (*codes != map->dependent_code()) map->set_dependent_code(*codes); |
| 12177 } | 12166 } |
| 12178 | 12167 |
| 12179 | 12168 |
| 12180 DependentCode::GroupStartIndexes::GroupStartIndexes(DependentCode* entries) { | 12169 DependentCode::GroupStartIndexes::GroupStartIndexes(DependentCode* entries) { |
| 12181 Recompute(entries); | 12170 Recompute(entries); |
| 12182 } | 12171 } |
| 12183 | 12172 |
| 12184 | 12173 |
| 12185 void DependentCode::GroupStartIndexes::Recompute(DependentCode* entries) { | 12174 void DependentCode::GroupStartIndexes::Recompute(DependentCode* entries) { |
| 12186 start_indexes_[0] = 0; | 12175 start_indexes_[0] = 0; |
| 12187 for (int g = 1; g <= kGroupCount; g++) { | 12176 for (int g = 1; g <= kGroupCount; g++) { |
| 12188 int count = entries->number_of_entries(static_cast<DependencyGroup>(g - 1)); | 12177 int count = entries->number_of_entries(static_cast<DependencyGroup>(g - 1)); |
| 12189 start_indexes_[g] = start_indexes_[g - 1] + count; | 12178 start_indexes_[g] = start_indexes_[g - 1] + count; |
| 12190 } | 12179 } |
| 12191 } | 12180 } |
| 12192 | 12181 |
| 12193 | 12182 |
| 12194 DependentCode* DependentCode::ForObject(Handle<HeapObject> object, | 12183 Handle<DependentCode> DependentCode::InsertCompilationDependencies( |
| 12195 DependencyGroup group) { | |
| 12196 AllowDeferredHandleDereference dependencies_are_safe; | |
| 12197 if (group == DependentCode::kPropertyCellChangedGroup) { | |
| 12198 return Handle<PropertyCell>::cast(object)->dependent_code(); | |
| 12199 } else if (group == DependentCode::kAllocationSiteTenuringChangedGroup || | |
| 12200 group == DependentCode::kAllocationSiteTransitionChangedGroup) { | |
| 12201 return Handle<AllocationSite>::cast(object)->dependent_code(); | |
| 12202 } | |
| 12203 return Handle<Map>::cast(object)->dependent_code(); | |
| 12204 } | |
| 12205 | |
| 12206 | |
| 12207 Handle<DependentCode> DependentCode::InsertCompilationInfo( | |
| 12208 Handle<DependentCode> entries, DependencyGroup group, | 12184 Handle<DependentCode> entries, DependencyGroup group, |
| 12209 Handle<Foreign> info) { | 12185 Handle<Foreign> info) { |
| 12210 return Insert(entries, group, info); | 12186 return Insert(entries, group, info); |
| 12211 } | 12187 } |
| 12212 | 12188 |
| 12213 | 12189 |
| 12214 Handle<DependentCode> DependentCode::InsertWeakCode( | 12190 Handle<DependentCode> DependentCode::InsertWeakCode( |
| 12215 Handle<DependentCode> entries, DependencyGroup group, | 12191 Handle<DependentCode> entries, DependencyGroup group, |
| 12216 Handle<WeakCell> code_cell) { | 12192 Handle<WeakCell> code_cell) { |
| 12217 return Insert(entries, group, code_cell); | 12193 return Insert(entries, group, code_cell); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12303 } | 12279 } |
| 12304 | 12280 |
| 12305 #ifdef DEBUG | 12281 #ifdef DEBUG |
| 12306 for (int i = start; i < end; i++) { | 12282 for (int i = start; i < end; i++) { |
| 12307 DCHECK(object_at(i) != info); | 12283 DCHECK(object_at(i) != info); |
| 12308 } | 12284 } |
| 12309 #endif | 12285 #endif |
| 12310 } | 12286 } |
| 12311 | 12287 |
| 12312 | 12288 |
| 12313 void DependentCode::RemoveCompilationInfo(DependentCode::DependencyGroup group, | 12289 void DependentCode::RemoveCompilationDependencies( |
| 12314 Foreign* info) { | 12290 DependentCode::DependencyGroup group, Foreign* info) { |
| 12315 DisallowHeapAllocation no_allocation; | 12291 DisallowHeapAllocation no_allocation; |
| 12316 GroupStartIndexes starts(this); | 12292 GroupStartIndexes starts(this); |
| 12317 int start = starts.at(group); | 12293 int start = starts.at(group); |
| 12318 int end = starts.at(group + 1); | 12294 int end = starts.at(group + 1); |
| 12319 // Find compilation info wrapper. | 12295 // Find compilation info wrapper. |
| 12320 int info_pos = -1; | 12296 int info_pos = -1; |
| 12321 for (int i = start; i < end; i++) { | 12297 for (int i = start; i < end; i++) { |
| 12322 if (object_at(i) == info) { | 12298 if (object_at(i) == info) { |
| 12323 info_pos = i; | 12299 info_pos = i; |
| 12324 break; | 12300 break; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12378 Code* code = Code::cast(cell->value()); | 12354 Code* code = Code::cast(cell->value()); |
| 12379 if (!code->marked_for_deoptimization()) { | 12355 if (!code->marked_for_deoptimization()) { |
| 12380 SetMarkedForDeoptimization(code, group); | 12356 SetMarkedForDeoptimization(code, group); |
| 12381 if (invalidate_embedded_objects) { | 12357 if (invalidate_embedded_objects) { |
| 12382 code->InvalidateEmbeddedObjects(); | 12358 code->InvalidateEmbeddedObjects(); |
| 12383 } | 12359 } |
| 12384 marked = true; | 12360 marked = true; |
| 12385 } | 12361 } |
| 12386 } else { | 12362 } else { |
| 12387 DCHECK(obj->IsForeign()); | 12363 DCHECK(obj->IsForeign()); |
| 12388 CompilationInfo* info = reinterpret_cast<CompilationInfo*>( | 12364 CompilationDependencies* info = |
| 12389 Foreign::cast(obj)->foreign_address()); | 12365 reinterpret_cast<CompilationDependencies*>( |
| 12390 info->AbortDueToDependencyChange(); | 12366 Foreign::cast(obj)->foreign_address()); |
| 12367 info->Abort(); |
| 12391 } | 12368 } |
| 12392 } | 12369 } |
| 12393 // Compact the array by moving all subsequent groups to fill in the new holes. | 12370 // Compact the array by moving all subsequent groups to fill in the new holes. |
| 12394 for (int src = end, dst = start; src < code_entries; src++, dst++) { | 12371 for (int src = end, dst = start; src < code_entries; src++, dst++) { |
| 12395 copy(src, dst); | 12372 copy(src, dst); |
| 12396 } | 12373 } |
| 12397 // Now the holes are at the end of the array, zap them for heap-verifier. | 12374 // Now the holes are at the end of the array, zap them for heap-verifier. |
| 12398 int removed = end - start; | 12375 int removed = end - start; |
| 12399 for (int i = code_entries - removed; i < code_entries; i++) { | 12376 for (int i = code_entries - removed; i < code_entries; i++) { |
| 12400 clear_at(i); | 12377 clear_at(i); |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13460 ElementsKindToString(to_kind)); | 13437 ElementsKindToString(to_kind)); |
| 13461 } | 13438 } |
| 13462 site->SetElementsKind(to_kind); | 13439 site->SetElementsKind(to_kind); |
| 13463 site->dependent_code()->DeoptimizeDependentCodeGroup( | 13440 site->dependent_code()->DeoptimizeDependentCodeGroup( |
| 13464 isolate, DependentCode::kAllocationSiteTransitionChangedGroup); | 13441 isolate, DependentCode::kAllocationSiteTransitionChangedGroup); |
| 13465 } | 13442 } |
| 13466 } | 13443 } |
| 13467 } | 13444 } |
| 13468 | 13445 |
| 13469 | 13446 |
| 13470 // static | |
| 13471 void AllocationSite::RegisterForDeoptOnTenureChange(Handle<AllocationSite> site, | |
| 13472 CompilationInfo* info) { | |
| 13473 AddDependentCompilationInfo( | |
| 13474 site, DependentCode::kAllocationSiteTenuringChangedGroup, info); | |
| 13475 } | |
| 13476 | |
| 13477 | |
| 13478 // static | |
| 13479 void AllocationSite::RegisterForDeoptOnTransitionChange( | |
| 13480 Handle<AllocationSite> site, CompilationInfo* info) { | |
| 13481 // Do nothing if the object doesn't have any useful element transitions left. | |
| 13482 ElementsKind kind = | |
| 13483 site->SitePointsToLiteral() | |
| 13484 ? JSObject::cast(site->transition_info())->GetElementsKind() | |
| 13485 : site->GetElementsKind(); | |
| 13486 if (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) { | |
| 13487 AddDependentCompilationInfo( | |
| 13488 site, DependentCode::kAllocationSiteTransitionChangedGroup, info); | |
| 13489 } | |
| 13490 } | |
| 13491 | |
| 13492 | |
| 13493 // static | |
| 13494 void AllocationSite::AddDependentCompilationInfo( | |
| 13495 Handle<AllocationSite> site, DependentCode::DependencyGroup group, | |
| 13496 CompilationInfo* info) { | |
| 13497 Handle<DependentCode> dep(site->dependent_code()); | |
| 13498 Handle<DependentCode> codes = | |
| 13499 DependentCode::InsertCompilationInfo(dep, group, info->object_wrapper()); | |
| 13500 if (*codes != site->dependent_code()) site->set_dependent_code(*codes); | |
| 13501 info->dependencies(group)->Add(Handle<HeapObject>(*site), info->zone()); | |
| 13502 } | |
| 13503 | |
| 13504 | |
| 13505 const char* AllocationSite::PretenureDecisionName(PretenureDecision decision) { | 13447 const char* AllocationSite::PretenureDecisionName(PretenureDecision decision) { |
| 13506 switch (decision) { | 13448 switch (decision) { |
| 13507 case kUndecided: return "undecided"; | 13449 case kUndecided: return "undecided"; |
| 13508 case kDontTenure: return "don't tenure"; | 13450 case kDontTenure: return "don't tenure"; |
| 13509 case kMaybeTenure: return "maybe tenure"; | 13451 case kMaybeTenure: return "maybe tenure"; |
| 13510 case kTenure: return "tenure"; | 13452 case kTenure: return "tenure"; |
| 13511 case kZombie: return "zombie"; | 13453 case kZombie: return "zombie"; |
| 13512 default: UNREACHABLE(); | 13454 default: UNREACHABLE(); |
| 13513 } | 13455 } |
| 13514 return NULL; | 13456 return NULL; |
| (...skipping 3633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17148 // Deopt when transitioning from a constant type. | 17090 // Deopt when transitioning from a constant type. |
| 17149 if (!invalidate && old_type == PropertyCellType::kConstant && | 17091 if (!invalidate && old_type == PropertyCellType::kConstant && |
| 17150 new_type != PropertyCellType::kConstant) { | 17092 new_type != PropertyCellType::kConstant) { |
| 17151 auto isolate = dictionary->GetIsolate(); | 17093 auto isolate = dictionary->GetIsolate(); |
| 17152 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 17094 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 17153 isolate, DependentCode::kPropertyCellChangedGroup); | 17095 isolate, DependentCode::kPropertyCellChangedGroup); |
| 17154 } | 17096 } |
| 17155 return value; | 17097 return value; |
| 17156 } | 17098 } |
| 17157 | 17099 |
| 17158 | |
| 17159 // static | |
| 17160 void PropertyCell::AddDependentCompilationInfo(Handle<PropertyCell> cell, | |
| 17161 CompilationInfo* info) { | |
| 17162 Handle<DependentCode> codes = DependentCode::InsertCompilationInfo( | |
| 17163 handle(cell->dependent_code(), info->isolate()), | |
| 17164 DependentCode::kPropertyCellChangedGroup, info->object_wrapper()); | |
| 17165 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); | |
| 17166 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( | |
| 17167 cell, info->zone()); | |
| 17168 } | |
| 17169 | |
| 17170 } } // namespace v8::internal | 17100 } } // namespace v8::internal |
| OLD | NEW |