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_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/assert-scope.h" | 9 #include "src/assert-scope.h" |
10 #include "src/builtins.h" | 10 #include "src/builtins.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 240 |
241 | 241 |
242 // PropertyNormalizationMode is used to specify whether to keep | 242 // PropertyNormalizationMode is used to specify whether to keep |
243 // inobject properties when normalizing properties of a JSObject. | 243 // inobject properties when normalizing properties of a JSObject. |
244 enum PropertyNormalizationMode { | 244 enum PropertyNormalizationMode { |
245 CLEAR_INOBJECT_PROPERTIES, | 245 CLEAR_INOBJECT_PROPERTIES, |
246 KEEP_INOBJECT_PROPERTIES | 246 KEEP_INOBJECT_PROPERTIES |
247 }; | 247 }; |
248 | 248 |
249 | 249 |
250 // NormalizedMapSharingMode is used to specify whether a map may be shared | 250 // Indicates how aggressively the prototype should be optimized. FAST_PROTOTYPE |
251 // by different objects with normalized properties. | 251 // will give the fastest result by tailoring the map to the prototype, but that |
252 enum NormalizedMapSharingMode { | 252 // will cause polymorphism with other objects. REGULAR_PROTOTYPE is to be used |
253 UNIQUE_NORMALIZED_MAP, | 253 // (at least for now) when dynamically modifying the prototype chain of an |
254 SHARED_NORMALIZED_MAP | 254 // object using __proto__ or Object.setPrototypeOf. |
255 }; | 255 enum PrototypeOptimizationMode { REGULAR_PROTOTYPE, FAST_PROTOTYPE }; |
256 | 256 |
257 | 257 |
258 // Indicates whether transitions can be added to a source map or not. | 258 // Indicates whether transitions can be added to a source map or not. |
259 enum TransitionFlag { | 259 enum TransitionFlag { |
260 INSERT_TRANSITION, | 260 INSERT_TRANSITION, |
261 OMIT_TRANSITION | 261 OMIT_TRANSITION |
262 }; | 262 }; |
263 | 263 |
264 | 264 |
265 enum DebugExtraICState { | 265 enum DebugExtraICState { |
(...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2189 const LookupResult* result, | 2189 const LookupResult* result, |
2190 Handle<Object> value); | 2190 Handle<Object> value); |
2191 | 2191 |
2192 // Sets the property value in a normalized object given (key, value, details). | 2192 // Sets the property value in a normalized object given (key, value, details). |
2193 // Handles the special representation of JS global objects. | 2193 // Handles the special representation of JS global objects. |
2194 static void SetNormalizedProperty(Handle<JSObject> object, | 2194 static void SetNormalizedProperty(Handle<JSObject> object, |
2195 Handle<Name> key, | 2195 Handle<Name> key, |
2196 Handle<Object> value, | 2196 Handle<Object> value, |
2197 PropertyDetails details); | 2197 PropertyDetails details); |
2198 | 2198 |
2199 static void OptimizeAsPrototype(Handle<JSObject> object); | 2199 static void OptimizeAsPrototype(Handle<JSObject> object, |
| 2200 PrototypeOptimizationMode mode); |
2200 static void ReoptimizeIfPrototype(Handle<JSObject> object); | 2201 static void ReoptimizeIfPrototype(Handle<JSObject> object); |
2201 | 2202 |
2202 // Retrieve interceptors. | 2203 // Retrieve interceptors. |
2203 InterceptorInfo* GetNamedInterceptor(); | 2204 InterceptorInfo* GetNamedInterceptor(); |
2204 InterceptorInfo* GetIndexedInterceptor(); | 2205 InterceptorInfo* GetIndexedInterceptor(); |
2205 | 2206 |
2206 // Used from JSReceiver. | 2207 // Used from JSReceiver. |
2207 MUST_USE_RESULT static Maybe<PropertyAttributes> | 2208 MUST_USE_RESULT static Maybe<PropertyAttributes> |
2208 GetPropertyAttributesWithInterceptor(Handle<JSObject> holder, | 2209 GetPropertyAttributesWithInterceptor(Handle<JSObject> holder, |
2209 Handle<Object> receiver, | 2210 Handle<Object> receiver, |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2468 // Access to in object properties. | 2469 // Access to in object properties. |
2469 inline int GetInObjectPropertyOffset(int index); | 2470 inline int GetInObjectPropertyOffset(int index); |
2470 inline Object* InObjectPropertyAt(int index); | 2471 inline Object* InObjectPropertyAt(int index); |
2471 inline Object* InObjectPropertyAtPut(int index, | 2472 inline Object* InObjectPropertyAtPut(int index, |
2472 Object* value, | 2473 Object* value, |
2473 WriteBarrierMode mode | 2474 WriteBarrierMode mode |
2474 = UPDATE_WRITE_BARRIER); | 2475 = UPDATE_WRITE_BARRIER); |
2475 | 2476 |
2476 // Set the object's prototype (only JSReceiver and null are allowed values). | 2477 // Set the object's prototype (only JSReceiver and null are allowed values). |
2477 MUST_USE_RESULT static MaybeHandle<Object> SetPrototype( | 2478 MUST_USE_RESULT static MaybeHandle<Object> SetPrototype( |
2478 Handle<JSObject> object, | 2479 Handle<JSObject> object, Handle<Object> value, bool from_javascript); |
2479 Handle<Object> value, | |
2480 bool skip_hidden_prototypes = false); | |
2481 | 2480 |
2482 // Initializes the body after properties slot, properties slot is | 2481 // Initializes the body after properties slot, properties slot is |
2483 // initialized by set_properties. Fill the pre-allocated fields with | 2482 // initialized by set_properties. Fill the pre-allocated fields with |
2484 // pre_allocated_value and the rest with filler_value. | 2483 // pre_allocated_value and the rest with filler_value. |
2485 // Note: this call does not update write barrier, the caller is responsible | 2484 // Note: this call does not update write barrier, the caller is responsible |
2486 // to ensure that |filler_value| can be collected without WB here. | 2485 // to ensure that |filler_value| can be collected without WB here. |
2487 inline void InitializeBody(Map* map, | 2486 inline void InitializeBody(Map* map, |
2488 Object* pre_allocated_value, | 2487 Object* pre_allocated_value, |
2489 Object* filler_value); | 2488 Object* filler_value); |
2490 | 2489 |
(...skipping 3627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6118 | 6117 |
6119 // Bit field 3. | 6118 // Bit field 3. |
6120 inline uint32_t bit_field3(); | 6119 inline uint32_t bit_field3(); |
6121 inline void set_bit_field3(uint32_t bits); | 6120 inline void set_bit_field3(uint32_t bits); |
6122 | 6121 |
6123 class EnumLengthBits: public BitField<int, | 6122 class EnumLengthBits: public BitField<int, |
6124 0, kDescriptorIndexBitCount> {}; // NOLINT | 6123 0, kDescriptorIndexBitCount> {}; // NOLINT |
6125 class NumberOfOwnDescriptorsBits: public BitField<int, | 6124 class NumberOfOwnDescriptorsBits: public BitField<int, |
6126 kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT | 6125 kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT |
6127 STATIC_ASSERT(kDescriptorIndexBitCount + kDescriptorIndexBitCount == 20); | 6126 STATIC_ASSERT(kDescriptorIndexBitCount + kDescriptorIndexBitCount == 20); |
6128 class IsShared: public BitField<bool, 20, 1> {}; | 6127 class DictionaryMap : public BitField<bool, 20, 1> {}; |
6129 class DictionaryMap: public BitField<bool, 21, 1> {}; | 6128 class OwnsDescriptors : public BitField<bool, 21, 1> {}; |
6130 class OwnsDescriptors: public BitField<bool, 22, 1> {}; | 6129 class HasInstanceCallHandler : public BitField<bool, 22, 1> {}; |
6131 class HasInstanceCallHandler: public BitField<bool, 23, 1> {}; | 6130 class Deprecated : public BitField<bool, 23, 1> {}; |
6132 class Deprecated: public BitField<bool, 24, 1> {}; | 6131 class IsFrozen : public BitField<bool, 24, 1> {}; |
6133 class IsFrozen: public BitField<bool, 25, 1> {}; | 6132 class IsUnstable : public BitField<bool, 25, 1> {}; |
6134 class IsUnstable: public BitField<bool, 26, 1> {}; | 6133 class IsMigrationTarget : public BitField<bool, 26, 1> {}; |
6135 class IsMigrationTarget: public BitField<bool, 27, 1> {}; | 6134 class DoneInobjectSlackTracking : public BitField<bool, 27, 1> {}; |
6136 class DoneInobjectSlackTracking: public BitField<bool, 28, 1> {}; | 6135 // Bit 28 is free. |
| 6136 |
6137 // Keep this bit field at the very end for better code in | 6137 // Keep this bit field at the very end for better code in |
6138 // Builtins::kJSConstructStubGeneric stub. | 6138 // Builtins::kJSConstructStubGeneric stub. |
6139 class ConstructionCount: public BitField<int, 29, 3> {}; | 6139 class ConstructionCount: public BitField<int, 29, 3> {}; |
6140 | 6140 |
6141 // Tells whether the object in the prototype property will be used | 6141 // Tells whether the object in the prototype property will be used |
6142 // for instances created from this function. If the prototype | 6142 // for instances created from this function. If the prototype |
6143 // property is set to a value that is not a JSObject, the prototype | 6143 // property is set to a value that is not a JSObject, the prototype |
6144 // property will not be used to create instances of the function. | 6144 // property will not be used to create instances of the function. |
6145 // See ECMA-262, 13.2.2. | 6145 // See ECMA-262, 13.2.2. |
6146 inline void set_non_instance_prototype(bool value); | 6146 inline void set_non_instance_prototype(bool value); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6328 static Handle<Map> PrepareForDataProperty(Handle<Map> old_map, | 6328 static Handle<Map> PrepareForDataProperty(Handle<Map> old_map, |
6329 int descriptor_number, | 6329 int descriptor_number, |
6330 Handle<Object> value); | 6330 Handle<Object> value); |
6331 | 6331 |
6332 static Handle<Map> Normalize(Handle<Map> map, PropertyNormalizationMode mode); | 6332 static Handle<Map> Normalize(Handle<Map> map, PropertyNormalizationMode mode); |
6333 | 6333 |
6334 // Returns the constructor name (the name (possibly, inferred name) of the | 6334 // Returns the constructor name (the name (possibly, inferred name) of the |
6335 // function that was used to instantiate the object). | 6335 // function that was used to instantiate the object). |
6336 String* constructor_name(); | 6336 String* constructor_name(); |
6337 | 6337 |
6338 // Tells whether the map is shared between objects that may have different | |
6339 // behavior. If true, the map should never be modified, instead a clone | |
6340 // should be created and modified. | |
6341 inline void set_is_shared(bool value); | |
6342 inline bool is_shared(); | |
6343 | |
6344 // Tells whether the map is used for JSObjects in dictionary mode (ie | 6338 // Tells whether the map is used for JSObjects in dictionary mode (ie |
6345 // normalized objects, ie objects for which HasFastProperties returns false). | 6339 // normalized objects, ie objects for which HasFastProperties returns false). |
6346 // A map can never be used for both dictionary mode and fast mode JSObjects. | 6340 // A map can never be used for both dictionary mode and fast mode JSObjects. |
6347 // False by default and for HeapObjects that are not JSObjects. | 6341 // False by default and for HeapObjects that are not JSObjects. |
6348 inline void set_dictionary_map(bool value); | 6342 inline void set_dictionary_map(bool value); |
6349 inline bool is_dictionary_map(); | 6343 inline bool is_dictionary_map(); |
6350 | 6344 |
6351 // Tells whether the instance needs security checks when accessing its | 6345 // Tells whether the instance needs security checks when accessing its |
6352 // properties. | 6346 // properties. |
6353 inline void set_is_access_check_needed(bool access_check_needed); | 6347 inline void set_is_access_check_needed(bool access_check_needed); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6453 void SetEnumLength(int length) { | 6447 void SetEnumLength(int length) { |
6454 if (length != kInvalidEnumCacheSentinel) { | 6448 if (length != kInvalidEnumCacheSentinel) { |
6455 DCHECK(length >= 0); | 6449 DCHECK(length >= 0); |
6456 DCHECK(length == 0 || instance_descriptors()->HasEnumCache()); | 6450 DCHECK(length == 0 || instance_descriptors()->HasEnumCache()); |
6457 DCHECK(length <= NumberOfOwnDescriptors()); | 6451 DCHECK(length <= NumberOfOwnDescriptors()); |
6458 } | 6452 } |
6459 set_bit_field3(EnumLengthBits::update(bit_field3(), length)); | 6453 set_bit_field3(EnumLengthBits::update(bit_field3(), length)); |
6460 } | 6454 } |
6461 | 6455 |
6462 inline bool owns_descriptors(); | 6456 inline bool owns_descriptors(); |
6463 inline void set_owns_descriptors(bool is_shared); | 6457 inline void set_owns_descriptors(bool owns_descriptors); |
6464 inline bool has_instance_call_handler(); | 6458 inline bool has_instance_call_handler(); |
6465 inline void set_has_instance_call_handler(); | 6459 inline void set_has_instance_call_handler(); |
6466 inline void freeze(); | 6460 inline void freeze(); |
6467 inline bool is_frozen(); | 6461 inline bool is_frozen(); |
6468 inline void mark_unstable(); | 6462 inline void mark_unstable(); |
6469 inline bool is_stable(); | 6463 inline bool is_stable(); |
6470 inline void set_migration_target(bool value); | 6464 inline void set_migration_target(bool value); |
6471 inline bool is_migration_target(); | 6465 inline bool is_migration_target(); |
6472 inline void set_done_inobject_slack_tracking(bool value); | 6466 inline void set_done_inobject_slack_tracking(bool value); |
6473 inline bool done_inobject_slack_tracking(); | 6467 inline bool done_inobject_slack_tracking(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6642 static void AddDependentIC(Handle<Map> map, | 6636 static void AddDependentIC(Handle<Map> map, |
6643 Handle<Code> stub); | 6637 Handle<Code> stub); |
6644 | 6638 |
6645 bool IsMapInArrayPrototypeChain(); | 6639 bool IsMapInArrayPrototypeChain(); |
6646 | 6640 |
6647 // Dispatched behavior. | 6641 // Dispatched behavior. |
6648 DECLARE_PRINTER(Map) | 6642 DECLARE_PRINTER(Map) |
6649 DECLARE_VERIFIER(Map) | 6643 DECLARE_VERIFIER(Map) |
6650 | 6644 |
6651 #ifdef VERIFY_HEAP | 6645 #ifdef VERIFY_HEAP |
6652 void SharedMapVerify(); | 6646 void DictionaryMapVerify(); |
6653 void VerifyOmittedMapChecks(); | 6647 void VerifyOmittedMapChecks(); |
6654 #endif | 6648 #endif |
6655 | 6649 |
6656 inline int visitor_id(); | 6650 inline int visitor_id(); |
6657 inline void set_visitor_id(int visitor_id); | 6651 inline void set_visitor_id(int visitor_id); |
6658 | 6652 |
6659 typedef void (*TraverseCallback)(Map* map, void* data); | 6653 typedef void (*TraverseCallback)(Map* map, void* data); |
6660 | 6654 |
6661 void TraverseTransitionTree(TraverseCallback callback, void* data); | 6655 void TraverseTransitionTree(TraverseCallback callback, void* data); |
6662 | 6656 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6788 TransitionFlag flag, | 6782 TransitionFlag flag, |
6789 MaybeHandle<Name> maybe_name, | 6783 MaybeHandle<Name> maybe_name, |
6790 SimpleTransitionFlag simple_flag = FULL_TRANSITION); | 6784 SimpleTransitionFlag simple_flag = FULL_TRANSITION); |
6791 static Handle<Map> CopyReplaceDescriptor(Handle<Map> map, | 6785 static Handle<Map> CopyReplaceDescriptor(Handle<Map> map, |
6792 Handle<DescriptorArray> descriptors, | 6786 Handle<DescriptorArray> descriptors, |
6793 Descriptor* descriptor, | 6787 Descriptor* descriptor, |
6794 int index, | 6788 int index, |
6795 TransitionFlag flag); | 6789 TransitionFlag flag); |
6796 | 6790 |
6797 static Handle<Map> CopyNormalized(Handle<Map> map, | 6791 static Handle<Map> CopyNormalized(Handle<Map> map, |
6798 PropertyNormalizationMode mode, | 6792 PropertyNormalizationMode mode); |
6799 NormalizedMapSharingMode sharing); | |
6800 | 6793 |
6801 // Fires when the layout of an object with a leaf map changes. | 6794 // Fires when the layout of an object with a leaf map changes. |
6802 // This includes adding transitions to the leaf map or changing | 6795 // This includes adding transitions to the leaf map or changing |
6803 // the descriptor array. | 6796 // the descriptor array. |
6804 inline void NotifyLeafMapLayoutChange(); | 6797 inline void NotifyLeafMapLayoutChange(); |
6805 | 6798 |
6806 static Handle<Map> TransitionElementsToSlow(Handle<Map> object, | 6799 static Handle<Map> TransitionElementsToSlow(Handle<Map> object, |
6807 ElementsKind to_kind); | 6800 ElementsKind to_kind); |
6808 | 6801 |
6809 // Zaps the contents of backing data structures. Note that the | 6802 // Zaps the contents of backing data structures. Note that the |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7773 DECL_ACCESSORS(literals_or_bindings, FixedArray) | 7766 DECL_ACCESSORS(literals_or_bindings, FixedArray) |
7774 | 7767 |
7775 inline FixedArray* literals(); | 7768 inline FixedArray* literals(); |
7776 inline void set_literals(FixedArray* literals); | 7769 inline void set_literals(FixedArray* literals); |
7777 | 7770 |
7778 inline FixedArray* function_bindings(); | 7771 inline FixedArray* function_bindings(); |
7779 inline void set_function_bindings(FixedArray* bindings); | 7772 inline void set_function_bindings(FixedArray* bindings); |
7780 | 7773 |
7781 // The initial map for an object created by this constructor. | 7774 // The initial map for an object created by this constructor. |
7782 inline Map* initial_map(); | 7775 inline Map* initial_map(); |
7783 static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map); | 7776 static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map, |
| 7777 Handle<Object> prototype); |
7784 inline bool has_initial_map(); | 7778 inline bool has_initial_map(); |
7785 static void EnsureHasInitialMap(Handle<JSFunction> function); | 7779 static void EnsureHasInitialMap(Handle<JSFunction> function); |
7786 | 7780 |
7787 // Get and set the prototype property on a JSFunction. If the | 7781 // Get and set the prototype property on a JSFunction. If the |
7788 // function has an initial map the prototype is set on the initial | 7782 // function has an initial map the prototype is set on the initial |
7789 // map. Otherwise, the prototype is put in the initial map field | 7783 // map. Otherwise, the prototype is put in the initial map field |
7790 // until an initial map is needed. | 7784 // until an initial map is needed. |
7791 inline bool has_prototype(); | 7785 inline bool has_prototype(); |
7792 inline bool has_instance_prototype(); | 7786 inline bool has_instance_prototype(); |
7793 inline Object* prototype(); | 7787 inline Object* prototype(); |
(...skipping 3476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11270 } else { | 11264 } else { |
11271 value &= ~(1 << bit_position); | 11265 value &= ~(1 << bit_position); |
11272 } | 11266 } |
11273 return value; | 11267 return value; |
11274 } | 11268 } |
11275 }; | 11269 }; |
11276 | 11270 |
11277 } } // namespace v8::internal | 11271 } } // namespace v8::internal |
11278 | 11272 |
11279 #endif // V8_OBJECTS_H_ | 11273 #endif // V8_OBJECTS_H_ |
OLD | NEW |