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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/allocation-site-scopes.h" | 10 #include "src/allocation-site-scopes.h" |
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 break; | 1570 break; |
1571 } | 1571 } |
1572 case PROPERTY_CELL_TYPE: { | 1572 case PROPERTY_CELL_TYPE: { |
1573 os << "PropertyCell for "; | 1573 os << "PropertyCell for "; |
1574 HeapStringAllocator allocator; | 1574 HeapStringAllocator allocator; |
1575 StringStream accumulator(&allocator); | 1575 StringStream accumulator(&allocator); |
1576 PropertyCell::cast(this)->value()->ShortPrint(&accumulator); | 1576 PropertyCell::cast(this)->value()->ShortPrint(&accumulator); |
1577 os << accumulator.ToCString().get(); | 1577 os << accumulator.ToCString().get(); |
1578 break; | 1578 break; |
1579 } | 1579 } |
| 1580 case WEAK_CELL_TYPE: { |
| 1581 os << "WeakCell for "; |
| 1582 HeapStringAllocator allocator; |
| 1583 StringStream accumulator(&allocator); |
| 1584 WeakCell::cast(this)->value()->ShortPrint(&accumulator); |
| 1585 os << accumulator.ToCString().get(); |
| 1586 break; |
| 1587 } |
1580 default: | 1588 default: |
1581 os << "<Other heap object (" << map()->instance_type() << ")>"; | 1589 os << "<Other heap object (" << map()->instance_type() << ")>"; |
1582 break; | 1590 break; |
1583 } | 1591 } |
1584 } | 1592 } |
1585 | 1593 |
1586 | 1594 |
1587 void HeapObject::Iterate(ObjectVisitor* v) { | 1595 void HeapObject::Iterate(ObjectVisitor* v) { |
1588 // Handle header | 1596 // Handle header |
1589 IteratePointer(v, kMapOffset); | 1597 IteratePointer(v, kMapOffset); |
(...skipping 1828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3418 } | 3426 } |
3419 | 3427 |
3420 if (isolate->initial_object_prototype()->map() == this) { | 3428 if (isolate->initial_object_prototype()->map() == this) { |
3421 return true; | 3429 return true; |
3422 } | 3430 } |
3423 | 3431 |
3424 return false; | 3432 return false; |
3425 } | 3433 } |
3426 | 3434 |
3427 | 3435 |
| 3436 Handle<WeakCell> Map::WeakCellForMap(Handle<Map> map) { |
| 3437 Isolate* isolate = map->GetIsolate(); |
| 3438 if (map->code_cache()->IsFixedArray()) { |
| 3439 return isolate->factory()->NewWeakCell(map); |
| 3440 } |
| 3441 Handle<CodeCache> code_cache(CodeCache::cast(map->code_cache()), isolate); |
| 3442 if (code_cache->weak_cell_cache()->IsWeakCell()) { |
| 3443 return Handle<WeakCell>(WeakCell::cast(code_cache->weak_cell_cache())); |
| 3444 } |
| 3445 Handle<WeakCell> weak_cell = isolate->factory()->NewWeakCell(map); |
| 3446 code_cache->set_weak_cell_cache(*weak_cell); |
| 3447 return weak_cell; |
| 3448 } |
| 3449 |
| 3450 |
3428 static Handle<Map> AddMissingElementsTransitions(Handle<Map> map, | 3451 static Handle<Map> AddMissingElementsTransitions(Handle<Map> map, |
3429 ElementsKind to_kind) { | 3452 ElementsKind to_kind) { |
3430 DCHECK(IsTransitionElementsKind(map->elements_kind())); | 3453 DCHECK(IsTransitionElementsKind(map->elements_kind())); |
3431 | 3454 |
3432 Handle<Map> current_map = map; | 3455 Handle<Map> current_map = map; |
3433 | 3456 |
3434 ElementsKind kind = map->elements_kind(); | 3457 ElementsKind kind = map->elements_kind(); |
3435 if (!map->is_prototype_map()) { | 3458 if (!map->is_prototype_map()) { |
3436 while (kind != to_kind && !IsTerminalElementsKind(kind)) { | 3459 while (kind != to_kind && !IsTerminalElementsKind(kind)) { |
3437 kind = GetNextTransitionElementsKind(kind); | 3460 kind = GetNextTransitionElementsKind(kind); |
(...skipping 7122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10560 } | 10583 } |
10561 | 10584 |
10562 | 10585 |
10563 Object* Code::FindNthObject(int n, Map* match_map) { | 10586 Object* Code::FindNthObject(int n, Map* match_map) { |
10564 DCHECK(is_inline_cache_stub()); | 10587 DCHECK(is_inline_cache_stub()); |
10565 DisallowHeapAllocation no_allocation; | 10588 DisallowHeapAllocation no_allocation; |
10566 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); | 10589 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
10567 for (RelocIterator it(this, mask); !it.done(); it.next()) { | 10590 for (RelocIterator it(this, mask); !it.done(); it.next()) { |
10568 RelocInfo* info = it.rinfo(); | 10591 RelocInfo* info = it.rinfo(); |
10569 Object* object = info->target_object(); | 10592 Object* object = info->target_object(); |
| 10593 if (object->IsWeakCell()) object = WeakCell::cast(object)->value(); |
10570 if (object->IsHeapObject()) { | 10594 if (object->IsHeapObject()) { |
10571 if (HeapObject::cast(object)->map() == match_map) { | 10595 if (HeapObject::cast(object)->map() == match_map) { |
10572 if (--n == 0) return object; | 10596 if (--n == 0) return object; |
10573 } | 10597 } |
10574 } | 10598 } |
10575 } | 10599 } |
10576 return NULL; | 10600 return NULL; |
10577 } | 10601 } |
10578 | 10602 |
10579 | 10603 |
(...skipping 12 matching lines...) Expand all Loading... |
10592 void Code::FindAndReplace(const FindAndReplacePattern& pattern) { | 10616 void Code::FindAndReplace(const FindAndReplacePattern& pattern) { |
10593 DCHECK(is_inline_cache_stub() || is_handler()); | 10617 DCHECK(is_inline_cache_stub() || is_handler()); |
10594 DisallowHeapAllocation no_allocation; | 10618 DisallowHeapAllocation no_allocation; |
10595 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); | 10619 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
10596 STATIC_ASSERT(FindAndReplacePattern::kMaxCount < 32); | 10620 STATIC_ASSERT(FindAndReplacePattern::kMaxCount < 32); |
10597 int current_pattern = 0; | 10621 int current_pattern = 0; |
10598 for (RelocIterator it(this, mask); !it.done(); it.next()) { | 10622 for (RelocIterator it(this, mask); !it.done(); it.next()) { |
10599 RelocInfo* info = it.rinfo(); | 10623 RelocInfo* info = it.rinfo(); |
10600 Object* object = info->target_object(); | 10624 Object* object = info->target_object(); |
10601 if (object->IsHeapObject()) { | 10625 if (object->IsHeapObject()) { |
| 10626 DCHECK(!object->IsWeakCell()); |
10602 Map* map = HeapObject::cast(object)->map(); | 10627 Map* map = HeapObject::cast(object)->map(); |
10603 if (map == *pattern.find_[current_pattern]) { | 10628 if (map == *pattern.find_[current_pattern]) { |
10604 info->set_target_object(*pattern.replace_[current_pattern]); | 10629 info->set_target_object(*pattern.replace_[current_pattern]); |
10605 if (++current_pattern == pattern.count_) return; | 10630 if (++current_pattern == pattern.count_) return; |
10606 } | 10631 } |
10607 } | 10632 } |
10608 } | 10633 } |
10609 UNREACHABLE(); | 10634 UNREACHABLE(); |
10610 } | 10635 } |
10611 | 10636 |
10612 | 10637 |
10613 void Code::FindAllMaps(MapHandleList* maps) { | 10638 void Code::FindAllMaps(MapHandleList* maps) { |
10614 DCHECK(is_inline_cache_stub()); | 10639 DCHECK(is_inline_cache_stub()); |
10615 DisallowHeapAllocation no_allocation; | 10640 DisallowHeapAllocation no_allocation; |
10616 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); | 10641 int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
10617 for (RelocIterator it(this, mask); !it.done(); it.next()) { | 10642 for (RelocIterator it(this, mask); !it.done(); it.next()) { |
10618 RelocInfo* info = it.rinfo(); | 10643 RelocInfo* info = it.rinfo(); |
10619 Object* object = info->target_object(); | 10644 Object* object = info->target_object(); |
| 10645 if (object->IsWeakCell()) object = WeakCell::cast(object)->value(); |
10620 if (object->IsMap()) maps->Add(handle(Map::cast(object))); | 10646 if (object->IsMap()) maps->Add(handle(Map::cast(object))); |
10621 } | 10647 } |
10622 } | 10648 } |
10623 | 10649 |
10624 | 10650 |
10625 Code* Code::FindFirstHandler() { | 10651 Code* Code::FindFirstHandler() { |
10626 DCHECK(is_inline_cache_stub()); | 10652 DCHECK(is_inline_cache_stub()); |
10627 DisallowHeapAllocation no_allocation; | 10653 DisallowHeapAllocation no_allocation; |
10628 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET); | 10654 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | |
| 10655 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| 10656 bool skip_next_handler = false; |
10629 for (RelocIterator it(this, mask); !it.done(); it.next()) { | 10657 for (RelocIterator it(this, mask); !it.done(); it.next()) { |
10630 RelocInfo* info = it.rinfo(); | 10658 RelocInfo* info = it.rinfo(); |
10631 Code* code = Code::GetCodeFromTargetAddress(info->target_address()); | 10659 if (info->rmode() == RelocInfo::EMBEDDED_OBJECT) { |
10632 if (code->kind() == Code::HANDLER) return code; | 10660 Object* obj = info->target_object(); |
| 10661 skip_next_handler |= obj->IsWeakCell() && WeakCell::cast(obj)->cleared(); |
| 10662 } else { |
| 10663 Code* code = Code::GetCodeFromTargetAddress(info->target_address()); |
| 10664 if (code->kind() == Code::HANDLER) { |
| 10665 if (!skip_next_handler) return code; |
| 10666 skip_next_handler = false; |
| 10667 } |
| 10668 } |
10633 } | 10669 } |
10634 return NULL; | 10670 return NULL; |
10635 } | 10671 } |
10636 | 10672 |
10637 | 10673 |
10638 bool Code::FindHandlers(CodeHandleList* code_list, int length) { | 10674 bool Code::FindHandlers(CodeHandleList* code_list, int length) { |
10639 DCHECK(is_inline_cache_stub()); | 10675 DCHECK(is_inline_cache_stub()); |
10640 DisallowHeapAllocation no_allocation; | 10676 DisallowHeapAllocation no_allocation; |
10641 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET); | 10677 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | |
| 10678 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| 10679 bool skip_next_handler = false; |
10642 int i = 0; | 10680 int i = 0; |
10643 for (RelocIterator it(this, mask); !it.done(); it.next()) { | 10681 for (RelocIterator it(this, mask); !it.done(); it.next()) { |
10644 if (i == length) return true; | 10682 if (i == length) return true; |
10645 RelocInfo* info = it.rinfo(); | 10683 RelocInfo* info = it.rinfo(); |
10646 Code* code = Code::GetCodeFromTargetAddress(info->target_address()); | 10684 if (info->rmode() == RelocInfo::EMBEDDED_OBJECT) { |
10647 // IC stubs with handlers never contain non-handler code objects before | 10685 Object* obj = info->target_object(); |
10648 // handler targets. | 10686 skip_next_handler |= obj->IsWeakCell() && WeakCell::cast(obj)->cleared(); |
10649 if (code->kind() != Code::HANDLER) break; | 10687 } else { |
10650 code_list->Add(Handle<Code>(code)); | 10688 Code* code = Code::GetCodeFromTargetAddress(info->target_address()); |
10651 i++; | 10689 // IC stubs with handlers never contain non-handler code objects before |
| 10690 // handler targets. |
| 10691 if (code->kind() != Code::HANDLER) break; |
| 10692 if (!skip_next_handler) { |
| 10693 code_list->Add(Handle<Code>(code)); |
| 10694 i++; |
| 10695 } |
| 10696 skip_next_handler = false; |
| 10697 } |
10652 } | 10698 } |
10653 return i == length; | 10699 return i == length; |
10654 } | 10700 } |
10655 | 10701 |
10656 | 10702 |
10657 MaybeHandle<Code> Code::FindHandlerForMap(Map* map) { | 10703 MaybeHandle<Code> Code::FindHandlerForMap(Map* map) { |
10658 DCHECK(is_inline_cache_stub()); | 10704 DCHECK(is_inline_cache_stub()); |
10659 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | | 10705 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | |
10660 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); | 10706 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
10661 bool return_next = false; | 10707 bool return_next = false; |
10662 for (RelocIterator it(this, mask); !it.done(); it.next()) { | 10708 for (RelocIterator it(this, mask); !it.done(); it.next()) { |
10663 RelocInfo* info = it.rinfo(); | 10709 RelocInfo* info = it.rinfo(); |
10664 if (info->rmode() == RelocInfo::EMBEDDED_OBJECT) { | 10710 if (info->rmode() == RelocInfo::EMBEDDED_OBJECT) { |
10665 Object* object = info->target_object(); | 10711 Object* object = info->target_object(); |
| 10712 if (object->IsWeakCell()) object = WeakCell::cast(object)->value(); |
10666 if (object == map) return_next = true; | 10713 if (object == map) return_next = true; |
10667 } else if (return_next) { | 10714 } else if (return_next) { |
10668 Code* code = Code::GetCodeFromTargetAddress(info->target_address()); | 10715 Code* code = Code::GetCodeFromTargetAddress(info->target_address()); |
10669 DCHECK(code->kind() == Code::HANDLER); | 10716 DCHECK(code->kind() == Code::HANDLER); |
10670 return handle(code); | 10717 return handle(code); |
10671 } | 10718 } |
10672 } | 10719 } |
10673 return MaybeHandle<Code>(); | 10720 return MaybeHandle<Code>(); |
10674 } | 10721 } |
10675 | 10722 |
(...skipping 6173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16849 Handle<DependentCode> codes = | 16896 Handle<DependentCode> codes = |
16850 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), | 16897 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), |
16851 DependentCode::kPropertyCellChangedGroup, | 16898 DependentCode::kPropertyCellChangedGroup, |
16852 info->object_wrapper()); | 16899 info->object_wrapper()); |
16853 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); | 16900 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); |
16854 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( | 16901 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( |
16855 cell, info->zone()); | 16902 cell, info->zone()); |
16856 } | 16903 } |
16857 | 16904 |
16858 } } // namespace v8::internal | 16905 } } // namespace v8::internal |
OLD | NEW |