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

Side by Side Diff: src/objects.h

Issue 7754015: Implement identity hashes for proxies. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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
« src/heap.cc ('K') | « src/heap.cc ('k') | src/objects.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 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 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 inline bool HasLocalProperty(String* name); 1423 inline bool HasLocalProperty(String* name);
1424 inline bool HasElement(uint32_t index); 1424 inline bool HasElement(uint32_t index);
1425 1425
1426 // Return the object's prototype (might be Heap::null_value()). 1426 // Return the object's prototype (might be Heap::null_value()).
1427 inline Object* GetPrototype(); 1427 inline Object* GetPrototype();
1428 1428
1429 // Set the object's prototype (only JSReceiver and null are allowed). 1429 // Set the object's prototype (only JSReceiver and null are allowed).
1430 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, 1430 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value,
1431 bool skip_hidden_prototypes); 1431 bool skip_hidden_prototypes);
1432 1432
1433 // Indicates whether a (hidden) property should be created upon lookup.
1434 enum CreationFlag { ALLOW_CREATION, OMIT_CREATION };
Michael Starzinger 2011/09/09 09:40:00 The use of this flag is ambiguous, it is used to i
rossberg 2011/09/12 10:50:08 As discussed offline, moved the enum type out of J
1435
1436 // Retrieves a permanent object identity hash code. The undefined value might
1437 // be returned in case no has been created yet and OMIT_CREATION was used.
1438 inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1439
1433 // Lookup a property. If found, the result is valid and has 1440 // Lookup a property. If found, the result is valid and has
1434 // detailed information. 1441 // detailed information.
1435 void LocalLookup(String* name, LookupResult* result); 1442 void LocalLookup(String* name, LookupResult* result);
1436 void Lookup(String* name, LookupResult* result); 1443 void Lookup(String* name, LookupResult* result);
1437 1444
1445 protected:
1446 Smi* GenerateIdentityHash();
1447
1438 private: 1448 private:
1439 PropertyAttributes GetPropertyAttribute(JSReceiver* receiver, 1449 PropertyAttributes GetPropertyAttribute(JSReceiver* receiver,
1440 LookupResult* result, 1450 LookupResult* result,
1441 String* name, 1451 String* name,
1442 bool continue_search); 1452 bool continue_search);
1443 1453
1444 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); 1454 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver);
1445 }; 1455 };
1446 1456
1447 // The JSObject describes real heap allocated JavaScript objects with 1457 // The JSObject describes real heap allocated JavaScript objects with
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 // Has/Get/SetHiddenPropertiesObject methods don't allow the holder to be 1669 // Has/Get/SetHiddenPropertiesObject methods don't allow the holder to be
1660 // a JSGlobalProxy. Use BypassGlobalProxy method above to get to the real 1670 // a JSGlobalProxy. Use BypassGlobalProxy method above to get to the real
1661 // holder. 1671 // holder.
1662 // 1672 //
1663 // These accessors do not touch interceptors or accessors. 1673 // These accessors do not touch interceptors or accessors.
1664 inline bool HasHiddenPropertiesObject(); 1674 inline bool HasHiddenPropertiesObject();
1665 inline Object* GetHiddenPropertiesObject(); 1675 inline Object* GetHiddenPropertiesObject();
1666 MUST_USE_RESULT inline MaybeObject* SetHiddenPropertiesObject( 1676 MUST_USE_RESULT inline MaybeObject* SetHiddenPropertiesObject(
1667 Object* hidden_obj); 1677 Object* hidden_obj);
1668 1678
1669 // Indicates whether the hidden properties object should be created.
1670 enum HiddenPropertiesFlag { ALLOW_CREATION, OMIT_CREATION };
1671
1672 // Retrieves the hidden properties object. 1679 // Retrieves the hidden properties object.
1673 // 1680 //
1674 // The undefined value might be returned in case no hidden properties object 1681 // The undefined value might be returned in case no hidden properties object
1675 // is present and creation was omitted. 1682 // is present and creation was omitted.
1676 inline bool HasHiddenProperties(); 1683 inline bool HasHiddenProperties();
1677 MUST_USE_RESULT MaybeObject* GetHiddenProperties(HiddenPropertiesFlag flag); 1684 MUST_USE_RESULT MaybeObject* GetHiddenProperties(CreationFlag flag);
1678 1685
1679 // Retrieves a permanent object identity hash code. 1686 MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1680 //
1681 // The identity hash is stored as a hidden property. The undefined value might
1682 // be returned in case no hidden properties object is present and creation was
1683 // omitted.
1684 MUST_USE_RESULT MaybeObject* GetIdentityHash(HiddenPropertiesFlag flag);
1685 1687
1686 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); 1688 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
1687 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); 1689 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1688 1690
1689 // Tests for the fast common case for property enumeration. 1691 // Tests for the fast common case for property enumeration.
1690 bool IsSimpleEnum(); 1692 bool IsSimpleEnum();
1691 1693
1692 // Do we want to keep the elements in fast case when increasing the 1694 // Do we want to keep the elements in fast case when increasing the
1693 // capacity? 1695 // capacity?
1694 bool ShouldConvertToSlowElements(int new_capacity); 1696 bool ShouldConvertToSlowElements(int new_capacity);
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2958 2960
2959 // Bit masks. 2961 // Bit masks.
2960 static const int kRequiresSlowElementsMask = 1; 2962 static const int kRequiresSlowElementsMask = 1;
2961 static const int kRequiresSlowElementsTagSize = 1; 2963 static const int kRequiresSlowElementsTagSize = 1;
2962 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; 2964 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
2963 }; 2965 };
2964 2966
2965 2967
2966 class ObjectHashTableShape { 2968 class ObjectHashTableShape {
2967 public: 2969 public:
2968 static inline bool IsMatch(JSObject* key, Object* other); 2970 static inline bool IsMatch(JSReceiver* key, Object* other);
2969 static inline uint32_t Hash(JSObject* key); 2971 static inline uint32_t Hash(JSReceiver* key);
2970 static inline uint32_t HashForObject(JSObject* key, Object* object); 2972 static inline uint32_t HashForObject(JSReceiver* key, Object* object);
2971 MUST_USE_RESULT static inline MaybeObject* AsObject(JSObject* key); 2973 MUST_USE_RESULT static inline MaybeObject* AsObject(JSReceiver* key);
2972 static const int kPrefixSize = 0; 2974 static const int kPrefixSize = 0;
2973 static const int kEntrySize = 2; 2975 static const int kEntrySize = 2;
2974 }; 2976 };
2975 2977
2976 2978
2977 // ObjectHashTable maps keys that are JavaScript objects to object values by 2979 // ObjectHashTable maps keys that are JavaScript objects to object values by
2978 // using the identity hash of the key for hashing purposes. 2980 // using the identity hash of the key for hashing purposes.
2979 class ObjectHashTable: public HashTable<ObjectHashTableShape, JSObject*> { 2981 class ObjectHashTable: public HashTable<ObjectHashTableShape, JSReceiver*> {
2980 public: 2982 public:
2981 static inline ObjectHashTable* cast(Object* obj) { 2983 static inline ObjectHashTable* cast(Object* obj) {
2982 ASSERT(obj->IsHashTable()); 2984 ASSERT(obj->IsHashTable());
2983 return reinterpret_cast<ObjectHashTable*>(obj); 2985 return reinterpret_cast<ObjectHashTable*>(obj);
2984 } 2986 }
2985 2987
2986 // Looks up the value associated with the given key. The undefined value is 2988 // Looks up the value associated with the given key. The undefined value is
2987 // returned in case the key is not present. 2989 // returned in case the key is not present.
2988 Object* Lookup(JSObject* key); 2990 Object* Lookup(JSReceiver* key);
2989 2991
2990 // Adds (or overwrites) the value associated with the given key. Mapping a 2992 // Adds (or overwrites) the value associated with the given key. Mapping a
2991 // key to the undefined value causes removal of the whole entry. 2993 // key to the undefined value causes removal of the whole entry.
2992 MUST_USE_RESULT MaybeObject* Put(JSObject* key, Object* value); 2994 MUST_USE_RESULT MaybeObject* Put(JSReceiver* key, Object* value);
2993 2995
2994 private: 2996 private:
2995 friend class MarkCompactCollector; 2997 friend class MarkCompactCollector;
2996 2998
2997 void AddEntry(int entry, JSObject* key, Object* value); 2999 void AddEntry(int entry, JSReceiver* key, Object* value);
2998 void RemoveEntry(int entry, Heap* heap); 3000 void RemoveEntry(int entry, Heap* heap);
2999 inline void RemoveEntry(int entry); 3001 inline void RemoveEntry(int entry);
3000 3002
3001 // Returns the index to the value of an entry. 3003 // Returns the index to the value of an entry.
3002 static inline int EntryToValueIndex(int entry) { 3004 static inline int EntryToValueIndex(int entry) {
3003 return EntryToIndex(entry) + 1; 3005 return EntryToIndex(entry) + 1;
3004 } 3006 }
3005 }; 3007 };
3006 3008
3007 3009
(...skipping 3583 matching lines...) Expand 10 before | Expand all | Expand 10 after
6591 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); 6593 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell);
6592 }; 6594 };
6593 6595
6594 6596
6595 // The JSProxy describes EcmaScript Harmony proxies 6597 // The JSProxy describes EcmaScript Harmony proxies
6596 class JSProxy: public JSReceiver { 6598 class JSProxy: public JSReceiver {
6597 public: 6599 public:
6598 // [handler]: The handler property. 6600 // [handler]: The handler property.
6599 DECL_ACCESSORS(handler, Object) 6601 DECL_ACCESSORS(handler, Object)
6600 6602
6603 // [hash]: The hash code property (undefined if not initialized yet).
6604 DECL_ACCESSORS(hash, Object)
6605
6601 // Casting. 6606 // Casting.
6602 static inline JSProxy* cast(Object* obj); 6607 static inline JSProxy* cast(Object* obj);
6603 6608
6604 bool HasPropertyWithHandler(String* name); 6609 bool HasPropertyWithHandler(String* name);
6605 bool HasElementWithHandler(uint32_t index); 6610 bool HasElementWithHandler(uint32_t index);
6606 6611
6607 MUST_USE_RESULT MaybeObject* GetPropertyWithHandler( 6612 MUST_USE_RESULT MaybeObject* GetPropertyWithHandler(
6608 Object* receiver, 6613 Object* receiver,
6609 String* name); 6614 String* name);
6610 MUST_USE_RESULT MaybeObject* GetElementWithHandler( 6615 MUST_USE_RESULT MaybeObject* GetElementWithHandler(
(...skipping 24 matching lines...) Expand all
6635 uint32_t index, 6640 uint32_t index,
6636 DeleteMode mode); 6641 DeleteMode mode);
6637 6642
6638 MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler( 6643 MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler(
6639 JSReceiver* receiver, 6644 JSReceiver* receiver,
6640 String* name); 6645 String* name);
6641 MUST_USE_RESULT PropertyAttributes GetElementAttributeWithHandler( 6646 MUST_USE_RESULT PropertyAttributes GetElementAttributeWithHandler(
6642 JSReceiver* receiver, 6647 JSReceiver* receiver,
6643 uint32_t index); 6648 uint32_t index);
6644 6649
6650 MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
6651
6645 // Turn this into an (empty) JSObject. 6652 // Turn this into an (empty) JSObject.
6646 void Fix(); 6653 void Fix();
6647 6654
6648 // Initializes the body after the handler slot. 6655 // Initializes the body after the handler slot.
6649 inline void InitializeBody(int object_size, Object* value); 6656 inline void InitializeBody(int object_size, Object* value);
6650 6657
6651 // Invoke a trap by name. If the trap does not exist on this's handler, 6658 // Invoke a trap by name. If the trap does not exist on this's handler,
6652 // but derived_trap is non-NULL, invoke that instead. May cause GC. 6659 // but derived_trap is non-NULL, invoke that instead. May cause GC.
6653 Handle<Object> CallTrap(const char* name, 6660 Handle<Object> CallTrap(const char* name,
6654 Handle<Object> derived_trap, 6661 Handle<Object> derived_trap,
6655 int argc, 6662 int argc,
6656 Handle<Object> args[]); 6663 Handle<Object> args[]);
6657 6664
6658 // Dispatched behavior. 6665 // Dispatched behavior.
6659 #ifdef OBJECT_PRINT 6666 #ifdef OBJECT_PRINT
6660 inline void JSProxyPrint() { 6667 inline void JSProxyPrint() {
6661 JSProxyPrint(stdout); 6668 JSProxyPrint(stdout);
6662 } 6669 }
6663 void JSProxyPrint(FILE* out); 6670 void JSProxyPrint(FILE* out);
6664 #endif 6671 #endif
6665 #ifdef DEBUG 6672 #ifdef DEBUG
6666 void JSProxyVerify(); 6673 void JSProxyVerify();
6667 #endif 6674 #endif
6668 6675
6669 // Layout description. We add padding so that a proxy has the same 6676 // Layout description. We add padding so that a proxy has the same
6670 // size as a virgin JSObject. This is essential for becoming a JSObject 6677 // size as a virgin JSObject. This is essential for becoming a JSObject
6671 // upon freeze. 6678 // upon freeze.
6672 static const int kHandlerOffset = HeapObject::kHeaderSize; 6679 static const int kHandlerOffset = HeapObject::kHeaderSize;
6673 static const int kPaddingOffset = kHandlerOffset + kPointerSize; 6680 static const int kHashOffset = kHandlerOffset + kPointerSize;
6681 static const int kPaddingOffset = kHashOffset + kPointerSize;
6674 static const int kSize = JSObject::kHeaderSize; 6682 static const int kSize = JSObject::kHeaderSize;
6675 static const int kHeaderSize = kPaddingOffset; 6683 static const int kHeaderSize = kPaddingOffset;
6676 static const int kPaddingSize = kSize - kPaddingOffset; 6684 static const int kPaddingSize = kSize - kPaddingOffset;
6677 6685
6678 STATIC_CHECK(kPaddingSize >= 0); 6686 STATIC_CHECK(kPaddingSize >= 0);
6679 6687
6680 typedef FixedBodyDescriptor<kHandlerOffset, 6688 typedef FixedBodyDescriptor<kHandlerOffset,
6681 kHandlerOffset + kPointerSize, 6689 kPaddingOffset,
6682 kSize> BodyDescriptor; 6690 kSize> BodyDescriptor;
6683 6691
6684 private: 6692 private:
6685 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); 6693 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
6686 }; 6694 };
6687 6695
6688 6696
6689 class JSFunctionProxy: public JSProxy { 6697 class JSFunctionProxy: public JSProxy {
6690 public: 6698 public:
6691 // [call_trap]: The call trap. 6699 // [call_trap]: The call trap.
(...skipping 10 matching lines...) Expand all
6702 inline void JSFunctionProxyPrint() { 6710 inline void JSFunctionProxyPrint() {
6703 JSFunctionProxyPrint(stdout); 6711 JSFunctionProxyPrint(stdout);
6704 } 6712 }
6705 void JSFunctionProxyPrint(FILE* out); 6713 void JSFunctionProxyPrint(FILE* out);
6706 #endif 6714 #endif
6707 #ifdef DEBUG 6715 #ifdef DEBUG
6708 void JSFunctionProxyVerify(); 6716 void JSFunctionProxyVerify();
6709 #endif 6717 #endif
6710 6718
6711 // Layout description. 6719 // Layout description.
6712 static const int kCallTrapOffset = kHandlerOffset + kPointerSize; 6720 static const int kCallTrapOffset = JSProxy::kPaddingOffset;
6713 static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize; 6721 static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize;
6714 static const int kPaddingOffset = kConstructTrapOffset + kPointerSize; 6722 static const int kPaddingOffset = kConstructTrapOffset + kPointerSize;
6715 static const int kSize = JSFunction::kSize; 6723 static const int kSize = JSFunction::kSize;
6716 static const int kPaddingSize = kSize - kPaddingOffset; 6724 static const int kPaddingSize = kSize - kPaddingOffset;
6717 6725
6718 STATIC_CHECK(kPaddingSize >= 0); 6726 STATIC_CHECK(kPaddingSize >= 0);
6719 6727
6720 typedef FixedBodyDescriptor<kHandlerOffset, 6728 typedef FixedBodyDescriptor<kHandlerOffset,
6721 kConstructTrapOffset + kPointerSize, 6729 kConstructTrapOffset + kPointerSize,
6722 kSize> BodyDescriptor; 6730 kSize> BodyDescriptor;
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
7396 } else { 7404 } else {
7397 value &= ~(1 << bit_position); 7405 value &= ~(1 << bit_position);
7398 } 7406 }
7399 return value; 7407 return value;
7400 } 7408 }
7401 }; 7409 };
7402 7410
7403 } } // namespace v8::internal 7411 } } // namespace v8::internal
7404 7412
7405 #endif // V8_OBJECTS_H_ 7413 #endif // V8_OBJECTS_H_
OLDNEW
« src/heap.cc ('K') | « src/heap.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698