OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 class LiteralsArray; | 847 class LiteralsArray; |
848 class LookupIterator; | 848 class LookupIterator; |
849 class ObjectHashTable; | 849 class ObjectHashTable; |
850 class ObjectVisitor; | 850 class ObjectVisitor; |
851 class PropertyCell; | 851 class PropertyCell; |
852 class PropertyDescriptor; | 852 class PropertyDescriptor; |
853 class SafepointEntry; | 853 class SafepointEntry; |
854 class SharedFunctionInfo; | 854 class SharedFunctionInfo; |
855 class StringStream; | 855 class StringStream; |
856 class TypeFeedbackInfo; | 856 class TypeFeedbackInfo; |
| 857 class TypeFeedbackMetadata; |
857 class TypeFeedbackVector; | 858 class TypeFeedbackVector; |
858 class WeakCell; | 859 class WeakCell; |
859 class TransitionArray; | 860 class TransitionArray; |
860 | 861 |
861 // We cannot just say "class HeapType;" if it is created from a template... =8-? | 862 // We cannot just say "class HeapType;" if it is created from a template... =8-? |
862 template<class> class TypeImpl; | 863 template<class> class TypeImpl; |
863 struct HeapTypeConfig; | 864 struct HeapTypeConfig; |
864 typedef TypeImpl<HeapTypeConfig> HeapType; | 865 typedef TypeImpl<HeapTypeConfig> HeapType; |
865 | 866 |
866 | 867 |
(...skipping 3779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4646 #endif | 4647 #endif |
4647 }; | 4648 }; |
4648 | 4649 |
4649 | 4650 |
4650 // A literals array contains the literals for a JSFunction. It also holds | 4651 // A literals array contains the literals for a JSFunction. It also holds |
4651 // the type feedback vector. | 4652 // the type feedback vector. |
4652 class LiteralsArray : public FixedArray { | 4653 class LiteralsArray : public FixedArray { |
4653 public: | 4654 public: |
4654 static const int kVectorIndex = 0; | 4655 static const int kVectorIndex = 0; |
4655 static const int kFirstLiteralIndex = 1; | 4656 static const int kFirstLiteralIndex = 1; |
4656 static const int kOffsetToFirstLiteral = | 4657 static const int kFeedbackVectorOffset = FixedArray::kHeaderSize; |
4657 FixedArray::kHeaderSize + kPointerSize; | 4658 static const int kOffsetToFirstLiteral = kFeedbackVectorOffset + kPointerSize; |
4658 | 4659 |
4659 static int OffsetOfLiteralAt(int index) { | 4660 static int OffsetOfLiteralAt(int index) { |
4660 return SizeFor(index + kFirstLiteralIndex); | 4661 return SizeFor(index + kFirstLiteralIndex); |
4661 } | 4662 } |
4662 | 4663 |
4663 inline TypeFeedbackVector* feedback_vector() const; | 4664 inline TypeFeedbackVector* feedback_vector() const; |
4664 inline void set_feedback_vector(TypeFeedbackVector* vector); | 4665 inline void set_feedback_vector(TypeFeedbackVector* vector); |
4665 inline Object* literal(int literal_index) const; | 4666 inline Object* literal(int literal_index) const; |
4666 inline void set_literal(int literal_index, Object* literal); | 4667 inline void set_literal(int literal_index, Object* literal); |
| 4668 inline void set_literal_undefined(int literal_index); |
4667 inline int literals_count() const; | 4669 inline int literals_count() const; |
4668 | 4670 |
4669 static Handle<LiteralsArray> New(Isolate* isolate, | 4671 static Handle<LiteralsArray> New(Isolate* isolate, |
4670 Handle<TypeFeedbackVector> vector, | 4672 Handle<TypeFeedbackVector> vector, |
4671 int number_of_literals, | 4673 int number_of_literals, |
4672 PretenureFlag pretenure); | 4674 PretenureFlag pretenure); |
4673 | 4675 |
4674 DECLARE_CAST(LiteralsArray) | 4676 DECLARE_CAST(LiteralsArray) |
4675 | 4677 |
4676 private: | 4678 private: |
(...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6478 // Returns entry from optimized code map for specified context and OSR entry. | 6480 // Returns entry from optimized code map for specified context and OSR entry. |
6479 // Note that {code == nullptr, literals == nullptr} indicates no matching | 6481 // Note that {code == nullptr, literals == nullptr} indicates no matching |
6480 // entry has been found, whereas {code, literals == nullptr} indicates that | 6482 // entry has been found, whereas {code, literals == nullptr} indicates that |
6481 // code is context-independent. | 6483 // code is context-independent. |
6482 CodeAndLiterals SearchOptimizedCodeMap(Context* native_context, | 6484 CodeAndLiterals SearchOptimizedCodeMap(Context* native_context, |
6483 BailoutId osr_ast_id); | 6485 BailoutId osr_ast_id); |
6484 | 6486 |
6485 // Clear optimized code map. | 6487 // Clear optimized code map. |
6486 void ClearOptimizedCodeMap(); | 6488 void ClearOptimizedCodeMap(); |
6487 | 6489 |
| 6490 // Like ClearOptimizedCodeMap, but preserves literals. |
| 6491 void ClearCodeFromOptimizedCodeMap(); |
| 6492 |
6488 // We have a special root FixedArray with the right shape and values | 6493 // We have a special root FixedArray with the right shape and values |
6489 // to represent the cleared optimized code map. This predicate checks | 6494 // to represent the cleared optimized code map. This predicate checks |
6490 // if that root is installed. | 6495 // if that root is installed. |
6491 inline bool OptimizedCodeMapIsCleared() const; | 6496 inline bool OptimizedCodeMapIsCleared() const; |
6492 | 6497 |
6493 // Removes a specific optimized code object from the optimized code map. | 6498 // Removes a specific optimized code object from the optimized code map. |
6494 // In case of non-OSR the code reference is cleared from the cache entry but | 6499 // In case of non-OSR the code reference is cleared from the cache entry but |
6495 // the entry itself is left in the map in order to proceed sharing literals. | 6500 // the entry itself is left in the map in order to proceed sharing literals. |
6496 void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason); | 6501 void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason); |
6497 | 6502 |
6498 // Trims the optimized code map after entries have been removed. | 6503 // Trims the optimized code map after entries have been removed. |
6499 void TrimOptimizedCodeMap(int shrink_by); | 6504 void TrimOptimizedCodeMap(int shrink_by); |
6500 | 6505 |
| 6506 static Handle<LiteralsArray> FindOrCreateLiterals( |
| 6507 Handle<SharedFunctionInfo> shared, Handle<Context> native_context); |
| 6508 |
6501 // Add a new entry to the optimized code map for context-independent code. | 6509 // Add a new entry to the optimized code map for context-independent code. |
6502 static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, | 6510 static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
6503 Handle<Code> code); | 6511 Handle<Code> code); |
6504 | 6512 |
6505 // Add a new entry to the optimized code map for context-dependent code. | 6513 // Add a new entry to the optimized code map for context-dependent code. |
6506 inline static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, | 6514 inline static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
6507 Handle<Context> native_context, | 6515 Handle<Context> native_context, |
6508 Handle<Code> code, | 6516 Handle<Code> code, |
6509 Handle<LiteralsArray> literals, | 6517 Handle<LiteralsArray> literals, |
6510 BailoutId osr_ast_id); | 6518 BailoutId osr_ast_id); |
(...skipping 14 matching lines...) Expand all Loading... |
6525 static const int kEntriesStart = 1; | 6533 static const int kEntriesStart = 1; |
6526 static const int kContextOffset = 0; | 6534 static const int kContextOffset = 0; |
6527 static const int kCachedCodeOffset = 1; | 6535 static const int kCachedCodeOffset = 1; |
6528 static const int kLiteralsOffset = 2; | 6536 static const int kLiteralsOffset = 2; |
6529 static const int kOsrAstIdOffset = 3; | 6537 static const int kOsrAstIdOffset = 3; |
6530 static const int kEntryLength = 4; | 6538 static const int kEntryLength = 4; |
6531 static const int kInitialLength = kEntriesStart + kEntryLength; | 6539 static const int kInitialLength = kEntriesStart + kEntryLength; |
6532 | 6540 |
6533 static const int kNotFound = -1; | 6541 static const int kNotFound = -1; |
6534 | 6542 |
| 6543 // Helpers for assembly code that does a backwards walk of the optimized code |
| 6544 // map. |
| 6545 static inline int OffsetToPreviousContext(); |
| 6546 static inline int OffsetToPreviousCachedCode(); |
| 6547 static inline int OffsetToPreviousLiterals(); |
| 6548 static inline int OffsetToPreviousOsrAstId(); |
| 6549 |
6535 // [scope_info]: Scope info. | 6550 // [scope_info]: Scope info. |
6536 DECL_ACCESSORS(scope_info, ScopeInfo) | 6551 DECL_ACCESSORS(scope_info, ScopeInfo) |
6537 | 6552 |
6538 // [construct stub]: Code stub for constructing instances of this function. | 6553 // [construct stub]: Code stub for constructing instances of this function. |
6539 DECL_ACCESSORS(construct_stub, Code) | 6554 DECL_ACCESSORS(construct_stub, Code) |
6540 | 6555 |
6541 // Returns if this function has been compiled to native code yet. | 6556 // Returns if this function has been compiled to native code yet. |
6542 inline bool is_compiled(); | 6557 inline bool is_compiled(); |
6543 | 6558 |
6544 // [length]: The function length - usually the number of declared parameters. | 6559 // [length]: The function length - usually the number of declared parameters. |
6545 // Use up to 2^30 parameters. | 6560 // Use up to 2^30 parameters. |
6546 inline int length() const; | 6561 inline int length() const; |
6547 inline void set_length(int value); | 6562 inline void set_length(int value); |
6548 | 6563 |
6549 // [internal formal parameter count]: The declared number of parameters. | 6564 // [internal formal parameter count]: The declared number of parameters. |
6550 // For subclass constructors, also includes new.target. | 6565 // For subclass constructors, also includes new.target. |
6551 // The size of function's frame is internal_formal_parameter_count + 1. | 6566 // The size of function's frame is internal_formal_parameter_count + 1. |
6552 inline int internal_formal_parameter_count() const; | 6567 inline int internal_formal_parameter_count() const; |
6553 inline void set_internal_formal_parameter_count(int value); | 6568 inline void set_internal_formal_parameter_count(int value); |
6554 | 6569 |
6555 // Set the formal parameter count so the function code will be | 6570 // Set the formal parameter count so the function code will be |
6556 // called without using argument adaptor frames. | 6571 // called without using argument adaptor frames. |
6557 inline void DontAdaptArguments(); | 6572 inline void DontAdaptArguments(); |
6558 | 6573 |
6559 // [expected_nof_properties]: Expected number of properties for the function. | 6574 // [expected_nof_properties]: Expected number of properties for the function. |
6560 inline int expected_nof_properties() const; | 6575 inline int expected_nof_properties() const; |
6561 inline void set_expected_nof_properties(int value); | 6576 inline void set_expected_nof_properties(int value); |
6562 | 6577 |
6563 // [feedback_vector] - accumulates ast node feedback from full-codegen and | 6578 // [feedback_metadata] - describes ast node feedback from full-codegen and |
6564 // (increasingly) from crankshafted code where sufficient feedback isn't | 6579 // (increasingly) from crankshafted code where sufficient feedback isn't |
6565 // available. | 6580 // available. |
6566 DECL_ACCESSORS(feedback_vector, TypeFeedbackVector) | 6581 DECL_ACCESSORS(feedback_metadata, TypeFeedbackMetadata) |
6567 | |
6568 // Unconditionally clear the type feedback vector (including vector ICs). | |
6569 void ClearTypeFeedbackInfo(); | |
6570 | |
6571 // Clear the type feedback vector with a more subtle policy at GC time. | |
6572 void ClearTypeFeedbackInfoAtGCTime(); | |
6573 | 6582 |
6574 #if TRACE_MAPS | 6583 #if TRACE_MAPS |
6575 // [unique_id] - For --trace-maps purposes, an identifier that's persistent | 6584 // [unique_id] - For --trace-maps purposes, an identifier that's persistent |
6576 // even if the GC moves this SharedFunctionInfo. | 6585 // even if the GC moves this SharedFunctionInfo. |
6577 inline int unique_id() const; | 6586 inline int unique_id() const; |
6578 inline void set_unique_id(int value); | 6587 inline void set_unique_id(int value); |
6579 #endif | 6588 #endif |
6580 | 6589 |
6581 // [instance class name]: class name for instances. | 6590 // [instance class name]: class name for instances. |
6582 DECL_ACCESSORS(instance_class_name, Object) | 6591 DECL_ACCESSORS(instance_class_name, Object) |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6856 static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize; | 6865 static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize; |
6857 static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize; | 6866 static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize; |
6858 static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; | 6867 static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
6859 static const int kInstanceClassNameOffset = | 6868 static const int kInstanceClassNameOffset = |
6860 kConstructStubOffset + kPointerSize; | 6869 kConstructStubOffset + kPointerSize; |
6861 static const int kFunctionDataOffset = | 6870 static const int kFunctionDataOffset = |
6862 kInstanceClassNameOffset + kPointerSize; | 6871 kInstanceClassNameOffset + kPointerSize; |
6863 static const int kScriptOffset = kFunctionDataOffset + kPointerSize; | 6872 static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
6864 static const int kDebugInfoOffset = kScriptOffset + kPointerSize; | 6873 static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
6865 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; | 6874 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
6866 static const int kFeedbackVectorOffset = | 6875 static const int kFeedbackMetadataOffset = kInferredNameOffset + kPointerSize; |
6867 kInferredNameOffset + kPointerSize; | |
6868 #if TRACE_MAPS | 6876 #if TRACE_MAPS |
6869 static const int kUniqueIdOffset = kFeedbackVectorOffset + kPointerSize; | 6877 static const int kUniqueIdOffset = kFeedbackMetadataOffset + kPointerSize; |
6870 static const int kLastPointerFieldOffset = kUniqueIdOffset; | 6878 static const int kLastPointerFieldOffset = kUniqueIdOffset; |
6871 #else | 6879 #else |
6872 // Just to not break the postmortrem support with conditional offsets | 6880 // Just to not break the postmortrem support with conditional offsets |
6873 static const int kUniqueIdOffset = kFeedbackVectorOffset; | 6881 static const int kUniqueIdOffset = kFeedbackMetadataOffset; |
6874 static const int kLastPointerFieldOffset = kFeedbackVectorOffset; | 6882 static const int kLastPointerFieldOffset = kFeedbackMetadataOffset; |
6875 #endif | 6883 #endif |
6876 | 6884 |
6877 #if V8_HOST_ARCH_32_BIT | 6885 #if V8_HOST_ARCH_32_BIT |
6878 // Smi fields. | 6886 // Smi fields. |
6879 static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; | 6887 static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; |
6880 static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; | 6888 static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
6881 static const int kExpectedNofPropertiesOffset = | 6889 static const int kExpectedNofPropertiesOffset = |
6882 kFormalParameterCountOffset + kPointerSize; | 6890 kFormalParameterCountOffset + kPointerSize; |
6883 static const int kNumLiteralsOffset = | 6891 static const int kNumLiteralsOffset = |
6884 kExpectedNofPropertiesOffset + kPointerSize; | 6892 kExpectedNofPropertiesOffset + kPointerSize; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7289 static Handle<Context> GetFunctionRealm(Handle<JSFunction> function); | 7297 static Handle<Context> GetFunctionRealm(Handle<JSFunction> function); |
7290 | 7298 |
7291 // [code]: The generated code object for this function. Executed | 7299 // [code]: The generated code object for this function. Executed |
7292 // when the function is invoked, e.g. foo() or new foo(). See | 7300 // when the function is invoked, e.g. foo() or new foo(). See |
7293 // [[Call]] and [[Construct]] description in ECMA-262, section | 7301 // [[Call]] and [[Construct]] description in ECMA-262, section |
7294 // 8.6.2, page 27. | 7302 // 8.6.2, page 27. |
7295 inline Code* code(); | 7303 inline Code* code(); |
7296 inline void set_code(Code* code); | 7304 inline void set_code(Code* code); |
7297 inline void set_code_no_write_barrier(Code* code); | 7305 inline void set_code_no_write_barrier(Code* code); |
7298 inline void ReplaceCode(Code* code); | 7306 inline void ReplaceCode(Code* code); |
| 7307 static void EnsureLiterals(Handle<JSFunction> function); |
7299 | 7308 |
7300 // Tells whether this function inlines the given shared function info. | 7309 // Tells whether this function inlines the given shared function info. |
7301 bool Inlines(SharedFunctionInfo* candidate); | 7310 bool Inlines(SharedFunctionInfo* candidate); |
7302 | 7311 |
7303 // Tells whether or not this function has been optimized. | 7312 // Tells whether or not this function has been optimized. |
7304 inline bool IsOptimized(); | 7313 inline bool IsOptimized(); |
7305 | 7314 |
7306 // Mark this function for lazy recompilation. The function will be | 7315 // Mark this function for lazy recompilation. The function will be |
7307 // recompiled the next time it is executed. | 7316 // recompiled the next time it is executed. |
7308 void MarkForOptimization(); | 7317 void MarkForOptimization(); |
7309 void AttemptConcurrentOptimization(); | 7318 void AttemptConcurrentOptimization(); |
7310 | 7319 |
7311 // Tells whether or not the function is already marked for lazy | 7320 // Tells whether or not the function is already marked for lazy |
7312 // recompilation. | 7321 // recompilation. |
7313 inline bool IsMarkedForOptimization(); | 7322 inline bool IsMarkedForOptimization(); |
7314 inline bool IsMarkedForConcurrentOptimization(); | 7323 inline bool IsMarkedForConcurrentOptimization(); |
7315 | 7324 |
7316 // Tells whether or not the function is on the concurrent recompilation queue. | 7325 // Tells whether or not the function is on the concurrent recompilation queue. |
7317 inline bool IsInOptimizationQueue(); | 7326 inline bool IsInOptimizationQueue(); |
7318 | 7327 |
| 7328 // Unconditionally clear the type feedback vector (including vector ICs). |
| 7329 void ClearTypeFeedbackInfo(); |
| 7330 |
| 7331 // Clear the type feedback vector with a more subtle policy at GC time. |
| 7332 void ClearTypeFeedbackInfoAtGCTime(); |
| 7333 |
7319 // Completes inobject slack tracking on initial map if it is active. | 7334 // Completes inobject slack tracking on initial map if it is active. |
7320 inline void CompleteInobjectSlackTrackingIfActive(); | 7335 inline void CompleteInobjectSlackTrackingIfActive(); |
7321 | 7336 |
7322 // [literals]: Fixed array holding the materialized literals. | 7337 // [literals]: Fixed array holding the materialized literals. |
7323 // | 7338 // |
7324 // If the function contains object, regexp or array literals, the | 7339 // If the function contains object, regexp or array literals, the |
7325 // literals array prefix contains the object, regexp, and array | 7340 // literals array prefix contains the object, regexp, and array |
7326 // function to be used when creating these literals. This is | 7341 // function to be used when creating these literals. This is |
7327 // necessary so that we do not dynamically lookup the object, regexp | 7342 // necessary so that we do not dynamically lookup the object, regexp |
7328 // or array functions. Performing a dynamic lookup, we might end up | 7343 // or array functions. Performing a dynamic lookup, we might end up |
7329 // using the functions from a new context that we should not have | 7344 // using the functions from a new context that we should not have |
7330 // access to. | 7345 // access to. |
7331 DECL_ACCESSORS(literals, LiteralsArray) | 7346 DECL_ACCESSORS(literals, LiteralsArray) |
7332 | 7347 |
| 7348 inline TypeFeedbackVector* feedback_vector(); |
| 7349 |
7333 // The initial map for an object created by this constructor. | 7350 // The initial map for an object created by this constructor. |
7334 inline Map* initial_map(); | 7351 inline Map* initial_map(); |
7335 static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map, | 7352 static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map, |
7336 Handle<Object> prototype); | 7353 Handle<Object> prototype); |
7337 inline bool has_initial_map(); | 7354 inline bool has_initial_map(); |
7338 static void EnsureHasInitialMap(Handle<JSFunction> function); | 7355 static void EnsureHasInitialMap(Handle<JSFunction> function); |
7339 | 7356 |
7340 // Creates a map that matches the constructor's initial map, but with | 7357 // Creates a map that matches the constructor's initial map, but with |
7341 // [[prototype]] being new.target.prototype. Because new.target can be a | 7358 // [[prototype]] being new.target.prototype. Because new.target can be a |
7342 // JSProxy, this can call back into JavaScript. | 7359 // JSProxy, this can call back into JavaScript. |
(...skipping 3396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10739 } | 10756 } |
10740 return value; | 10757 return value; |
10741 } | 10758 } |
10742 }; | 10759 }; |
10743 | 10760 |
10744 | 10761 |
10745 } // NOLINT, false-positive due to second-order macros. | 10762 } // NOLINT, false-positive due to second-order macros. |
10746 } // NOLINT, false-positive due to second-order macros. | 10763 } // NOLINT, false-positive due to second-order macros. |
10747 | 10764 |
10748 #endif // V8_OBJECTS_H_ | 10765 #endif // V8_OBJECTS_H_ |
OLD | NEW |