OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 "src/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 12269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12280 PrintF(" ** Marking "); | 12280 PrintF(" ** Marking "); |
12281 ShortPrint(); | 12281 ShortPrint(); |
12282 PrintF(" for concurrent recompilation.\n"); | 12282 PrintF(" for concurrent recompilation.\n"); |
12283 } | 12283 } |
12284 set_code_no_write_barrier( | 12284 set_code_no_write_barrier( |
12285 isolate->builtins()->builtin(Builtins::kCompileOptimizedConcurrent)); | 12285 isolate->builtins()->builtin(Builtins::kCompileOptimizedConcurrent)); |
12286 // No write barrier required, since the builtin is part of the root set. | 12286 // No write barrier required, since the builtin is part of the root set. |
12287 } | 12287 } |
12288 | 12288 |
12289 | 12289 |
| 12290 // static |
| 12291 Handle<LiteralsArray> SharedFunctionInfo::FindOrCreateLiterals( |
| 12292 Handle<SharedFunctionInfo> shared, Handle<Context> native_context) { |
| 12293 Isolate* isolate = shared->GetIsolate(); |
| 12294 CodeAndLiterals result = |
| 12295 shared->SearchOptimizedCodeMap(*native_context, BailoutId::None()); |
| 12296 if (result.literals != nullptr) { |
| 12297 return handle(result.literals, isolate); |
| 12298 } |
| 12299 Handle<TypeFeedbackVector> feedback_vector = |
| 12300 TypeFeedbackVector::New(isolate, handle(shared->feedback_metadata())); |
| 12301 Handle<LiteralsArray> literals = LiteralsArray::New( |
| 12302 isolate, feedback_vector, shared->num_literals(), TENURED); |
| 12303 AddLiteralsToOptimizedCodeMap(shared, native_context, literals); |
| 12304 return literals; |
| 12305 } |
| 12306 |
| 12307 |
12290 void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( | 12308 void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( |
12291 Handle<SharedFunctionInfo> shared, Handle<Code> code) { | 12309 Handle<SharedFunctionInfo> shared, Handle<Code> code) { |
12292 Isolate* isolate = shared->GetIsolate(); | 12310 Isolate* isolate = shared->GetIsolate(); |
12293 if (isolate->serializer_enabled()) return; | 12311 if (isolate->serializer_enabled()) return; |
12294 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); | 12312 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); |
12295 // Empty code maps are unsupported. | 12313 // Empty code maps are unsupported. |
12296 if (!shared->OptimizedCodeMapIsCleared()) { | 12314 if (!shared->OptimizedCodeMapIsCleared()) { |
12297 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); | 12315 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); |
12298 // A collection may have occured and cleared the optimized code map in the | 12316 // A collection may have occured and cleared the optimized code map in the |
12299 // allocation above. | 12317 // allocation above. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12483 // Always trim even when array is cleared because of heap verifier. | 12501 // Always trim even when array is cleared because of heap verifier. |
12484 GetHeap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(code_map, | 12502 GetHeap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(code_map, |
12485 shrink_by); | 12503 shrink_by); |
12486 if (code_map->length() == kEntriesStart && | 12504 if (code_map->length() == kEntriesStart && |
12487 WeakCell::cast(code_map->get(kSharedCodeIndex))->cleared()) { | 12505 WeakCell::cast(code_map->get(kSharedCodeIndex))->cleared()) { |
12488 ClearOptimizedCodeMap(); | 12506 ClearOptimizedCodeMap(); |
12489 } | 12507 } |
12490 } | 12508 } |
12491 | 12509 |
12492 | 12510 |
| 12511 // static |
| 12512 void JSFunction::EnsureLiterals(Handle<JSFunction> function) { |
| 12513 Handle<SharedFunctionInfo> shared(function->shared()); |
| 12514 Handle<Context> native_context(function->context()->native_context()); |
| 12515 Handle<LiteralsArray> literals = |
| 12516 SharedFunctionInfo::FindOrCreateLiterals(shared, native_context); |
| 12517 function->set_literals(*literals); |
| 12518 } |
| 12519 |
| 12520 |
12493 static void GetMinInobjectSlack(Map* map, void* data) { | 12521 static void GetMinInobjectSlack(Map* map, void* data) { |
12494 int slack = map->unused_property_fields(); | 12522 int slack = map->unused_property_fields(); |
12495 if (*reinterpret_cast<int*>(data) > slack) { | 12523 if (*reinterpret_cast<int*>(data) > slack) { |
12496 *reinterpret_cast<int*>(data) = slack; | 12524 *reinterpret_cast<int*>(data) = slack; |
12497 } | 12525 } |
12498 } | 12526 } |
12499 | 12527 |
12500 | 12528 |
12501 static void ShrinkInstanceSize(Map* map, void* data) { | 12529 static void ShrinkInstanceSize(Map* map, void* data) { |
12502 int slack = *reinterpret_cast<int*>(data); | 12530 int slack = *reinterpret_cast<int*>(data); |
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13754 if (isolate->serializer_enabled()) return; | 13782 if (isolate->serializer_enabled()) return; |
13755 | 13783 |
13756 if (unused_property_fields() == 0) return; | 13784 if (unused_property_fields() == 0) return; |
13757 | 13785 |
13758 set_construction_counter(Map::kSlackTrackingCounterStart); | 13786 set_construction_counter(Map::kSlackTrackingCounterStart); |
13759 } | 13787 } |
13760 | 13788 |
13761 | 13789 |
13762 void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { | 13790 void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { |
13763 code()->ClearInlineCaches(); | 13791 code()->ClearInlineCaches(); |
13764 // If we clear ICs, we need to clear the type feedback vector too, since | |
13765 // CallICs are synced with a feedback vector slot. | |
13766 ClearTypeFeedbackInfo(); | |
13767 set_ic_age(new_ic_age); | 13792 set_ic_age(new_ic_age); |
13768 if (code()->kind() == Code::FUNCTION) { | 13793 if (code()->kind() == Code::FUNCTION) { |
13769 code()->set_profiler_ticks(0); | 13794 code()->set_profiler_ticks(0); |
13770 if (optimization_disabled() && | 13795 if (optimization_disabled() && |
13771 opt_count() >= FLAG_max_opt_count) { | 13796 opt_count() >= FLAG_max_opt_count) { |
13772 // Re-enable optimizations if they were disabled due to opt_count limit. | 13797 // Re-enable optimizations if they were disabled due to opt_count limit. |
13773 set_optimization_disabled(false); | 13798 set_optimization_disabled(false); |
13774 } | 13799 } |
13775 set_opt_count(0); | 13800 set_opt_count(0); |
13776 set_deopt_count(0); | 13801 set_deopt_count(0); |
(...skipping 19 matching lines...) Expand all Loading... |
13796 Object* shared_code = | 13821 Object* shared_code = |
13797 WeakCell::cast(optimized_code_map->get(kSharedCodeIndex))->value(); | 13822 WeakCell::cast(optimized_code_map->get(kSharedCodeIndex))->value(); |
13798 if (shared_code->IsCode() && osr_ast_id.IsNone()) { | 13823 if (shared_code->IsCode() && osr_ast_id.IsNone()) { |
13799 return kSharedCodeIndex; | 13824 return kSharedCodeIndex; |
13800 } | 13825 } |
13801 } | 13826 } |
13802 return -1; | 13827 return -1; |
13803 } | 13828 } |
13804 | 13829 |
13805 | 13830 |
| 13831 void SharedFunctionInfo::ClearCodeFromOptimizedCodeMap() { |
| 13832 if (!OptimizedCodeMapIsCleared()) { |
| 13833 FixedArray* optimized_code_map = this->optimized_code_map(); |
| 13834 int length = optimized_code_map->length(); |
| 13835 WeakCell* empty_weak_cell = GetHeap()->empty_weak_cell(); |
| 13836 for (int i = kEntriesStart; i < length; i += kEntryLength) { |
| 13837 optimized_code_map->set(i + kCachedCodeOffset, empty_weak_cell, |
| 13838 SKIP_WRITE_BARRIER); |
| 13839 } |
| 13840 optimized_code_map->set(kSharedCodeIndex, empty_weak_cell, |
| 13841 SKIP_WRITE_BARRIER); |
| 13842 } |
| 13843 } |
| 13844 |
| 13845 |
13806 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( | 13846 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( |
13807 Context* native_context, BailoutId osr_ast_id) { | 13847 Context* native_context, BailoutId osr_ast_id) { |
13808 CodeAndLiterals result = {nullptr, nullptr}; | 13848 CodeAndLiterals result = {nullptr, nullptr}; |
13809 int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id); | 13849 int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id); |
13810 if (entry != kNotFound) { | 13850 if (entry != kNotFound) { |
13811 FixedArray* code_map = optimized_code_map(); | 13851 FixedArray* code_map = optimized_code_map(); |
13812 if (entry == kSharedCodeIndex) { | 13852 if (entry == kSharedCodeIndex) { |
13813 // We know the weak cell isn't cleared because we made sure of it in | 13853 // We know the weak cell isn't cleared because we made sure of it in |
13814 // SearchOptimizedCodeMapEntry and performed no allocations since that | 13854 // SearchOptimizedCodeMapEntry and performed no allocations since that |
13815 // call. | 13855 // call. |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14234 if (target->is_inline_cache_stub()) { | 14274 if (target->is_inline_cache_stub()) { |
14235 if (kind == NULL || *kind == target->kind()) { | 14275 if (kind == NULL || *kind == target->kind()) { |
14236 IC::Clear(this->GetIsolate(), info->pc(), | 14276 IC::Clear(this->GetIsolate(), info->pc(), |
14237 info->host()->constant_pool()); | 14277 info->host()->constant_pool()); |
14238 } | 14278 } |
14239 } | 14279 } |
14240 } | 14280 } |
14241 } | 14281 } |
14242 | 14282 |
14243 | 14283 |
14244 void SharedFunctionInfo::ClearTypeFeedbackInfo() { | 14284 void JSFunction::ClearTypeFeedbackInfo() { |
14245 feedback_vector()->ClearSlots(this); | 14285 feedback_vector()->ClearSlots(shared()); |
14246 } | 14286 } |
14247 | 14287 |
14248 | 14288 |
14249 void SharedFunctionInfo::ClearTypeFeedbackInfoAtGCTime() { | 14289 void JSFunction::ClearTypeFeedbackInfoAtGCTime() { |
14250 feedback_vector()->ClearSlotsAtGCTime(this); | 14290 feedback_vector()->ClearSlotsAtGCTime(shared()); |
14251 } | 14291 } |
14252 | 14292 |
14253 | 14293 |
14254 BailoutId Code::TranslatePcOffsetToAstId(uint32_t pc_offset) { | 14294 BailoutId Code::TranslatePcOffsetToAstId(uint32_t pc_offset) { |
14255 DisallowHeapAllocation no_gc; | 14295 DisallowHeapAllocation no_gc; |
14256 DCHECK(kind() == FUNCTION); | 14296 DCHECK(kind() == FUNCTION); |
14257 BackEdgeTable back_edges(this, &no_gc); | 14297 BackEdgeTable back_edges(this, &no_gc); |
14258 for (uint32_t i = 0; i < back_edges.length(); i++) { | 14298 for (uint32_t i = 0; i < back_edges.length(); i++) { |
14259 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i); | 14299 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i); |
14260 } | 14300 } |
(...skipping 5389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19650 if (cell->value() != *new_value) { | 19690 if (cell->value() != *new_value) { |
19651 cell->set_value(*new_value); | 19691 cell->set_value(*new_value); |
19652 Isolate* isolate = cell->GetIsolate(); | 19692 Isolate* isolate = cell->GetIsolate(); |
19653 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19693 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19654 isolate, DependentCode::kPropertyCellChangedGroup); | 19694 isolate, DependentCode::kPropertyCellChangedGroup); |
19655 } | 19695 } |
19656 } | 19696 } |
19657 | 19697 |
19658 } // namespace internal | 19698 } // namespace internal |
19659 } // namespace v8 | 19699 } // namespace v8 |
OLD | NEW |