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