| 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_COMPILATION_CACHE_H_ | 5 #ifndef V8_COMPILATION_CACHE_H_ |
| 6 #define V8_COMPILATION_CACHE_H_ | 6 #define V8_COMPILATION_CACHE_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/objects.h" | 9 #include "src/objects.h" |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 int generations_; // Number of generations. | 69 int generations_; // Number of generations. |
| 70 Object** tables_; // Compilation cache tables - one for each generation. | 70 Object** tables_; // Compilation cache tables - one for each generation. |
| 71 | 71 |
| 72 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache); | 72 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationSubCache); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 | 75 |
| 76 // Sub-cache for scripts. | 76 // Sub-cache for scripts. |
| 77 class CompilationCacheScript : public CompilationSubCache { | 77 class CompilationCacheScript : public CompilationSubCache { |
| 78 public: | 78 public: |
| 79 CompilationCacheScript(Isolate* isolate, int generations); | 79 explicit CompilationCacheScript(Isolate* isolate); |
| 80 | 80 |
| 81 Handle<SharedFunctionInfo> Lookup(Handle<String> source, Handle<Object> name, | 81 InfoVectorPair Lookup(Handle<String> source, Handle<Object> name, |
| 82 int line_offset, int column_offset, | 82 int line_offset, int column_offset, |
| 83 ScriptOriginOptions resource_options, | 83 ScriptOriginOptions resource_options, |
| 84 Handle<Context> context, | 84 Handle<Context> context, LanguageMode language_mode); |
| 85 LanguageMode language_mode); | 85 |
| 86 void Put(Handle<String> source, | 86 void Put(Handle<String> source, Handle<Context> context, |
| 87 Handle<Context> context, | 87 LanguageMode language_mode, Handle<SharedFunctionInfo> function_info, |
| 88 LanguageMode language_mode, | 88 Handle<Cell> literals); |
| 89 Handle<SharedFunctionInfo> function_info); | |
| 90 | 89 |
| 91 private: | 90 private: |
| 92 bool HasOrigin(Handle<SharedFunctionInfo> function_info, Handle<Object> name, | 91 bool HasOrigin(Handle<SharedFunctionInfo> function_info, Handle<Object> name, |
| 93 int line_offset, int column_offset, | 92 int line_offset, int column_offset, |
| 94 ScriptOriginOptions resource_options); | 93 ScriptOriginOptions resource_options); |
| 95 | 94 |
| 96 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript); | 95 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript); |
| 97 }; | 96 }; |
| 98 | 97 |
| 99 | 98 |
| 100 // Sub-cache for eval scripts. Two caches for eval are used. One for eval calls | 99 // Sub-cache for eval scripts. Two caches for eval are used. One for eval calls |
| 101 // in native contexts and one for eval calls in other contexts. The cache | 100 // in native contexts and one for eval calls in other contexts. The cache |
| 102 // considers the following pieces of information when checking for matching | 101 // considers the following pieces of information when checking for matching |
| 103 // entries: | 102 // entries: |
| 104 // 1. The source string. | 103 // 1. The source string. |
| 105 // 2. The shared function info of the calling function. | 104 // 2. The shared function info of the calling function. |
| 106 // 3. Whether the source should be compiled as strict code or as sloppy code. | 105 // 3. Whether the source should be compiled as strict code or as sloppy code. |
| 107 // Note: Currently there are clients of CompileEval that always compile | 106 // Note: Currently there are clients of CompileEval that always compile |
| 108 // sloppy code even if the calling function is a strict mode function. | 107 // sloppy code even if the calling function is a strict mode function. |
| 109 // More specifically these are the CompileString, DebugEvaluate and | 108 // More specifically these are the CompileString, DebugEvaluate and |
| 110 // DebugEvaluateGlobal runtime functions. | 109 // DebugEvaluateGlobal runtime functions. |
| 111 // 4. The start position of the calling scope. | 110 // 4. The start position of the calling scope. |
| 112 class CompilationCacheEval: public CompilationSubCache { | 111 class CompilationCacheEval: public CompilationSubCache { |
| 113 public: | 112 public: |
| 114 CompilationCacheEval(Isolate* isolate, int generations) | 113 explicit CompilationCacheEval(Isolate* isolate) |
| 115 : CompilationSubCache(isolate, generations) { } | 114 : CompilationSubCache(isolate, 1) {} |
| 116 | 115 |
| 117 MaybeHandle<SharedFunctionInfo> Lookup(Handle<String> source, | 116 InfoVectorPair Lookup(Handle<String> source, |
| 118 Handle<SharedFunctionInfo> outer_info, | 117 Handle<SharedFunctionInfo> outer_info, |
| 119 LanguageMode language_mode, | 118 Handle<Context> native_context, |
| 120 int scope_position); | 119 LanguageMode language_mode, int scope_position); |
| 121 | 120 |
| 122 void Put(Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 121 void Put(Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
| 123 Handle<SharedFunctionInfo> function_info, int scope_position); | 122 Handle<SharedFunctionInfo> function_info, |
| 123 Handle<Context> native_context, Handle<Cell> literals, |
| 124 int scope_position); |
| 124 | 125 |
| 125 private: | 126 private: |
| 126 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); | 127 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 | 130 |
| 130 // Sub-cache for regular expressions. | 131 // Sub-cache for regular expressions. |
| 131 class CompilationCacheRegExp: public CompilationSubCache { | 132 class CompilationCacheRegExp: public CompilationSubCache { |
| 132 public: | 133 public: |
| 133 CompilationCacheRegExp(Isolate* isolate, int generations) | 134 CompilationCacheRegExp(Isolate* isolate, int generations) |
| 134 : CompilationSubCache(isolate, generations) { } | 135 : CompilationSubCache(isolate, generations) { } |
| 135 | 136 |
| 136 MaybeHandle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags); | 137 MaybeHandle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags); |
| 137 | 138 |
| 138 void Put(Handle<String> source, | 139 void Put(Handle<String> source, |
| 139 JSRegExp::Flags flags, | 140 JSRegExp::Flags flags, |
| 140 Handle<FixedArray> data); | 141 Handle<FixedArray> data); |
| 141 private: | 142 private: |
| 142 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp); | 143 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp); |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 | |
| 146 // The compilation cache keeps shared function infos for compiled | 146 // The compilation cache keeps shared function infos for compiled |
| 147 // scripts and evals. The shared function infos are looked up using | 147 // scripts and evals. The shared function infos are looked up using |
| 148 // the source string as the key. For regular expressions the | 148 // the source string as the key. For regular expressions the |
| 149 // compilation data is cached. | 149 // compilation data is cached. |
| 150 class CompilationCache { | 150 class CompilationCache { |
| 151 public: | 151 public: |
| 152 // Finds the script shared function info for a source | 152 // Finds the script shared function info for a source |
| 153 // string. Returns an empty handle if the cache doesn't contain a | 153 // string. Returns an empty handle if the cache doesn't contain a |
| 154 // script for the given source string with the right origin. | 154 // script for the given source string with the right origin. |
| 155 MaybeHandle<SharedFunctionInfo> LookupScript( | 155 InfoVectorPair LookupScript(Handle<String> source, Handle<Object> name, |
| 156 Handle<String> source, Handle<Object> name, int line_offset, | 156 int line_offset, int column_offset, |
| 157 int column_offset, ScriptOriginOptions resource_options, | 157 ScriptOriginOptions resource_options, |
| 158 Handle<Context> context, LanguageMode language_mode); | 158 Handle<Context> context, |
| 159 LanguageMode language_mode); |
| 159 | 160 |
| 160 // Finds the shared function info for a source string for eval in a | 161 // Finds the shared function info for a source string for eval in a |
| 161 // given context. Returns an empty handle if the cache doesn't | 162 // given context. Returns an empty handle if the cache doesn't |
| 162 // contain a script for the given source string. | 163 // contain a script for the given source string. |
| 163 MaybeHandle<SharedFunctionInfo> LookupEval( | 164 InfoVectorPair LookupEval(Handle<String> source, |
| 164 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 165 Handle<SharedFunctionInfo> outer_info, |
| 165 Handle<Context> context, LanguageMode language_mode, int scope_position); | 166 Handle<Context> context, LanguageMode language_mode, |
| 167 int scope_position); |
| 166 | 168 |
| 167 // Returns the regexp data associated with the given regexp if it | 169 // Returns the regexp data associated with the given regexp if it |
| 168 // is in cache, otherwise an empty handle. | 170 // is in cache, otherwise an empty handle. |
| 169 MaybeHandle<FixedArray> LookupRegExp( | 171 MaybeHandle<FixedArray> LookupRegExp( |
| 170 Handle<String> source, JSRegExp::Flags flags); | 172 Handle<String> source, JSRegExp::Flags flags); |
| 171 | 173 |
| 172 // Associate the (source, kind) pair to the shared function | 174 // Associate the (source, kind) pair to the shared function |
| 173 // info. This may overwrite an existing mapping. | 175 // info. This may overwrite an existing mapping. |
| 174 void PutScript(Handle<String> source, | 176 void PutScript(Handle<String> source, Handle<Context> context, |
| 175 Handle<Context> context, | |
| 176 LanguageMode language_mode, | 177 LanguageMode language_mode, |
| 177 Handle<SharedFunctionInfo> function_info); | 178 Handle<SharedFunctionInfo> function_info, |
| 179 Handle<Cell> literals); |
| 178 | 180 |
| 179 // Associate the (source, context->closure()->shared(), kind) triple | 181 // Associate the (source, context->closure()->shared(), kind) triple |
| 180 // with the shared function info. This may overwrite an existing mapping. | 182 // with the shared function info. This may overwrite an existing mapping. |
| 181 void PutEval(Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 183 void PutEval(Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
| 182 Handle<Context> context, | 184 Handle<Context> context, |
| 183 Handle<SharedFunctionInfo> function_info, int scope_position); | 185 Handle<SharedFunctionInfo> function_info, Handle<Cell> literals, |
| 186 int scope_position); |
| 184 | 187 |
| 185 // Associate the (source, flags) pair to the given regexp data. | 188 // Associate the (source, flags) pair to the given regexp data. |
| 186 // This may overwrite an existing mapping. | 189 // This may overwrite an existing mapping. |
| 187 void PutRegExp(Handle<String> source, | 190 void PutRegExp(Handle<String> source, |
| 188 JSRegExp::Flags flags, | 191 JSRegExp::Flags flags, |
| 189 Handle<FixedArray> data); | 192 Handle<FixedArray> data); |
| 190 | 193 |
| 191 // Clear the cache - also used to initialize the cache at startup. | 194 // Clear the cache - also used to initialize the cache at startup. |
| 192 void Clear(); | 195 void Clear(); |
| 193 | 196 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 friend class Isolate; | 238 friend class Isolate; |
| 236 | 239 |
| 237 DISALLOW_COPY_AND_ASSIGN(CompilationCache); | 240 DISALLOW_COPY_AND_ASSIGN(CompilationCache); |
| 238 }; | 241 }; |
| 239 | 242 |
| 240 | 243 |
| 241 } // namespace internal | 244 } // namespace internal |
| 242 } // namespace v8 | 245 } // namespace v8 |
| 243 | 246 |
| 244 #endif // V8_COMPILATION_CACHE_H_ | 247 #endif // V8_COMPILATION_CACHE_H_ |
| OLD | NEW |