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 12324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12335 if (FLAG_trace_concurrent_recompilation) { | 12335 if (FLAG_trace_concurrent_recompilation) { |
12336 PrintF(" ** Marking "); | 12336 PrintF(" ** Marking "); |
12337 ShortPrint(); | 12337 ShortPrint(); |
12338 PrintF(" for concurrent recompilation.\n"); | 12338 PrintF(" for concurrent recompilation.\n"); |
12339 } | 12339 } |
12340 set_code_no_write_barrier( | 12340 set_code_no_write_barrier( |
12341 isolate->builtins()->builtin(Builtins::kCompileOptimizedConcurrent)); | 12341 isolate->builtins()->builtin(Builtins::kCompileOptimizedConcurrent)); |
12342 // No write barrier required, since the builtin is part of the root set. | 12342 // No write barrier required, since the builtin is part of the root set. |
12343 } | 12343 } |
12344 | 12344 |
| 12345 // static |
| 12346 Handle<LiteralsArray> SharedFunctionInfo::FindOrCreateLiterals( |
| 12347 Handle<SharedFunctionInfo> shared, Handle<Context> native_context) { |
| 12348 Isolate* isolate = shared->GetIsolate(); |
| 12349 CodeAndLiterals result = |
| 12350 shared->SearchOptimizedCodeMap(*native_context, BailoutId::None()); |
| 12351 if (result.literals != nullptr) { |
| 12352 return handle(result.literals, isolate); |
| 12353 } |
| 12354 Handle<TypeFeedbackVector> feedback_vector = |
| 12355 TypeFeedbackVector::New(isolate, handle(shared->feedback_metadata())); |
| 12356 Handle<LiteralsArray> literals = LiteralsArray::New( |
| 12357 isolate, feedback_vector, shared->num_literals(), TENURED); |
| 12358 AddLiteralsToOptimizedCodeMap(shared, native_context, literals); |
| 12359 return literals; |
| 12360 } |
12345 | 12361 |
12346 void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( | 12362 void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( |
12347 Handle<SharedFunctionInfo> shared, Handle<Code> code) { | 12363 Handle<SharedFunctionInfo> shared, Handle<Code> code) { |
12348 Isolate* isolate = shared->GetIsolate(); | 12364 Isolate* isolate = shared->GetIsolate(); |
12349 if (isolate->serializer_enabled()) return; | 12365 if (isolate->serializer_enabled()) return; |
12350 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); | 12366 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); |
12351 // Empty code maps are unsupported. | 12367 // Empty code maps are unsupported. |
12352 if (!shared->OptimizedCodeMapIsCleared()) { | 12368 if (!shared->OptimizedCodeMapIsCleared()) { |
12353 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); | 12369 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); |
12354 // A collection may have occured and cleared the optimized code map in the | 12370 // A collection may have occured and cleared the optimized code map in the |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12538 DCHECK(shrink_by <= code_map->length() - kEntriesStart); | 12554 DCHECK(shrink_by <= code_map->length() - kEntriesStart); |
12539 // Always trim even when array is cleared because of heap verifier. | 12555 // Always trim even when array is cleared because of heap verifier. |
12540 GetHeap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(code_map, | 12556 GetHeap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(code_map, |
12541 shrink_by); | 12557 shrink_by); |
12542 if (code_map->length() == kEntriesStart && | 12558 if (code_map->length() == kEntriesStart && |
12543 WeakCell::cast(code_map->get(kSharedCodeIndex))->cleared()) { | 12559 WeakCell::cast(code_map->get(kSharedCodeIndex))->cleared()) { |
12544 ClearOptimizedCodeMap(); | 12560 ClearOptimizedCodeMap(); |
12545 } | 12561 } |
12546 } | 12562 } |
12547 | 12563 |
| 12564 // static |
| 12565 void JSFunction::EnsureLiterals(Handle<JSFunction> function) { |
| 12566 Handle<SharedFunctionInfo> shared(function->shared()); |
| 12567 Handle<Context> native_context(function->context()->native_context()); |
| 12568 Handle<LiteralsArray> literals = |
| 12569 SharedFunctionInfo::FindOrCreateLiterals(shared, native_context); |
| 12570 function->set_literals(*literals); |
| 12571 } |
12548 | 12572 |
12549 static void GetMinInobjectSlack(Map* map, void* data) { | 12573 static void GetMinInobjectSlack(Map* map, void* data) { |
12550 int slack = map->unused_property_fields(); | 12574 int slack = map->unused_property_fields(); |
12551 if (*reinterpret_cast<int*>(data) > slack) { | 12575 if (*reinterpret_cast<int*>(data) > slack) { |
12552 *reinterpret_cast<int*>(data) = slack; | 12576 *reinterpret_cast<int*>(data) = slack; |
12553 } | 12577 } |
12554 } | 12578 } |
12555 | 12579 |
12556 | 12580 |
12557 static void ShrinkInstanceSize(Map* map, void* data) { | 12581 static void ShrinkInstanceSize(Map* map, void* data) { |
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13815 if (isolate->serializer_enabled()) return; | 13839 if (isolate->serializer_enabled()) return; |
13816 | 13840 |
13817 if (unused_property_fields() == 0) return; | 13841 if (unused_property_fields() == 0) return; |
13818 | 13842 |
13819 set_construction_counter(Map::kSlackTrackingCounterStart); | 13843 set_construction_counter(Map::kSlackTrackingCounterStart); |
13820 } | 13844 } |
13821 | 13845 |
13822 | 13846 |
13823 void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { | 13847 void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { |
13824 code()->ClearInlineCaches(); | 13848 code()->ClearInlineCaches(); |
13825 // If we clear ICs, we need to clear the type feedback vector too, since | |
13826 // CallICs are synced with a feedback vector slot. | |
13827 ClearTypeFeedbackInfo(); | |
13828 set_ic_age(new_ic_age); | 13849 set_ic_age(new_ic_age); |
13829 if (code()->kind() == Code::FUNCTION) { | 13850 if (code()->kind() == Code::FUNCTION) { |
13830 code()->set_profiler_ticks(0); | 13851 code()->set_profiler_ticks(0); |
13831 if (optimization_disabled() && | 13852 if (optimization_disabled() && |
13832 opt_count() >= FLAG_max_opt_count) { | 13853 opt_count() >= FLAG_max_opt_count) { |
13833 // Re-enable optimizations if they were disabled due to opt_count limit. | 13854 // Re-enable optimizations if they were disabled due to opt_count limit. |
13834 set_optimization_disabled(false); | 13855 set_optimization_disabled(false); |
13835 } | 13856 } |
13836 set_opt_count(0); | 13857 set_opt_count(0); |
13837 set_deopt_count(0); | 13858 set_deopt_count(0); |
(...skipping 18 matching lines...) Expand all Loading... |
13856 } | 13877 } |
13857 Object* shared_code = | 13878 Object* shared_code = |
13858 WeakCell::cast(optimized_code_map->get(kSharedCodeIndex))->value(); | 13879 WeakCell::cast(optimized_code_map->get(kSharedCodeIndex))->value(); |
13859 if (shared_code->IsCode() && osr_ast_id.IsNone()) { | 13880 if (shared_code->IsCode() && osr_ast_id.IsNone()) { |
13860 return kSharedCodeIndex; | 13881 return kSharedCodeIndex; |
13861 } | 13882 } |
13862 } | 13883 } |
13863 return -1; | 13884 return -1; |
13864 } | 13885 } |
13865 | 13886 |
| 13887 void SharedFunctionInfo::ClearCodeFromOptimizedCodeMap() { |
| 13888 if (!OptimizedCodeMapIsCleared()) { |
| 13889 FixedArray* optimized_code_map = this->optimized_code_map(); |
| 13890 int length = optimized_code_map->length(); |
| 13891 WeakCell* empty_weak_cell = GetHeap()->empty_weak_cell(); |
| 13892 for (int i = kEntriesStart; i < length; i += kEntryLength) { |
| 13893 optimized_code_map->set(i + kCachedCodeOffset, empty_weak_cell, |
| 13894 SKIP_WRITE_BARRIER); |
| 13895 } |
| 13896 optimized_code_map->set(kSharedCodeIndex, empty_weak_cell, |
| 13897 SKIP_WRITE_BARRIER); |
| 13898 } |
| 13899 } |
13866 | 13900 |
13867 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( | 13901 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( |
13868 Context* native_context, BailoutId osr_ast_id) { | 13902 Context* native_context, BailoutId osr_ast_id) { |
13869 CodeAndLiterals result = {nullptr, nullptr}; | 13903 CodeAndLiterals result = {nullptr, nullptr}; |
13870 int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id); | 13904 int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id); |
13871 if (entry != kNotFound) { | 13905 if (entry != kNotFound) { |
13872 FixedArray* code_map = optimized_code_map(); | 13906 FixedArray* code_map = optimized_code_map(); |
13873 if (entry == kSharedCodeIndex) { | 13907 if (entry == kSharedCodeIndex) { |
13874 // We know the weak cell isn't cleared because we made sure of it in | 13908 // We know the weak cell isn't cleared because we made sure of it in |
13875 // SearchOptimizedCodeMapEntry and performed no allocations since that | 13909 // SearchOptimizedCodeMapEntry and performed no allocations since that |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14294 Code* target(Code::GetCodeFromTargetAddress(info->target_address())); | 14328 Code* target(Code::GetCodeFromTargetAddress(info->target_address())); |
14295 if (target->is_inline_cache_stub()) { | 14329 if (target->is_inline_cache_stub()) { |
14296 if (kind == NULL || *kind == target->kind()) { | 14330 if (kind == NULL || *kind == target->kind()) { |
14297 IC::Clear(this->GetIsolate(), info->pc(), | 14331 IC::Clear(this->GetIsolate(), info->pc(), |
14298 info->host()->constant_pool()); | 14332 info->host()->constant_pool()); |
14299 } | 14333 } |
14300 } | 14334 } |
14301 } | 14335 } |
14302 } | 14336 } |
14303 | 14337 |
| 14338 void JSFunction::ClearTypeFeedbackInfo() { |
| 14339 feedback_vector()->ClearSlots(shared()); |
| 14340 } |
14304 | 14341 |
14305 void SharedFunctionInfo::ClearTypeFeedbackInfo() { | 14342 void JSFunction::ClearTypeFeedbackInfoAtGCTime() { |
14306 feedback_vector()->ClearSlots(this); | 14343 feedback_vector()->ClearSlotsAtGCTime(shared()); |
14307 } | 14344 } |
14308 | 14345 |
14309 | 14346 |
14310 void SharedFunctionInfo::ClearTypeFeedbackInfoAtGCTime() { | |
14311 feedback_vector()->ClearSlotsAtGCTime(this); | |
14312 } | |
14313 | |
14314 | |
14315 BailoutId Code::TranslatePcOffsetToAstId(uint32_t pc_offset) { | 14347 BailoutId Code::TranslatePcOffsetToAstId(uint32_t pc_offset) { |
14316 DisallowHeapAllocation no_gc; | 14348 DisallowHeapAllocation no_gc; |
14317 DCHECK(kind() == FUNCTION); | 14349 DCHECK(kind() == FUNCTION); |
14318 BackEdgeTable back_edges(this, &no_gc); | 14350 BackEdgeTable back_edges(this, &no_gc); |
14319 for (uint32_t i = 0; i < back_edges.length(); i++) { | 14351 for (uint32_t i = 0; i < back_edges.length(); i++) { |
14320 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i); | 14352 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i); |
14321 } | 14353 } |
14322 return BailoutId::None(); | 14354 return BailoutId::None(); |
14323 } | 14355 } |
14324 | 14356 |
(...skipping 5420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19745 if (cell->value() != *new_value) { | 19777 if (cell->value() != *new_value) { |
19746 cell->set_value(*new_value); | 19778 cell->set_value(*new_value); |
19747 Isolate* isolate = cell->GetIsolate(); | 19779 Isolate* isolate = cell->GetIsolate(); |
19748 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19780 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19749 isolate, DependentCode::kPropertyCellChangedGroup); | 19781 isolate, DependentCode::kPropertyCellChangedGroup); |
19750 } | 19782 } |
19751 } | 19783 } |
19752 | 19784 |
19753 } // namespace internal | 19785 } // namespace internal |
19754 } // namespace v8 | 19786 } // namespace v8 |
OLD | NEW |