| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 Handle<Object> name, | 99 Handle<Object> name, |
| 100 int line_offset, | 100 int line_offset, |
| 101 int column_offset, | 101 int column_offset, |
| 102 bool is_shared_cross_origin, | 102 bool is_shared_cross_origin, |
| 103 Handle<Context> context); | 103 Handle<Context> context); |
| 104 void Put(Handle<String> source, | 104 void Put(Handle<String> source, |
| 105 Handle<Context> context, | 105 Handle<Context> context, |
| 106 Handle<SharedFunctionInfo> function_info); | 106 Handle<SharedFunctionInfo> function_info); |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 MUST_USE_RESULT MaybeObject* TryTablePut( | |
| 110 Handle<String> source, | |
| 111 Handle<Context> context, | |
| 112 Handle<SharedFunctionInfo> function_info); | |
| 113 | |
| 114 // Note: Returns a new hash table if operation results in expansion. | |
| 115 Handle<CompilationCacheTable> TablePut( | |
| 116 Handle<String> source, | |
| 117 Handle<Context> context, | |
| 118 Handle<SharedFunctionInfo> function_info); | |
| 119 | |
| 120 bool HasOrigin(Handle<SharedFunctionInfo> function_info, | 109 bool HasOrigin(Handle<SharedFunctionInfo> function_info, |
| 121 Handle<Object> name, | 110 Handle<Object> name, |
| 122 int line_offset, | 111 int line_offset, |
| 123 int column_offset, | 112 int column_offset, |
| 124 bool is_shared_cross_origin); | 113 bool is_shared_cross_origin); |
| 125 | 114 |
| 126 void* script_histogram_; | 115 void* script_histogram_; |
| 127 bool script_histogram_initialized_; | 116 bool script_histogram_initialized_; |
| 128 | 117 |
| 129 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript); | 118 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 // Note: Currently there are clients of CompileEval that always compile | 129 // Note: Currently there are clients of CompileEval that always compile |
| 141 // sloppy code even if the calling function is a strict mode function. | 130 // sloppy code even if the calling function is a strict mode function. |
| 142 // More specifically these are the CompileString, DebugEvaluate and | 131 // More specifically these are the CompileString, DebugEvaluate and |
| 143 // DebugEvaluateGlobal runtime functions. | 132 // DebugEvaluateGlobal runtime functions. |
| 144 // 4. The start position of the calling scope. | 133 // 4. The start position of the calling scope. |
| 145 class CompilationCacheEval: public CompilationSubCache { | 134 class CompilationCacheEval: public CompilationSubCache { |
| 146 public: | 135 public: |
| 147 CompilationCacheEval(Isolate* isolate, int generations) | 136 CompilationCacheEval(Isolate* isolate, int generations) |
| 148 : CompilationSubCache(isolate, generations) { } | 137 : CompilationSubCache(isolate, generations) { } |
| 149 | 138 |
| 150 Handle<SharedFunctionInfo> Lookup(Handle<String> source, | 139 MaybeHandle<SharedFunctionInfo> Lookup(Handle<String> source, |
| 151 Handle<Context> context, | 140 Handle<Context> context, |
| 152 StrictMode strict_mode, | 141 StrictMode strict_mode, |
| 153 int scope_position); | 142 int scope_position); |
| 154 | 143 |
| 155 void Put(Handle<String> source, | 144 void Put(Handle<String> source, |
| 156 Handle<Context> context, | 145 Handle<Context> context, |
| 157 Handle<SharedFunctionInfo> function_info, | 146 Handle<SharedFunctionInfo> function_info, |
| 158 int scope_position); | 147 int scope_position); |
| 159 | 148 |
| 160 private: | 149 private: |
| 161 MUST_USE_RESULT MaybeObject* TryTablePut( | |
| 162 Handle<String> source, | |
| 163 Handle<Context> context, | |
| 164 Handle<SharedFunctionInfo> function_info, | |
| 165 int scope_position); | |
| 166 | |
| 167 // Note: Returns a new hash table if operation results in expansion. | |
| 168 Handle<CompilationCacheTable> TablePut( | |
| 169 Handle<String> source, | |
| 170 Handle<Context> context, | |
| 171 Handle<SharedFunctionInfo> function_info, | |
| 172 int scope_position); | |
| 173 | |
| 174 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); | 150 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval); |
| 175 }; | 151 }; |
| 176 | 152 |
| 177 | 153 |
| 178 // Sub-cache for regular expressions. | 154 // Sub-cache for regular expressions. |
| 179 class CompilationCacheRegExp: public CompilationSubCache { | 155 class CompilationCacheRegExp: public CompilationSubCache { |
| 180 public: | 156 public: |
| 181 CompilationCacheRegExp(Isolate* isolate, int generations) | 157 CompilationCacheRegExp(Isolate* isolate, int generations) |
| 182 : CompilationSubCache(isolate, generations) { } | 158 : CompilationSubCache(isolate, generations) { } |
| 183 | 159 |
| 184 Handle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags); | 160 MaybeHandle<FixedArray> Lookup(Handle<String> source, JSRegExp::Flags flags); |
| 185 | 161 |
| 186 void Put(Handle<String> source, | 162 void Put(Handle<String> source, |
| 187 JSRegExp::Flags flags, | 163 JSRegExp::Flags flags, |
| 188 Handle<FixedArray> data); | 164 Handle<FixedArray> data); |
| 189 private: | 165 private: |
| 190 MUST_USE_RESULT MaybeObject* TryTablePut(Handle<String> source, | |
| 191 JSRegExp::Flags flags, | |
| 192 Handle<FixedArray> data); | |
| 193 | |
| 194 // Note: Returns a new hash table if operation results in expansion. | |
| 195 Handle<CompilationCacheTable> TablePut(Handle<String> source, | |
| 196 JSRegExp::Flags flags, | |
| 197 Handle<FixedArray> data); | |
| 198 | |
| 199 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp); | 166 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp); |
| 200 }; | 167 }; |
| 201 | 168 |
| 202 | 169 |
| 203 // The compilation cache keeps shared function infos for compiled | 170 // The compilation cache keeps shared function infos for compiled |
| 204 // scripts and evals. The shared function infos are looked up using | 171 // scripts and evals. The shared function infos are looked up using |
| 205 // the source string as the key. For regular expressions the | 172 // the source string as the key. For regular expressions the |
| 206 // compilation data is cached. | 173 // compilation data is cached. |
| 207 class CompilationCache { | 174 class CompilationCache { |
| 208 public: | 175 public: |
| 209 // Finds the script shared function info for a source | 176 // Finds the script shared function info for a source |
| 210 // string. Returns an empty handle if the cache doesn't contain a | 177 // string. Returns an empty handle if the cache doesn't contain a |
| 211 // script for the given source string with the right origin. | 178 // script for the given source string with the right origin. |
| 212 Handle<SharedFunctionInfo> LookupScript(Handle<String> source, | 179 MaybeHandle<SharedFunctionInfo> LookupScript( |
| 213 Handle<Object> name, | 180 Handle<String> source, Handle<Object> name, int line_offset, |
| 214 int line_offset, | 181 int column_offset, bool is_shared_cross_origin, Handle<Context> context); |
| 215 int column_offset, | |
| 216 bool is_shared_cross_origin, | |
| 217 Handle<Context> context); | |
| 218 | 182 |
| 219 // Finds the shared function info for a source string for eval in a | 183 // Finds the shared function info for a source string for eval in a |
| 220 // given context. Returns an empty handle if the cache doesn't | 184 // given context. Returns an empty handle if the cache doesn't |
| 221 // contain a script for the given source string. | 185 // contain a script for the given source string. |
| 222 Handle<SharedFunctionInfo> LookupEval(Handle<String> source, | 186 MaybeHandle<SharedFunctionInfo> LookupEval( |
| 223 Handle<Context> context, | 187 Handle<String> source, Handle<Context> context, StrictMode strict_mode, |
| 224 StrictMode strict_mode, | 188 int scope_position); |
| 225 int scope_position); | |
| 226 | 189 |
| 227 // Returns the regexp data associated with the given regexp if it | 190 // Returns the regexp data associated with the given regexp if it |
| 228 // is in cache, otherwise an empty handle. | 191 // is in cache, otherwise an empty handle. |
| 229 Handle<FixedArray> LookupRegExp(Handle<String> source, | 192 MaybeHandle<FixedArray> LookupRegExp( |
| 230 JSRegExp::Flags flags); | 193 Handle<String> source, JSRegExp::Flags flags); |
| 231 | 194 |
| 232 // Associate the (source, kind) pair to the shared function | 195 // Associate the (source, kind) pair to the shared function |
| 233 // info. This may overwrite an existing mapping. | 196 // info. This may overwrite an existing mapping. |
| 234 void PutScript(Handle<String> source, | 197 void PutScript(Handle<String> source, |
| 235 Handle<Context> context, | 198 Handle<Context> context, |
| 236 Handle<SharedFunctionInfo> function_info); | 199 Handle<SharedFunctionInfo> function_info); |
| 237 | 200 |
| 238 // Associate the (source, context->closure()->shared(), kind) triple | 201 // Associate the (source, context->closure()->shared(), kind) triple |
| 239 // with the shared function info. This may overwrite an existing mapping. | 202 // with the shared function info. This may overwrite an existing mapping. |
| 240 void PutEval(Handle<String> source, | 203 void PutEval(Handle<String> source, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 257 |
| 295 friend class Isolate; | 258 friend class Isolate; |
| 296 | 259 |
| 297 DISALLOW_COPY_AND_ASSIGN(CompilationCache); | 260 DISALLOW_COPY_AND_ASSIGN(CompilationCache); |
| 298 }; | 261 }; |
| 299 | 262 |
| 300 | 263 |
| 301 } } // namespace v8::internal | 264 } } // namespace v8::internal |
| 302 | 265 |
| 303 #endif // V8_COMPILATION_CACHE_H_ | 266 #endif // V8_COMPILATION_CACHE_H_ |
| OLD | NEW |