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 12348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12359 if (FLAG_trace_concurrent_recompilation) { | 12359 if (FLAG_trace_concurrent_recompilation) { |
12360 PrintF(" ** Marking "); | 12360 PrintF(" ** Marking "); |
12361 ShortPrint(); | 12361 ShortPrint(); |
12362 PrintF(" for concurrent recompilation.\n"); | 12362 PrintF(" for concurrent recompilation.\n"); |
12363 } | 12363 } |
12364 set_code_no_write_barrier( | 12364 set_code_no_write_barrier( |
12365 isolate->builtins()->builtin(Builtins::kCompileOptimizedConcurrent)); | 12365 isolate->builtins()->builtin(Builtins::kCompileOptimizedConcurrent)); |
12366 // No write barrier required, since the builtin is part of the root set. | 12366 // No write barrier required, since the builtin is part of the root set. |
12367 } | 12367 } |
12368 | 12368 |
| 12369 // static |
| 12370 Handle<LiteralsArray> SharedFunctionInfo::FindOrCreateLiterals( |
| 12371 Handle<SharedFunctionInfo> shared, Handle<Context> native_context) { |
| 12372 Isolate* isolate = shared->GetIsolate(); |
| 12373 CodeAndLiterals result = |
| 12374 shared->SearchOptimizedCodeMap(*native_context, BailoutId::None()); |
| 12375 if (result.literals != nullptr) { |
| 12376 return handle(result.literals, isolate); |
| 12377 } |
| 12378 Handle<TypeFeedbackVector> feedback_vector = |
| 12379 TypeFeedbackVector::New(isolate, handle(shared->feedback_metadata())); |
| 12380 Handle<LiteralsArray> literals = LiteralsArray::New( |
| 12381 isolate, feedback_vector, shared->num_literals(), TENURED); |
| 12382 AddLiteralsToOptimizedCodeMap(shared, native_context, literals); |
| 12383 return literals; |
| 12384 } |
12369 | 12385 |
12370 void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( | 12386 void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( |
12371 Handle<SharedFunctionInfo> shared, Handle<Code> code) { | 12387 Handle<SharedFunctionInfo> shared, Handle<Code> code) { |
12372 Isolate* isolate = shared->GetIsolate(); | 12388 Isolate* isolate = shared->GetIsolate(); |
12373 if (isolate->serializer_enabled()) return; | 12389 if (isolate->serializer_enabled()) return; |
12374 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); | 12390 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); |
12375 // Empty code maps are unsupported. | 12391 // Empty code maps are unsupported. |
12376 if (!shared->OptimizedCodeMapIsCleared()) { | 12392 if (!shared->OptimizedCodeMapIsCleared()) { |
12377 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); | 12393 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(code); |
12378 // A collection may have occured and cleared the optimized code map in the | 12394 // 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... |
12562 DCHECK(shrink_by <= code_map->length() - kEntriesStart); | 12578 DCHECK(shrink_by <= code_map->length() - kEntriesStart); |
12563 // Always trim even when array is cleared because of heap verifier. | 12579 // Always trim even when array is cleared because of heap verifier. |
12564 GetHeap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(code_map, | 12580 GetHeap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(code_map, |
12565 shrink_by); | 12581 shrink_by); |
12566 if (code_map->length() == kEntriesStart && | 12582 if (code_map->length() == kEntriesStart && |
12567 WeakCell::cast(code_map->get(kSharedCodeIndex))->cleared()) { | 12583 WeakCell::cast(code_map->get(kSharedCodeIndex))->cleared()) { |
12568 ClearOptimizedCodeMap(); | 12584 ClearOptimizedCodeMap(); |
12569 } | 12585 } |
12570 } | 12586 } |
12571 | 12587 |
| 12588 // static |
| 12589 void JSFunction::EnsureLiterals(Handle<JSFunction> function) { |
| 12590 Handle<SharedFunctionInfo> shared(function->shared()); |
| 12591 Handle<Context> native_context(function->context()->native_context()); |
| 12592 Handle<LiteralsArray> literals = |
| 12593 SharedFunctionInfo::FindOrCreateLiterals(shared, native_context); |
| 12594 function->set_literals(*literals); |
| 12595 } |
12572 | 12596 |
12573 static void GetMinInobjectSlack(Map* map, void* data) { | 12597 static void GetMinInobjectSlack(Map* map, void* data) { |
12574 int slack = map->unused_property_fields(); | 12598 int slack = map->unused_property_fields(); |
12575 if (*reinterpret_cast<int*>(data) > slack) { | 12599 if (*reinterpret_cast<int*>(data) > slack) { |
12576 *reinterpret_cast<int*>(data) = slack; | 12600 *reinterpret_cast<int*>(data) = slack; |
12577 } | 12601 } |
12578 } | 12602 } |
12579 | 12603 |
12580 | 12604 |
12581 static void ShrinkInstanceSize(Map* map, void* data) { | 12605 static void ShrinkInstanceSize(Map* map, void* data) { |
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13839 if (isolate->serializer_enabled()) return; | 13863 if (isolate->serializer_enabled()) return; |
13840 | 13864 |
13841 if (unused_property_fields() == 0) return; | 13865 if (unused_property_fields() == 0) return; |
13842 | 13866 |
13843 set_construction_counter(Map::kSlackTrackingCounterStart); | 13867 set_construction_counter(Map::kSlackTrackingCounterStart); |
13844 } | 13868 } |
13845 | 13869 |
13846 | 13870 |
13847 void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { | 13871 void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { |
13848 code()->ClearInlineCaches(); | 13872 code()->ClearInlineCaches(); |
13849 // If we clear ICs, we need to clear the type feedback vector too, since | |
13850 // CallICs are synced with a feedback vector slot. | |
13851 ClearTypeFeedbackInfo(); | |
13852 set_ic_age(new_ic_age); | 13873 set_ic_age(new_ic_age); |
13853 if (code()->kind() == Code::FUNCTION) { | 13874 if (code()->kind() == Code::FUNCTION) { |
13854 code()->set_profiler_ticks(0); | 13875 code()->set_profiler_ticks(0); |
13855 if (optimization_disabled() && | 13876 if (optimization_disabled() && |
13856 opt_count() >= FLAG_max_opt_count) { | 13877 opt_count() >= FLAG_max_opt_count) { |
13857 // Re-enable optimizations if they were disabled due to opt_count limit. | 13878 // Re-enable optimizations if they were disabled due to opt_count limit. |
13858 set_optimization_disabled(false); | 13879 set_optimization_disabled(false); |
13859 } | 13880 } |
13860 set_opt_count(0); | 13881 set_opt_count(0); |
13861 set_deopt_count(0); | 13882 set_deopt_count(0); |
(...skipping 18 matching lines...) Expand all Loading... |
13880 } | 13901 } |
13881 Object* shared_code = | 13902 Object* shared_code = |
13882 WeakCell::cast(optimized_code_map->get(kSharedCodeIndex))->value(); | 13903 WeakCell::cast(optimized_code_map->get(kSharedCodeIndex))->value(); |
13883 if (shared_code->IsCode() && osr_ast_id.IsNone()) { | 13904 if (shared_code->IsCode() && osr_ast_id.IsNone()) { |
13884 return kSharedCodeIndex; | 13905 return kSharedCodeIndex; |
13885 } | 13906 } |
13886 } | 13907 } |
13887 return -1; | 13908 return -1; |
13888 } | 13909 } |
13889 | 13910 |
| 13911 void SharedFunctionInfo::ClearCodeFromOptimizedCodeMap() { |
| 13912 if (!OptimizedCodeMapIsCleared()) { |
| 13913 FixedArray* optimized_code_map = this->optimized_code_map(); |
| 13914 int length = optimized_code_map->length(); |
| 13915 WeakCell* empty_weak_cell = GetHeap()->empty_weak_cell(); |
| 13916 for (int i = kEntriesStart; i < length; i += kEntryLength) { |
| 13917 optimized_code_map->set(i + kCachedCodeOffset, empty_weak_cell, |
| 13918 SKIP_WRITE_BARRIER); |
| 13919 } |
| 13920 optimized_code_map->set(kSharedCodeIndex, empty_weak_cell, |
| 13921 SKIP_WRITE_BARRIER); |
| 13922 } |
| 13923 } |
13890 | 13924 |
13891 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( | 13925 CodeAndLiterals SharedFunctionInfo::SearchOptimizedCodeMap( |
13892 Context* native_context, BailoutId osr_ast_id) { | 13926 Context* native_context, BailoutId osr_ast_id) { |
13893 CodeAndLiterals result = {nullptr, nullptr}; | 13927 CodeAndLiterals result = {nullptr, nullptr}; |
13894 int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id); | 13928 int entry = SearchOptimizedCodeMapEntry(native_context, osr_ast_id); |
13895 if (entry != kNotFound) { | 13929 if (entry != kNotFound) { |
13896 FixedArray* code_map = optimized_code_map(); | 13930 FixedArray* code_map = optimized_code_map(); |
13897 if (entry == kSharedCodeIndex) { | 13931 if (entry == kSharedCodeIndex) { |
13898 // We know the weak cell isn't cleared because we made sure of it in | 13932 // We know the weak cell isn't cleared because we made sure of it in |
13899 // SearchOptimizedCodeMapEntry and performed no allocations since that | 13933 // SearchOptimizedCodeMapEntry and performed no allocations since that |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14323 } | 14357 } |
14324 } | 14358 } |
14325 } | 14359 } |
14326 } | 14360 } |
14327 | 14361 |
14328 int AbstractCode::SourcePosition(int offset) { | 14362 int AbstractCode::SourcePosition(int offset) { |
14329 if (IsBytecodeArray()) return GetBytecodeArray()->SourcePosition(offset); | 14363 if (IsBytecodeArray()) return GetBytecodeArray()->SourcePosition(offset); |
14330 return GetCode()->SourcePosition(offset); | 14364 return GetCode()->SourcePosition(offset); |
14331 } | 14365 } |
14332 | 14366 |
14333 void SharedFunctionInfo::ClearTypeFeedbackInfo() { | 14367 void JSFunction::ClearTypeFeedbackInfo() { |
14334 feedback_vector()->ClearSlots(this); | 14368 feedback_vector()->ClearSlots(shared()); |
| 14369 } |
| 14370 |
| 14371 void JSFunction::ClearTypeFeedbackInfoAtGCTime() { |
| 14372 feedback_vector()->ClearSlotsAtGCTime(shared()); |
14335 } | 14373 } |
14336 | 14374 |
14337 | 14375 |
14338 void SharedFunctionInfo::ClearTypeFeedbackInfoAtGCTime() { | |
14339 feedback_vector()->ClearSlotsAtGCTime(this); | |
14340 } | |
14341 | |
14342 | |
14343 BailoutId Code::TranslatePcOffsetToAstId(uint32_t pc_offset) { | 14376 BailoutId Code::TranslatePcOffsetToAstId(uint32_t pc_offset) { |
14344 DisallowHeapAllocation no_gc; | 14377 DisallowHeapAllocation no_gc; |
14345 DCHECK(kind() == FUNCTION); | 14378 DCHECK(kind() == FUNCTION); |
14346 BackEdgeTable back_edges(this, &no_gc); | 14379 BackEdgeTable back_edges(this, &no_gc); |
14347 for (uint32_t i = 0; i < back_edges.length(); i++) { | 14380 for (uint32_t i = 0; i < back_edges.length(); i++) { |
14348 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i); | 14381 if (back_edges.pc_offset(i) == pc_offset) return back_edges.ast_id(i); |
14349 } | 14382 } |
14350 return BailoutId::None(); | 14383 return BailoutId::None(); |
14351 } | 14384 } |
14352 | 14385 |
(...skipping 5426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19779 if (cell->value() != *new_value) { | 19812 if (cell->value() != *new_value) { |
19780 cell->set_value(*new_value); | 19813 cell->set_value(*new_value); |
19781 Isolate* isolate = cell->GetIsolate(); | 19814 Isolate* isolate = cell->GetIsolate(); |
19782 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19815 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19783 isolate, DependentCode::kPropertyCellChangedGroup); | 19816 isolate, DependentCode::kPropertyCellChangedGroup); |
19784 } | 19817 } |
19785 } | 19818 } |
19786 | 19819 |
19787 } // namespace internal | 19820 } // namespace internal |
19788 } // namespace v8 | 19821 } // namespace v8 |
OLD | NEW |