| 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 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 7055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7066 inline bool IsInterpreted() const; | 7066 inline bool IsInterpreted() const; |
| 7067 | 7067 |
| 7068 inline void ReplaceCode(Code* code); | 7068 inline void ReplaceCode(Code* code); |
| 7069 inline bool HasBaselineCode() const; | 7069 inline bool HasBaselineCode() const; |
| 7070 | 7070 |
| 7071 // [optimized_code_map]: Map from native context to optimized code | 7071 // [optimized_code_map]: Map from native context to optimized code |
| 7072 // and a shared literals array. | 7072 // and a shared literals array. |
| 7073 DECL_ACCESSORS(optimized_code_map, FixedArray) | 7073 DECL_ACCESSORS(optimized_code_map, FixedArray) |
| 7074 | 7074 |
| 7075 // Returns entry from optimized code map for specified context and OSR entry. | 7075 // Returns entry from optimized code map for specified context and OSR entry. |
| 7076 // Note that {code == nullptr, literals == nullptr} indicates no matching | 7076 Code* SearchOptimizedCodeMap(Context* native_context, BailoutId osr_ast_id); |
| 7077 // entry has been found, whereas {code, literals == nullptr} indicates that | |
| 7078 // code is context-independent. | |
| 7079 CodeAndVector SearchOptimizedCodeMap(Context* native_context, | |
| 7080 BailoutId osr_ast_id); | |
| 7081 | 7077 |
| 7082 // Clear optimized code map. | 7078 // Clear optimized code map. |
| 7083 void ClearOptimizedCodeMap(); | 7079 void ClearOptimizedCodeMap(); |
| 7084 | 7080 |
| 7085 // Like ClearOptimizedCodeMap, but preserves literals. | 7081 // Like ClearOptimizedCodeMap, but preserves literals. |
| 7086 void ClearCodeFromOptimizedCodeMap(); | 7082 void ClearCodeFromOptimizedCodeMap(); |
| 7087 | 7083 |
| 7088 // We have a special root FixedArray with the right shape and values | 7084 // We have a special root FixedArray with the right shape and values |
| 7089 // to represent the cleared optimized code map. This predicate checks | 7085 // to represent the cleared optimized code map. This predicate checks |
| 7090 // if that root is installed. | 7086 // if that root is installed. |
| 7091 inline bool OptimizedCodeMapIsCleared() const; | 7087 inline bool OptimizedCodeMapIsCleared() const; |
| 7092 | 7088 |
| 7093 // Removes a specific optimized code object from the optimized code map. | 7089 // Removes a specific optimized code object from the optimized code map. |
| 7094 // In case of non-OSR the code reference is cleared from the cache entry but | 7090 // In case of non-OSR the code reference is cleared from the cache entry but |
| 7095 // the entry itself is left in the map in order to proceed sharing literals. | 7091 // the entry itself is left in the map in order to proceed sharing literals. |
| 7096 void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason); | 7092 void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason); |
| 7097 | 7093 |
| 7098 static Handle<TypeFeedbackVector> FindOrCreateVector( | 7094 static Handle<TypeFeedbackVector> FindOrCreateVector( |
| 7099 Handle<SharedFunctionInfo> shared, Handle<Context> native_context); | 7095 Handle<SharedFunctionInfo> shared, Handle<Context> native_context); |
| 7100 | 7096 |
| 7101 // Add or update entry in the optimized code map for context-dependent code. | 7097 // Add or update entry in the optimized code map for context-dependent code. |
| 7102 // If {code} is not given, then an existing entry's code won't be overwritten. | |
| 7103 static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, | 7098 static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 7104 Handle<Context> native_context, | 7099 Handle<Context> native_context, |
| 7105 MaybeHandle<Code> code, | 7100 Handle<Code> code, BailoutId osr_ast_id); |
| 7106 Handle<TypeFeedbackVector> vector, | |
| 7107 BailoutId osr_ast_id); | |
| 7108 | 7101 |
| 7109 // Set up the link between shared function info and the script. The shared | 7102 // Set up the link between shared function info and the script. The shared |
| 7110 // function info is added to the list on the script. | 7103 // function info is added to the list on the script. |
| 7111 V8_EXPORT_PRIVATE static void SetScript(Handle<SharedFunctionInfo> shared, | 7104 V8_EXPORT_PRIVATE static void SetScript(Handle<SharedFunctionInfo> shared, |
| 7112 Handle<Object> script_object); | 7105 Handle<Object> script_object); |
| 7113 | 7106 |
| 7114 // Layout description of the optimized code map. | 7107 // Layout description of the optimized code map. |
| 7115 static const int kEntriesStart = 0; | 7108 static const int kEntriesStart = 0; |
| 7116 static const int kContextOffset = 0; | 7109 static const int kContextOffset = 0; |
| 7117 static const int kCachedCodeOffset = 1; | 7110 static const int kCachedCodeOffset = 1; |
| 7118 static const int kFeedbackVectorOffset = 2; | 7111 static const int kEntryLength = 2; |
| 7119 static const int kEntryLength = 3; | |
| 7120 static const int kInitialLength = kEntriesStart + kEntryLength; | 7112 static const int kInitialLength = kEntriesStart + kEntryLength; |
| 7121 | 7113 |
| 7122 static const int kNotFound = -1; | 7114 static const int kNotFound = -1; |
| 7123 | 7115 |
| 7124 // Helpers for assembly code that does a backwards walk of the optimized code | 7116 // Helpers for assembly code that does a backwards walk of the optimized code |
| 7125 // map. | 7117 // map. |
| 7126 static const int kOffsetToPreviousContext = | 7118 static const int kOffsetToPreviousContext = |
| 7127 FixedArray::kHeaderSize + kPointerSize * (kContextOffset - kEntryLength); | 7119 FixedArray::kHeaderSize + kPointerSize * (kContextOffset - kEntryLength); |
| 7128 static const int kOffsetToPreviousCachedCode = | 7120 static const int kOffsetToPreviousCachedCode = |
| 7129 FixedArray::kHeaderSize + | 7121 FixedArray::kHeaderSize + |
| 7130 kPointerSize * (kCachedCodeOffset - kEntryLength); | 7122 kPointerSize * (kCachedCodeOffset - kEntryLength); |
| 7131 static const int kOffsetToPreviousLiterals = | |
| 7132 FixedArray::kHeaderSize + | |
| 7133 kPointerSize * (kFeedbackVectorOffset - kEntryLength); | |
| 7134 | 7123 |
| 7135 // [scope_info]: Scope info. | 7124 // [scope_info]: Scope info. |
| 7136 DECL_ACCESSORS(scope_info, ScopeInfo) | 7125 DECL_ACCESSORS(scope_info, ScopeInfo) |
| 7137 | 7126 |
| 7138 // The outer scope info for the purpose of parsing this function, or the hole | 7127 // The outer scope info for the purpose of parsing this function, or the hole |
| 7139 // value if it isn't yet known. | 7128 // value if it isn't yet known. |
| 7140 DECL_ACCESSORS(outer_scope_info, HeapObject) | 7129 DECL_ACCESSORS(outer_scope_info, HeapObject) |
| 7141 | 7130 |
| 7142 // [construct stub]: Code stub for constructing instances of this function. | 7131 // [construct stub]: Code stub for constructing instances of this function. |
| 7143 DECL_ACCESSORS(construct_stub, Code) | 7132 DECL_ACCESSORS(construct_stub, Code) |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8083 inline bool IsMarkedForBaseline(); | 8072 inline bool IsMarkedForBaseline(); |
| 8084 inline bool IsMarkedForOptimization(); | 8073 inline bool IsMarkedForOptimization(); |
| 8085 inline bool IsMarkedForConcurrentOptimization(); | 8074 inline bool IsMarkedForConcurrentOptimization(); |
| 8086 | 8075 |
| 8087 // Tells whether or not the function is on the concurrent recompilation queue. | 8076 // Tells whether or not the function is on the concurrent recompilation queue. |
| 8088 inline bool IsInOptimizationQueue(); | 8077 inline bool IsInOptimizationQueue(); |
| 8089 | 8078 |
| 8090 // Completes inobject slack tracking on initial map if it is active. | 8079 // Completes inobject slack tracking on initial map if it is active. |
| 8091 inline void CompleteInobjectSlackTrackingIfActive(); | 8080 inline void CompleteInobjectSlackTrackingIfActive(); |
| 8092 | 8081 |
| 8093 // [feedback_vector]: Fixed array holding the feedback vector. | 8082 // [feedback_vector_cell]: Fixed array holding the feedback vector. |
| 8094 DECL_ACCESSORS(feedback_vector, TypeFeedbackVector) | 8083 DECL_ACCESSORS(feedback_vector_cell, Cell) |
| 8095 | 8084 |
| 8085 // feedback_vector() can be used once the function is compiled. |
| 8086 inline TypeFeedbackVector* feedback_vector() const; |
| 8087 inline bool has_feedback_vector() const; |
| 8096 static void EnsureLiterals(Handle<JSFunction> function); | 8088 static void EnsureLiterals(Handle<JSFunction> function); |
| 8097 | 8089 |
| 8098 // Unconditionally clear the type feedback vector (including vector ICs). | 8090 // Unconditionally clear the type feedback vector (including vector ICs). |
| 8099 void ClearTypeFeedbackInfo(); | 8091 void ClearTypeFeedbackInfo(); |
| 8100 | 8092 |
| 8101 // Clear the type feedback vector with a more subtle policy at GC time. | 8093 // Clear the type feedback vector with a more subtle policy at GC time. |
| 8102 void ClearTypeFeedbackInfoAtGCTime(); | 8094 void ClearTypeFeedbackInfoAtGCTime(); |
| 8103 | 8095 |
| 8104 // The initial map for an object created by this constructor. | 8096 // The initial map for an object created by this constructor. |
| 8105 inline Map* initial_map(); | 8097 inline Map* initial_map(); |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8731 return key->Hash(); | 8723 return key->Hash(); |
| 8732 } | 8724 } |
| 8733 | 8725 |
| 8734 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { | 8726 static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 8735 return key->HashForObject(object); | 8727 return key->HashForObject(object); |
| 8736 } | 8728 } |
| 8737 | 8729 |
| 8738 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); | 8730 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
| 8739 | 8731 |
| 8740 static const int kPrefixSize = 0; | 8732 static const int kPrefixSize = 0; |
| 8741 static const int kEntrySize = 2; | 8733 static const int kEntrySize = 3; |
| 8742 }; | 8734 }; |
| 8743 | 8735 |
| 8736 class InfoVectorPair { |
| 8737 public: |
| 8738 InfoVectorPair() : shared_(nullptr), vector_cell_(nullptr) {} |
| 8739 InfoVectorPair(SharedFunctionInfo* shared, Cell* vector_cell) |
| 8740 : shared_(shared), vector_cell_(vector_cell) {} |
| 8741 |
| 8742 SharedFunctionInfo* shared() const { return shared_; } |
| 8743 Cell* vector() const { return vector_cell_; } |
| 8744 |
| 8745 bool has_shared() const { return shared_ != nullptr; } |
| 8746 bool has_vector() const { return vector_cell_ != nullptr; } |
| 8747 |
| 8748 private: |
| 8749 SharedFunctionInfo* shared_; |
| 8750 Cell* vector_cell_; |
| 8751 }; |
| 8744 | 8752 |
| 8745 // This cache is used in two different variants. For regexp caching, it simply | 8753 // This cache is used in two different variants. For regexp caching, it simply |
| 8746 // maps identifying info of the regexp to the cached regexp object. Scripts and | 8754 // maps identifying info of the regexp to the cached regexp object. Scripts and |
| 8747 // eval code only gets cached after a second probe for the code object. To do | 8755 // eval code only gets cached after a second probe for the code object. To do |
| 8748 // so, on first "put" only a hash identifying the source is entered into the | 8756 // so, on first "put" only a hash identifying the source is entered into the |
| 8749 // cache, mapping it to a lifetime count of the hash. On each call to Age all | 8757 // cache, mapping it to a lifetime count of the hash. On each call to Age all |
| 8750 // such lifetimes get reduced, and removed once they reach zero. If a second put | 8758 // such lifetimes get reduced, and removed once they reach zero. If a second put |
| 8751 // is called while such a hash is live in the cache, the hash gets replaced by | 8759 // is called while such a hash is live in the cache, the hash gets replaced by |
| 8752 // an actual cache entry. Age also removes stale live entries from the cache. | 8760 // an actual cache entry. Age also removes stale live entries from the cache. |
| 8753 // Such entries are identified by SharedFunctionInfos pointing to either the | 8761 // Such entries are identified by SharedFunctionInfos pointing to either the |
| 8754 // recompilation stub, or to "old" code. This avoids memory leaks due to | 8762 // recompilation stub, or to "old" code. This avoids memory leaks due to |
| 8755 // premature caching of scripts and eval strings that are never needed later. | 8763 // premature caching of scripts and eval strings that are never needed later. |
| 8756 class CompilationCacheTable: public HashTable<CompilationCacheTable, | 8764 class CompilationCacheTable: public HashTable<CompilationCacheTable, |
| 8757 CompilationCacheShape, | 8765 CompilationCacheShape, |
| 8758 HashTableKey*> { | 8766 HashTableKey*> { |
| 8759 public: | 8767 public: |
| 8760 // Find cached value for a string key, otherwise return null. | 8768 // Find cached value for a string key, otherwise return null. |
| 8761 Handle<Object> Lookup( | 8769 Handle<Object> Lookup( |
| 8762 Handle<String> src, Handle<Context> context, LanguageMode language_mode); | 8770 Handle<String> src, Handle<Context> context, LanguageMode language_mode); |
| 8763 Handle<Object> LookupEval( | 8771 InfoVectorPair LookupScript(Handle<String> src, Handle<Context> context, |
| 8764 Handle<String> src, Handle<SharedFunctionInfo> shared, | 8772 LanguageMode language_mode); |
| 8765 LanguageMode language_mode, int scope_position); | 8773 InfoVectorPair LookupEval(Handle<String> src, |
| 8774 Handle<SharedFunctionInfo> shared, |
| 8775 Handle<Context> native_context, |
| 8776 LanguageMode language_mode, int scope_position); |
| 8766 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); | 8777 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); |
| 8767 static Handle<CompilationCacheTable> Put( | 8778 static Handle<CompilationCacheTable> Put( |
| 8768 Handle<CompilationCacheTable> cache, Handle<String> src, | 8779 Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8769 Handle<Context> context, LanguageMode language_mode, | 8780 Handle<Context> context, LanguageMode language_mode, |
| 8770 Handle<Object> value); | 8781 Handle<Object> value); |
| 8782 static Handle<CompilationCacheTable> PutScript( |
| 8783 Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8784 Handle<Context> context, LanguageMode language_mode, |
| 8785 Handle<SharedFunctionInfo> value, Handle<Cell> literals); |
| 8771 static Handle<CompilationCacheTable> PutEval( | 8786 static Handle<CompilationCacheTable> PutEval( |
| 8772 Handle<CompilationCacheTable> cache, Handle<String> src, | 8787 Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8773 Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value, | 8788 Handle<SharedFunctionInfo> outer_info, Handle<SharedFunctionInfo> value, |
| 8789 Handle<Context> native_context, Handle<Cell> literals, |
| 8774 int scope_position); | 8790 int scope_position); |
| 8775 static Handle<CompilationCacheTable> PutRegExp( | 8791 static Handle<CompilationCacheTable> PutRegExp( |
| 8776 Handle<CompilationCacheTable> cache, Handle<String> src, | 8792 Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8777 JSRegExp::Flags flags, Handle<FixedArray> value); | 8793 JSRegExp::Flags flags, Handle<FixedArray> value); |
| 8778 void Remove(Object* value); | 8794 void Remove(Object* value); |
| 8779 void Age(); | 8795 void Age(); |
| 8780 static const int kHashGenerations = 10; | 8796 static const int kHashGenerations = 10; |
| 8781 | 8797 |
| 8782 DECLARE_CAST(CompilationCacheTable) | 8798 DECLARE_CAST(CompilationCacheTable) |
| 8783 | 8799 |
| (...skipping 2836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11620 } | 11636 } |
| 11621 }; | 11637 }; |
| 11622 | 11638 |
| 11623 | 11639 |
| 11624 } // NOLINT, false-positive due to second-order macros. | 11640 } // NOLINT, false-positive due to second-order macros. |
| 11625 } // NOLINT, false-positive due to second-order macros. | 11641 } // NOLINT, false-positive due to second-order macros. |
| 11626 | 11642 |
| 11627 #include "src/objects/object-macros-undef.h" | 11643 #include "src/objects/object-macros-undef.h" |
| 11628 | 11644 |
| 11629 #endif // V8_OBJECTS_H_ | 11645 #endif // V8_OBJECTS_H_ |
| OLD | NEW |