| OLD | NEW |
| 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 #ifndef V8_HEAP_HEAP_H_ | 5 #ifndef V8_HEAP_HEAP_H_ |
| 6 #define V8_HEAP_HEAP_H_ | 6 #define V8_HEAP_HEAP_H_ |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 2486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2497 | 2497 |
| 2498 Heap* heap_; | 2498 Heap* heap_; |
| 2499 HeapObjectsFiltering filtering_; | 2499 HeapObjectsFiltering filtering_; |
| 2500 HeapObjectsFilter* filter_; | 2500 HeapObjectsFilter* filter_; |
| 2501 // Space iterator for iterating all the spaces. | 2501 // Space iterator for iterating all the spaces. |
| 2502 SpaceIterator* space_iterator_; | 2502 SpaceIterator* space_iterator_; |
| 2503 // Object iterator for the space currently being iterated. | 2503 // Object iterator for the space currently being iterated. |
| 2504 ObjectIterator* object_iterator_; | 2504 ObjectIterator* object_iterator_; |
| 2505 }; | 2505 }; |
| 2506 | 2506 |
| 2507 | |
| 2508 // Cache for mapping (map, property name) into field offset. | |
| 2509 // Cleared at startup and prior to mark sweep collection. | |
| 2510 class KeyedLookupCache { | |
| 2511 public: | |
| 2512 // Lookup field offset for (map, name). If absent, -1 is returned. | |
| 2513 int Lookup(Handle<Map> map, Handle<Name> name); | |
| 2514 | |
| 2515 // Update an element in the cache. | |
| 2516 void Update(Handle<Map> map, Handle<Name> name, int field_offset); | |
| 2517 | |
| 2518 // Clear the cache. | |
| 2519 void Clear(); | |
| 2520 | |
| 2521 static const int kLength = 256; | |
| 2522 static const int kCapacityMask = kLength - 1; | |
| 2523 static const int kMapHashShift = 5; | |
| 2524 static const int kHashMask = -4; // Zero the last two bits. | |
| 2525 static const int kEntriesPerBucket = 4; | |
| 2526 static const int kEntryLength = 2; | |
| 2527 static const int kMapIndex = 0; | |
| 2528 static const int kKeyIndex = 1; | |
| 2529 static const int kNotFound = -1; | |
| 2530 | |
| 2531 // kEntriesPerBucket should be a power of 2. | |
| 2532 STATIC_ASSERT((kEntriesPerBucket & (kEntriesPerBucket - 1)) == 0); | |
| 2533 STATIC_ASSERT(kEntriesPerBucket == -kHashMask); | |
| 2534 | |
| 2535 private: | |
| 2536 KeyedLookupCache() { | |
| 2537 for (int i = 0; i < kLength; ++i) { | |
| 2538 keys_[i].map = NULL; | |
| 2539 keys_[i].name = NULL; | |
| 2540 field_offsets_[i] = kNotFound; | |
| 2541 } | |
| 2542 } | |
| 2543 | |
| 2544 static inline int Hash(Handle<Map> map, Handle<Name> name); | |
| 2545 | |
| 2546 // Get the address of the keys and field_offsets arrays. Used in | |
| 2547 // generated code to perform cache lookups. | |
| 2548 Address keys_address() { return reinterpret_cast<Address>(&keys_); } | |
| 2549 | |
| 2550 Address field_offsets_address() { | |
| 2551 return reinterpret_cast<Address>(&field_offsets_); | |
| 2552 } | |
| 2553 | |
| 2554 struct Key { | |
| 2555 Map* map; | |
| 2556 Name* name; | |
| 2557 }; | |
| 2558 | |
| 2559 Key keys_[kLength]; | |
| 2560 int field_offsets_[kLength]; | |
| 2561 | |
| 2562 friend class ExternalReference; | |
| 2563 friend class Isolate; | |
| 2564 DISALLOW_COPY_AND_ASSIGN(KeyedLookupCache); | |
| 2565 }; | |
| 2566 | |
| 2567 | |
| 2568 // Cache for mapping (map, property name) into descriptor index. | |
| 2569 // The cache contains both positive and negative results. | |
| 2570 // Descriptor index equals kNotFound means the property is absent. | |
| 2571 // Cleared at startup and prior to any gc. | |
| 2572 class DescriptorLookupCache { | |
| 2573 public: | |
| 2574 // Lookup descriptor index for (map, name). | |
| 2575 // If absent, kAbsent is returned. | |
| 2576 inline int Lookup(Map* source, Name* name); | |
| 2577 | |
| 2578 // Update an element in the cache. | |
| 2579 inline void Update(Map* source, Name* name, int result); | |
| 2580 | |
| 2581 // Clear the cache. | |
| 2582 void Clear(); | |
| 2583 | |
| 2584 static const int kAbsent = -2; | |
| 2585 | |
| 2586 private: | |
| 2587 DescriptorLookupCache() { | |
| 2588 for (int i = 0; i < kLength; ++i) { | |
| 2589 keys_[i].source = NULL; | |
| 2590 keys_[i].name = NULL; | |
| 2591 results_[i] = kAbsent; | |
| 2592 } | |
| 2593 } | |
| 2594 | |
| 2595 static inline int Hash(Object* source, Name* name); | |
| 2596 | |
| 2597 static const int kLength = 64; | |
| 2598 struct Key { | |
| 2599 Map* source; | |
| 2600 Name* name; | |
| 2601 }; | |
| 2602 | |
| 2603 Key keys_[kLength]; | |
| 2604 int results_[kLength]; | |
| 2605 | |
| 2606 friend class Isolate; | |
| 2607 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); | |
| 2608 }; | |
| 2609 | |
| 2610 | |
| 2611 // Abstract base class for checking whether a weak object should be retained. | 2507 // Abstract base class for checking whether a weak object should be retained. |
| 2612 class WeakObjectRetainer { | 2508 class WeakObjectRetainer { |
| 2613 public: | 2509 public: |
| 2614 virtual ~WeakObjectRetainer() {} | 2510 virtual ~WeakObjectRetainer() {} |
| 2615 | 2511 |
| 2616 // Return whether this object should be retained. If NULL is returned the | 2512 // Return whether this object should be retained. If NULL is returned the |
| 2617 // object has no references. Otherwise the address of the retained object | 2513 // object has no references. Otherwise the address of the retained object |
| 2618 // should be returned as in some GC situations the object has been moved. | 2514 // should be returned as in some GC situations the object has been moved. |
| 2619 virtual Object* RetainAs(Object* object) = 0; | 2515 virtual Object* RetainAs(Object* object) = 0; |
| 2620 }; | 2516 }; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2729 friend class LargeObjectSpace; | 2625 friend class LargeObjectSpace; |
| 2730 friend class NewSpace; | 2626 friend class NewSpace; |
| 2731 friend class PagedSpace; | 2627 friend class PagedSpace; |
| 2732 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); | 2628 DISALLOW_COPY_AND_ASSIGN(AllocationObserver); |
| 2733 }; | 2629 }; |
| 2734 | 2630 |
| 2735 } // namespace internal | 2631 } // namespace internal |
| 2736 } // namespace v8 | 2632 } // namespace v8 |
| 2737 | 2633 |
| 2738 #endif // V8_HEAP_HEAP_H_ | 2634 #endif // V8_HEAP_HEAP_H_ |
| OLD | NEW |