OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/code-stub-assembler.h" | 5 #include "src/code-stub-assembler.h" |
6 #include "src/code-factory.h" | 6 #include "src/code-factory.h" |
7 #include "src/frames-inl.h" | 7 #include "src/frames-inl.h" |
8 #include "src/frames.h" | 8 #include "src/frames.h" |
9 #include "src/ic/stub-cache.h" | 9 #include "src/ic/stub-cache.h" |
10 | 10 |
(...skipping 2712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2723 var_handler->Bind(handler); | 2723 var_handler->Bind(handler); |
2724 Goto(if_handler); | 2724 Goto(if_handler); |
2725 | 2725 |
2726 Bind(&next_entry); | 2726 Bind(&next_entry); |
2727 var_index.Bind(Int32Add(index, Int32Constant(kEntrySize))); | 2727 var_index.Bind(Int32Add(index, Int32Constant(kEntrySize))); |
2728 Goto(&loop); | 2728 Goto(&loop); |
2729 } | 2729 } |
2730 } | 2730 } |
2731 | 2731 |
2732 compiler::Node* CodeStubAssembler::StubCachePrimaryOffset(compiler::Node* name, | 2732 compiler::Node* CodeStubAssembler::StubCachePrimaryOffset(compiler::Node* name, |
2733 Code::Flags flags, | |
2734 compiler::Node* map) { | 2733 compiler::Node* map) { |
2735 // See v8::internal::StubCache::PrimaryOffset(). | 2734 // See v8::internal::StubCache::PrimaryOffset(). |
2736 STATIC_ASSERT(StubCache::kCacheIndexShift == Name::kHashShift); | 2735 STATIC_ASSERT(StubCache::kCacheIndexShift == Name::kHashShift); |
2737 // Compute the hash of the name (use entire hash field). | 2736 // Compute the hash of the name (use entire hash field). |
2738 Node* hash_field = LoadNameHashField(name); | 2737 Node* hash_field = LoadNameHashField(name); |
2739 Assert(WordEqual( | 2738 Assert(WordEqual( |
2740 Word32And(hash_field, Int32Constant(Name::kHashNotComputedMask)), | 2739 Word32And(hash_field, Int32Constant(Name::kHashNotComputedMask)), |
2741 Int32Constant(0))); | 2740 Int32Constant(0))); |
2742 | 2741 |
2743 // Using only the low bits in 64-bit mode is unlikely to increase the | 2742 // Using only the low bits in 64-bit mode is unlikely to increase the |
2744 // risk of collision even if the heap is spread over an area larger than | 2743 // risk of collision even if the heap is spread over an area larger than |
2745 // 4Gb (and not at all if it isn't). | 2744 // 4Gb (and not at all if it isn't). |
2746 Node* hash = Int32Add(hash_field, map); | 2745 Node* hash = Int32Add(hash_field, map); |
2747 // We always set the in_loop bit to zero when generating the lookup code | 2746 // Base the offset on a simple combination of name and map. |
2748 // so do it here too so the hash codes match. | |
2749 uint32_t iflags = | |
2750 (static_cast<uint32_t>(flags) & ~Code::kFlagsNotUsedInLookup); | |
2751 // Base the offset on a simple combination of name, flags, and map. | |
2752 hash = Word32Xor(hash, Int32Constant(iflags)); | |
2753 uint32_t mask = (StubCache::kPrimaryTableSize - 1) | 2747 uint32_t mask = (StubCache::kPrimaryTableSize - 1) |
2754 << StubCache::kCacheIndexShift; | 2748 << StubCache::kCacheIndexShift; |
2755 return Word32And(hash, Int32Constant(mask)); | 2749 return Word32And(hash, Int32Constant(mask)); |
2756 } | 2750 } |
2757 | 2751 |
2758 compiler::Node* CodeStubAssembler::StubCacheSecondaryOffset( | 2752 compiler::Node* CodeStubAssembler::StubCacheSecondaryOffset( |
2759 compiler::Node* name, Code::Flags flags, compiler::Node* seed) { | 2753 compiler::Node* name, compiler::Node* seed) { |
2760 // See v8::internal::StubCache::SecondaryOffset(). | 2754 // See v8::internal::StubCache::SecondaryOffset(). |
2761 | 2755 |
2762 // Use the seed from the primary cache in the secondary cache. | 2756 // Use the seed from the primary cache in the secondary cache. |
2763 Node* hash = Int32Sub(seed, name); | 2757 Node* hash = Int32Sub(seed, name); |
2764 // We always set the in_loop bit to zero when generating the lookup code | |
2765 // so do it here too so the hash codes match. | |
2766 uint32_t iflags = | |
2767 (static_cast<uint32_t>(flags) & ~Code::kFlagsNotUsedInLookup); | |
2768 hash = Int32Add(hash, Int32Constant(iflags)); | |
2769 int32_t mask = (StubCache::kSecondaryTableSize - 1) | 2758 int32_t mask = (StubCache::kSecondaryTableSize - 1) |
2770 << StubCache::kCacheIndexShift; | 2759 << StubCache::kCacheIndexShift; |
2771 return Word32And(hash, Int32Constant(mask)); | 2760 return Word32And(hash, Int32Constant(mask)); |
2772 } | 2761 } |
2773 | 2762 |
2774 enum CodeStubAssembler::StubCacheTable : int { | 2763 enum CodeStubAssembler::StubCacheTable : int { |
2775 kPrimary = static_cast<int>(StubCache::kPrimary), | 2764 kPrimary = static_cast<int>(StubCache::kPrimary), |
2776 kSecondary = static_cast<int>(StubCache::kSecondary) | 2765 kSecondary = static_cast<int>(StubCache::kSecondary) |
2777 }; | 2766 }; |
2778 | 2767 |
2779 void CodeStubAssembler::TryProbeStubCacheTable( | 2768 void CodeStubAssembler::TryProbeStubCacheTable( |
2780 StubCache* stub_cache, StubCacheTable table_id, | 2769 StubCache* stub_cache, StubCacheTable table_id, |
2781 compiler::Node* entry_offset, compiler::Node* name, Code::Flags flags, | 2770 compiler::Node* entry_offset, compiler::Node* name, compiler::Node* map, |
2782 compiler::Node* map, Label* if_handler, Variable* var_handler, | 2771 Label* if_handler, Variable* var_handler, Label* if_miss) { |
2783 Label* if_miss) { | |
2784 StubCache::Table table = static_cast<StubCache::Table>(table_id); | 2772 StubCache::Table table = static_cast<StubCache::Table>(table_id); |
2785 #ifdef DEBUG | 2773 #ifdef DEBUG |
2786 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { | 2774 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
2787 Goto(if_miss); | 2775 Goto(if_miss); |
2788 return; | 2776 return; |
2789 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { | 2777 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
2790 Goto(if_miss); | 2778 Goto(if_miss); |
2791 return; | 2779 return; |
2792 } | 2780 } |
2793 #endif | 2781 #endif |
2794 // The {table_offset} holds the entry offset times four (due to masking | 2782 // The {table_offset} holds the entry offset times four (due to masking |
2795 // and shifting optimizations). | 2783 // and shifting optimizations). |
2796 const int kMultiplier = sizeof(StubCache::Entry) >> Name::kHashShift; | 2784 const int kMultiplier = sizeof(StubCache::Entry) >> Name::kHashShift; |
2797 entry_offset = Int32Mul(entry_offset, Int32Constant(kMultiplier)); | 2785 entry_offset = Int32Mul(entry_offset, Int32Constant(kMultiplier)); |
2798 | 2786 |
2799 // Check that the key in the entry matches the name. | 2787 // Check that the key in the entry matches the name. |
2800 Node* key_base = | 2788 Node* key_base = |
2801 ExternalConstant(ExternalReference(stub_cache->key_reference(table))); | 2789 ExternalConstant(ExternalReference(stub_cache->key_reference(table))); |
2802 Node* entry_key = Load(MachineType::Pointer(), key_base, entry_offset); | 2790 Node* entry_key = Load(MachineType::Pointer(), key_base, entry_offset); |
2803 GotoIf(WordNotEqual(name, entry_key), if_miss); | 2791 GotoIf(WordNotEqual(name, entry_key), if_miss); |
2804 | 2792 |
2805 // Get the map entry from the cache. | 2793 // Get the map entry from the cache. |
2806 DCHECK_EQ(kPointerSize * 2, stub_cache->map_reference(table).address() - | 2794 DCHECK_EQ(kPointerSize * 2, stub_cache->map_reference(table).address() - |
2807 stub_cache->key_reference(table).address()); | 2795 stub_cache->key_reference(table).address()); |
2808 Node* entry_map = | 2796 Node* entry_map = |
2809 Load(MachineType::Pointer(), key_base, | 2797 Load(MachineType::Pointer(), key_base, |
2810 Int32Add(entry_offset, Int32Constant(kPointerSize * 2))); | 2798 Int32Add(entry_offset, Int32Constant(kPointerSize * 2))); |
2811 GotoIf(WordNotEqual(map, entry_map), if_miss); | 2799 GotoIf(WordNotEqual(map, entry_map), if_miss); |
2812 | 2800 |
2813 // Check that the flags match what we're looking for. | |
2814 DCHECK_EQ(kPointerSize, stub_cache->value_reference(table).address() - | 2801 DCHECK_EQ(kPointerSize, stub_cache->value_reference(table).address() - |
2815 stub_cache->key_reference(table).address()); | 2802 stub_cache->key_reference(table).address()); |
2816 Node* code = Load(MachineType::Pointer(), key_base, | 2803 Node* code = Load(MachineType::Pointer(), key_base, |
2817 Int32Add(entry_offset, Int32Constant(kPointerSize))); | 2804 Int32Add(entry_offset, Int32Constant(kPointerSize))); |
2818 | 2805 |
2806 // Check that the flags match what we're looking for. | |
Jakob Kummerow
2016/07/12 12:55:49
Any particular reason this isn't behind an #ifdef
Igor Sheludko
2016/07/12 13:06:54
TF compiler is good at throwing non used code away
| |
2807 Code::Flags flags = Code::RemoveHolderFromFlags( | |
2808 Code::ComputeHandlerFlags(stub_cache->ic_kind())); | |
2819 Node* code_flags = | 2809 Node* code_flags = |
2820 LoadObjectField(code, Code::kFlagsOffset, MachineType::Uint32()); | 2810 LoadObjectField(code, Code::kFlagsOffset, MachineType::Uint32()); |
2821 GotoIf(Word32NotEqual(Int32Constant(flags), | 2811 Assert(Word32Equal( |
2822 Word32And(code_flags, | 2812 Int32Constant(flags), |
2823 Int32Constant(~Code::kFlagsNotUsedInLookup))), | 2813 Word32And(code_flags, Int32Constant(~Code::kFlagsNotUsedInLookup)))); |
2824 if_miss); | |
2825 | 2814 |
2826 // We found the handler. | 2815 // We found the handler. |
2827 var_handler->Bind(code); | 2816 var_handler->Bind(code); |
2828 Goto(if_handler); | 2817 Goto(if_handler); |
2829 } | 2818 } |
2830 | 2819 |
2831 void CodeStubAssembler::TryProbeStubCache( | 2820 void CodeStubAssembler::TryProbeStubCache( |
2832 StubCache* stub_cache, compiler::Node* receiver, compiler::Node* name, | 2821 StubCache* stub_cache, compiler::Node* receiver, compiler::Node* name, |
2833 Label* if_handler, Variable* var_handler, Label* if_miss) { | 2822 Label* if_handler, Variable* var_handler, Label* if_miss) { |
2834 Code::Flags flags = Code::RemoveHolderFromFlags( | |
2835 Code::ComputeHandlerFlags(stub_cache->ic_kind())); | |
2836 | |
2837 Label try_secondary(this), miss(this); | 2823 Label try_secondary(this), miss(this); |
2838 | 2824 |
2839 Counters* counters = isolate()->counters(); | 2825 Counters* counters = isolate()->counters(); |
2840 IncrementCounter(counters->megamorphic_stub_cache_probes(), 1); | 2826 IncrementCounter(counters->megamorphic_stub_cache_probes(), 1); |
2841 | 2827 |
2842 // Check that the {receiver} isn't a smi. | 2828 // Check that the {receiver} isn't a smi. |
2843 GotoIf(WordIsSmi(receiver), &miss); | 2829 GotoIf(WordIsSmi(receiver), &miss); |
2844 | 2830 |
2845 Node* receiver_map = LoadMap(receiver); | 2831 Node* receiver_map = LoadMap(receiver); |
2846 | 2832 |
2847 // Probe the primary table. | 2833 // Probe the primary table. |
2848 Node* primary_offset = StubCachePrimaryOffset(name, flags, receiver_map); | 2834 Node* primary_offset = StubCachePrimaryOffset(name, receiver_map); |
2849 TryProbeStubCacheTable(stub_cache, kPrimary, primary_offset, name, flags, | 2835 TryProbeStubCacheTable(stub_cache, kPrimary, primary_offset, name, |
2850 receiver_map, if_handler, var_handler, &try_secondary); | 2836 receiver_map, if_handler, var_handler, &try_secondary); |
2851 | 2837 |
2852 Bind(&try_secondary); | 2838 Bind(&try_secondary); |
2853 { | 2839 { |
2854 // Probe the secondary table. | 2840 // Probe the secondary table. |
2855 Node* secondary_offset = | 2841 Node* secondary_offset = StubCacheSecondaryOffset(name, primary_offset); |
2856 StubCacheSecondaryOffset(name, flags, primary_offset); | |
2857 TryProbeStubCacheTable(stub_cache, kSecondary, secondary_offset, name, | 2842 TryProbeStubCacheTable(stub_cache, kSecondary, secondary_offset, name, |
2858 flags, receiver_map, if_handler, var_handler, &miss); | 2843 receiver_map, if_handler, var_handler, &miss); |
2859 } | 2844 } |
2860 | 2845 |
2861 Bind(&miss); | 2846 Bind(&miss); |
2862 { | 2847 { |
2863 IncrementCounter(counters->megamorphic_stub_cache_misses(), 1); | 2848 IncrementCounter(counters->megamorphic_stub_cache_misses(), 1); |
2864 Goto(if_miss); | 2849 Goto(if_miss); |
2865 } | 2850 } |
2866 } | 2851 } |
2867 | 2852 |
2868 void CodeStubAssembler::LoadIC(const LoadICParameters* p) { | 2853 void CodeStubAssembler::LoadIC(const LoadICParameters* p) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2944 } | 2929 } |
2945 Bind(&miss); | 2930 Bind(&miss); |
2946 { | 2931 { |
2947 TailCallRuntime(Runtime::kLoadGlobalIC_Miss, p->context, p->slot, | 2932 TailCallRuntime(Runtime::kLoadGlobalIC_Miss, p->context, p->slot, |
2948 p->vector); | 2933 p->vector); |
2949 } | 2934 } |
2950 } | 2935 } |
2951 | 2936 |
2952 } // namespace internal | 2937 } // namespace internal |
2953 } // namespace v8 | 2938 } // namespace v8 |
OLD | NEW |