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

Side by Side Diff: src/objects.h

Issue 776143005: Optimize Object.seal and Object.preventExtensions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add support for preventExtensions Created 6 years 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
OLDNEW
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_OBJECTS_H_ 5 #ifndef V8_OBJECTS_H_
6 #define V8_OBJECTS_H_ 6 #define V8_OBJECTS_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 9
10 #include "src/allocation.h" 10 #include "src/allocation.h"
(...skipping 2088 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 Object* pre_allocated_value, 2099 Object* pre_allocated_value,
2100 Object* filler_value); 2100 Object* filler_value);
2101 2101
2102 // Check whether this object references another object 2102 // Check whether this object references another object
2103 bool ReferencesObject(Object* obj); 2103 bool ReferencesObject(Object* obj);
2104 2104
2105 // Disalow further properties to be added to the object. 2105 // Disalow further properties to be added to the object.
2106 MUST_USE_RESULT static MaybeHandle<Object> PreventExtensions( 2106 MUST_USE_RESULT static MaybeHandle<Object> PreventExtensions(
2107 Handle<JSObject> object); 2107 Handle<JSObject> object);
2108 2108
2109 // ES5 Object.seal
2110 MUST_USE_RESULT static MaybeHandle<Object> Seal(Handle<JSObject> object);
2111
2109 // ES5 Object.freeze 2112 // ES5 Object.freeze
2110 MUST_USE_RESULT static MaybeHandle<Object> Freeze(Handle<JSObject> object); 2113 MUST_USE_RESULT static MaybeHandle<Object> Freeze(Handle<JSObject> object);
2111 2114
2112 // Called the first time an object is observed with ES7 Object.observe. 2115 // Called the first time an object is observed with ES7 Object.observe.
2113 static void SetObserved(Handle<JSObject> object); 2116 static void SetObserved(Handle<JSObject> object);
2114 2117
2115 // Copy object. 2118 // Copy object.
2116 enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 }; 2119 enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 };
2117 2120
2118 static Handle<JSObject> Copy(Handle<JSObject> object); 2121 static Handle<JSObject> Copy(Handle<JSObject> object);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2386 // Set the hidden property backing store to either a hash table or 2389 // Set the hidden property backing store to either a hash table or
2387 // the inline-stored identity hash. 2390 // the inline-stored identity hash.
2388 static Handle<Object> SetHiddenPropertiesHashTable( 2391 static Handle<Object> SetHiddenPropertiesHashTable(
2389 Handle<JSObject> object, 2392 Handle<JSObject> object,
2390 Handle<Object> value); 2393 Handle<Object> value);
2391 2394
2392 MUST_USE_RESULT Object* GetIdentityHash(); 2395 MUST_USE_RESULT Object* GetIdentityHash();
2393 2396
2394 static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object); 2397 static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object);
2395 2398
2399 static Handle<SeededNumberDictionary> GetNormalizedElementDictionary(
2400 Handle<JSObject> object);
2401
2402 // Helper for fast versions of preventExtensions, seal, and freeze.
2403 // attrs is one of NONE, SEALED, or FROZEN (depending on the operation).
2404 template <PropertyAttributes attrs>
2405 MUST_USE_RESULT static MaybeHandle<Object> PreventExtensionsWithTransition(
2406 Handle<JSObject> object);
2407
2396 DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); 2408 DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
2397 }; 2409 };
2398 2410
2399 2411
2400 // Common superclass for FixedArrays that allow implementations to share 2412 // Common superclass for FixedArrays that allow implementations to share
2401 // common accessors and some code paths. 2413 // common accessors and some code paths.
2402 class FixedArrayBase: public HeapObject { 2414 class FixedArrayBase: public HeapObject {
2403 public: 2415 public:
2404 // [length]: length of the array. 2416 // [length]: length of the array.
2405 inline int length() const; 2417 inline int length() const;
(...skipping 3199 matching lines...) Expand 10 before | Expand all | Expand 10 after
5605 static void SetMarkedForDeoptimization(Code* code, DependencyGroup group); 5617 static void SetMarkedForDeoptimization(Code* code, DependencyGroup group);
5606 5618
5607 private: 5619 private:
5608 // Make a room at the end of the given group by moving out the first 5620 // Make a room at the end of the given group by moving out the first
5609 // code objects of the subsequent groups. 5621 // code objects of the subsequent groups.
5610 inline void ExtendGroup(DependencyGroup group); 5622 inline void ExtendGroup(DependencyGroup group);
5611 static const int kCodesStartIndex = kGroupCount; 5623 static const int kCodesStartIndex = kGroupCount;
5612 }; 5624 };
5613 5625
5614 5626
5627 class Symbol;
Igor Sheludko 2014/12/10 10:36:14 I think src/globals.h is a better place for this.
adamk 2014/12/10 18:46:01 Thanks for the pointer, I didn't know about that l
5628
5629
5615 // All heap objects have a Map that describes their structure. 5630 // All heap objects have a Map that describes their structure.
5616 // A Map contains information about: 5631 // A Map contains information about:
5617 // - Size information about the object 5632 // - Size information about the object
5618 // - How to iterate over an object (for garbage collection) 5633 // - How to iterate over an object (for garbage collection)
5619 class Map: public HeapObject { 5634 class Map: public HeapObject {
5620 public: 5635 public:
5621 // Instance size. 5636 // Instance size.
5622 // Size in bytes or kVariableSizeSentinel if instances do not have 5637 // Size in bytes or kVariableSizeSentinel if instances do not have
5623 // a fixed size. 5638 // a fixed size.
5624 inline int instance_size(); 5639 inline int instance_size();
(...skipping 30 matching lines...) Expand all
5655 5670
5656 class EnumLengthBits: public BitField<int, 5671 class EnumLengthBits: public BitField<int,
5657 0, kDescriptorIndexBitCount> {}; // NOLINT 5672 0, kDescriptorIndexBitCount> {}; // NOLINT
5658 class NumberOfOwnDescriptorsBits: public BitField<int, 5673 class NumberOfOwnDescriptorsBits: public BitField<int,
5659 kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT 5674 kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT
5660 STATIC_ASSERT(kDescriptorIndexBitCount + kDescriptorIndexBitCount == 20); 5675 STATIC_ASSERT(kDescriptorIndexBitCount + kDescriptorIndexBitCount == 20);
5661 class DictionaryMap : public BitField<bool, 20, 1> {}; 5676 class DictionaryMap : public BitField<bool, 20, 1> {};
5662 class OwnsDescriptors : public BitField<bool, 21, 1> {}; 5677 class OwnsDescriptors : public BitField<bool, 21, 1> {};
5663 class HasInstanceCallHandler : public BitField<bool, 22, 1> {}; 5678 class HasInstanceCallHandler : public BitField<bool, 22, 1> {};
5664 class Deprecated : public BitField<bool, 23, 1> {}; 5679 class Deprecated : public BitField<bool, 23, 1> {};
5665 class IsFrozen : public BitField<bool, 24, 1> {}; 5680 class IsUnstable : public BitField<bool, 24, 1> {};
5666 class IsUnstable : public BitField<bool, 25, 1> {}; 5681 class IsMigrationTarget : public BitField<bool, 25, 1> {};
5667 class IsMigrationTarget : public BitField<bool, 26, 1> {}; 5682 class DoneInobjectSlackTracking : public BitField<bool, 26, 1> {};
5668 class DoneInobjectSlackTracking : public BitField<bool, 27, 1> {}; 5683 // Bits 27 and 28 are free.
5669 // Bit 28 is free.
5670 5684
5671 // Keep this bit field at the very end for better code in 5685 // Keep this bit field at the very end for better code in
5672 // Builtins::kJSConstructStubGeneric stub. 5686 // Builtins::kJSConstructStubGeneric stub.
5673 class ConstructionCount: public BitField<int, 29, 3> {}; 5687 class ConstructionCount: public BitField<int, 29, 3> {};
5674 5688
5675 // Tells whether the object in the prototype property will be used 5689 // Tells whether the object in the prototype property will be used
5676 // for instances created from this function. If the prototype 5690 // for instances created from this function. If the prototype
5677 // property is set to a value that is not a JSObject, the prototype 5691 // property is set to a value that is not a JSObject, the prototype
5678 // property will not be used to create instances of the function. 5692 // property will not be used to create instances of the function.
5679 // See ECMA-262, 13.2.2. 5693 // See ECMA-262, 13.2.2.
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
5999 DCHECK(length == 0 || instance_descriptors()->HasEnumCache()); 6013 DCHECK(length == 0 || instance_descriptors()->HasEnumCache());
6000 DCHECK(length <= NumberOfOwnDescriptors()); 6014 DCHECK(length <= NumberOfOwnDescriptors());
6001 } 6015 }
6002 set_bit_field3(EnumLengthBits::update(bit_field3(), length)); 6016 set_bit_field3(EnumLengthBits::update(bit_field3(), length));
6003 } 6017 }
6004 6018
6005 inline bool owns_descriptors(); 6019 inline bool owns_descriptors();
6006 inline void set_owns_descriptors(bool owns_descriptors); 6020 inline void set_owns_descriptors(bool owns_descriptors);
6007 inline bool has_instance_call_handler(); 6021 inline bool has_instance_call_handler();
6008 inline void set_has_instance_call_handler(); 6022 inline void set_has_instance_call_handler();
6009 inline void freeze();
6010 inline bool is_frozen();
6011 inline void mark_unstable(); 6023 inline void mark_unstable();
6012 inline bool is_stable(); 6024 inline bool is_stable();
6013 inline void set_migration_target(bool value); 6025 inline void set_migration_target(bool value);
6014 inline bool is_migration_target(); 6026 inline bool is_migration_target();
6015 inline void set_done_inobject_slack_tracking(bool value); 6027 inline void set_done_inobject_slack_tracking(bool value);
6016 inline bool done_inobject_slack_tracking(); 6028 inline bool done_inobject_slack_tracking();
6017 inline void set_construction_count(int value); 6029 inline void set_construction_count(int value);
6018 inline int construction_count(); 6030 inline int construction_count();
6019 inline void deprecate(); 6031 inline void deprecate();
6020 inline bool is_deprecated(); 6032 inline bool is_deprecated();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
6060 ElementsKind to_kind); 6072 ElementsKind to_kind);
6061 6073
6062 static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind); 6074 static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind);
6063 6075
6064 static Handle<Map> CopyAsElementsKind(Handle<Map> map, 6076 static Handle<Map> CopyAsElementsKind(Handle<Map> map,
6065 ElementsKind kind, 6077 ElementsKind kind,
6066 TransitionFlag flag); 6078 TransitionFlag flag);
6067 6079
6068 static Handle<Map> CopyForObserved(Handle<Map> map); 6080 static Handle<Map> CopyForObserved(Handle<Map> map);
6069 6081
6070 static Handle<Map> CopyForFreeze(Handle<Map> map); 6082 static Handle<Map> CopyForPreventExtensions(Handle<Map> map,
6083 PropertyAttributes attrs_to_add,
6084 Handle<Symbol> transition_marker,
6085 const char* reason);
6071 // Maximal number of fast properties. Used to restrict the number of map 6086 // Maximal number of fast properties. Used to restrict the number of map
6072 // transitions to avoid an explosion in the number of maps for objects used as 6087 // transitions to avoid an explosion in the number of maps for objects used as
6073 // dictionaries. 6088 // dictionaries.
6074 inline bool TooManyFastProperties(StoreFromKeyed store_mode); 6089 inline bool TooManyFastProperties(StoreFromKeyed store_mode);
6075 static Handle<Map> TransitionToDataProperty(Handle<Map> map, 6090 static Handle<Map> TransitionToDataProperty(Handle<Map> map,
6076 Handle<Name> name, 6091 Handle<Name> name,
6077 Handle<Object> value, 6092 Handle<Object> value,
6078 PropertyAttributes attributes, 6093 PropertyAttributes attributes,
6079 StoreFromKeyed store_mode); 6094 StoreFromKeyed store_mode);
6080 static Handle<Map> TransitionToAccessorProperty( 6095 static Handle<Map> TransitionToAccessorProperty(
(...skipping 4924 matching lines...) Expand 10 before | Expand all | Expand 10 after
11005 } else { 11020 } else {
11006 value &= ~(1 << bit_position); 11021 value &= ~(1 << bit_position);
11007 } 11022 }
11008 return value; 11023 return value;
11009 } 11024 }
11010 }; 11025 };
11011 11026
11012 } } // namespace v8::internal 11027 } } // namespace v8::internal
11013 11028
11014 #endif // V8_OBJECTS_H_ 11029 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/objects.cc » ('j') | src/objects-printer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698