| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 | 1090 |
| 1091 isolate()->stub_cache()->Set(*name, map, Code::cast(code)); | 1091 isolate()->stub_cache()->Set(*name, map, Code::cast(code)); |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 #ifdef DEBUG | 1094 #ifdef DEBUG |
| 1095 TraceIC("LoadIC", name, state, target()); | 1095 TraceIC("LoadIC", name, state, target()); |
| 1096 #endif | 1096 #endif |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 | 1099 |
| 1100 String* KeyedLoadIC::GetStubNameForCache(IC::State ic_state) { | |
| 1101 if (ic_state == MONOMORPHIC) { | |
| 1102 return isolate()->heap()->KeyedLoadElementMonomorphic_symbol(); | |
| 1103 } else { | |
| 1104 ASSERT(ic_state == MEGAMORPHIC); | |
| 1105 return isolate()->heap()->KeyedLoadElementPolymorphic_symbol(); | |
| 1106 } | |
| 1107 } | |
| 1108 | |
| 1109 | |
| 1110 MaybeObject* KeyedLoadIC::GetFastElementStubWithoutMapCheck( | 1100 MaybeObject* KeyedLoadIC::GetFastElementStubWithoutMapCheck( |
| 1111 bool is_js_array) { | 1101 bool is_js_array) { |
| 1112 return KeyedLoadFastElementStub().TryGetCode(); | 1102 return KeyedLoadFastElementStub().TryGetCode(); |
| 1113 } | 1103 } |
| 1114 | 1104 |
| 1115 | 1105 |
| 1116 MaybeObject* KeyedLoadIC::GetExternalArrayStubWithoutMapCheck( | 1106 MaybeObject* KeyedLoadIC::GetExternalArrayStubWithoutMapCheck( |
| 1117 JSObject::ElementsKind elements_kind) { | 1107 JSObject::ElementsKind elements_kind) { |
| 1118 return KeyedLoadExternalArrayStub(elements_kind).TryGetCode(); | 1108 return KeyedLoadExternalArrayStub(elements_kind).TryGetCode(); |
| 1119 } | 1109 } |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 } | 1617 } |
| 1628 } | 1618 } |
| 1629 } | 1619 } |
| 1630 | 1620 |
| 1631 | 1621 |
| 1632 MaybeObject* KeyedIC::ComputeStub(JSObject* receiver, | 1622 MaybeObject* KeyedIC::ComputeStub(JSObject* receiver, |
| 1633 bool is_store, | 1623 bool is_store, |
| 1634 StrictModeFlag strict_mode, | 1624 StrictModeFlag strict_mode, |
| 1635 Code* generic_stub) { | 1625 Code* generic_stub) { |
| 1636 State ic_state = target()->ic_state(); | 1626 State ic_state = target()->ic_state(); |
| 1637 Code* monomorphic_stub; | 1627 if (ic_state == UNINITIALIZED || ic_state == PREMONOMORPHIC) { |
| 1638 // Always compute the MONOMORPHIC stub, even if the MEGAMORPHIC stub ends up | 1628 Code* monomorphic_stub; |
| 1639 // being used. This is necessary because the megamorphic stub needs to have | 1629 MaybeObject* maybe_stub = ComputeMonomorphicStub(receiver, |
| 1640 // access to more information than what is stored in the receiver map in some | 1630 is_store, |
| 1641 // cases (external arrays need the array type from the MONOMORPHIC stub). | 1631 strict_mode, |
| 1642 MaybeObject* maybe_stub = ComputeMonomorphicStub(receiver, | 1632 generic_stub); |
| 1643 is_store, | 1633 if (!maybe_stub->To(&monomorphic_stub)) return maybe_stub; |
| 1644 strict_mode, | |
| 1645 generic_stub); | |
| 1646 if (!maybe_stub->To(&monomorphic_stub)) return maybe_stub; | |
| 1647 | 1634 |
| 1648 if (ic_state == UNINITIALIZED || ic_state == PREMONOMORPHIC) { | |
| 1649 return monomorphic_stub; | 1635 return monomorphic_stub; |
| 1650 } | 1636 } |
| 1651 ASSERT(target() != generic_stub); | 1637 ASSERT(target() != generic_stub); |
| 1652 | 1638 |
| 1653 // Don't handle megamorphic property accesses for INTERCEPTORS or CALLBACKS | 1639 // Don't handle megamorphic property accesses for INTERCEPTORS or CALLBACKS |
| 1654 // via megamorphic stubs, since they don't have a map in their relocation info | 1640 // via megamorphic stubs, since they don't have a map in their relocation info |
| 1655 // and so the stubs can't be harvested for the object needed for a map check. | 1641 // and so the stubs can't be harvested for the object needed for a map check. |
| 1656 if (target()->type() != NORMAL) { | 1642 if (target()->type() != NORMAL) { |
| 1657 return generic_stub; | 1643 return generic_stub; |
| 1658 } | 1644 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1689 for (int i = 0; i < target_receiver_maps.length(); ++i) { | 1675 for (int i = 0; i < target_receiver_maps.length(); ++i) { |
| 1690 Map* receiver_map(target_receiver_maps.at(i)); | 1676 Map* receiver_map(target_receiver_maps.at(i)); |
| 1691 MaybeObject* maybe_cached_stub = ComputeMonomorphicStubWithoutMapCheck( | 1677 MaybeObject* maybe_cached_stub = ComputeMonomorphicStubWithoutMapCheck( |
| 1692 receiver_map, strict_mode, generic_stub); | 1678 receiver_map, strict_mode, generic_stub); |
| 1693 Code* cached_stub; | 1679 Code* cached_stub; |
| 1694 if (!maybe_cached_stub->To(&cached_stub)) return maybe_cached_stub; | 1680 if (!maybe_cached_stub->To(&cached_stub)) return maybe_cached_stub; |
| 1695 handler_ics.Add(cached_stub); | 1681 handler_ics.Add(cached_stub); |
| 1696 } | 1682 } |
| 1697 // Build the MEGAMORPHIC stub. | 1683 // Build the MEGAMORPHIC stub. |
| 1698 Code* stub; | 1684 Code* stub; |
| 1699 maybe_stub = ConstructMegamorphicStub(&target_receiver_maps, | 1685 MaybeObject* maybe_stub = ConstructMegamorphicStub(&target_receiver_maps, |
| 1700 &handler_ics, | 1686 &handler_ics, |
| 1701 strict_mode); | 1687 strict_mode); |
| 1702 if (!maybe_stub->To(&stub)) return maybe_stub; | 1688 if (!maybe_stub->To(&stub)) return maybe_stub; |
| 1703 MaybeObject* maybe_update = cache->Update(&target_receiver_maps, flags, stub); | 1689 MaybeObject* maybe_update = cache->Update(&target_receiver_maps, flags, stub); |
| 1704 if (maybe_update->IsFailure()) return maybe_update; | 1690 if (maybe_update->IsFailure()) return maybe_update; |
| 1705 return stub; | 1691 return stub; |
| 1706 } | 1692 } |
| 1707 | 1693 |
| 1708 | 1694 |
| 1709 MaybeObject* KeyedIC::ComputeMonomorphicStubWithoutMapCheck( | 1695 MaybeObject* KeyedIC::ComputeMonomorphicStubWithoutMapCheck( |
| 1710 Map* receiver_map, | 1696 Map* receiver_map, |
| 1711 StrictModeFlag strict_mode, | 1697 StrictModeFlag strict_mode, |
| 1712 Code* generic_stub) { | 1698 Code* generic_stub) { |
| 1713 if ((receiver_map->instance_type() & kNotStringTag) == 0) { | 1699 if ((receiver_map->instance_type() & kNotStringTag) == 0) { |
| 1714 ASSERT(string_stub() != NULL); | 1700 ASSERT(string_stub() != NULL); |
| 1715 return string_stub(); | 1701 return string_stub(); |
| 1716 } else if (receiver_map->has_external_array_elements()) { | 1702 } else if (receiver_map->has_external_array_elements()) { |
| 1717 // Determine the array type from the default MONOMORPHIC already generated | 1703 return GetExternalArrayStubWithoutMapCheck(receiver_map->elements_kind()); |
| 1718 // stub. There is no other way to determine the type of the external array | |
| 1719 // directly from the receiver type. | |
| 1720 Code::Kind kind = this->kind(); | |
| 1721 Code::Flags flags = Code::ComputeMonomorphicFlags(kind, | |
| 1722 NORMAL, | |
| 1723 strict_mode); | |
| 1724 String* monomorphic_name = GetStubNameForCache(MONOMORPHIC); | |
| 1725 Object* maybe_default_stub = receiver_map->FindInCodeCache(monomorphic_name, | |
| 1726 flags); | |
| 1727 if (maybe_default_stub->IsUndefined()) { | |
| 1728 return generic_stub; | |
| 1729 } | |
| 1730 Code* default_stub = Code::cast(maybe_default_stub); | |
| 1731 Map* first_map = default_stub->FindFirstMap(); | |
| 1732 return GetExternalArrayStubWithoutMapCheck(first_map->elements_kind()); | |
| 1733 } else if (receiver_map->has_fast_elements()) { | 1704 } else if (receiver_map->has_fast_elements()) { |
| 1734 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; | 1705 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; |
| 1735 return GetFastElementStubWithoutMapCheck(is_js_array); | 1706 return GetFastElementStubWithoutMapCheck(is_js_array); |
| 1736 } else { | 1707 } else { |
| 1737 return generic_stub; | 1708 return generic_stub; |
| 1738 } | 1709 } |
| 1739 } | 1710 } |
| 1740 | 1711 |
| 1741 | 1712 |
| 1742 MaybeObject* KeyedIC::ComputeMonomorphicStub(JSObject* receiver, | 1713 MaybeObject* KeyedIC::ComputeMonomorphicStub(JSObject* receiver, |
| 1743 bool is_store, | 1714 bool is_store, |
| 1744 StrictModeFlag strict_mode, | 1715 StrictModeFlag strict_mode, |
| 1745 Code* generic_stub) { | 1716 Code* generic_stub) { |
| 1746 Code* result = NULL; | 1717 Code* result = NULL; |
| 1747 if (receiver->HasFastElements() || | 1718 if (receiver->HasFastElements() || |
| 1748 receiver->HasExternalArrayElements() || | 1719 receiver->HasExternalArrayElements() || |
| 1749 receiver->HasDictionaryElements()) { | 1720 receiver->HasDictionaryElements()) { |
| 1750 MaybeObject* maybe_stub = | 1721 MaybeObject* maybe_stub = |
| 1751 isolate()->stub_cache()->ComputeKeyedLoadOrStoreElement( | 1722 isolate()->stub_cache()->ComputeKeyedLoadOrStoreElement( |
| 1752 receiver, is_store, strict_mode); | 1723 receiver, is_store, strict_mode); |
| 1753 if (!maybe_stub->To(&result)) return maybe_stub; | 1724 if (!maybe_stub->To(&result)) return maybe_stub; |
| 1754 } else { | 1725 } else { |
| 1755 result = generic_stub; | 1726 result = generic_stub; |
| 1756 } | 1727 } |
| 1757 return result; | 1728 return result; |
| 1758 } | 1729 } |
| 1759 | 1730 |
| 1760 | 1731 |
| 1761 String* KeyedStoreIC::GetStubNameForCache(IC::State ic_state) { | |
| 1762 if (ic_state == MONOMORPHIC) { | |
| 1763 return isolate()->heap()->KeyedStoreElementMonomorphic_symbol(); | |
| 1764 } else { | |
| 1765 ASSERT(ic_state == MEGAMORPHIC); | |
| 1766 return isolate()->heap()->KeyedStoreElementPolymorphic_symbol(); | |
| 1767 } | |
| 1768 } | |
| 1769 | |
| 1770 | |
| 1771 MaybeObject* KeyedStoreIC::GetFastElementStubWithoutMapCheck( | 1732 MaybeObject* KeyedStoreIC::GetFastElementStubWithoutMapCheck( |
| 1772 bool is_js_array) { | 1733 bool is_js_array) { |
| 1773 return KeyedStoreFastElementStub(is_js_array).TryGetCode(); | 1734 return KeyedStoreFastElementStub(is_js_array).TryGetCode(); |
| 1774 } | 1735 } |
| 1775 | 1736 |
| 1776 | 1737 |
| 1777 MaybeObject* KeyedStoreIC::GetExternalArrayStubWithoutMapCheck( | 1738 MaybeObject* KeyedStoreIC::GetExternalArrayStubWithoutMapCheck( |
| 1778 JSObject::ElementsKind elements_kind) { | 1739 JSObject::ElementsKind elements_kind) { |
| 1779 return KeyedStoreExternalArrayStub(elements_kind).TryGetCode(); | 1740 return KeyedStoreExternalArrayStub(elements_kind).TryGetCode(); |
| 1780 } | 1741 } |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2560 #undef ADDR | 2521 #undef ADDR |
| 2561 }; | 2522 }; |
| 2562 | 2523 |
| 2563 | 2524 |
| 2564 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2525 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
| 2565 return IC_utilities[id]; | 2526 return IC_utilities[id]; |
| 2566 } | 2527 } |
| 2567 | 2528 |
| 2568 | 2529 |
| 2569 } } // namespace v8::internal | 2530 } } // namespace v8::internal |
| OLD | NEW |