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

Side by Side Diff: src/objects.cc

Issue 610363002: Map::Hash() calculation made deterministic in predictable mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/allocation-site-scopes.h" 8 #include "src/allocation-site-scopes.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/arguments.h" 10 #include "src/arguments.h"
(...skipping 8981 matching lines...) Expand 10 before | Expand all | Expand 10 after
8992 8992
8993 8993
8994 void String::PrintOn(FILE* file) { 8994 void String::PrintOn(FILE* file) {
8995 int length = this->length(); 8995 int length = this->length();
8996 for (int i = 0; i < length; i++) { 8996 for (int i = 0; i < length; i++) {
8997 PrintF(file, "%c", Get(i)); 8997 PrintF(file, "%c", Get(i));
8998 } 8998 }
8999 } 8999 }
9000 9000
9001 9001
9002 inline static uint32_t ObjectAddressForHashing(Object* object) {
9003 uint32_t value = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(object));
9004 return value & MemoryChunk::kAlignmentMask;
9005 }
9006
9007
9002 int Map::Hash() { 9008 int Map::Hash() {
9003 // For performance reasons we only hash the 3 most variable fields of a map: 9009 // For performance reasons we only hash the 3 most variable fields of a map:
9004 // constructor, prototype and bit_field2. 9010 // constructor, prototype and bit_field2.
9005 9011
9006 // Shift away the tag. 9012 // Shift away the tag.
9007 int hash = (static_cast<uint32_t>( 9013 int hash = ObjectAddressForHashing(constructor()) >> 2;
9008 reinterpret_cast<uintptr_t>(constructor())) >> 2);
9009 9014
9010 // XOR-ing the prototype and constructor directly yields too many zero bits 9015 // XOR-ing the prototype and constructor directly yields too many zero bits
9011 // when the two pointers are close (which is fairly common). 9016 // when the two pointers are close (which is fairly common).
9012 // To avoid this we shift the prototype 4 bits relatively to the constructor. 9017 // To avoid this we shift the prototype 4 bits relatively to the constructor.
9013 hash ^= (static_cast<uint32_t>( 9018 hash ^= ObjectAddressForHashing(prototype()) << 2;
Jakob Kummerow 2014/09/29 10:38:21 To document our offline discussion for posterity:
9014 reinterpret_cast<uintptr_t>(prototype())) << 2);
9015 9019
9016 return hash ^ (hash >> 16) ^ bit_field2(); 9020 return hash ^ (hash >> 16) ^ bit_field2();
9017 } 9021 }
9018 9022
9019 9023
9020 static bool CheckEquivalent(Map* first, Map* second) { 9024 static bool CheckEquivalent(Map* first, Map* second) {
9021 return 9025 return
9022 first->constructor() == second->constructor() && 9026 first->constructor() == second->constructor() &&
9023 first->prototype() == second->prototype() && 9027 first->prototype() == second->prototype() &&
9024 first->instance_type() == second->instance_type() && 9028 first->instance_type() == second->instance_type() &&
(...skipping 7338 matching lines...) Expand 10 before | Expand all | Expand 10 after
16363 Handle<DependentCode> codes = 16367 Handle<DependentCode> codes =
16364 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), 16368 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()),
16365 DependentCode::kPropertyCellChangedGroup, 16369 DependentCode::kPropertyCellChangedGroup,
16366 info->object_wrapper()); 16370 info->object_wrapper());
16367 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); 16371 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes);
16368 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( 16372 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add(
16369 cell, info->zone()); 16373 cell, info->zone());
16370 } 16374 }
16371 16375
16372 } } // namespace v8::internal 16376 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698