| 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 1611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1622 // Determine the list of receiver maps that this call site has seen, | 1622 // Determine the list of receiver maps that this call site has seen, |
| 1623 // adding the map that was just encountered. | 1623 // adding the map that was just encountered. |
| 1624 MapList target_receiver_maps; | 1624 MapList target_receiver_maps; |
| 1625 GetReceiverMapsForStub(target(), &target_receiver_maps); | 1625 GetReceiverMapsForStub(target(), &target_receiver_maps); |
| 1626 if (!AddOneReceiverMapIfMissing(&target_receiver_maps, receiver->map())) { | 1626 if (!AddOneReceiverMapIfMissing(&target_receiver_maps, receiver->map())) { |
| 1627 // If the miss wasn't due to an unseen map, a MEGAMORPHIC stub | 1627 // If the miss wasn't due to an unseen map, a MEGAMORPHIC stub |
| 1628 // won't help, use the generic stub. | 1628 // won't help, use the generic stub. |
| 1629 return generic_stub; | 1629 return generic_stub; |
| 1630 } | 1630 } |
| 1631 | 1631 |
| 1632 // TODO(1385): Currently MEGAMORPHIC stubs are cached in the receiver map stub | 1632 // If the maximum number of receiver maps has been exceeded, use the generic |
| 1633 // cache, but that can put receiver types together from unrelated call sites | 1633 // version of the IC. |
| 1634 // into the same stub--they always handle the union of all receiver maps seen | 1634 if (target_receiver_maps.length() > KeyedIC::kMaxKeyedPolymorphism) { |
| 1635 // at all call sites involving the receiver map. This is only an | 1635 return generic_stub; |
| 1636 // approximation: ideally, there would be a global cache that mapped sets of | 1636 } |
| 1637 // receiver maps to MEGAMORPHIC stubs. The complexity of the MEGAMORPHIC stub | 1637 |
| 1638 // computation also leads to direct manipulation of the stub cache from the IC | 1638 PolymorphicCodeCache* cache = isolate()->heap()->polymorphic_code_cache(); |
| 1639 // code, which the global cache solution would avoid. | 1639 Code::Flags flags = Code::ComputeFlags(this->kind(), |
| 1640 Code::Kind kind = this->kind(); | |
| 1641 Code::Flags flags = Code::ComputeFlags(kind, | |
| 1642 NOT_IN_LOOP, | 1640 NOT_IN_LOOP, |
| 1643 MEGAMORPHIC, | 1641 MEGAMORPHIC, |
| 1644 strict_mode); | 1642 strict_mode); |
| 1645 String* megamorphic_name = GetStubNameForCache(MEGAMORPHIC); | 1643 Object* maybe_cached_stub = cache->Lookup(&target_receiver_maps, flags); |
| 1646 Object* maybe_cached_stub = receiver->map()->FindInCodeCache(megamorphic_name, | 1644 // If there is a cached stub, use it. |
| 1647 flags); | |
| 1648 | |
| 1649 // Create a set of all receiver maps that have been seen at the IC call site | |
| 1650 // and those seen by the MEGAMORPHIC cached stub, if that's the stub that's | |
| 1651 // been selected. | |
| 1652 MapList receiver_maps; | |
| 1653 if (!maybe_cached_stub->IsUndefined()) { | 1645 if (!maybe_cached_stub->IsUndefined()) { |
| 1654 GetReceiverMapsForStub(Code::cast(maybe_cached_stub), &receiver_maps); | |
| 1655 } | |
| 1656 bool added_map = false; | |
| 1657 for (int i = 0; i < target_receiver_maps.length(); ++i) { | |
| 1658 if (AddOneReceiverMapIfMissing(&receiver_maps, | |
| 1659 target_receiver_maps.at(i))) { | |
| 1660 added_map = true; | |
| 1661 } | |
| 1662 } | |
| 1663 ASSERT(receiver_maps.length() > 0); | |
| 1664 | |
| 1665 // If the maximum number of receiver maps has been exceeded, use the Generic | |
| 1666 // version of the IC. | |
| 1667 if (receiver_maps.length() > KeyedIC::kMaxKeyedPolymorphism) { | |
| 1668 return generic_stub; | |
| 1669 } | |
| 1670 | |
| 1671 // If no maps have been seen at the call site that aren't in the cached | |
| 1672 // stub, then use it. | |
| 1673 if (!added_map) { | |
| 1674 ASSERT(!maybe_cached_stub->IsUndefined()); | |
| 1675 ASSERT(maybe_cached_stub->IsCode()); | 1646 ASSERT(maybe_cached_stub->IsCode()); |
| 1676 return Code::cast(maybe_cached_stub); | 1647 return Code::cast(maybe_cached_stub); |
| 1677 } | 1648 } |
| 1678 | 1649 // Collect MONOMORPHIC stubs for all target_receiver_maps. |
| 1679 // Lookup all of the receiver maps in the cache, they should all already | 1650 CodeList handler_ics(target_receiver_maps.length()); |
| 1680 // have MONOMORPHIC stubs. | 1651 for (int i = 0; i < target_receiver_maps.length(); ++i) { |
| 1681 CodeList handler_ics(KeyedIC::kMaxKeyedPolymorphism); | 1652 Map* receiver_map(target_receiver_maps.at(i)); |
| 1682 for (int current = 0; current < receiver_maps.length(); ++current) { | |
| 1683 Map* receiver_map(receiver_maps.at(current)); | |
| 1684 MaybeObject* maybe_cached_stub = ComputeMonomorphicStubWithoutMapCheck( | 1653 MaybeObject* maybe_cached_stub = ComputeMonomorphicStubWithoutMapCheck( |
| 1685 receiver_map, | 1654 receiver_map, strict_mode, generic_stub); |
| 1686 strict_mode, | |
| 1687 generic_stub); | |
| 1688 Code* cached_stub; | 1655 Code* cached_stub; |
| 1689 if (!maybe_cached_stub->To(&cached_stub)) { | 1656 if (!maybe_cached_stub->To(&cached_stub)) return maybe_cached_stub; |
| 1690 return maybe_cached_stub; | |
| 1691 } | |
| 1692 handler_ics.Add(cached_stub); | 1657 handler_ics.Add(cached_stub); |
| 1693 } | 1658 } |
| 1694 | 1659 // Build the MEGAMORPHIC stub. |
| 1695 Code* stub; | 1660 Code* stub; |
| 1696 // Build the MEGAMORPHIC stub. | 1661 maybe_stub = ConstructMegamorphicStub(&target_receiver_maps, |
| 1697 maybe_stub = ConstructMegamorphicStub(&receiver_maps, | |
| 1698 &handler_ics, | 1662 &handler_ics, |
| 1699 strict_mode); | 1663 strict_mode); |
| 1700 if (!maybe_stub->To(&stub)) return maybe_stub; | 1664 if (!maybe_stub->To(&stub)) return maybe_stub; |
| 1701 | 1665 MaybeObject* maybe_update = cache->Update(&target_receiver_maps, flags, stub); |
| 1702 MaybeObject* maybe_update = receiver->UpdateMapCodeCache( | |
| 1703 megamorphic_name, | |
| 1704 stub); | |
| 1705 if (maybe_update->IsFailure()) return maybe_update; | 1666 if (maybe_update->IsFailure()) return maybe_update; |
| 1706 return stub; | 1667 return stub; |
| 1707 } | 1668 } |
| 1708 | 1669 |
| 1709 | 1670 |
| 1710 MaybeObject* KeyedIC::ComputeMonomorphicStubWithoutMapCheck( | 1671 MaybeObject* KeyedIC::ComputeMonomorphicStubWithoutMapCheck( |
| 1711 Map* receiver_map, | 1672 Map* receiver_map, |
| 1712 StrictModeFlag strict_mode, | 1673 StrictModeFlag strict_mode, |
| 1713 Code* generic_stub) { | 1674 Code* generic_stub) { |
| 1714 if ((receiver_map->instance_type() & kNotStringTag) == 0) { | 1675 if ((receiver_map->instance_type() & kNotStringTag) == 0) { |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2568 #undef ADDR | 2529 #undef ADDR |
| 2569 }; | 2530 }; |
| 2570 | 2531 |
| 2571 | 2532 |
| 2572 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2533 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
| 2573 return IC_utilities[id]; | 2534 return IC_utilities[id]; |
| 2574 } | 2535 } |
| 2575 | 2536 |
| 2576 | 2537 |
| 2577 } } // namespace v8::internal | 2538 } } // namespace v8::internal |
| OLD | NEW |