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

Side by Side Diff: src/heap.h

Issue 10909007: Sharing of descriptor arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 8 years, 3 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/handles.cc ('k') | src/heap.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 // 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 2350 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 2361
2362 Key keys_[kLength]; 2362 Key keys_[kLength];
2363 int field_offsets_[kLength]; 2363 int field_offsets_[kLength];
2364 2364
2365 friend class ExternalReference; 2365 friend class ExternalReference;
2366 friend class Isolate; 2366 friend class Isolate;
2367 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache); 2367 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache);
2368 }; 2368 };
2369 2369
2370 2370
2371 // Cache for mapping (array, property name) into descriptor index. 2371 // Cache for mapping (map, property name) into descriptor index.
2372 // The cache contains both positive and negative results. 2372 // The cache contains both positive and negative results.
2373 // Descriptor index equals kNotFound means the property is absent. 2373 // Descriptor index equals kNotFound means the property is absent.
2374 // Cleared at startup and prior to any gc. 2374 // Cleared at startup and prior to any gc.
2375 class DescriptorLookupCache { 2375 class DescriptorLookupCache {
2376 public: 2376 public:
2377 // Lookup descriptor index for (map, name). 2377 // Lookup descriptor index for (map, name).
2378 // If absent, kAbsent is returned. 2378 // If absent, kAbsent is returned.
2379 int Lookup(DescriptorArray* array, String* name) { 2379 int Lookup(Map* source, String* name) {
2380 if (!StringShape(name).IsSymbol()) return kAbsent; 2380 if (!StringShape(name).IsSymbol()) return kAbsent;
2381 int index = Hash(array, name); 2381 int index = Hash(source, name);
2382 Key& key = keys_[index]; 2382 Key& key = keys_[index];
2383 if ((key.array == array) && (key.name == name)) return results_[index]; 2383 if ((key.source == source) && (key.name == name)) return results_[index];
2384 return kAbsent; 2384 return kAbsent;
2385 } 2385 }
2386 2386
2387 // Update an element in the cache. 2387 // Update an element in the cache.
2388 void Update(DescriptorArray* array, String* name, int result) { 2388 void Update(Map* source, String* name, int result) {
2389 ASSERT(result != kAbsent); 2389 ASSERT(result != kAbsent);
2390 if (StringShape(name).IsSymbol()) { 2390 if (StringShape(name).IsSymbol()) {
2391 int index = Hash(array, name); 2391 int index = Hash(source, name);
2392 Key& key = keys_[index]; 2392 Key& key = keys_[index];
2393 key.array = array; 2393 key.source = source;
2394 key.name = name; 2394 key.name = name;
2395 results_[index] = result; 2395 results_[index] = result;
2396 } 2396 }
2397 } 2397 }
2398 2398
2399 // Clear the cache. 2399 // Clear the cache.
2400 void Clear(); 2400 void Clear();
2401 2401
2402 static const int kAbsent = -2; 2402 static const int kAbsent = -2;
2403 2403
2404 private: 2404 private:
2405 DescriptorLookupCache() { 2405 DescriptorLookupCache() {
2406 for (int i = 0; i < kLength; ++i) { 2406 for (int i = 0; i < kLength; ++i) {
2407 keys_[i].array = NULL; 2407 keys_[i].source = NULL;
2408 keys_[i].name = NULL; 2408 keys_[i].name = NULL;
2409 results_[i] = kAbsent; 2409 results_[i] = kAbsent;
2410 } 2410 }
2411 } 2411 }
2412 2412
2413 static int Hash(DescriptorArray* array, String* name) { 2413 static int Hash(Object* source, String* name) {
2414 // Uses only lower 32 bits if pointers are larger. 2414 // Uses only lower 32 bits if pointers are larger.
2415 uint32_t array_hash = 2415 uint32_t source_hash =
2416 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(array)) 2416 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(source))
2417 >> kPointerSizeLog2; 2417 >> kPointerSizeLog2;
2418 uint32_t name_hash = 2418 uint32_t name_hash =
2419 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) 2419 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name))
2420 >> kPointerSizeLog2; 2420 >> kPointerSizeLog2;
2421 return (array_hash ^ name_hash) % kLength; 2421 return (source_hash ^ name_hash) % kLength;
2422 } 2422 }
2423 2423
2424 static const int kLength = 64; 2424 static const int kLength = 64;
2425 struct Key { 2425 struct Key {
2426 DescriptorArray* array; 2426 Map* source;
2427 String* name; 2427 String* name;
2428 }; 2428 };
2429 2429
2430 Key keys_[kLength]; 2430 Key keys_[kLength];
2431 int results_[kLength]; 2431 int results_[kLength];
2432 2432
2433 friend class Isolate; 2433 friend class Isolate;
2434 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); 2434 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache);
2435 }; 2435 };
2436 2436
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2792 AssertNoAllocation no_alloc; // i.e. no gc allowed. 2792 AssertNoAllocation no_alloc; // i.e. no gc allowed.
2793 2793
2794 private: 2794 private:
2795 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); 2795 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer);
2796 }; 2796 };
2797 #endif // DEBUG || LIVE_OBJECT_LIST 2797 #endif // DEBUG || LIVE_OBJECT_LIST
2798 2798
2799 } } // namespace v8::internal 2799 } } // namespace v8::internal
2800 2800
2801 #endif // V8_HEAP_H_ 2801 #endif // V8_HEAP_H_
OLDNEW
« no previous file with comments | « src/handles.cc ('k') | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698