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