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 11592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11603 } else { | 11603 } else { |
11604 Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate); | 11604 Handle<FixedArray> old_code_map(shared->optimized_code_map(), isolate); |
11605 entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id); | 11605 entry = shared->SearchOptimizedCodeMapEntry(*native_context, osr_ast_id); |
11606 if (entry > kSharedCodeIndex) { | 11606 if (entry > kSharedCodeIndex) { |
11607 // Just set the code and literals of the entry. | 11607 // Just set the code and literals of the entry. |
11608 if (!code.is_null()) { | 11608 if (!code.is_null()) { |
11609 Handle<WeakCell> code_cell = | 11609 Handle<WeakCell> code_cell = |
11610 isolate->factory()->NewWeakCell(code.ToHandleChecked()); | 11610 isolate->factory()->NewWeakCell(code.ToHandleChecked()); |
11611 old_code_map->set(entry + kCachedCodeOffset, *code_cell); | 11611 old_code_map->set(entry + kCachedCodeOffset, *code_cell); |
11612 } | 11612 } |
11613 Handle<WeakCell> literals_cell = | 11613 if (literals->literals_count() == 0) { |
11614 isolate->factory()->NewWeakCell(literals); | 11614 old_code_map->set(entry + kLiteralsOffset, *literals); |
11615 old_code_map->set(entry + kLiteralsOffset, *literals_cell); | 11615 } else { |
| 11616 Handle<WeakCell> literals_cell = |
| 11617 isolate->factory()->NewWeakCell(literals); |
| 11618 old_code_map->set(entry + kLiteralsOffset, *literals_cell); |
| 11619 } |
11616 return; | 11620 return; |
11617 } | 11621 } |
11618 | 11622 |
11619 // Can we reuse an entry? | 11623 // Can we reuse an entry? |
11620 DCHECK(entry < kEntriesStart); | 11624 DCHECK(entry < kEntriesStart); |
11621 int length = old_code_map->length(); | 11625 int length = old_code_map->length(); |
11622 for (int i = kEntriesStart; i < length; i += kEntryLength) { | 11626 for (int i = kEntriesStart; i < length; i += kEntryLength) { |
11623 if (WeakCell::cast(old_code_map->get(i + kContextOffset))->cleared()) { | 11627 if (WeakCell::cast(old_code_map->get(i + kContextOffset))->cleared()) { |
11624 new_code_map = old_code_map; | 11628 new_code_map = old_code_map; |
11625 entry = i; | 11629 entry = i; |
(...skipping 10 matching lines...) Expand all Loading... |
11636 // holes. For now we just give up on adding the entry and pretend it got | 11640 // holes. For now we just give up on adding the entry and pretend it got |
11637 // flushed. | 11641 // flushed. |
11638 if (shared->OptimizedCodeMapIsCleared()) return; | 11642 if (shared->OptimizedCodeMapIsCleared()) return; |
11639 entry = old_code_map->length(); | 11643 entry = old_code_map->length(); |
11640 } | 11644 } |
11641 } | 11645 } |
11642 | 11646 |
11643 Handle<WeakCell> code_cell = | 11647 Handle<WeakCell> code_cell = |
11644 code.is_null() ? isolate->factory()->empty_weak_cell() | 11648 code.is_null() ? isolate->factory()->empty_weak_cell() |
11645 : isolate->factory()->NewWeakCell(code.ToHandleChecked()); | 11649 : isolate->factory()->NewWeakCell(code.ToHandleChecked()); |
11646 Handle<WeakCell> literals_cell = isolate->factory()->NewWeakCell(literals); | |
11647 WeakCell* context_cell = native_context->self_weak_cell(); | 11650 WeakCell* context_cell = native_context->self_weak_cell(); |
11648 | 11651 |
11649 new_code_map->set(entry + kContextOffset, context_cell); | 11652 new_code_map->set(entry + kContextOffset, context_cell); |
11650 new_code_map->set(entry + kCachedCodeOffset, *code_cell); | 11653 new_code_map->set(entry + kCachedCodeOffset, *code_cell); |
11651 new_code_map->set(entry + kLiteralsOffset, *literals_cell); | 11654 |
| 11655 if (literals->literals_count() == 0) { |
| 11656 new_code_map->set(entry + kLiteralsOffset, *literals); |
| 11657 } else { |
| 11658 Handle<WeakCell> literals_cell = isolate->factory()->NewWeakCell(literals); |
| 11659 new_code_map->set(entry + kLiteralsOffset, *literals_cell); |
| 11660 } |
| 11661 |
11652 new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt())); | 11662 new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt())); |
11653 | 11663 |
11654 #ifdef DEBUG | 11664 #ifdef DEBUG |
11655 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) { | 11665 for (int i = kEntriesStart; i < new_code_map->length(); i += kEntryLength) { |
11656 WeakCell* cell = WeakCell::cast(new_code_map->get(i + kContextOffset)); | 11666 WeakCell* cell = WeakCell::cast(new_code_map->get(i + kContextOffset)); |
11657 DCHECK(cell->cleared() || cell->value()->IsNativeContext()); | 11667 DCHECK(cell->cleared() || cell->value()->IsNativeContext()); |
11658 cell = WeakCell::cast(new_code_map->get(i + kCachedCodeOffset)); | 11668 cell = WeakCell::cast(new_code_map->get(i + kCachedCodeOffset)); |
11659 DCHECK(cell->cleared() || | 11669 DCHECK(cell->cleared() || |
11660 (cell->value()->IsCode() && | 11670 (cell->value()->IsCode() && |
11661 Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION)); | 11671 Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION)); |
11662 cell = WeakCell::cast(new_code_map->get(i + kLiteralsOffset)); | 11672 Object* lits = new_code_map->get(i + kLiteralsOffset); |
11663 DCHECK(cell->cleared() || cell->value()->IsFixedArray()); | 11673 if (lits->IsWeakCell()) { |
| 11674 cell = WeakCell::cast(lits); |
| 11675 DCHECK(cell->cleared() || |
| 11676 (cell->value()->IsLiteralsArray() && |
| 11677 LiteralsArray::cast(cell->value())->literals_count() > 0)); |
| 11678 } else { |
| 11679 DCHECK(lits->IsLiteralsArray() && |
| 11680 LiteralsArray::cast(lits)->literals_count() == 0); |
| 11681 } |
11664 DCHECK(new_code_map->get(i + kOsrAstIdOffset)->IsSmi()); | 11682 DCHECK(new_code_map->get(i + kOsrAstIdOffset)->IsSmi()); |
11665 } | 11683 } |
11666 #endif | 11684 #endif |
11667 | 11685 |
11668 FixedArray* old_code_map = shared->optimized_code_map(); | 11686 FixedArray* old_code_map = shared->optimized_code_map(); |
11669 if (old_code_map != *new_code_map) { | 11687 if (old_code_map != *new_code_map) { |
11670 shared->set_optimized_code_map(*new_code_map); | 11688 shared->set_optimized_code_map(*new_code_map); |
11671 } | 11689 } |
11672 } | 11690 } |
11673 | 11691 |
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13271 if (entry == kSharedCodeIndex) { | 13289 if (entry == kSharedCodeIndex) { |
13272 // We know the weak cell isn't cleared because we made sure of it in | 13290 // We know the weak cell isn't cleared because we made sure of it in |
13273 // SearchOptimizedCodeMapEntry and performed no allocations since that | 13291 // SearchOptimizedCodeMapEntry and performed no allocations since that |
13274 // call. | 13292 // call. |
13275 result = { | 13293 result = { |
13276 Code::cast(WeakCell::cast(code_map->get(kSharedCodeIndex))->value()), | 13294 Code::cast(WeakCell::cast(code_map->get(kSharedCodeIndex))->value()), |
13277 nullptr}; | 13295 nullptr}; |
13278 } else { | 13296 } else { |
13279 DCHECK_LE(entry + kEntryLength, code_map->length()); | 13297 DCHECK_LE(entry + kEntryLength, code_map->length()); |
13280 WeakCell* cell = WeakCell::cast(code_map->get(entry + kCachedCodeOffset)); | 13298 WeakCell* cell = WeakCell::cast(code_map->get(entry + kCachedCodeOffset)); |
13281 WeakCell* literals_cell = | 13299 Object* lits = code_map->get(entry + kLiteralsOffset); |
13282 WeakCell::cast(code_map->get(entry + kLiteralsOffset)); | 13300 LiteralsArray* literals = nullptr; |
13283 | 13301 if (lits->IsWeakCell()) { |
| 13302 WeakCell* literal_cell = WeakCell::cast(lits); |
| 13303 if (!literal_cell->cleared()) { |
| 13304 literals = LiteralsArray::cast(literal_cell->value()); |
| 13305 } |
| 13306 } else { |
| 13307 literals = LiteralsArray::cast(lits); |
| 13308 } |
13284 result = {cell->cleared() ? nullptr : Code::cast(cell->value()), | 13309 result = {cell->cleared() ? nullptr : Code::cast(cell->value()), |
13285 literals_cell->cleared() | 13310 literals}; |
13286 ? nullptr | |
13287 : LiteralsArray::cast(literals_cell->value())}; | |
13288 } | 13311 } |
13289 } | 13312 } |
13290 return result; | 13313 return result; |
13291 } | 13314 } |
13292 | 13315 |
13293 | 13316 |
13294 #define DECLARE_TAG(ignore1, name, ignore2) name, | 13317 #define DECLARE_TAG(ignore1, name, ignore2) name, |
13295 const char* const VisitorSynchronization::kTags[ | 13318 const char* const VisitorSynchronization::kTags[ |
13296 VisitorSynchronization::kNumberOfSyncTags] = { | 13319 VisitorSynchronization::kNumberOfSyncTags] = { |
13297 VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_TAG) | 13320 VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_TAG) |
(...skipping 5488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18786 if (cell->value() != *new_value) { | 18809 if (cell->value() != *new_value) { |
18787 cell->set_value(*new_value); | 18810 cell->set_value(*new_value); |
18788 Isolate* isolate = cell->GetIsolate(); | 18811 Isolate* isolate = cell->GetIsolate(); |
18789 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18812 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18790 isolate, DependentCode::kPropertyCellChangedGroup); | 18813 isolate, DependentCode::kPropertyCellChangedGroup); |
18791 } | 18814 } |
18792 } | 18815 } |
18793 | 18816 |
18794 } // namespace internal | 18817 } // namespace internal |
18795 } // namespace v8 | 18818 } // namespace v8 |
OLD | NEW |