Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: src/code-stub-assembler.cc

Issue 2167493003: [ic] [stubs] Don't use Code::flags in megamorphic stub cache hash computations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@stub-cache-fix
Patch Set: Rebasing Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/code-stub-assembler.h ('k') | src/code-stubs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2845 matching lines...) Expand 10 before | Expand all | Expand 10 after
2856 var_handler->Bind(handler); 2856 var_handler->Bind(handler);
2857 Goto(if_handler); 2857 Goto(if_handler);
2858 2858
2859 Bind(&next_entry); 2859 Bind(&next_entry);
2860 var_index.Bind(Int32Add(index, Int32Constant(kEntrySize))); 2860 var_index.Bind(Int32Add(index, Int32Constant(kEntrySize)));
2861 Goto(&loop); 2861 Goto(&loop);
2862 } 2862 }
2863 } 2863 }
2864 2864
2865 compiler::Node* CodeStubAssembler::StubCachePrimaryOffset(compiler::Node* name, 2865 compiler::Node* CodeStubAssembler::StubCachePrimaryOffset(compiler::Node* name,
2866 Code::Flags flags,
2867 compiler::Node* map) { 2866 compiler::Node* map) {
2868 // See v8::internal::StubCache::PrimaryOffset(). 2867 // See v8::internal::StubCache::PrimaryOffset().
2869 STATIC_ASSERT(StubCache::kCacheIndexShift == Name::kHashShift); 2868 STATIC_ASSERT(StubCache::kCacheIndexShift == Name::kHashShift);
2870 // Compute the hash of the name (use entire hash field). 2869 // Compute the hash of the name (use entire hash field).
2871 Node* hash_field = LoadNameHashField(name); 2870 Node* hash_field = LoadNameHashField(name);
2872 Assert(WordEqual( 2871 Assert(WordEqual(
2873 Word32And(hash_field, Int32Constant(Name::kHashNotComputedMask)), 2872 Word32And(hash_field, Int32Constant(Name::kHashNotComputedMask)),
2874 Int32Constant(0))); 2873 Int32Constant(0)));
2875 2874
2876 // Using only the low bits in 64-bit mode is unlikely to increase the 2875 // Using only the low bits in 64-bit mode is unlikely to increase the
2877 // risk of collision even if the heap is spread over an area larger than 2876 // risk of collision even if the heap is spread over an area larger than
2878 // 4Gb (and not at all if it isn't). 2877 // 4Gb (and not at all if it isn't).
2879 Node* hash = Int32Add(hash_field, map); 2878 Node* hash = Int32Add(hash_field, map);
2880 // We always set the in_loop bit to zero when generating the lookup code 2879 // Base the offset on a simple combination of name and map.
2881 // so do it here too so the hash codes match. 2880 hash = Word32Xor(hash, Int32Constant(StubCache::kPrimaryMagic));
2882 uint32_t iflags =
2883 (static_cast<uint32_t>(flags) & ~Code::kFlagsNotUsedInLookup);
2884 // Base the offset on a simple combination of name, flags, and map.
2885 hash = Word32Xor(hash, Int32Constant(iflags));
2886 uint32_t mask = (StubCache::kPrimaryTableSize - 1) 2881 uint32_t mask = (StubCache::kPrimaryTableSize - 1)
2887 << StubCache::kCacheIndexShift; 2882 << StubCache::kCacheIndexShift;
2888 return Word32And(hash, Int32Constant(mask)); 2883 return Word32And(hash, Int32Constant(mask));
2889 } 2884 }
2890 2885
2891 compiler::Node* CodeStubAssembler::StubCacheSecondaryOffset( 2886 compiler::Node* CodeStubAssembler::StubCacheSecondaryOffset(
2892 compiler::Node* name, Code::Flags flags, compiler::Node* seed) { 2887 compiler::Node* name, compiler::Node* seed) {
2893 // See v8::internal::StubCache::SecondaryOffset(). 2888 // See v8::internal::StubCache::SecondaryOffset().
2894 2889
2895 // Use the seed from the primary cache in the secondary cache. 2890 // Use the seed from the primary cache in the secondary cache.
2896 Node* hash = Int32Sub(seed, name); 2891 Node* hash = Int32Sub(seed, name);
2897 // We always set the in_loop bit to zero when generating the lookup code 2892 hash = Int32Add(hash, Int32Constant(StubCache::kSecondaryMagic));
2898 // so do it here too so the hash codes match.
2899 uint32_t iflags =
2900 (static_cast<uint32_t>(flags) & ~Code::kFlagsNotUsedInLookup);
2901 hash = Int32Add(hash, Int32Constant(iflags));
2902 int32_t mask = (StubCache::kSecondaryTableSize - 1) 2893 int32_t mask = (StubCache::kSecondaryTableSize - 1)
2903 << StubCache::kCacheIndexShift; 2894 << StubCache::kCacheIndexShift;
2904 return Word32And(hash, Int32Constant(mask)); 2895 return Word32And(hash, Int32Constant(mask));
2905 } 2896 }
2906 2897
2907 enum CodeStubAssembler::StubCacheTable : int { 2898 enum CodeStubAssembler::StubCacheTable : int {
2908 kPrimary = static_cast<int>(StubCache::kPrimary), 2899 kPrimary = static_cast<int>(StubCache::kPrimary),
2909 kSecondary = static_cast<int>(StubCache::kSecondary) 2900 kSecondary = static_cast<int>(StubCache::kSecondary)
2910 }; 2901 };
2911 2902
2912 void CodeStubAssembler::TryProbeStubCacheTable( 2903 void CodeStubAssembler::TryProbeStubCacheTable(
2913 StubCache* stub_cache, StubCacheTable table_id, 2904 StubCache* stub_cache, StubCacheTable table_id,
2914 compiler::Node* entry_offset, compiler::Node* name, Code::Flags flags, 2905 compiler::Node* entry_offset, compiler::Node* name, compiler::Node* map,
2915 compiler::Node* map, Label* if_handler, Variable* var_handler, 2906 Label* if_handler, Variable* var_handler, Label* if_miss) {
2916 Label* if_miss) {
2917 StubCache::Table table = static_cast<StubCache::Table>(table_id); 2907 StubCache::Table table = static_cast<StubCache::Table>(table_id);
2918 #ifdef DEBUG 2908 #ifdef DEBUG
2919 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { 2909 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
2920 Goto(if_miss); 2910 Goto(if_miss);
2921 return; 2911 return;
2922 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { 2912 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
2923 Goto(if_miss); 2913 Goto(if_miss);
2924 return; 2914 return;
2925 } 2915 }
2926 #endif 2916 #endif
2927 // The {table_offset} holds the entry offset times four (due to masking 2917 // The {table_offset} holds the entry offset times four (due to masking
2928 // and shifting optimizations). 2918 // and shifting optimizations).
2929 const int kMultiplier = sizeof(StubCache::Entry) >> Name::kHashShift; 2919 const int kMultiplier = sizeof(StubCache::Entry) >> Name::kHashShift;
2930 entry_offset = Int32Mul(entry_offset, Int32Constant(kMultiplier)); 2920 entry_offset = Int32Mul(entry_offset, Int32Constant(kMultiplier));
2931 2921
2932 // Check that the key in the entry matches the name. 2922 // Check that the key in the entry matches the name.
2933 Node* key_base = 2923 Node* key_base =
2934 ExternalConstant(ExternalReference(stub_cache->key_reference(table))); 2924 ExternalConstant(ExternalReference(stub_cache->key_reference(table)));
2935 Node* entry_key = Load(MachineType::Pointer(), key_base, entry_offset); 2925 Node* entry_key = Load(MachineType::Pointer(), key_base, entry_offset);
2936 GotoIf(WordNotEqual(name, entry_key), if_miss); 2926 GotoIf(WordNotEqual(name, entry_key), if_miss);
2937 2927
2938 // Get the map entry from the cache. 2928 // Get the map entry from the cache.
2939 DCHECK_EQ(kPointerSize * 2, stub_cache->map_reference(table).address() - 2929 DCHECK_EQ(kPointerSize * 2, stub_cache->map_reference(table).address() -
2940 stub_cache->key_reference(table).address()); 2930 stub_cache->key_reference(table).address());
2941 Node* entry_map = 2931 Node* entry_map =
2942 Load(MachineType::Pointer(), key_base, 2932 Load(MachineType::Pointer(), key_base,
2943 Int32Add(entry_offset, Int32Constant(kPointerSize * 2))); 2933 Int32Add(entry_offset, Int32Constant(kPointerSize * 2)));
2944 GotoIf(WordNotEqual(map, entry_map), if_miss); 2934 GotoIf(WordNotEqual(map, entry_map), if_miss);
2945 2935
2946 // Check that the flags match what we're looking for.
2947 DCHECK_EQ(kPointerSize, stub_cache->value_reference(table).address() - 2936 DCHECK_EQ(kPointerSize, stub_cache->value_reference(table).address() -
2948 stub_cache->key_reference(table).address()); 2937 stub_cache->key_reference(table).address());
2949 Node* code = Load(MachineType::Pointer(), key_base, 2938 Node* code = Load(MachineType::Pointer(), key_base,
2950 Int32Add(entry_offset, Int32Constant(kPointerSize))); 2939 Int32Add(entry_offset, Int32Constant(kPointerSize)));
2951 2940
2952 Node* code_flags =
2953 LoadObjectField(code, Code::kFlagsOffset, MachineType::Uint32());
2954 GotoIf(Word32NotEqual(Int32Constant(flags),
2955 Word32And(code_flags,
2956 Int32Constant(~Code::kFlagsNotUsedInLookup))),
2957 if_miss);
2958
2959 // We found the handler. 2941 // We found the handler.
2960 var_handler->Bind(code); 2942 var_handler->Bind(code);
2961 Goto(if_handler); 2943 Goto(if_handler);
2962 } 2944 }
2963 2945
2964 void CodeStubAssembler::TryProbeStubCache( 2946 void CodeStubAssembler::TryProbeStubCache(
2965 StubCache* stub_cache, compiler::Node* receiver, compiler::Node* name, 2947 StubCache* stub_cache, compiler::Node* receiver, compiler::Node* name,
2966 Label* if_handler, Variable* var_handler, Label* if_miss) { 2948 Label* if_handler, Variable* var_handler, Label* if_miss) {
2967 Code::Flags flags = Code::RemoveHolderFromFlags(
2968 Code::ComputeHandlerFlags(stub_cache->ic_kind()));
2969
2970 Label try_secondary(this), miss(this); 2949 Label try_secondary(this), miss(this);
2971 2950
2972 Counters* counters = isolate()->counters(); 2951 Counters* counters = isolate()->counters();
2973 IncrementCounter(counters->megamorphic_stub_cache_probes(), 1); 2952 IncrementCounter(counters->megamorphic_stub_cache_probes(), 1);
2974 2953
2975 // Check that the {receiver} isn't a smi. 2954 // Check that the {receiver} isn't a smi.
2976 GotoIf(WordIsSmi(receiver), &miss); 2955 GotoIf(WordIsSmi(receiver), &miss);
2977 2956
2978 Node* receiver_map = LoadMap(receiver); 2957 Node* receiver_map = LoadMap(receiver);
2979 2958
2980 // Probe the primary table. 2959 // Probe the primary table.
2981 Node* primary_offset = StubCachePrimaryOffset(name, flags, receiver_map); 2960 Node* primary_offset = StubCachePrimaryOffset(name, receiver_map);
2982 TryProbeStubCacheTable(stub_cache, kPrimary, primary_offset, name, flags, 2961 TryProbeStubCacheTable(stub_cache, kPrimary, primary_offset, name,
2983 receiver_map, if_handler, var_handler, &try_secondary); 2962 receiver_map, if_handler, var_handler, &try_secondary);
2984 2963
2985 Bind(&try_secondary); 2964 Bind(&try_secondary);
2986 { 2965 {
2987 // Probe the secondary table. 2966 // Probe the secondary table.
2988 Node* secondary_offset = 2967 Node* secondary_offset = StubCacheSecondaryOffset(name, primary_offset);
2989 StubCacheSecondaryOffset(name, flags, primary_offset);
2990 TryProbeStubCacheTable(stub_cache, kSecondary, secondary_offset, name, 2968 TryProbeStubCacheTable(stub_cache, kSecondary, secondary_offset, name,
2991 flags, receiver_map, if_handler, var_handler, &miss); 2969 receiver_map, if_handler, var_handler, &miss);
2992 } 2970 }
2993 2971
2994 Bind(&miss); 2972 Bind(&miss);
2995 { 2973 {
2996 IncrementCounter(counters->megamorphic_stub_cache_misses(), 1); 2974 IncrementCounter(counters->megamorphic_stub_cache_misses(), 1);
2997 Goto(if_miss); 2975 Goto(if_miss);
2998 } 2976 }
2999 } 2977 }
3000 2978
3001 void CodeStubAssembler::LoadIC(const LoadICParameters* p) { 2979 void CodeStubAssembler::LoadIC(const LoadICParameters* p) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3132 } 3110 }
3133 Bind(&miss); 3111 Bind(&miss);
3134 { 3112 {
3135 TailCallRuntime(Runtime::kLoadGlobalIC_Miss, p->context, p->slot, 3113 TailCallRuntime(Runtime::kLoadGlobalIC_Miss, p->context, p->slot,
3136 p->vector); 3114 p->vector);
3137 } 3115 }
3138 } 3116 }
3139 3117
3140 } // namespace internal 3118 } // namespace internal
3141 } // namespace v8 3119 } // namespace v8
OLDNEW
« no previous file with comments | « src/code-stub-assembler.h ('k') | src/code-stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698