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

Side by Side Diff: src/objects.h

Issue 8372027: Implement Harmony sets and maps. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Andreas Rossberg. Created 9 years, 2 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
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // 45 //
46 // Inheritance hierarchy: 46 // Inheritance hierarchy:
47 // - MaybeObject (an object or a failure) 47 // - MaybeObject (an object or a failure)
48 // - Failure (immediate for marking failed operation) 48 // - Failure (immediate for marking failed operation)
49 // - Object 49 // - Object
50 // - Smi (immediate small integer) 50 // - Smi (immediate small integer)
51 // - HeapObject (superclass for everything allocated in the heap) 51 // - HeapObject (superclass for everything allocated in the heap)
52 // - JSReceiver (suitable for property access) 52 // - JSReceiver (suitable for property access)
53 // - JSObject 53 // - JSObject
54 // - JSArray 54 // - JSArray
55 // - JSSet
56 // - JSMap
55 // - JSWeakMap 57 // - JSWeakMap
56 // - JSRegExp 58 // - JSRegExp
57 // - JSFunction 59 // - JSFunction
58 // - GlobalObject 60 // - GlobalObject
59 // - JSGlobalObject 61 // - JSGlobalObject
60 // - JSBuiltinsObject 62 // - JSBuiltinsObject
61 // - JSGlobalProxy 63 // - JSGlobalProxy
62 // - JSValue 64 // - JSValue
63 // - JSMessageObject 65 // - JSMessageObject
64 // - JSProxy 66 // - JSProxy
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE 623 JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE
622 JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE 624 JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE
623 625
624 JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE 626 JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE
625 JS_OBJECT_TYPE, 627 JS_OBJECT_TYPE,
626 JS_CONTEXT_EXTENSION_OBJECT_TYPE, 628 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
627 JS_GLOBAL_OBJECT_TYPE, 629 JS_GLOBAL_OBJECT_TYPE,
628 JS_BUILTINS_OBJECT_TYPE, 630 JS_BUILTINS_OBJECT_TYPE,
629 JS_GLOBAL_PROXY_TYPE, 631 JS_GLOBAL_PROXY_TYPE,
630 JS_ARRAY_TYPE, 632 JS_ARRAY_TYPE,
633 JS_SET_TYPE,
634 JS_MAP_TYPE,
631 JS_WEAK_MAP_TYPE, 635 JS_WEAK_MAP_TYPE,
632 636
633 JS_REGEXP_TYPE, 637 JS_REGEXP_TYPE,
634 638
635 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE 639 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
636 640
637 // Pseudo-types 641 // Pseudo-types
638 FIRST_TYPE = 0x0, 642 FIRST_TYPE = 0x0,
639 LAST_TYPE = JS_FUNCTION_TYPE, 643 LAST_TYPE = JS_FUNCTION_TYPE,
640 INVALID_TYPE = FIRST_TYPE - 1, 644 INVALID_TYPE = FIRST_TYPE - 1,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 V(Oddball) \ 817 V(Oddball) \
814 V(SharedFunctionInfo) \ 818 V(SharedFunctionInfo) \
815 V(JSValue) \ 819 V(JSValue) \
816 V(JSMessageObject) \ 820 V(JSMessageObject) \
817 V(StringWrapper) \ 821 V(StringWrapper) \
818 V(Foreign) \ 822 V(Foreign) \
819 V(Boolean) \ 823 V(Boolean) \
820 V(JSArray) \ 824 V(JSArray) \
821 V(JSProxy) \ 825 V(JSProxy) \
822 V(JSFunctionProxy) \ 826 V(JSFunctionProxy) \
827 V(JSSet) \
828 V(JSMap) \
823 V(JSWeakMap) \ 829 V(JSWeakMap) \
824 V(JSRegExp) \ 830 V(JSRegExp) \
825 V(HashTable) \ 831 V(HashTable) \
826 V(Dictionary) \ 832 V(Dictionary) \
827 V(SymbolTable) \ 833 V(SymbolTable) \
828 V(JSFunctionResultCache) \ 834 V(JSFunctionResultCache) \
829 V(NormalizedMapCache) \ 835 V(NormalizedMapCache) \
830 V(CompilationCacheTable) \ 836 V(CompilationCacheTable) \
831 V(CodeCacheHashTable) \ 837 V(CodeCacheHashTable) \
832 V(PolymorphicCodeCacheHashTable) \ 838 V(PolymorphicCodeCacheHashTable) \
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 935
930 static Handle<Object> GetElement(Handle<Object> object, uint32_t index); 936 static Handle<Object> GetElement(Handle<Object> object, uint32_t index);
931 inline MaybeObject* GetElement(uint32_t index); 937 inline MaybeObject* GetElement(uint32_t index);
932 // For use when we know that no exception can be thrown. 938 // For use when we know that no exception can be thrown.
933 inline Object* GetElementNoExceptionThrown(uint32_t index); 939 inline Object* GetElementNoExceptionThrown(uint32_t index);
934 MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); 940 MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index);
935 941
936 // Return the object's prototype (might be Heap::null_value()). 942 // Return the object's prototype (might be Heap::null_value()).
937 Object* GetPrototype(); 943 Object* GetPrototype();
938 944
945 // Returns the permanent hash code associated with this object depending on
946 // the actual object type. Might return a failure in case no hash was
947 // created yet or GC was caused by creation.
948 MUST_USE_RESULT MaybeObject* GetHash(CreationFlag flag);
949
950 // Checks whether this object has the same value as the given one. This
951 // function is implemented according to ES5, section 9.12 and can be used
952 // to implement the Harmony "egal" function.
953 bool SameValue(Object* other);
954
939 // Tries to convert an object to an array index. Returns true and sets 955 // Tries to convert an object to an array index. Returns true and sets
940 // the output parameter if it succeeds. 956 // the output parameter if it succeeds.
941 inline bool ToArrayIndex(uint32_t* index); 957 inline bool ToArrayIndex(uint32_t* index);
942 958
943 // Returns true if this is a JSValue containing a string and the index is 959 // Returns true if this is a JSValue containing a string and the index is
944 // < the length of the string. Used to implement [] on strings. 960 // < the length of the string. Used to implement [] on strings.
945 inline bool IsStringObjectWithCharacterAt(uint32_t index); 961 inline bool IsStringObjectWithCharacterAt(uint32_t index);
946 962
947 #ifdef DEBUG 963 #ifdef DEBUG
948 // Verify a pointer is a valid object pointer. 964 // Verify a pointer is a valid object pointer.
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 inline bool HasElement(uint32_t index); 1394 inline bool HasElement(uint32_t index);
1379 1395
1380 // Return the object's prototype (might be Heap::null_value()). 1396 // Return the object's prototype (might be Heap::null_value()).
1381 inline Object* GetPrototype(); 1397 inline Object* GetPrototype();
1382 1398
1383 // Set the object's prototype (only JSReceiver and null are allowed). 1399 // Set the object's prototype (only JSReceiver and null are allowed).
1384 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, 1400 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value,
1385 bool skip_hidden_prototypes); 1401 bool skip_hidden_prototypes);
1386 1402
1387 // Retrieves a permanent object identity hash code. The undefined value might 1403 // Retrieves a permanent object identity hash code. The undefined value might
1388 // be returned in case no has been created yet and OMIT_CREATION was used. 1404 // be returned in case no hash was created yet and OMIT_CREATION was used.
1389 inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); 1405 inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1390 1406
1391 // Lookup a property. If found, the result is valid and has 1407 // Lookup a property. If found, the result is valid and has
1392 // detailed information. 1408 // detailed information.
1393 void LocalLookup(String* name, LookupResult* result); 1409 void LocalLookup(String* name, LookupResult* result);
1394 void Lookup(String* name, LookupResult* result); 1410 void Lookup(String* name, LookupResult* result);
1395 1411
1396 protected: 1412 protected:
1397 Smi* GenerateIdentityHash(); 1413 Smi* GenerateIdentityHash();
1398 1414
(...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after
2943 // Remove all entries were key is a number and (from <= key && key < to). 2959 // Remove all entries were key is a number and (from <= key && key < to).
2944 void RemoveNumberEntries(uint32_t from, uint32_t to); 2960 void RemoveNumberEntries(uint32_t from, uint32_t to);
2945 2961
2946 // Bit masks. 2962 // Bit masks.
2947 static const int kRequiresSlowElementsMask = 1; 2963 static const int kRequiresSlowElementsMask = 1;
2948 static const int kRequiresSlowElementsTagSize = 1; 2964 static const int kRequiresSlowElementsTagSize = 1;
2949 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; 2965 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
2950 }; 2966 };
2951 2967
2952 2968
2969 template <int entrysize>
2953 class ObjectHashTableShape { 2970 class ObjectHashTableShape {
2954 public: 2971 public:
2955 static inline bool IsMatch(JSReceiver* key, Object* other); 2972 static inline bool IsMatch(Object* key, Object* other);
2956 static inline uint32_t Hash(JSReceiver* key); 2973 static inline uint32_t Hash(Object* key);
2957 static inline uint32_t HashForObject(JSReceiver* key, Object* object); 2974 static inline uint32_t HashForObject(Object* key, Object* object);
2958 MUST_USE_RESULT static inline MaybeObject* AsObject(JSReceiver* key); 2975 MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key);
2959 static const int kPrefixSize = 0; 2976 static const int kPrefixSize = 0;
2960 static const int kEntrySize = 2; 2977 static const int kEntrySize = entrysize;
2961 }; 2978 };
2962 2979
2963 2980
2964 // ObjectHashTable maps keys that are JavaScript objects to object values by 2981 // ObjectHashSet holds keys that are arbitrary objects by using the identity
2982 // hash of the key for hashing purposes.
2983 class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> {
2984 public:
2985 static inline ObjectHashSet* cast(Object* obj) {
2986 ASSERT(obj->IsHashTable());
2987 return reinterpret_cast<ObjectHashSet*>(obj);
2988 }
2989
2990 // Looks up whether the given key is part of this hash set.
2991 bool Contains(Object* key);
2992
2993 // Adds the given key to this hash set.
2994 MUST_USE_RESULT MaybeObject* Add(Object* key);
2995
2996 // Removes the given key from this hash set.
2997 MUST_USE_RESULT MaybeObject* Remove(Object* key);
2998 };
2999
3000
3001 // ObjectHashTable maps keys that are arbitrary objects to object values by
2965 // using the identity hash of the key for hashing purposes. 3002 // using the identity hash of the key for hashing purposes.
2966 class ObjectHashTable: public HashTable<ObjectHashTableShape, JSReceiver*> { 3003 class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> {
2967 public: 3004 public:
2968 static inline ObjectHashTable* cast(Object* obj) { 3005 static inline ObjectHashTable* cast(Object* obj) {
2969 ASSERT(obj->IsHashTable()); 3006 ASSERT(obj->IsHashTable());
2970 return reinterpret_cast<ObjectHashTable*>(obj); 3007 return reinterpret_cast<ObjectHashTable*>(obj);
2971 } 3008 }
2972 3009
2973 // Looks up the value associated with the given key. The undefined value is 3010 // Looks up the value associated with the given key. The undefined value is
2974 // returned in case the key is not present. 3011 // returned in case the key is not present.
2975 Object* Lookup(JSReceiver* key); 3012 Object* Lookup(Object* key);
2976 3013
2977 // Adds (or overwrites) the value associated with the given key. Mapping a 3014 // Adds (or overwrites) the value associated with the given key. Mapping a
2978 // key to the undefined value causes removal of the whole entry. 3015 // key to the undefined value causes removal of the whole entry.
2979 MUST_USE_RESULT MaybeObject* Put(JSReceiver* key, Object* value); 3016 MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value);
2980 3017
2981 private: 3018 private:
2982 friend class MarkCompactCollector; 3019 friend class MarkCompactCollector;
2983 3020
2984 void AddEntry(int entry, JSReceiver* key, Object* value); 3021 void AddEntry(int entry, Object* key, Object* value);
2985 void RemoveEntry(int entry, Heap* heap); 3022 void RemoveEntry(int entry, Heap* heap);
2986 inline void RemoveEntry(int entry); 3023 inline void RemoveEntry(int entry);
2987 3024
2988 // Returns the index to the value of an entry. 3025 // Returns the index to the value of an entry.
2989 static inline int EntryToValueIndex(int entry) { 3026 static inline int EntryToValueIndex(int entry) {
2990 return EntryToIndex(entry) + 1; 3027 return EntryToIndex(entry) + 1;
2991 } 3028 }
2992 }; 3029 };
2993 3030
2994 3031
(...skipping 3980 matching lines...) Expand 10 before | Expand all | Expand 10 after
6975 7012
6976 typedef FixedBodyDescriptor<kHandlerOffset, 7013 typedef FixedBodyDescriptor<kHandlerOffset,
6977 kConstructTrapOffset + kPointerSize, 7014 kConstructTrapOffset + kPointerSize,
6978 kSize> BodyDescriptor; 7015 kSize> BodyDescriptor;
6979 7016
6980 private: 7017 private:
6981 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy); 7018 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy);
6982 }; 7019 };
6983 7020
6984 7021
7022 // The JSSet describes EcmaScript Harmony maps
arv (Not doing code reviews) 2011/10/26 17:09:44 nit // The JSSet describes EcmaScript Harmony *s
Michael Starzinger 2011/10/27 15:36:05 Done (will include in next CL).
7023 class JSSet: public JSObject {
7024 public:
7025 // [set]: the backing hash set containing keys.
7026 DECL_ACCESSORS(table, Object)
7027
7028 // Casting.
7029 static inline JSSet* cast(Object* obj);
7030
7031 #ifdef OBJECT_PRINT
7032 inline void JSSetPrint() {
7033 JSSetPrint(stdout);
7034 }
7035 void JSSetPrint(FILE* out);
7036 #endif
7037 #ifdef DEBUG
7038 void JSSetVerify();
7039 #endif
7040
7041 static const int kTableOffset = JSObject::kHeaderSize;
7042 static const int kSize = kTableOffset + kPointerSize;
7043
7044 private:
7045 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet);
7046 };
7047
7048
7049 // The JSMap describes EcmaScript Harmony maps
7050 class JSMap: public JSObject {
7051 public:
7052 // [table]: the backing hash table mapping keys to values.
7053 DECL_ACCESSORS(table, Object)
7054
7055 // Casting.
7056 static inline JSMap* cast(Object* obj);
7057
7058 #ifdef OBJECT_PRINT
7059 inline void JSMapPrint() {
7060 JSMapPrint(stdout);
7061 }
7062 void JSMapPrint(FILE* out);
7063 #endif
7064 #ifdef DEBUG
7065 void JSMapVerify();
7066 #endif
7067
7068 static const int kTableOffset = JSObject::kHeaderSize;
7069 static const int kSize = kTableOffset + kPointerSize;
7070
7071 private:
7072 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
7073 };
7074
7075
6985 // The JSWeakMap describes EcmaScript Harmony weak maps 7076 // The JSWeakMap describes EcmaScript Harmony weak maps
6986 class JSWeakMap: public JSObject { 7077 class JSWeakMap: public JSObject {
6987 public: 7078 public:
6988 // [table]: the backing hash table mapping keys to values. 7079 // [table]: the backing hash table mapping keys to values.
6989 DECL_ACCESSORS(table, Object) 7080 DECL_ACCESSORS(table, Object)
6990 7081
6991 // [next]: linked list of encountered weak maps during GC. 7082 // [next]: linked list of encountered weak maps during GC.
6992 DECL_ACCESSORS(next, Object) 7083 DECL_ACCESSORS(next, Object)
6993 7084
6994 // Unchecked accessors to be used during GC. 7085 // Unchecked accessors to be used during GC.
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
7654 } else { 7745 } else {
7655 value &= ~(1 << bit_position); 7746 value &= ~(1 << bit_position);
7656 } 7747 }
7657 return value; 7748 return value;
7658 } 7749 }
7659 }; 7750 };
7660 7751
7661 } } // namespace v8::internal 7752 } } // namespace v8::internal
7662 7753
7663 #endif // V8_OBJECTS_H_ 7754 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698