OLD | NEW |
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 2358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2369 | 2369 |
2370 Key keys_[kLength]; | 2370 Key keys_[kLength]; |
2371 int field_offsets_[kLength]; | 2371 int field_offsets_[kLength]; |
2372 | 2372 |
2373 friend class ExternalReference; | 2373 friend class ExternalReference; |
2374 friend class Isolate; | 2374 friend class Isolate; |
2375 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache); | 2375 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache); |
2376 }; | 2376 }; |
2377 | 2377 |
2378 | 2378 |
2379 // Cache for mapping (array, property name) into descriptor index. | 2379 // Cache for mapping (map, property name) into descriptor index. |
2380 // The cache contains both positive and negative results. | 2380 // The cache contains both positive and negative results. |
2381 // Descriptor index equals kNotFound means the property is absent. | 2381 // Descriptor index equals kNotFound means the property is absent. |
2382 // Cleared at startup and prior to any gc. | 2382 // Cleared at startup and prior to any gc. |
2383 class DescriptorLookupCache { | 2383 class DescriptorLookupCache { |
2384 public: | 2384 public: |
2385 // Lookup descriptor index for (map, name). | 2385 // Lookup descriptor index for (map, name). |
2386 // If absent, kAbsent is returned. | 2386 // If absent, kAbsent is returned. |
2387 int Lookup(DescriptorArray* array, String* name) { | 2387 int Lookup(Map* source, String* name) { |
2388 if (!StringShape(name).IsSymbol()) return kAbsent; | 2388 if (!StringShape(name).IsSymbol()) return kAbsent; |
2389 int index = Hash(array, name); | 2389 int index = Hash(source, name); |
2390 Key& key = keys_[index]; | 2390 Key& key = keys_[index]; |
2391 if ((key.array == array) && (key.name == name)) return results_[index]; | 2391 if ((key.source == source) && (key.name == name)) return results_[index]; |
2392 return kAbsent; | 2392 return kAbsent; |
2393 } | 2393 } |
2394 | 2394 |
2395 // Update an element in the cache. | 2395 // Update an element in the cache. |
2396 void Update(DescriptorArray* array, String* name, int result) { | 2396 void Update(Map* source, String* name, int result) { |
2397 ASSERT(result != kAbsent); | 2397 ASSERT(result != kAbsent); |
2398 if (StringShape(name).IsSymbol()) { | 2398 if (StringShape(name).IsSymbol()) { |
2399 int index = Hash(array, name); | 2399 int index = Hash(source, name); |
2400 Key& key = keys_[index]; | 2400 Key& key = keys_[index]; |
2401 key.array = array; | 2401 key.source = source; |
2402 key.name = name; | 2402 key.name = name; |
2403 results_[index] = result; | 2403 results_[index] = result; |
2404 } | 2404 } |
2405 } | 2405 } |
2406 | 2406 |
2407 // Clear the cache. | 2407 // Clear the cache. |
2408 void Clear(); | 2408 void Clear(); |
2409 | 2409 |
2410 static const int kAbsent = -2; | 2410 static const int kAbsent = -2; |
2411 | 2411 |
2412 private: | 2412 private: |
2413 DescriptorLookupCache() { | 2413 DescriptorLookupCache() { |
2414 for (int i = 0; i < kLength; ++i) { | 2414 for (int i = 0; i < kLength; ++i) { |
2415 keys_[i].array = NULL; | 2415 keys_[i].source = NULL; |
2416 keys_[i].name = NULL; | 2416 keys_[i].name = NULL; |
2417 results_[i] = kAbsent; | 2417 results_[i] = kAbsent; |
2418 } | 2418 } |
2419 } | 2419 } |
2420 | 2420 |
2421 static int Hash(DescriptorArray* array, String* name) { | 2421 static int Hash(Object* source, String* name) { |
2422 // Uses only lower 32 bits if pointers are larger. | 2422 // Uses only lower 32 bits if pointers are larger. |
2423 uint32_t array_hash = | 2423 uint32_t source_hash = |
2424 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(array)) | 2424 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(source)) |
2425 >> kPointerSizeLog2; | 2425 >> kPointerSizeLog2; |
2426 uint32_t name_hash = | 2426 uint32_t name_hash = |
2427 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) | 2427 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name)) |
2428 >> kPointerSizeLog2; | 2428 >> kPointerSizeLog2; |
2429 return (array_hash ^ name_hash) % kLength; | 2429 return (source_hash ^ name_hash) % kLength; |
2430 } | 2430 } |
2431 | 2431 |
2432 static const int kLength = 64; | 2432 static const int kLength = 64; |
2433 struct Key { | 2433 struct Key { |
2434 DescriptorArray* array; | 2434 Map* source; |
2435 String* name; | 2435 String* name; |
2436 }; | 2436 }; |
2437 | 2437 |
2438 Key keys_[kLength]; | 2438 Key keys_[kLength]; |
2439 int results_[kLength]; | 2439 int results_[kLength]; |
2440 | 2440 |
2441 friend class Isolate; | 2441 friend class Isolate; |
2442 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); | 2442 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); |
2443 }; | 2443 }; |
2444 | 2444 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2800 AssertNoAllocation no_alloc; // i.e. no gc allowed. | 2800 AssertNoAllocation no_alloc; // i.e. no gc allowed. |
2801 | 2801 |
2802 private: | 2802 private: |
2803 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2803 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2804 }; | 2804 }; |
2805 #endif // DEBUG || LIVE_OBJECT_LIST | 2805 #endif // DEBUG || LIVE_OBJECT_LIST |
2806 | 2806 |
2807 } } // namespace v8::internal | 2807 } } // namespace v8::internal |
2808 | 2808 |
2809 #endif // V8_HEAP_H_ | 2809 #endif // V8_HEAP_H_ |
OLD | NEW |