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

Side by Side Diff: src/heap.cc

Issue 126262: Reimplemented the KeyedLookupCache to speed up access. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 6 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/heap-inl.h » ('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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 Shrink(); 493 Shrink();
494 494
495 Counters::objs_since_last_full.Set(0); 495 Counters::objs_since_last_full.Set(0);
496 context_disposed_pending_ = false; 496 context_disposed_pending_ = false;
497 } 497 }
498 498
499 499
500 void Heap::MarkCompactPrologue(bool is_compacting) { 500 void Heap::MarkCompactPrologue(bool is_compacting) {
501 // At any old GC clear the keyed lookup cache to enable collection of unused 501 // At any old GC clear the keyed lookup cache to enable collection of unused
502 // maps. 502 // maps.
503 ClearKeyedLookupCache(); 503 KeyedLookupCache::Clear();
504 504
505 CompilationCache::MarkCompactPrologue(); 505 CompilationCache::MarkCompactPrologue();
506 506
507 Top::MarkCompactPrologue(is_compacting); 507 Top::MarkCompactPrologue(is_compacting);
508 ThreadManager::MarkCompactPrologue(is_compacting); 508 ThreadManager::MarkCompactPrologue(is_compacting);
509 } 509 }
510 510
511 511
512 void Heap::MarkCompactEpilogue(bool is_compacting) { 512 void Heap::MarkCompactEpilogue(bool is_compacting) {
513 Top::MarkCompactEpilogue(is_compacting); 513 Top::MarkCompactEpilogue(is_compacting);
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 1357
1358 // Allocate cache for external strings pointing to native source code. 1358 // Allocate cache for external strings pointing to native source code.
1359 obj = AllocateFixedArray(Natives::GetBuiltinsCount()); 1359 obj = AllocateFixedArray(Natives::GetBuiltinsCount());
1360 if (obj->IsFailure()) return false; 1360 if (obj->IsFailure()) return false;
1361 natives_source_cache_ = FixedArray::cast(obj); 1361 natives_source_cache_ = FixedArray::cast(obj);
1362 1362
1363 // Handling of script id generation is in Factory::NewScript. 1363 // Handling of script id generation is in Factory::NewScript.
1364 last_script_id_ = undefined_value(); 1364 last_script_id_ = undefined_value();
1365 1365
1366 // Initialize keyed lookup cache. 1366 // Initialize keyed lookup cache.
1367 ClearKeyedLookupCache(); 1367 KeyedLookupCache::Clear();
1368 1368
1369 // Initialize compilation cache. 1369 // Initialize compilation cache.
1370 CompilationCache::Clear(); 1370 CompilationCache::Clear();
1371 1371
1372 return true; 1372 return true;
1373 } 1373 }
1374 1374
1375 1375
1376 static inline int double_get_hash(double d) { 1376 static inline int double_get_hash(double d) {
1377 DoubleRepresentation rep(d); 1377 DoubleRepresentation rep(d);
(...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after
3471 case SCAVENGER: 3471 case SCAVENGER:
3472 return "Scavenge"; 3472 return "Scavenge";
3473 case MARK_COMPACTOR: 3473 case MARK_COMPACTOR:
3474 return MarkCompactCollector::HasCompacted() ? "Mark-compact" 3474 return MarkCompactCollector::HasCompacted() ? "Mark-compact"
3475 : "Mark-sweep"; 3475 : "Mark-sweep";
3476 } 3476 }
3477 return "Unknown GC"; 3477 return "Unknown GC";
3478 } 3478 }
3479 3479
3480 3480
3481 int KeyedLookupCache::Hash(Map* map, String* name) {
3482 // Uses only lower 32 bits if pointers are larger.
3483 uintptr_t addr_hash =
3484 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(map)) >> 2;
3485 return (addr_hash ^ name->Hash()) % kLength;
3486 }
3487
3488
3489 int KeyedLookupCache::Lookup(Map* map, String* name) {
3490 int index = Hash(map, name);
3491 Key& key = keys_[index];
3492 if ((key.map == map) && key.name->Equals(name)) {
3493 return field_offsets_[index];
3494 }
3495 return -1;
3496 }
3497
3498
3499 void KeyedLookupCache::Update(Map* map, String* name, int field_offset) {
3500 String* symbol;
3501 if (Heap::LookupSymbolIfExists(name, &symbol)) {
3502 int index = Hash(map, symbol);
3503 Key& key = keys_[index];
3504 key.map = map;
3505 key.name = symbol;
3506 field_offsets_[index] = field_offset;
3507 }
3508 }
3509
3510
3511 void KeyedLookupCache::Clear() {
3512 for (int index = 0; index < kLength; index++) keys_[index].map = NULL;
3513 }
3514
3515 KeyedLookupCache::Key KeyedLookupCache::keys_[KeyedLookupCache::kLength];
3516
3517 int KeyedLookupCache::field_offsets_[KeyedLookupCache::kLength];
3518
3519
3481 #ifdef DEBUG 3520 #ifdef DEBUG
3482 bool Heap::GarbageCollectionGreedyCheck() { 3521 bool Heap::GarbageCollectionGreedyCheck() {
3483 ASSERT(FLAG_gc_greedy); 3522 ASSERT(FLAG_gc_greedy);
3484 if (Bootstrapper::IsActive()) return true; 3523 if (Bootstrapper::IsActive()) return true;
3485 if (disallow_allocation_failure()) return true; 3524 if (disallow_allocation_failure()) return true;
3486 return CollectGarbage(0, NEW_SPACE); 3525 return CollectGarbage(0, NEW_SPACE);
3487 } 3526 }
3488 #endif 3527 #endif
3489 3528
3490 } } // namespace v8::internal 3529 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698