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

Side by Side Diff: src/profile-generator.cc

Issue 9086006: Randomize the seed used for string hashing. This helps guard against (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 11 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 DeleteArray(reinterpret_cast<const char*>(p->value)); 103 DeleteArray(reinterpret_cast<const char*>(p->value));
104 } 104 }
105 } 105 }
106 106
107 107
108 const char* StringsStorage::GetCopy(const char* src) { 108 const char* StringsStorage::GetCopy(const char* src) {
109 int len = static_cast<int>(strlen(src)); 109 int len = static_cast<int>(strlen(src));
110 Vector<char> dst = Vector<char>::New(len + 1); 110 Vector<char> dst = Vector<char>::New(len + 1);
111 OS::StrNCpy(dst, src, len); 111 OS::StrNCpy(dst, src, len);
112 dst[len] = '\0'; 112 dst[len] = '\0';
113 uint32_t hash = HashSequentialString(dst.start(), len); 113 uint32_t hash =
114 HashSequentialString(dst.start(), len, HEAP->StringHashSeed());
114 return AddOrDisposeString(dst.start(), hash); 115 return AddOrDisposeString(dst.start(), hash);
115 } 116 }
116 117
117 118
118 const char* StringsStorage::GetFormatted(const char* format, ...) { 119 const char* StringsStorage::GetFormatted(const char* format, ...) {
119 va_list args; 120 va_list args;
120 va_start(args, format); 121 va_start(args, format);
121 const char* result = GetVFormatted(format, args); 122 const char* result = GetVFormatted(format, args);
122 va_end(args); 123 va_end(args);
123 return result; 124 return result;
(...skipping 12 matching lines...) Expand all
136 } 137 }
137 138
138 139
139 const char* StringsStorage::GetVFormatted(const char* format, va_list args) { 140 const char* StringsStorage::GetVFormatted(const char* format, va_list args) {
140 Vector<char> str = Vector<char>::New(1024); 141 Vector<char> str = Vector<char>::New(1024);
141 int len = OS::VSNPrintF(str, format, args); 142 int len = OS::VSNPrintF(str, format, args);
142 if (len == -1) { 143 if (len == -1) {
143 DeleteArray(str.start()); 144 DeleteArray(str.start());
144 return format; 145 return format;
145 } 146 }
146 uint32_t hash = HashSequentialString(str.start(), len); 147 uint32_t hash = HashSequentialString(
148 str.start(), len, HEAP->StringHashSeed());
147 return AddOrDisposeString(str.start(), hash); 149 return AddOrDisposeString(str.start(), hash);
148 } 150 }
149 151
150 152
151 const char* StringsStorage::GetName(String* name) { 153 const char* StringsStorage::GetName(String* name) {
152 if (name->IsString()) { 154 if (name->IsString()) {
153 int length = Min(kMaxNameSize, name->length()); 155 int length = Min(kMaxNameSize, name->length());
154 SmartArrayPointer<char> data = 156 SmartArrayPointer<char> data =
155 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL, 0, length); 157 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL, 0, length);
156 uint32_t hash = HashSequentialString(*data, length); 158 uint32_t hash =
159 HashSequentialString(*data, length, name->GetHeap()->StringHashSeed());
157 return AddOrDisposeString(data.Detach(), hash); 160 return AddOrDisposeString(data.Detach(), hash);
158 } 161 }
159 return ""; 162 return "";
160 } 163 }
161 164
162 165
163 const char* StringsStorage::GetName(int index) { 166 const char* StringsStorage::GetName(int index) {
164 return GetFormatted("%d", index); 167 return GetFormatted("%d", index);
165 } 168 }
166 169
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 raw_entry, AddressHash(reinterpret_cast<Address>(raw_entry))); 1497 raw_entry, AddressHash(reinterpret_cast<Address>(raw_entry)));
1495 } 1498 }
1496 delete entries_; 1499 delete entries_;
1497 entries_ = new_entries; 1500 entries_ = new_entries;
1498 } 1501 }
1499 1502
1500 1503
1501 uint64_t HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) { 1504 uint64_t HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) {
1502 uint64_t id = static_cast<uint64_t>(info->GetHash()); 1505 uint64_t id = static_cast<uint64_t>(info->GetHash());
1503 const char* label = info->GetLabel(); 1506 const char* label = info->GetLabel();
1504 id ^= HashSequentialString(label, static_cast<int>(strlen(label))); 1507 id ^= HashSequentialString(label,
1508 static_cast<int>(strlen(label)),
1509 HEAP->StringHashSeed());
1505 intptr_t element_count = info->GetElementCount(); 1510 intptr_t element_count = info->GetElementCount();
1506 if (element_count != -1) 1511 if (element_count != -1)
1507 id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count)); 1512 id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count));
1508 return id << 1; 1513 return id << 1;
1509 } 1514 }
1510 1515
1511 1516
1512 HeapSnapshotsCollection::HeapSnapshotsCollection() 1517 HeapSnapshotsCollection::HeapSnapshotsCollection()
1513 : is_tracking_objects_(false), 1518 : is_tracking_objects_(false),
1514 snapshots_uids_(HeapSnapshotsMatch), 1519 snapshots_uids_(HeapSnapshotsMatch),
(...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3629 3634
3630 3635
3631 void HeapSnapshotJSONSerializer::SortHashMap( 3636 void HeapSnapshotJSONSerializer::SortHashMap(
3632 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 3637 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
3633 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 3638 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
3634 sorted_entries->Add(p); 3639 sorted_entries->Add(p);
3635 sorted_entries->Sort(SortUsingEntryValue); 3640 sorted_entries->Sort(SortUsingEntryValue);
3636 } 3641 }
3637 3642
3638 } } // namespace v8::internal 3643 } } // namespace v8::internal
OLDNEW
« src/objects.cc ('K') | « src/objects-inl.h ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698