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 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 class LiteralsArray; | 841 class LiteralsArray; |
842 class LookupIterator; | 842 class LookupIterator; |
843 class ObjectHashTable; | 843 class ObjectHashTable; |
844 class ObjectVisitor; | 844 class ObjectVisitor; |
845 class PropertyCell; | 845 class PropertyCell; |
846 class PropertyDescriptor; | 846 class PropertyDescriptor; |
847 class SafepointEntry; | 847 class SafepointEntry; |
848 class SharedFunctionInfo; | 848 class SharedFunctionInfo; |
849 class StringStream; | 849 class StringStream; |
850 class TypeFeedbackInfo; | 850 class TypeFeedbackInfo; |
851 class TypeFeedbackMetadata; | |
852 class TypeFeedbackVector; | 851 class TypeFeedbackVector; |
853 class WeakCell; | 852 class WeakCell; |
854 class TransitionArray; | 853 class TransitionArray; |
855 | 854 |
856 // We cannot just say "class HeapType;" if it is created from a template... =8-? | 855 // We cannot just say "class HeapType;" if it is created from a template... =8-? |
857 template<class> class TypeImpl; | 856 template<class> class TypeImpl; |
858 struct HeapTypeConfig; | 857 struct HeapTypeConfig; |
859 typedef TypeImpl<HeapTypeConfig> HeapType; | 858 typedef TypeImpl<HeapTypeConfig> HeapType; |
860 | 859 |
861 | 860 |
(...skipping 3846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4708 #endif | 4707 #endif |
4709 }; | 4708 }; |
4710 | 4709 |
4711 | 4710 |
4712 // A literals array contains the literals for a JSFunction. It also holds | 4711 // A literals array contains the literals for a JSFunction. It also holds |
4713 // the type feedback vector. | 4712 // the type feedback vector. |
4714 class LiteralsArray : public FixedArray { | 4713 class LiteralsArray : public FixedArray { |
4715 public: | 4714 public: |
4716 static const int kVectorIndex = 0; | 4715 static const int kVectorIndex = 0; |
4717 static const int kFirstLiteralIndex = 1; | 4716 static const int kFirstLiteralIndex = 1; |
4718 static const int kFeedbackVectorOffset = FixedArray::kHeaderSize; | 4717 static const int kOffsetToFirstLiteral = |
4719 static const int kOffsetToFirstLiteral = kFeedbackVectorOffset + kPointerSize; | 4718 FixedArray::kHeaderSize + kPointerSize; |
4720 | 4719 |
4721 static int OffsetOfLiteralAt(int index) { | 4720 static int OffsetOfLiteralAt(int index) { |
4722 return SizeFor(index + kFirstLiteralIndex); | 4721 return SizeFor(index + kFirstLiteralIndex); |
4723 } | 4722 } |
4724 | 4723 |
4725 inline TypeFeedbackVector* feedback_vector() const; | 4724 inline TypeFeedbackVector* feedback_vector() const; |
4726 inline void set_feedback_vector(TypeFeedbackVector* vector); | 4725 inline void set_feedback_vector(TypeFeedbackVector* vector); |
4727 inline Object* literal(int literal_index) const; | 4726 inline Object* literal(int literal_index) const; |
4728 inline void set_literal(int literal_index, Object* literal); | 4727 inline void set_literal(int literal_index, Object* literal); |
4729 inline void set_literal_undefined(int literal_index); | |
4730 inline int literals_count() const; | 4728 inline int literals_count() const; |
4731 | 4729 |
4732 static Handle<LiteralsArray> New(Isolate* isolate, | 4730 static Handle<LiteralsArray> New(Isolate* isolate, |
4733 Handle<TypeFeedbackVector> vector, | 4731 Handle<TypeFeedbackVector> vector, |
4734 int number_of_literals, | 4732 int number_of_literals, |
4735 PretenureFlag pretenure); | 4733 PretenureFlag pretenure); |
4736 | 4734 |
4737 DECLARE_CAST(LiteralsArray) | 4735 DECLARE_CAST(LiteralsArray) |
4738 | 4736 |
4739 private: | 4737 private: |
(...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6541 // Returns entry from optimized code map for specified context and OSR entry. | 6539 // Returns entry from optimized code map for specified context and OSR entry. |
6542 // Note that {code == nullptr, literals == nullptr} indicates no matching | 6540 // Note that {code == nullptr, literals == nullptr} indicates no matching |
6543 // entry has been found, whereas {code, literals == nullptr} indicates that | 6541 // entry has been found, whereas {code, literals == nullptr} indicates that |
6544 // code is context-independent. | 6542 // code is context-independent. |
6545 CodeAndLiterals SearchOptimizedCodeMap(Context* native_context, | 6543 CodeAndLiterals SearchOptimizedCodeMap(Context* native_context, |
6546 BailoutId osr_ast_id); | 6544 BailoutId osr_ast_id); |
6547 | 6545 |
6548 // Clear optimized code map. | 6546 // Clear optimized code map. |
6549 void ClearOptimizedCodeMap(); | 6547 void ClearOptimizedCodeMap(); |
6550 | 6548 |
6551 // Like ClearOptimizedCodeMap, but preserves literals. | |
6552 void ClearCodeFromOptimizedCodeMap(); | |
6553 | |
6554 // We have a special root FixedArray with the right shape and values | 6549 // We have a special root FixedArray with the right shape and values |
6555 // to represent the cleared optimized code map. This predicate checks | 6550 // to represent the cleared optimized code map. This predicate checks |
6556 // if that root is installed. | 6551 // if that root is installed. |
6557 inline bool OptimizedCodeMapIsCleared() const; | 6552 inline bool OptimizedCodeMapIsCleared() const; |
6558 | 6553 |
6559 // Removes a specific optimized code object from the optimized code map. | 6554 // Removes a specific optimized code object from the optimized code map. |
6560 // In case of non-OSR the code reference is cleared from the cache entry but | 6555 // In case of non-OSR the code reference is cleared from the cache entry but |
6561 // the entry itself is left in the map in order to proceed sharing literals. | 6556 // the entry itself is left in the map in order to proceed sharing literals. |
6562 void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason); | 6557 void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason); |
6563 | 6558 |
6564 // Trims the optimized code map after entries have been removed. | 6559 // Trims the optimized code map after entries have been removed. |
6565 void TrimOptimizedCodeMap(int shrink_by); | 6560 void TrimOptimizedCodeMap(int shrink_by); |
6566 | 6561 |
6567 static Handle<LiteralsArray> FindOrCreateLiterals( | |
6568 Handle<SharedFunctionInfo> shared, Handle<Context> native_context); | |
6569 | |
6570 // Add a new entry to the optimized code map for context-independent code. | 6562 // Add a new entry to the optimized code map for context-independent code. |
6571 static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, | 6563 static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
6572 Handle<Code> code); | 6564 Handle<Code> code); |
6573 | 6565 |
6574 // Add a new entry to the optimized code map for context-dependent code. | 6566 // Add a new entry to the optimized code map for context-dependent code. |
6575 inline static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, | 6567 inline static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
6576 Handle<Context> native_context, | 6568 Handle<Context> native_context, |
6577 Handle<Code> code, | 6569 Handle<Code> code, |
6578 Handle<LiteralsArray> literals, | 6570 Handle<LiteralsArray> literals, |
6579 BailoutId osr_ast_id); | 6571 BailoutId osr_ast_id); |
(...skipping 14 matching lines...) Expand all Loading... |
6594 static const int kEntriesStart = 1; | 6586 static const int kEntriesStart = 1; |
6595 static const int kContextOffset = 0; | 6587 static const int kContextOffset = 0; |
6596 static const int kCachedCodeOffset = 1; | 6588 static const int kCachedCodeOffset = 1; |
6597 static const int kLiteralsOffset = 2; | 6589 static const int kLiteralsOffset = 2; |
6598 static const int kOsrAstIdOffset = 3; | 6590 static const int kOsrAstIdOffset = 3; |
6599 static const int kEntryLength = 4; | 6591 static const int kEntryLength = 4; |
6600 static const int kInitialLength = kEntriesStart + kEntryLength; | 6592 static const int kInitialLength = kEntriesStart + kEntryLength; |
6601 | 6593 |
6602 static const int kNotFound = -1; | 6594 static const int kNotFound = -1; |
6603 | 6595 |
6604 // Helpers for assembly code that does a backwards walk of the optimized code | |
6605 // map. | |
6606 static inline int OffsetToPreviousContext(); | |
6607 static inline int OffsetToPreviousCachedCode(); | |
6608 static inline int OffsetToPreviousLiterals(); | |
6609 static inline int OffsetToPreviousOsrAstId(); | |
6610 | |
6611 // [scope_info]: Scope info. | 6596 // [scope_info]: Scope info. |
6612 DECL_ACCESSORS(scope_info, ScopeInfo) | 6597 DECL_ACCESSORS(scope_info, ScopeInfo) |
6613 | 6598 |
6614 // [construct stub]: Code stub for constructing instances of this function. | 6599 // [construct stub]: Code stub for constructing instances of this function. |
6615 DECL_ACCESSORS(construct_stub, Code) | 6600 DECL_ACCESSORS(construct_stub, Code) |
6616 | 6601 |
6617 // Returns if this function has been compiled to native code yet. | 6602 // Returns if this function has been compiled to native code yet. |
6618 inline bool is_compiled(); | 6603 inline bool is_compiled(); |
6619 | 6604 |
6620 // [length]: The function length - usually the number of declared parameters. | 6605 // [length]: The function length - usually the number of declared parameters. |
6621 // Use up to 2^30 parameters. | 6606 // Use up to 2^30 parameters. |
6622 inline int length() const; | 6607 inline int length() const; |
6623 inline void set_length(int value); | 6608 inline void set_length(int value); |
6624 | 6609 |
6625 // [internal formal parameter count]: The declared number of parameters. | 6610 // [internal formal parameter count]: The declared number of parameters. |
6626 // For subclass constructors, also includes new.target. | 6611 // For subclass constructors, also includes new.target. |
6627 // The size of function's frame is internal_formal_parameter_count + 1. | 6612 // The size of function's frame is internal_formal_parameter_count + 1. |
6628 inline int internal_formal_parameter_count() const; | 6613 inline int internal_formal_parameter_count() const; |
6629 inline void set_internal_formal_parameter_count(int value); | 6614 inline void set_internal_formal_parameter_count(int value); |
6630 | 6615 |
6631 // Set the formal parameter count so the function code will be | 6616 // Set the formal parameter count so the function code will be |
6632 // called without using argument adaptor frames. | 6617 // called without using argument adaptor frames. |
6633 inline void DontAdaptArguments(); | 6618 inline void DontAdaptArguments(); |
6634 | 6619 |
6635 // [expected_nof_properties]: Expected number of properties for the function. | 6620 // [expected_nof_properties]: Expected number of properties for the function. |
6636 inline int expected_nof_properties() const; | 6621 inline int expected_nof_properties() const; |
6637 inline void set_expected_nof_properties(int value); | 6622 inline void set_expected_nof_properties(int value); |
6638 | 6623 |
6639 // [feedback_metadata] - describes ast node feedback from full-codegen and | 6624 // [feedback_vector] - accumulates ast node feedback from full-codegen and |
6640 // (increasingly) from crankshafted code where sufficient feedback isn't | 6625 // (increasingly) from crankshafted code where sufficient feedback isn't |
6641 // available. | 6626 // available. |
6642 DECL_ACCESSORS(feedback_metadata, TypeFeedbackMetadata) | 6627 DECL_ACCESSORS(feedback_vector, TypeFeedbackVector) |
| 6628 |
| 6629 // Unconditionally clear the type feedback vector (including vector ICs). |
| 6630 void ClearTypeFeedbackInfo(); |
| 6631 |
| 6632 // Clear the type feedback vector with a more subtle policy at GC time. |
| 6633 void ClearTypeFeedbackInfoAtGCTime(); |
6643 | 6634 |
6644 #if TRACE_MAPS | 6635 #if TRACE_MAPS |
6645 // [unique_id] - For --trace-maps purposes, an identifier that's persistent | 6636 // [unique_id] - For --trace-maps purposes, an identifier that's persistent |
6646 // even if the GC moves this SharedFunctionInfo. | 6637 // even if the GC moves this SharedFunctionInfo. |
6647 inline int unique_id() const; | 6638 inline int unique_id() const; |
6648 inline void set_unique_id(int value); | 6639 inline void set_unique_id(int value); |
6649 #endif | 6640 #endif |
6650 | 6641 |
6651 // [instance class name]: class name for instances. | 6642 // [instance class name]: class name for instances. |
6652 DECL_ACCESSORS(instance_class_name, Object) | 6643 DECL_ACCESSORS(instance_class_name, Object) |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6926 static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize; | 6917 static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize; |
6927 static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize; | 6918 static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize; |
6928 static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; | 6919 static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
6929 static const int kInstanceClassNameOffset = | 6920 static const int kInstanceClassNameOffset = |
6930 kConstructStubOffset + kPointerSize; | 6921 kConstructStubOffset + kPointerSize; |
6931 static const int kFunctionDataOffset = | 6922 static const int kFunctionDataOffset = |
6932 kInstanceClassNameOffset + kPointerSize; | 6923 kInstanceClassNameOffset + kPointerSize; |
6933 static const int kScriptOffset = kFunctionDataOffset + kPointerSize; | 6924 static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
6934 static const int kDebugInfoOffset = kScriptOffset + kPointerSize; | 6925 static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
6935 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; | 6926 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
6936 static const int kFeedbackMetadataOffset = kInferredNameOffset + kPointerSize; | 6927 static const int kFeedbackVectorOffset = |
| 6928 kInferredNameOffset + kPointerSize; |
6937 #if TRACE_MAPS | 6929 #if TRACE_MAPS |
6938 static const int kUniqueIdOffset = kFeedbackMetadataOffset + kPointerSize; | 6930 static const int kUniqueIdOffset = kFeedbackVectorOffset + kPointerSize; |
6939 static const int kLastPointerFieldOffset = kUniqueIdOffset; | 6931 static const int kLastPointerFieldOffset = kUniqueIdOffset; |
6940 #else | 6932 #else |
6941 // Just to not break the postmortrem support with conditional offsets | 6933 // Just to not break the postmortrem support with conditional offsets |
6942 static const int kUniqueIdOffset = kFeedbackMetadataOffset; | 6934 static const int kUniqueIdOffset = kFeedbackVectorOffset; |
6943 static const int kLastPointerFieldOffset = kFeedbackMetadataOffset; | 6935 static const int kLastPointerFieldOffset = kFeedbackVectorOffset; |
6944 #endif | 6936 #endif |
6945 | 6937 |
6946 #if V8_HOST_ARCH_32_BIT | 6938 #if V8_HOST_ARCH_32_BIT |
6947 // Smi fields. | 6939 // Smi fields. |
6948 static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; | 6940 static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; |
6949 static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; | 6941 static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
6950 static const int kExpectedNofPropertiesOffset = | 6942 static const int kExpectedNofPropertiesOffset = |
6951 kFormalParameterCountOffset + kPointerSize; | 6943 kFormalParameterCountOffset + kPointerSize; |
6952 static const int kNumLiteralsOffset = | 6944 static const int kNumLiteralsOffset = |
6953 kExpectedNofPropertiesOffset + kPointerSize; | 6945 kExpectedNofPropertiesOffset + kPointerSize; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7350 static Handle<Context> GetFunctionRealm(Handle<JSFunction> function); | 7342 static Handle<Context> GetFunctionRealm(Handle<JSFunction> function); |
7351 | 7343 |
7352 // [code]: The generated code object for this function. Executed | 7344 // [code]: The generated code object for this function. Executed |
7353 // when the function is invoked, e.g. foo() or new foo(). See | 7345 // when the function is invoked, e.g. foo() or new foo(). See |
7354 // [[Call]] and [[Construct]] description in ECMA-262, section | 7346 // [[Call]] and [[Construct]] description in ECMA-262, section |
7355 // 8.6.2, page 27. | 7347 // 8.6.2, page 27. |
7356 inline Code* code(); | 7348 inline Code* code(); |
7357 inline void set_code(Code* code); | 7349 inline void set_code(Code* code); |
7358 inline void set_code_no_write_barrier(Code* code); | 7350 inline void set_code_no_write_barrier(Code* code); |
7359 inline void ReplaceCode(Code* code); | 7351 inline void ReplaceCode(Code* code); |
7360 static void EnsureLiterals(Handle<JSFunction> function); | |
7361 | 7352 |
7362 // Tells whether this function inlines the given shared function info. | 7353 // Tells whether this function inlines the given shared function info. |
7363 bool Inlines(SharedFunctionInfo* candidate); | 7354 bool Inlines(SharedFunctionInfo* candidate); |
7364 | 7355 |
7365 // Tells whether or not this function has been optimized. | 7356 // Tells whether or not this function has been optimized. |
7366 inline bool IsOptimized(); | 7357 inline bool IsOptimized(); |
7367 | 7358 |
7368 // Mark this function for lazy recompilation. The function will be | 7359 // Mark this function for lazy recompilation. The function will be |
7369 // recompiled the next time it is executed. | 7360 // recompiled the next time it is executed. |
7370 void MarkForOptimization(); | 7361 void MarkForOptimization(); |
7371 void AttemptConcurrentOptimization(); | 7362 void AttemptConcurrentOptimization(); |
7372 | 7363 |
7373 // Tells whether or not the function is already marked for lazy | 7364 // Tells whether or not the function is already marked for lazy |
7374 // recompilation. | 7365 // recompilation. |
7375 inline bool IsMarkedForOptimization(); | 7366 inline bool IsMarkedForOptimization(); |
7376 inline bool IsMarkedForConcurrentOptimization(); | 7367 inline bool IsMarkedForConcurrentOptimization(); |
7377 | 7368 |
7378 // Tells whether or not the function is on the concurrent recompilation queue. | 7369 // Tells whether or not the function is on the concurrent recompilation queue. |
7379 inline bool IsInOptimizationQueue(); | 7370 inline bool IsInOptimizationQueue(); |
7380 | 7371 |
7381 // Unconditionally clear the type feedback vector (including vector ICs). | |
7382 void ClearTypeFeedbackInfo(); | |
7383 | |
7384 // Clear the type feedback vector with a more subtle policy at GC time. | |
7385 void ClearTypeFeedbackInfoAtGCTime(); | |
7386 | |
7387 // Completes inobject slack tracking on initial map if it is active. | 7372 // Completes inobject slack tracking on initial map if it is active. |
7388 inline void CompleteInobjectSlackTrackingIfActive(); | 7373 inline void CompleteInobjectSlackTrackingIfActive(); |
7389 | 7374 |
7390 // [literals]: Fixed array holding the materialized literals. | 7375 // [literals]: Fixed array holding the materialized literals. |
7391 // | 7376 // |
7392 // If the function contains object, regexp or array literals, the | 7377 // If the function contains object, regexp or array literals, the |
7393 // literals array prefix contains the object, regexp, and array | 7378 // literals array prefix contains the object, regexp, and array |
7394 // function to be used when creating these literals. This is | 7379 // function to be used when creating these literals. This is |
7395 // necessary so that we do not dynamically lookup the object, regexp | 7380 // necessary so that we do not dynamically lookup the object, regexp |
7396 // or array functions. Performing a dynamic lookup, we might end up | 7381 // or array functions. Performing a dynamic lookup, we might end up |
7397 // using the functions from a new context that we should not have | 7382 // using the functions from a new context that we should not have |
7398 // access to. | 7383 // access to. |
7399 DECL_ACCESSORS(literals, LiteralsArray) | 7384 DECL_ACCESSORS(literals, LiteralsArray) |
7400 | 7385 |
7401 inline TypeFeedbackVector* feedback_vector(); | |
7402 | |
7403 // The initial map for an object created by this constructor. | 7386 // The initial map for an object created by this constructor. |
7404 inline Map* initial_map(); | 7387 inline Map* initial_map(); |
7405 static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map, | 7388 static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map, |
7406 Handle<Object> prototype); | 7389 Handle<Object> prototype); |
7407 inline bool has_initial_map(); | 7390 inline bool has_initial_map(); |
7408 static void EnsureHasInitialMap(Handle<JSFunction> function); | 7391 static void EnsureHasInitialMap(Handle<JSFunction> function); |
7409 | 7392 |
7410 // Creates a map that matches the constructor's initial map, but with | 7393 // Creates a map that matches the constructor's initial map, but with |
7411 // [[prototype]] being new.target.prototype. Because new.target can be a | 7394 // [[prototype]] being new.target.prototype. Because new.target can be a |
7412 // JSProxy, this can call back into JavaScript. | 7395 // JSProxy, this can call back into JavaScript. |
(...skipping 3387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10800 } | 10783 } |
10801 return value; | 10784 return value; |
10802 } | 10785 } |
10803 }; | 10786 }; |
10804 | 10787 |
10805 | 10788 |
10806 } // NOLINT, false-positive due to second-order macros. | 10789 } // NOLINT, false-positive due to second-order macros. |
10807 } // NOLINT, false-positive due to second-order macros. | 10790 } // NOLINT, false-positive due to second-order macros. |
10808 | 10791 |
10809 #endif // V8_OBJECTS_H_ | 10792 #endif // V8_OBJECTS_H_ |
OLD | NEW |