OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 7919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7930 return key->HashForObject(object); | 7930 return key->HashForObject(object); |
7931 } | 7931 } |
7932 | 7932 |
7933 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); | 7933 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
7934 | 7934 |
7935 static const int kPrefixSize = 0; | 7935 static const int kPrefixSize = 0; |
7936 static const int kEntrySize = 2; | 7936 static const int kEntrySize = 2; |
7937 }; | 7937 }; |
7938 | 7938 |
7939 | 7939 |
| 7940 // This cache is used in two different variants. For regexp caching, it simply |
| 7941 // maps identifying info of the regexp to the cached regexp object. Scripts and |
| 7942 // eval code only gets cached after a second probe for the code object. To do |
| 7943 // so, on first "put" only a hash identifying the source is entered into the |
| 7944 // cache, mapping it to a lifetime count of the hash. On each call to Age all |
| 7945 // such lifetimes get reduced, and removed once they reach zero. If a second put |
| 7946 // is called while such a hash is live in the cache, the hash gets replaced by |
| 7947 // an actual cache entry. Age also removes stale live entries from the cache. |
| 7948 // Such entries are identified by SharedFunctionInfos pointing to either the |
| 7949 // recompilation stub, or to "old" code. This avoids memory leaks due to |
| 7950 // premature caching of scripts and eval strings that are never needed later. |
7940 class CompilationCacheTable: public HashTable<CompilationCacheTable, | 7951 class CompilationCacheTable: public HashTable<CompilationCacheTable, |
7941 CompilationCacheShape, | 7952 CompilationCacheShape, |
7942 HashTableKey*> { | 7953 HashTableKey*> { |
7943 public: | 7954 public: |
7944 // Find cached value for a string key, otherwise return null. | 7955 // Find cached value for a string key, otherwise return null. |
7945 Handle<Object> Lookup(Handle<String> src, Handle<Context> context); | 7956 Handle<Object> Lookup(Handle<String> src, Handle<Context> context); |
7946 Handle<Object> LookupEval(Handle<String> src, | 7957 Handle<Object> LookupEval(Handle<String> src, |
7947 Handle<SharedFunctionInfo> shared, | 7958 Handle<SharedFunctionInfo> shared, |
7948 StrictMode strict_mode, int scope_position); | 7959 StrictMode strict_mode, int scope_position); |
7949 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); | 7960 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); |
7950 static Handle<CompilationCacheTable> Put( | 7961 static Handle<CompilationCacheTable> Put( |
7951 Handle<CompilationCacheTable> cache, Handle<String> src, | 7962 Handle<CompilationCacheTable> cache, Handle<String> src, |
7952 Handle<Context> context, Handle<Object> value); | 7963 Handle<Context> context, Handle<Object> value); |
7953 static Handle<CompilationCacheTable> PutEval( | 7964 static Handle<CompilationCacheTable> PutEval( |
7954 Handle<CompilationCacheTable> cache, Handle<String> src, | 7965 Handle<CompilationCacheTable> cache, Handle<String> src, |
7955 Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value, | 7966 Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value, |
7956 int scope_position); | 7967 int scope_position); |
7957 static Handle<CompilationCacheTable> PutRegExp( | 7968 static Handle<CompilationCacheTable> PutRegExp( |
7958 Handle<CompilationCacheTable> cache, Handle<String> src, | 7969 Handle<CompilationCacheTable> cache, Handle<String> src, |
7959 JSRegExp::Flags flags, Handle<FixedArray> value); | 7970 JSRegExp::Flags flags, Handle<FixedArray> value); |
7960 void Remove(Object* value); | 7971 void Remove(Object* value); |
| 7972 void Age(); |
| 7973 static const int kHashGenerations = 10; |
7961 | 7974 |
7962 DECLARE_CAST(CompilationCacheTable) | 7975 DECLARE_CAST(CompilationCacheTable) |
7963 | 7976 |
7964 private: | 7977 private: |
7965 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); | 7978 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
7966 }; | 7979 }; |
7967 | 7980 |
7968 | 7981 |
7969 class CodeCache: public Struct { | 7982 class CodeCache: public Struct { |
7970 public: | 7983 public: |
(...skipping 2938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10909 } else { | 10922 } else { |
10910 value &= ~(1 << bit_position); | 10923 value &= ~(1 << bit_position); |
10911 } | 10924 } |
10912 return value; | 10925 return value; |
10913 } | 10926 } |
10914 }; | 10927 }; |
10915 | 10928 |
10916 } } // namespace v8::internal | 10929 } } // namespace v8::internal |
10917 | 10930 |
10918 #endif // V8_OBJECTS_H_ | 10931 #endif // V8_OBJECTS_H_ |
OLD | NEW |