From f1e1b39ebacb6d4a5b5eb2df4b0d8294da30b105 Mon Sep 17 00:00:00 2001 From: "lrn@chromium.org" Date: Wed, 6 May 2009 08:42:36 +0000 Subject: [PATCH] X64: Changed hash computations to only use lower 32 bits of pointers. Review URL: http://codereview.chromium.org/115017 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1876 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/stub-cache.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/stub-cache.h b/src/stub-cache.h index 824f4ff..369b15d 100644 --- a/src/stub-cache.h +++ b/src/stub-cache.h @@ -203,14 +203,21 @@ class StubCache : public AllStatic { // Compute the hash of the name (use entire length field). ASSERT(name->HasHashCode()); uint32_t field = name->length_field(); + // Using only the low bits in 64-bit mode is unlikely to increase the + // risk of collision even if the heap is spread over an area larger than + // 4Gb (and not at all if it isn't). + uint32_t map_low32bits = + static_cast(reinterpret_cast(map)); // Base the offset on a simple combination of name, flags, and map. - uint32_t key = (reinterpret_cast(map) + field) ^ flags; + uint32_t key = (map_low32bits + field) ^ flags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } static int SecondaryOffset(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. - uint32_t key = seed - reinterpret_cast(name) + flags; + uint32_t string_low32bits = + static_cast(reinterpret_cast(name)); + uint32_t key = seed - string_low32bits + flags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } -- 2.7.4