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

Side by Side Diff: src/heap.cc

Issue 264563003: Public interface of KeyedLookupCache handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing review notes Created 6 years, 7 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 | « src/heap.h ('k') | src/runtime.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 "v8.h" 5 #include "v8.h"
6 6
7 #include "accessors.h" 7 #include "accessors.h"
8 #include "api.h" 8 #include "api.h"
9 #include "bootstrapper.h" 9 #include "bootstrapper.h"
10 #include "codegen.h" 10 #include "codegen.h"
(...skipping 6220 matching lines...) Expand 10 before | Expand all | Expand 10 after
6231 switch (collector_) { 6231 switch (collector_) {
6232 case SCAVENGER: 6232 case SCAVENGER:
6233 return "Scavenge"; 6233 return "Scavenge";
6234 case MARK_COMPACTOR: 6234 case MARK_COMPACTOR:
6235 return "Mark-sweep"; 6235 return "Mark-sweep";
6236 } 6236 }
6237 return "Unknown GC"; 6237 return "Unknown GC";
6238 } 6238 }
6239 6239
6240 6240
6241 int KeyedLookupCache::Hash(Map* map, Name* name) { 6241 int KeyedLookupCache::Hash(Handle<Map> map, Handle<Name> name) {
6242 DisallowHeapAllocation no_gc;
6242 // Uses only lower 32 bits if pointers are larger. 6243 // Uses only lower 32 bits if pointers are larger.
6243 uintptr_t addr_hash = 6244 uintptr_t addr_hash =
6244 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(map)) >> kMapHashShift; 6245 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(*map)) >> kMapHashShift;
6245 return static_cast<uint32_t>((addr_hash ^ name->Hash()) & kCapacityMask); 6246 return static_cast<uint32_t>((addr_hash ^ name->Hash()) & kCapacityMask);
6246 } 6247 }
6247 6248
6248 6249
6249 int KeyedLookupCache::Lookup(Map* map, Name* name) { 6250 int KeyedLookupCache::Lookup(Handle<Map> map, Handle<Name> name) {
6251 DisallowHeapAllocation no_gc;
6250 int index = (Hash(map, name) & kHashMask); 6252 int index = (Hash(map, name) & kHashMask);
6251 for (int i = 0; i < kEntriesPerBucket; i++) { 6253 for (int i = 0; i < kEntriesPerBucket; i++) {
6252 Key& key = keys_[index + i]; 6254 Key& key = keys_[index + i];
6253 if ((key.map == map) && key.name->Equals(name)) { 6255 if ((key.map == *map) && key.name->Equals(*name)) {
6254 return field_offsets_[index + i]; 6256 return field_offsets_[index + i];
6255 } 6257 }
6256 } 6258 }
6257 return kNotFound; 6259 return kNotFound;
6258 } 6260 }
6259 6261
6260 6262
6261 void KeyedLookupCache::Update(Map* map, Name* name, int field_offset) { 6263 void KeyedLookupCache::Update(Handle<Map> map,
6264 Handle<Name> name,
6265 int field_offset) {
6266 DisallowHeapAllocation no_gc;
6262 if (!name->IsUniqueName()) { 6267 if (!name->IsUniqueName()) {
6263 String* internalized_string; 6268 String* internalized_string;
6264 if (!map->GetIsolate()->heap()->InternalizeStringIfExists( 6269 if (!map->GetIsolate()->heap()->InternalizeStringIfExists(
6265 String::cast(name), &internalized_string)) { 6270 String::cast(*name), &internalized_string)) {
6266 return; 6271 return;
6267 } 6272 }
6268 name = internalized_string; 6273 name = handle(internalized_string);
6269 } 6274 }
6270 // This cache is cleared only between mark compact passes, so we expect the 6275 // This cache is cleared only between mark compact passes, so we expect the
6271 // cache to only contain old space names. 6276 // cache to only contain old space names.
6272 ASSERT(!map->GetIsolate()->heap()->InNewSpace(name)); 6277 ASSERT(!map->GetIsolate()->heap()->InNewSpace(*name));
6273 6278
6274 int index = (Hash(map, name) & kHashMask); 6279 int index = (Hash(map, name) & kHashMask);
6275 // After a GC there will be free slots, so we use them in order (this may 6280 // After a GC there will be free slots, so we use them in order (this may
6276 // help to get the most frequently used one in position 0). 6281 // help to get the most frequently used one in position 0).
6277 for (int i = 0; i< kEntriesPerBucket; i++) { 6282 for (int i = 0; i< kEntriesPerBucket; i++) {
6278 Key& key = keys_[index]; 6283 Key& key = keys_[index];
6279 Object* free_entry_indicator = NULL; 6284 Object* free_entry_indicator = NULL;
6280 if (key.map == free_entry_indicator) { 6285 if (key.map == free_entry_indicator) {
6281 key.map = map; 6286 key.map = *map;
6282 key.name = name; 6287 key.name = *name;
6283 field_offsets_[index + i] = field_offset; 6288 field_offsets_[index + i] = field_offset;
6284 return; 6289 return;
6285 } 6290 }
6286 } 6291 }
6287 // No free entry found in this bucket, so we move them all down one and 6292 // No free entry found in this bucket, so we move them all down one and
6288 // put the new entry at position zero. 6293 // put the new entry at position zero.
6289 for (int i = kEntriesPerBucket - 1; i > 0; i--) { 6294 for (int i = kEntriesPerBucket - 1; i > 0; i--) {
6290 Key& key = keys_[index + i]; 6295 Key& key = keys_[index + i];
6291 Key& key2 = keys_[index + i - 1]; 6296 Key& key2 = keys_[index + i - 1];
6292 key = key2; 6297 key = key2;
6293 field_offsets_[index + i] = field_offsets_[index + i - 1]; 6298 field_offsets_[index + i] = field_offsets_[index + i - 1];
6294 } 6299 }
6295 6300
6296 // Write the new first entry. 6301 // Write the new first entry.
6297 Key& key = keys_[index]; 6302 Key& key = keys_[index];
6298 key.map = map; 6303 key.map = *map;
6299 key.name = name; 6304 key.name = *name;
6300 field_offsets_[index] = field_offset; 6305 field_offsets_[index] = field_offset;
6301 } 6306 }
6302 6307
6303 6308
6304 void KeyedLookupCache::Clear() { 6309 void KeyedLookupCache::Clear() {
6305 for (int index = 0; index < kLength; index++) keys_[index].map = NULL; 6310 for (int index = 0; index < kLength; index++) keys_[index].map = NULL;
6306 } 6311 }
6307 6312
6308 6313
6309 void DescriptorLookupCache::Clear() { 6314 void DescriptorLookupCache::Clear() {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
6492 static_cast<int>(object_sizes_last_time_[index])); 6497 static_cast<int>(object_sizes_last_time_[index]));
6493 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 6498 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
6494 #undef ADJUST_LAST_TIME_OBJECT_COUNT 6499 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6495 6500
6496 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 6501 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
6497 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 6502 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
6498 ClearObjectStats(); 6503 ClearObjectStats();
6499 } 6504 }
6500 6505
6501 } } // namespace v8::internal 6506 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698