Revision: 24281
Author: [email protected]
Date: Mon Sep 29 11:29:43 2014 UTC
Log: Map::Hash() calculation made deterministic in predictable mode.
BUG=v8:3563
LOG=N
[email protected]
Review URL: https://codereview.chromium.org/610363002
https://code.google.com/p/v8/source/detail?r=24281
Modified:
/branches/bleeding_edge/src/objects.cc
=======================================
--- /branches/bleeding_edge/src/objects.cc Mon Sep 29 08:16:24 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc Mon Sep 29 11:29:43 2014 UTC
@@ -9008,21 +9008,27 @@
PrintF(file, "%c", Get(i));
}
}
+
+
+inline static uint32_t ObjectAddressForHashing(Object* object) {
+ uint32_t value =
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(object));
+ return value & MemoryChunk::kAlignmentMask;
+}
int Map::Hash() {
// For performance reasons we only hash the 3 most variable fields of a
map:
- // constructor, prototype and bit_field2.
+ // constructor, prototype and bit_field2. For predictability reasons we
+ // use objects' offsets in respective pages for hashing instead of raw
+ // addresses.
// Shift away the tag.
- int hash = (static_cast<uint32_t>(
- reinterpret_cast<uintptr_t>(constructor())) >> 2);
+ int hash = ObjectAddressForHashing(constructor()) >> 2;
// XOR-ing the prototype and constructor directly yields too many zero
bits
// when the two pointers are close (which is fairly common).
- // To avoid this we shift the prototype 4 bits relatively to the
constructor.
- hash ^= (static_cast<uint32_t>(
- reinterpret_cast<uintptr_t>(prototype())) << 2);
+ // To avoid this we shift the prototype bits relatively to the
constructor.
+ hash ^= ObjectAddressForHashing(prototype()) << (32 - kPageSizeBits);
return hash ^ (hash >> 16) ^ bit_field2();
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.