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 9787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9798 } | 9798 } |
9799 return Handle<DeoptimizationOutputData>::cast(result); | 9799 return Handle<DeoptimizationOutputData>::cast(result); |
9800 } | 9800 } |
9801 | 9801 |
9802 | 9802 |
9803 // static | 9803 // static |
9804 Handle<LiteralsArray> LiteralsArray::New(Isolate* isolate, | 9804 Handle<LiteralsArray> LiteralsArray::New(Isolate* isolate, |
9805 Handle<TypeFeedbackVector> vector, | 9805 Handle<TypeFeedbackVector> vector, |
9806 int number_of_literals, | 9806 int number_of_literals, |
9807 PretenureFlag pretenure) { | 9807 PretenureFlag pretenure) { |
| 9808 if (vector->is_empty() && number_of_literals == 0) { |
| 9809 return Handle<LiteralsArray>::cast( |
| 9810 isolate->factory()->empty_literals_array()); |
| 9811 } |
9808 Handle<FixedArray> literals = isolate->factory()->NewFixedArray( | 9812 Handle<FixedArray> literals = isolate->factory()->NewFixedArray( |
9809 number_of_literals + kFirstLiteralIndex, pretenure); | 9813 number_of_literals + kFirstLiteralIndex, pretenure); |
9810 Handle<LiteralsArray> casted_literals = Handle<LiteralsArray>::cast(literals); | 9814 Handle<LiteralsArray> casted_literals = Handle<LiteralsArray>::cast(literals); |
9811 casted_literals->set_feedback_vector(*vector); | 9815 casted_literals->set_feedback_vector(*vector); |
9812 return casted_literals; | 9816 return casted_literals; |
9813 } | 9817 } |
9814 | 9818 |
9815 int HandlerTable::LookupRange(int pc_offset, int* data_out, | 9819 int HandlerTable::LookupRange(int pc_offset, int* data_out, |
9816 CatchPrediction* prediction_out) { | 9820 CatchPrediction* prediction_out) { |
9817 int innermost_handler = -1; | 9821 int innermost_handler = -1; |
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11178 if (FLAG_trace_concurrent_recompilation) { | 11182 if (FLAG_trace_concurrent_recompilation) { |
11179 PrintF(" ** Marking "); | 11183 PrintF(" ** Marking "); |
11180 ShortPrint(); | 11184 ShortPrint(); |
11181 PrintF(" for concurrent recompilation.\n"); | 11185 PrintF(" for concurrent recompilation.\n"); |
11182 } | 11186 } |
11183 set_code_no_write_barrier( | 11187 set_code_no_write_barrier( |
11184 isolate->builtins()->builtin(Builtins::kCompileOptimizedConcurrent)); | 11188 isolate->builtins()->builtin(Builtins::kCompileOptimizedConcurrent)); |
11185 // No write barrier required, since the builtin is part of the root set. | 11189 // No write barrier required, since the builtin is part of the root set. |
11186 } | 11190 } |
11187 | 11191 |
| 11192 // static |
| 11193 Handle<LiteralsArray> SharedFunctionInfo::FindOrCreateLiterals( |
| 11194 Handle<SharedFunctionInfo> shared, Handle<Context> native_context) { |
| 11195 Isolate* isolate = shared->GetIsolate(); |
| 11196 CodeAndLiterals result = |
| 11197 shared->SearchOptimizedCodeMap(*native_context, BailoutId::None()); |
| 11198 if (result.literals != nullptr) { |
| 11199 DCHECK(shared->feedback_metadata()->is_empty() || |
| 11200 !result.literals->feedback_vector()->is_empty()); |
| 11201 return handle(result.literals, isolate); |
| 11202 } |
| 11203 |
| 11204 Handle<TypeFeedbackVector> feedback_vector = |
| 11205 TypeFeedbackVector::New(isolate, handle(shared->feedback_metadata())); |
| 11206 Handle<LiteralsArray> literals = LiteralsArray::New( |
| 11207 isolate, feedback_vector, shared->num_literals(), TENURED); |
| 11208 Handle<Code> code; |
| 11209 if (result.code != nullptr) { |
| 11210 code = Handle<Code>(result.code, isolate); |
| 11211 } |
| 11212 AddToOptimizedCodeMap(shared, native_context, code, literals, |
| 11213 BailoutId::None()); |
| 11214 return literals; |
| 11215 } |
11188 | 11216 |
11189 void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( | 11217 void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( |
11190 Handle<SharedFunctionInfo> shared, Handle<Code> code) { | 11218 Handle<SharedFunctionInfo> shared, Handle<Code> code) { |
11191 Isolate* isolate = shared->GetIsolate(); | 11219 Isolate* isolate = shared->GetIsolate(); |
11192 if (isolate->serializer_enabled()) return; | 11220 if (isolate->serializer_enabled()) return; |
11193 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); | 11221 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); |
11194 // Empty code maps are unsupported. | 11222 // Empty code maps are unsupported. |
11195 if (!shared->OptimizedCodeMapIsCleared()) { | 11223 if (!shared->OptimizedCodeMapIsCleared()) { |
11196 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); | 11224 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); |
11197 // A collection may have occured and cleared the optimized code map in the | 11225 // A collection may have occured and cleared the optimized code map in the |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11374 DCHECK(shrink_by <= code_map->length() - kEntriesStart); | 11402 DCHECK(shrink_by <= code_map->length() - kEntriesStart); |
11375 // Always trim even when array is cleared because of heap verifier. | 11403 // Always trim even when array is cleared because of heap verifier. |
11376 GetHeap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(code_map, | 11404 GetHeap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(code_map, |
11377 shrink_by); | 11405 shrink_by); |
11378 if (code_map->length() == kEntriesStart && | 11406 if (code_map->length() == kEntriesStart && |
11379 WeakCell::cast(code_map->get(kSharedCodeIndex))->cleared()) { | 11407 WeakCell::cast(code_map->get(kSharedCodeIndex))->cleared()) { |
11380 ClearOptimizedCodeMap(); | 11408 ClearOptimizedCodeMap(); |
11381 } | 11409 } |
11382 } | 11410 } |
11383 | 11411 |
| 11412 // static |
| 11413 void JSFunction::EnsureLiterals(Handle<JSFunction> function) { |
| 11414 Handle<SharedFunctionInfo> shared(function->shared()); |
| 11415 Handle<Context> native_context(function->context()->native_context()); |
| 11416 if (function->literals() == |
| 11417 function->GetIsolate()->heap()->empty_literals_array()) { |
| 11418 Handle<LiteralsArray> literals = |
| 11419 SharedFunctionInfo::FindOrCreateLiterals(shared, native_context); |
| 11420 function->set_literals(*literals); |
| 11421 } |
| 11422 } |
11384 | 11423 |
11385 static void GetMinInobjectSlack(Map* map, void* data) { | 11424 static void GetMinInobjectSlack(Map* map, void* data) { |
11386 int slack = map->unused_property_fields(); | 11425 int slack = map->unused_property_fields(); |
11387 if (*reinterpret_cast<int*>(data) > slack) { | 11426 if (*reinterpret_cast<int*>(data) > slack) { |
11388 *reinterpret_cast<int*>(data) = slack; | 11427 *reinterpret_cast<int*>(data) = slack; |
11389 } | 11428 } |
11390 } | 11429 } |
11391 | 11430 |
11392 | 11431 |
11393 static void ShrinkInstanceSize(Map* map, void* data) { | 11432 static void ShrinkInstanceSize(Map* map, void* data) { |
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12743 if (isolate->serializer_enabled()) return; | 12782 if (isolate->serializer_enabled()) return; |
12744 | 12783 |
12745 if (unused_property_fields() == 0) return; | 12784 if (unused_property_fields() == 0) return; |
12746 | 12785 |
12747 set_construction_counter(Map::kSlackTrackingCounterStart); | 12786 set_construction_counter(Map::kSlackTrackingCounterStart); |
12748 } | 12787 } |
12749 | 12788 |
12750 | 12789 |
12751 void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { | 12790 void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { |
12752 code()->ClearInlineCaches(); | 12791 code()->ClearInlineCaches(); |
12753 // If we clear ICs, we need to clear the type feedback vector too, since | |
12754 // CallICs are synced with a feedback vector slot. | |
12755 ClearTypeFeedbackInfo(); | |
12756 set_ic_age(new_ic_age); | 12792 set_ic_age(new_ic_age); |
12757 if (code()->kind() == Code::FUNCTION) { | 12793 if (code()->kind() == Code::FUNCTION) { |
12758 code()->set_profiler_ticks(0); | 12794 code()->set_profiler_ticks(0); |
12759 if (optimization_disabled() && opt_count() >= FLAG_max_opt_count) { | 12795 if (optimization_disabled() && opt_count() >= FLAG_max_opt_count) { |
12760 // Re-enable optimizations if they were disabled due to opt_count limit. | 12796 // Re-enable optimizations if they were disabled due to opt_count limit. |
12761 set_optimization_disabled(false); | 12797 set_optimization_disabled(false); |
12762 } | 12798 } |
12763 set_opt_count(0); | 12799 set_opt_count(0); |
12764 set_deopt_count(0); | 12800 set_deopt_count(0); |
12765 } else if (code()->is_interpreter_entry_trampoline()) { | 12801 } else if (code()->is_interpreter_entry_trampoline()) { |
(...skipping 25 matching lines...) Expand all Loading... |
12791 } | 12827 } |
12792 Object* shared_code = | 12828 Object* shared_code = |
12793 WeakCell::cast(optimized_code_map->get(kSharedCodeIndex))->value(); | 12829 WeakCell::cast(optimized_code_map->get(kSharedCodeIndex))->value(); |
12794 if (shared_code->IsCode() && osr_ast_id.IsNone()) { | 12830 if (shared_code->IsCode() && osr_ast_id.IsNone()) { |
12795 return kSharedCodeIndex; | 12831 return kSharedCodeIndex; |
12796 } | 12832 } |
12797 } | 12833 } |
12798 return -1; | 12834 return -1; |
12799 } | 12835 } |
12800 | 12836 |
| 12837 void SharedFunctionInfo::ClearCodeFromOptimizedCodeMap() { |
| 12838 if (!OptimizedCodeMapIsCleared()) { |
| 12839 FixedArray* optimized_code_map = this->optimized_code_map(); |
| 12840 int length = optimized_code_map->length(); |
| 12841 WeakCell* empty_weak_cell = GetHeap()->empty_weak_cell(); |
| 12842 for (int i = kEntriesStart; i < length; i += kEntryLength) { |
| 12843 optimized_code_map->set(i + kCachedCodeOffset, empty_weak_cell, |
| 12844 SKIP_WRITE_BARRIER); |
| 12845 } |
| 12846 optimized_code_map->set(kSharedCodeIndex, empty_weak_cell, |
| 12847 SKIP_WRITE_BARRIER); |
| 12848 } |
| 12849 } |
12801 | 12850 |
12802 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( | 12851 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( |
12803 Context* native_context, BailoutId osr_ast_id) { | 12852 Context* native_context, BailoutId osr_ast_id) { |
12804 CodeAndLiterals result = {nullptr, nullptr}; | 12853 CodeAndLiterals result = {nullptr, nullptr}; |
12805 int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id); | 12854 int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id); |
12806 if (entry != kNotFound) { | 12855 if (entry != kNotFound) { |
12807 FixedArray* code_map = optimized_code_map(); | 12856 FixedArray* code_map = optimized_code_map(); |
12808 if (entry == kSharedCodeIndex) { | 12857 if (entry == kSharedCodeIndex) { |
12809 // We know the weak cell isn't cleared because we made sure of it in | 12858 // We know the weak cell isn't cleared because we made sure of it in |
12810 // SearchOptimizedCodeMapEntry and performed no allocations since that | 12859 // SearchOptimizedCodeMapEntry and performed no allocations since that |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13122 int AbstractCode::SourcePosition(int offset) { | 13171 int AbstractCode::SourcePosition(int offset) { |
13123 return IsBytecodeArray() ? GetBytecodeArray()->SourcePosition(offset) | 13172 return IsBytecodeArray() ? GetBytecodeArray()->SourcePosition(offset) |
13124 : GetCode()->SourcePosition(offset); | 13173 : GetCode()->SourcePosition(offset); |
13125 } | 13174 } |
13126 | 13175 |
13127 int AbstractCode::SourceStatementPosition(int offset) { | 13176 int AbstractCode::SourceStatementPosition(int offset) { |
13128 return IsBytecodeArray() ? GetBytecodeArray()->SourceStatementPosition(offset) | 13177 return IsBytecodeArray() ? GetBytecodeArray()->SourceStatementPosition(offset) |
13129 : GetCode()->SourceStatementPosition(offset); | 13178 : GetCode()->SourceStatementPosition(offset); |
13130 } | 13179 } |
13131 | 13180 |
13132 void SharedFunctionInfo::ClearTypeFeedbackInfo() { | 13181 void JSFunction::ClearTypeFeedbackInfo() { |
13133 feedback_vector()->ClearSlots(this); | 13182 feedback_vector()->ClearSlots(shared()); |
13134 } | 13183 } |
13135 | 13184 |
13136 | 13185 void JSFunction::ClearTypeFeedbackInfoAtGCTime() { |
13137 void SharedFunctionInfo::ClearTypeFeedbackInfoAtGCTime() { | 13186 feedback_vector()->ClearSlotsAtGCTime(shared()); |
13138 feedback_vector()->ClearSlotsAtGCTime(this); | |
13139 } | 13187 } |
13140 | 13188 |
13141 | |
13142 BailoutId Code::TranslatePcOffsetToAstId(uint32_t pc_offset) { | 13189 BailoutId Code::TranslatePcOffsetToAstId(uint32_t pc_offset) { |
13143 DisallowHeapAllocation no_gc; | 13190 DisallowHeapAllocation no_gc; |
13144 DCHECK(kind() == FUNCTION); | 13191 DCHECK(kind() == FUNCTION); |
13145 BackEdgeTable back_edges(this, &no_gc); | 13192 BackEdgeTable back_edges(this, &no_gc); |
13146 for (uint32_t i = 0; i < back_edges.length(); i++) { | 13193 for (uint32_t i = 0; i < back_edges.length(); i++) { |
13147 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i); | 13194 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i); |
13148 } | 13195 } |
13149 return BailoutId::None(); | 13196 return BailoutId::None(); |
13150 } | 13197 } |
13151 | 13198 |
(...skipping 5094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18246 if (cell->value() != *new_value) { | 18293 if (cell->value() != *new_value) { |
18247 cell->set_value(*new_value); | 18294 cell->set_value(*new_value); |
18248 Isolate* isolate = cell->GetIsolate(); | 18295 Isolate* isolate = cell->GetIsolate(); |
18249 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18296 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18250 isolate, DependentCode::kPropertyCellChangedGroup); | 18297 isolate, DependentCode::kPropertyCellChangedGroup); |
18251 } | 18298 } |
18252 } | 18299 } |
18253 | 18300 |
18254 } // namespace internal | 18301 } // namespace internal |
18255 } // namespace v8 | 18302 } // namespace v8 |
OLD | NEW |