| 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" |
| (...skipping 9550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9561 // In rare cases when that is not true, we mutate the clone's __proto__. | 9561 // In rare cases when that is not true, we mutate the clone's __proto__. |
| 9562 Handle<Object> original_prototype(map->prototype(), isolate); | 9562 Handle<Object> original_prototype(map->prototype(), isolate); |
| 9563 if (*original_prototype != clone->map()->prototype()) { | 9563 if (*original_prototype != clone->map()->prototype()) { |
| 9564 JSObject::SetPrototype(clone, original_prototype, false).Assert(); | 9564 JSObject::SetPrototype(clone, original_prototype, false).Assert(); |
| 9565 } | 9565 } |
| 9566 | 9566 |
| 9567 return clone; | 9567 return clone; |
| 9568 } | 9568 } |
| 9569 | 9569 |
| 9570 | 9570 |
| 9571 void SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap( |
| 9572 Handle<SharedFunctionInfo> shared, Handle<Code> code) { |
| 9573 Isolate* isolate = shared->GetIsolate(); |
| 9574 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); |
| 9575 Handle<Object> value(shared->optimized_code_map(), isolate); |
| 9576 if (value->IsSmi()) return; // Empty code maps are unsupported. |
| 9577 Handle<FixedArray> code_map = Handle<FixedArray>::cast(value); |
| 9578 code_map->set(kSharedCodeIndex, *code); |
| 9579 } |
| 9580 |
| 9581 |
| 9571 void SharedFunctionInfo::AddToOptimizedCodeMap( | 9582 void SharedFunctionInfo::AddToOptimizedCodeMap( |
| 9572 Handle<SharedFunctionInfo> shared, | 9583 Handle<SharedFunctionInfo> shared, |
| 9573 Handle<Context> native_context, | 9584 Handle<Context> native_context, |
| 9574 Handle<Code> code, | 9585 Handle<Code> code, |
| 9575 Handle<FixedArray> literals, | 9586 Handle<FixedArray> literals, |
| 9576 BailoutId osr_ast_id) { | 9587 BailoutId osr_ast_id) { |
| 9577 Isolate* isolate = shared->GetIsolate(); | 9588 Isolate* isolate = shared->GetIsolate(); |
| 9578 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); | 9589 DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); |
| 9579 DCHECK(native_context->IsNativeContext()); | 9590 DCHECK(native_context->IsNativeContext()); |
| 9580 STATIC_ASSERT(kEntryLength == 4); | 9591 STATIC_ASSERT(kEntryLength == 4); |
| 9581 Handle<FixedArray> new_code_map; | 9592 Handle<FixedArray> new_code_map; |
| 9582 Handle<Object> value(shared->optimized_code_map(), isolate); | 9593 Handle<Object> value(shared->optimized_code_map(), isolate); |
| 9583 int old_length; | 9594 int old_length; |
| 9584 if (value->IsSmi()) { | 9595 if (value->IsSmi()) { |
| 9585 // No optimized code map. | 9596 // No optimized code map. |
| 9586 DCHECK_EQ(0, Smi::cast(*value)->value()); | 9597 DCHECK_EQ(0, Smi::cast(*value)->value()); |
| 9587 // Create 3 entries per context {context, code, literals}. | |
| 9588 new_code_map = isolate->factory()->NewFixedArray(kInitialLength); | 9598 new_code_map = isolate->factory()->NewFixedArray(kInitialLength); |
| 9589 old_length = kEntriesStart; | 9599 old_length = kEntriesStart; |
| 9590 } else { | 9600 } else { |
| 9591 // Copy old map and append one new entry. | 9601 // Copy old map and append one new entry. |
| 9592 Handle<FixedArray> old_code_map = Handle<FixedArray>::cast(value); | 9602 Handle<FixedArray> old_code_map = Handle<FixedArray>::cast(value); |
| 9593 DCHECK(!shared->SearchOptimizedCodeMap(*native_context, osr_ast_id).code); | 9603 DCHECK(!shared->SearchOptimizedCodeMap(*native_context, osr_ast_id).code); |
| 9594 old_length = old_code_map->length(); | 9604 old_length = old_code_map->length(); |
| 9595 new_code_map = FixedArray::CopySize( | 9605 new_code_map = FixedArray::CopySize( |
| 9596 old_code_map, old_length + kEntryLength); | 9606 old_code_map, old_length + kEntryLength); |
| 9597 // Zap the old map for the sake of the heap verifier. | 9607 // Zap the old map for the sake of the heap verifier. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9665 code_map->set(dst + kCachedCodeOffset, | 9675 code_map->set(dst + kCachedCodeOffset, |
| 9666 code_map->get(src + kCachedCodeOffset)); | 9676 code_map->get(src + kCachedCodeOffset)); |
| 9667 code_map->set(dst + kLiteralsOffset, | 9677 code_map->set(dst + kLiteralsOffset, |
| 9668 code_map->get(src + kLiteralsOffset)); | 9678 code_map->get(src + kLiteralsOffset)); |
| 9669 code_map->set(dst + kOsrAstIdOffset, | 9679 code_map->set(dst + kOsrAstIdOffset, |
| 9670 code_map->get(src + kOsrAstIdOffset)); | 9680 code_map->get(src + kOsrAstIdOffset)); |
| 9671 } | 9681 } |
| 9672 dst += kEntryLength; | 9682 dst += kEntryLength; |
| 9673 } | 9683 } |
| 9674 } | 9684 } |
| 9685 if (code_map->get(kSharedCodeIndex) == optimized_code) { |
| 9686 // Evict context-independent code as well. |
| 9687 code_map->set_undefined(kSharedCodeIndex); |
| 9688 if (FLAG_trace_opt) { |
| 9689 PrintF("[evicting entry from optimizing code map (%s) for ", reason); |
| 9690 ShortPrint(); |
| 9691 PrintF(" (context-independent code)]\n"); |
| 9692 } |
| 9693 } |
| 9675 if (dst != length) { | 9694 if (dst != length) { |
| 9676 // Always trim even when array is cleared because of heap verifier. | 9695 // Always trim even when array is cleared because of heap verifier. |
| 9677 GetHeap()->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(code_map, | 9696 GetHeap()->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(code_map, |
| 9678 length - dst); | 9697 length - dst); |
| 9679 if (code_map->length() == kEntriesStart) ClearOptimizedCodeMap(); | 9698 if (code_map->length() == kEntriesStart) ClearOptimizedCodeMap(); |
| 9680 } | 9699 } |
| 9681 } | 9700 } |
| 9682 | 9701 |
| 9683 | 9702 |
| 9684 void SharedFunctionInfo::TrimOptimizedCodeMap(int shrink_by) { | 9703 void SharedFunctionInfo::TrimOptimizedCodeMap(int shrink_by) { |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10652 FixedArray* optimized_code_map = FixedArray::cast(value); | 10671 FixedArray* optimized_code_map = FixedArray::cast(value); |
| 10653 int length = optimized_code_map->length(); | 10672 int length = optimized_code_map->length(); |
| 10654 Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt()); | 10673 Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt()); |
| 10655 for (int i = kEntriesStart; i < length; i += kEntryLength) { | 10674 for (int i = kEntriesStart; i < length; i += kEntryLength) { |
| 10656 if (optimized_code_map->get(i + kContextOffset) == native_context && | 10675 if (optimized_code_map->get(i + kContextOffset) == native_context && |
| 10657 optimized_code_map->get(i + kOsrAstIdOffset) == osr_ast_id_smi) { | 10676 optimized_code_map->get(i + kOsrAstIdOffset) == osr_ast_id_smi) { |
| 10658 return {Code::cast(optimized_code_map->get(i + kCachedCodeOffset)), | 10677 return {Code::cast(optimized_code_map->get(i + kCachedCodeOffset)), |
| 10659 FixedArray::cast(optimized_code_map->get(i + kLiteralsOffset))}; | 10678 FixedArray::cast(optimized_code_map->get(i + kLiteralsOffset))}; |
| 10660 } | 10679 } |
| 10661 } | 10680 } |
| 10681 Object* shared_code = optimized_code_map->get(kSharedCodeIndex); |
| 10682 if (shared_code->IsCode() && osr_ast_id.IsNone()) { |
| 10683 return {Code::cast(shared_code), nullptr}; |
| 10684 } |
| 10662 if (FLAG_trace_opt) { | 10685 if (FLAG_trace_opt) { |
| 10663 PrintF("[didn't find optimized code in optimized code map for "); | 10686 PrintF("[didn't find optimized code in optimized code map for "); |
| 10664 ShortPrint(); | 10687 ShortPrint(); |
| 10665 PrintF("]\n"); | 10688 PrintF("]\n"); |
| 10666 } | 10689 } |
| 10667 } | 10690 } |
| 10668 return {nullptr, nullptr}; | 10691 return {nullptr, nullptr}; |
| 10669 } | 10692 } |
| 10670 | 10693 |
| 10671 | 10694 |
| (...skipping 5483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16155 Handle<Object> new_value) { | 16178 Handle<Object> new_value) { |
| 16156 if (cell->value() != *new_value) { | 16179 if (cell->value() != *new_value) { |
| 16157 cell->set_value(*new_value); | 16180 cell->set_value(*new_value); |
| 16158 Isolate* isolate = cell->GetIsolate(); | 16181 Isolate* isolate = cell->GetIsolate(); |
| 16159 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16182 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 16160 isolate, DependentCode::kPropertyCellChangedGroup); | 16183 isolate, DependentCode::kPropertyCellChangedGroup); |
| 16161 } | 16184 } |
| 16162 } | 16185 } |
| 16163 } // namespace internal | 16186 } // namespace internal |
| 16164 } // namespace v8 | 16187 } // namespace v8 |
| OLD | NEW |