| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2581 // // The prefix size indicates number of elements in the beginning | 2581 // // The prefix size indicates number of elements in the beginning |
| 2582 // // of the backing storage. | 2582 // // of the backing storage. |
| 2583 // static const int kPrefixSize = ..; | 2583 // static const int kPrefixSize = ..; |
| 2584 // // The Element size indicates number of elements per entry. | 2584 // // The Element size indicates number of elements per entry. |
| 2585 // static const int kEntrySize = ..; | 2585 // static const int kEntrySize = ..; |
| 2586 // }; | 2586 // }; |
| 2587 // The prefix size indicates an amount of memory in the | 2587 // The prefix size indicates an amount of memory in the |
| 2588 // beginning of the backing storage that can be used for non-element | 2588 // beginning of the backing storage that can be used for non-element |
| 2589 // information by subclasses. | 2589 // information by subclasses. |
| 2590 | 2590 |
| 2591 template<typename Key> |
| 2592 class BaseShape { |
| 2593 public: |
| 2594 static const bool UsesSeed = false; |
| 2595 static uint32_t Hash(Key key) { return 0; } |
| 2596 static uint32_t SeededHash(Key key, uint32_t seed) { |
| 2597 // Won't be called if UsesSeed isn't overrided by child class |
| 2598 return Hash(key); |
| 2599 } |
| 2600 static uint32_t HashForObject(Key key, Object* object) { return 0; } |
| 2601 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { |
| 2602 // Won't be called if UsesSeed isn't overrided by child class |
| 2603 return HashForObject(key, object); |
| 2604 } |
| 2605 }; |
| 2606 |
| 2591 template<typename Shape, typename Key> | 2607 template<typename Shape, typename Key> |
| 2592 class HashTable: public FixedArray { | 2608 class HashTable: public FixedArray { |
| 2593 public: | 2609 public: |
| 2610 // Wrapper methods |
| 2611 inline uint32_t Hash(Key key) { |
| 2612 if (Shape::UsesSeed) { |
| 2613 return Shape::SeededHash(key, |
| 2614 GetHeap()->StringHashSeed()); |
| 2615 } else { |
| 2616 return Shape::Hash(key); |
| 2617 } |
| 2618 } |
| 2619 |
| 2620 inline uint32_t HashForObject(Key key, Object* object) { |
| 2621 if (Shape::UsesSeed) { |
| 2622 return Shape::SeededHashForObject(key, |
| 2623 GetHeap()->StringHashSeed(), object); |
| 2624 } else { |
| 2625 return Shape::HashForObject(key, object); |
| 2626 } |
| 2627 } |
| 2628 |
| 2594 // Returns the number of elements in the hash table. | 2629 // Returns the number of elements in the hash table. |
| 2595 int NumberOfElements() { | 2630 int NumberOfElements() { |
| 2596 return Smi::cast(get(kNumberOfElementsIndex))->value(); | 2631 return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2597 } | 2632 } |
| 2598 | 2633 |
| 2599 // Returns the number of deleted elements in the hash table. | 2634 // Returns the number of deleted elements in the hash table. |
| 2600 int NumberOfDeletedElements() { | 2635 int NumberOfDeletedElements() { |
| 2601 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); | 2636 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2602 } | 2637 } |
| 2603 | 2638 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2742 virtual uint32_t Hash() = 0; | 2777 virtual uint32_t Hash() = 0; |
| 2743 // Returns the hash value for object. | 2778 // Returns the hash value for object. |
| 2744 virtual uint32_t HashForObject(Object* key) = 0; | 2779 virtual uint32_t HashForObject(Object* key) = 0; |
| 2745 // Returns the key object for storing into the hash table. | 2780 // Returns the key object for storing into the hash table. |
| 2746 // If allocations fails a failure object is returned. | 2781 // If allocations fails a failure object is returned. |
| 2747 MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; | 2782 MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
| 2748 // Required. | 2783 // Required. |
| 2749 virtual ~HashTableKey() {} | 2784 virtual ~HashTableKey() {} |
| 2750 }; | 2785 }; |
| 2751 | 2786 |
| 2752 class SymbolTableShape { | 2787 class SymbolTableShape : public BaseShape<HashTableKey*> { |
| 2753 public: | 2788 public: |
| 2754 static inline bool IsMatch(HashTableKey* key, Object* value) { | 2789 static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 2755 return key->IsMatch(value); | 2790 return key->IsMatch(value); |
| 2756 } | 2791 } |
| 2757 static inline uint32_t Hash(HashTableKey* key) { | 2792 static inline uint32_t Hash(HashTableKey* key) { |
| 2758 return key->Hash(); | 2793 return key->Hash(); |
| 2759 } | 2794 } |
| 2760 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { | 2795 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 2761 return key->HashForObject(object); | 2796 return key->HashForObject(object); |
| 2762 } | 2797 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2801 // Casting. | 2836 // Casting. |
| 2802 static inline SymbolTable* cast(Object* obj); | 2837 static inline SymbolTable* cast(Object* obj); |
| 2803 | 2838 |
| 2804 private: | 2839 private: |
| 2805 MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); | 2840 MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
| 2806 | 2841 |
| 2807 DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); | 2842 DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 2808 }; | 2843 }; |
| 2809 | 2844 |
| 2810 | 2845 |
| 2811 class MapCacheShape { | 2846 class MapCacheShape : public BaseShape<HashTableKey*> { |
| 2812 public: | 2847 public: |
| 2813 static inline bool IsMatch(HashTableKey* key, Object* value) { | 2848 static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 2814 return key->IsMatch(value); | 2849 return key->IsMatch(value); |
| 2815 } | 2850 } |
| 2816 static inline uint32_t Hash(HashTableKey* key) { | 2851 static inline uint32_t Hash(HashTableKey* key) { |
| 2817 return key->Hash(); | 2852 return key->Hash(); |
| 2818 } | 2853 } |
| 2819 | 2854 |
| 2820 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { | 2855 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 2821 return key->HashForObject(object); | 2856 return key->HashForObject(object); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2957 uint32_t hash); | 2992 uint32_t hash); |
| 2958 | 2993 |
| 2959 // Generate new enumeration indices to avoid enumeration index overflow. | 2994 // Generate new enumeration indices to avoid enumeration index overflow. |
| 2960 MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); | 2995 MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
| 2961 static const int kMaxNumberKeyIndex = | 2996 static const int kMaxNumberKeyIndex = |
| 2962 HashTable<Shape, Key>::kPrefixStartIndex; | 2997 HashTable<Shape, Key>::kPrefixStartIndex; |
| 2963 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; | 2998 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 2964 }; | 2999 }; |
| 2965 | 3000 |
| 2966 | 3001 |
| 2967 class StringDictionaryShape { | 3002 class StringDictionaryShape : public BaseShape<String*> { |
| 2968 public: | 3003 public: |
| 2969 static inline bool IsMatch(String* key, Object* other); | 3004 static inline bool IsMatch(String* key, Object* other); |
| 2970 static inline uint32_t Hash(String* key); | 3005 static inline uint32_t Hash(String* key); |
| 2971 static inline uint32_t HashForObject(String* key, Object* object); | 3006 static inline uint32_t HashForObject(String* key, Object* object); |
| 2972 MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); | 3007 MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
| 2973 static const int kPrefixSize = 2; | 3008 static const int kPrefixSize = 2; |
| 2974 static const int kEntrySize = 3; | 3009 static const int kEntrySize = 3; |
| 2975 static const bool kIsEnumerable = true; | 3010 static const bool kIsEnumerable = true; |
| 2976 }; | 3011 }; |
| 2977 | 3012 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2990 MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( | 3025 MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 2991 JSObject* obj, | 3026 JSObject* obj, |
| 2992 int unused_property_fields); | 3027 int unused_property_fields); |
| 2993 | 3028 |
| 2994 // Find entry for key, otherwise return kNotFound. Optimized version of | 3029 // Find entry for key, otherwise return kNotFound. Optimized version of |
| 2995 // HashTable::FindEntry. | 3030 // HashTable::FindEntry. |
| 2996 int FindEntry(String* key); | 3031 int FindEntry(String* key); |
| 2997 }; | 3032 }; |
| 2998 | 3033 |
| 2999 | 3034 |
| 3000 class NumberDictionaryShape { | 3035 class NumberDictionaryShape : public BaseShape<uint32_t> { |
| 3001 public: | 3036 public: |
| 3037 static const bool UsesSeed = true; |
| 3038 |
| 3002 static inline bool IsMatch(uint32_t key, Object* other); | 3039 static inline bool IsMatch(uint32_t key, Object* other); |
| 3003 static inline uint32_t Hash(uint32_t key); | 3040 static inline uint32_t Hash(uint32_t key); |
| 3041 static inline uint32_t SeededHash(uint32_t key, uint32_t seed); |
| 3004 static inline uint32_t HashForObject(uint32_t key, Object* object); | 3042 static inline uint32_t HashForObject(uint32_t key, Object* object); |
| 3043 static inline uint32_t SeededHashForObject(uint32_t key, uint32_t seed, |
| 3044 Object* object); |
| 3005 MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); | 3045 MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
| 3006 static const int kPrefixSize = 2; | 3046 static const int kPrefixSize = 2; |
| 3007 static const int kEntrySize = 3; | 3047 static const int kEntrySize = 3; |
| 3008 static const bool kIsEnumerable = false; | 3048 static const bool kIsEnumerable = false; |
| 3009 }; | 3049 }; |
| 3010 | 3050 |
| 3011 | 3051 |
| 3012 class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> { | 3052 class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> { |
| 3013 public: | 3053 public: |
| 3014 static NumberDictionary* cast(Object* obj) { | 3054 static NumberDictionary* cast(Object* obj) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3050 inline uint32_t max_number_key(); | 3090 inline uint32_t max_number_key(); |
| 3051 | 3091 |
| 3052 // Bit masks. | 3092 // Bit masks. |
| 3053 static const int kRequiresSlowElementsMask = 1; | 3093 static const int kRequiresSlowElementsMask = 1; |
| 3054 static const int kRequiresSlowElementsTagSize = 1; | 3094 static const int kRequiresSlowElementsTagSize = 1; |
| 3055 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; | 3095 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 3056 }; | 3096 }; |
| 3057 | 3097 |
| 3058 | 3098 |
| 3059 template <int entrysize> | 3099 template <int entrysize> |
| 3060 class ObjectHashTableShape { | 3100 class ObjectHashTableShape : public BaseShape<Object*> { |
| 3061 public: | 3101 public: |
| 3062 static inline bool IsMatch(Object* key, Object* other); | 3102 static inline bool IsMatch(Object* key, Object* other); |
| 3063 static inline uint32_t Hash(Object* key); | 3103 static inline uint32_t Hash(Object* key); |
| 3064 static inline uint32_t HashForObject(Object* key, Object* object); | 3104 static inline uint32_t HashForObject(Object* key, Object* object); |
| 3065 MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key); | 3105 MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key); |
| 3066 static const int kPrefixSize = 0; | 3106 static const int kPrefixSize = 0; |
| 3067 static const int kEntrySize = entrysize; | 3107 static const int kEntrySize = entrysize; |
| 3068 }; | 3108 }; |
| 3069 | 3109 |
| 3070 | 3110 |
| (...skipping 2891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5962 // object is in the saved code field. | 6002 // object is in the saved code field. |
| 5963 static const int kCompilationErrorValue = -2; | 6003 static const int kCompilationErrorValue = -2; |
| 5964 | 6004 |
| 5965 // When we store the sweep generation at which we moved the code from the | 6005 // When we store the sweep generation at which we moved the code from the |
| 5966 // code index to the saved code index we mask it of to be in the [0:255] | 6006 // code index to the saved code index we mask it of to be in the [0:255] |
| 5967 // range. | 6007 // range. |
| 5968 static const int kCodeAgeMask = 0xff; | 6008 static const int kCodeAgeMask = 0xff; |
| 5969 }; | 6009 }; |
| 5970 | 6010 |
| 5971 | 6011 |
| 5972 class CompilationCacheShape { | 6012 class CompilationCacheShape : public BaseShape<HashTableKey*> { |
| 5973 public: | 6013 public: |
| 5974 static inline bool IsMatch(HashTableKey* key, Object* value) { | 6014 static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5975 return key->IsMatch(value); | 6015 return key->IsMatch(value); |
| 5976 } | 6016 } |
| 5977 | 6017 |
| 5978 static inline uint32_t Hash(HashTableKey* key) { | 6018 static inline uint32_t Hash(HashTableKey* key) { |
| 5979 return key->Hash(); | 6019 return key->Hash(); |
| 5980 } | 6020 } |
| 5981 | 6021 |
| 5982 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { | 6022 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6066 // Code cache layout of the default cache. Elements are alternating name and | 6106 // Code cache layout of the default cache. Elements are alternating name and |
| 6067 // code objects for non normal load/store/call IC's. | 6107 // code objects for non normal load/store/call IC's. |
| 6068 static const int kCodeCacheEntrySize = 2; | 6108 static const int kCodeCacheEntrySize = 2; |
| 6069 static const int kCodeCacheEntryNameOffset = 0; | 6109 static const int kCodeCacheEntryNameOffset = 0; |
| 6070 static const int kCodeCacheEntryCodeOffset = 1; | 6110 static const int kCodeCacheEntryCodeOffset = 1; |
| 6071 | 6111 |
| 6072 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); | 6112 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 6073 }; | 6113 }; |
| 6074 | 6114 |
| 6075 | 6115 |
| 6076 class CodeCacheHashTableShape { | 6116 class CodeCacheHashTableShape : public BaseShape<HashTableKey*> { |
| 6077 public: | 6117 public: |
| 6078 static inline bool IsMatch(HashTableKey* key, Object* value) { | 6118 static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 6079 return key->IsMatch(value); | 6119 return key->IsMatch(value); |
| 6080 } | 6120 } |
| 6081 | 6121 |
| 6082 static inline uint32_t Hash(HashTableKey* key) { | 6122 static inline uint32_t Hash(HashTableKey* key) { |
| 6083 return key->Hash(); | 6123 return key->Hash(); |
| 6084 } | 6124 } |
| 6085 | 6125 |
| 6086 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { | 6126 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| (...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8072 } else { | 8112 } else { |
| 8073 value &= ~(1 << bit_position); | 8113 value &= ~(1 << bit_position); |
| 8074 } | 8114 } |
| 8075 return value; | 8115 return value; |
| 8076 } | 8116 } |
| 8077 }; | 8117 }; |
| 8078 | 8118 |
| 8079 } } // namespace v8::internal | 8119 } } // namespace v8::internal |
| 8080 | 8120 |
| 8081 #endif // V8_OBJECTS_H_ | 8121 #endif // V8_OBJECTS_H_ |
| OLD | NEW |