Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/compilation-cache.cc

Issue 923573002: Properly thread language mode to compilation cache (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compilation-cache.h ('k') | src/compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/assembler.h" 7 #include "src/assembler.h"
8 #include "src/compilation-cache.h" 8 #include "src/compilation-cache.h"
9 #include "src/serialize.h" 9 #include "src/serialize.h"
10 10
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 141
142 142
143 // TODO(245): Need to allow identical code from different contexts to 143 // TODO(245): Need to allow identical code from different contexts to
144 // be cached in the same script generation. Currently the first use 144 // be cached in the same script generation. Currently the first use
145 // will be cached, but subsequent code from different source / line 145 // will be cached, but subsequent code from different source / line
146 // won't. 146 // won't.
147 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( 147 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
148 Handle<String> source, Handle<Object> name, int line_offset, 148 Handle<String> source, Handle<Object> name, int line_offset,
149 int column_offset, bool is_embedder_debug_script, 149 int column_offset, bool is_embedder_debug_script,
150 bool is_shared_cross_origin, Handle<Context> context) { 150 bool is_shared_cross_origin, Handle<Context> context,
151 LanguageMode language_mode) {
151 Object* result = NULL; 152 Object* result = NULL;
152 int generation; 153 int generation;
153 154
154 // Probe the script generation tables. Make sure not to leak handles 155 // Probe the script generation tables. Make sure not to leak handles
155 // into the caller's handle scope. 156 // into the caller's handle scope.
156 { HandleScope scope(isolate()); 157 { HandleScope scope(isolate());
157 for (generation = 0; generation < generations(); generation++) { 158 for (generation = 0; generation < generations(); generation++) {
158 Handle<CompilationCacheTable> table = GetTable(generation); 159 Handle<CompilationCacheTable> table = GetTable(generation);
159 Handle<Object> probe = table->Lookup(source, context); 160 Handle<Object> probe = table->Lookup(source, context, language_mode);
160 if (probe->IsSharedFunctionInfo()) { 161 if (probe->IsSharedFunctionInfo()) {
161 Handle<SharedFunctionInfo> function_info = 162 Handle<SharedFunctionInfo> function_info =
162 Handle<SharedFunctionInfo>::cast(probe); 163 Handle<SharedFunctionInfo>::cast(probe);
163 // Break when we've found a suitable shared function info that 164 // Break when we've found a suitable shared function info that
164 // matches the origin. 165 // matches the origin.
165 if (HasOrigin(function_info, name, line_offset, column_offset, 166 if (HasOrigin(function_info, name, line_offset, column_offset,
166 is_embedder_debug_script, is_shared_cross_origin)) { 167 is_embedder_debug_script, is_shared_cross_origin)) {
167 result = *function_info; 168 result = *function_info;
168 break; 169 break;
169 } 170 }
170 } 171 }
171 } 172 }
172 } 173 }
173 174
174 // Once outside the manacles of the handle scope, we need to recheck 175 // Once outside the manacles of the handle scope, we need to recheck
175 // to see if we actually found a cached script. If so, we return a 176 // to see if we actually found a cached script. If so, we return a
176 // handle created in the caller's handle scope. 177 // handle created in the caller's handle scope.
177 if (result != NULL) { 178 if (result != NULL) {
178 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result), 179 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result),
179 isolate()); 180 isolate());
180 DCHECK(HasOrigin(shared, name, line_offset, column_offset, 181 DCHECK(HasOrigin(shared, name, line_offset, column_offset,
181 is_embedder_debug_script, is_shared_cross_origin)); 182 is_embedder_debug_script, is_shared_cross_origin));
182 // If the script was found in a later generation, we promote it to 183 // If the script was found in a later generation, we promote it to
183 // the first generation to let it survive longer in the cache. 184 // the first generation to let it survive longer in the cache.
184 if (generation != 0) Put(source, context, shared); 185 if (generation != 0) Put(source, context, language_mode, shared);
185 isolate()->counters()->compilation_cache_hits()->Increment(); 186 isolate()->counters()->compilation_cache_hits()->Increment();
186 return shared; 187 return shared;
187 } else { 188 } else {
188 isolate()->counters()->compilation_cache_misses()->Increment(); 189 isolate()->counters()->compilation_cache_misses()->Increment();
189 return Handle<SharedFunctionInfo>::null(); 190 return Handle<SharedFunctionInfo>::null();
190 } 191 }
191 } 192 }
192 193
193 194
194 void CompilationCacheScript::Put(Handle<String> source, 195 void CompilationCacheScript::Put(Handle<String> source,
195 Handle<Context> context, 196 Handle<Context> context,
197 LanguageMode language_mode,
196 Handle<SharedFunctionInfo> function_info) { 198 Handle<SharedFunctionInfo> function_info) {
197 HandleScope scope(isolate()); 199 HandleScope scope(isolate());
198 Handle<CompilationCacheTable> table = GetFirstTable(); 200 Handle<CompilationCacheTable> table = GetFirstTable();
199 SetFirstTable( 201 SetFirstTable(CompilationCacheTable::Put(table, source, context,
200 CompilationCacheTable::Put(table, source, context, function_info)); 202 language_mode, function_info));
201 } 203 }
202 204
203 205
204 MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup( 206 MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup(
205 Handle<String> source, Handle<SharedFunctionInfo> outer_info, 207 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
206 LanguageMode language_mode, int scope_position) { 208 LanguageMode language_mode, int scope_position) {
207 HandleScope scope(isolate()); 209 HandleScope scope(isolate());
208 // Make sure not to leak the table into the surrounding handle 210 // Make sure not to leak the table into the surrounding handle
209 // scope. Otherwise, we risk keeping old tables around even after 211 // scope. Otherwise, we risk keeping old tables around even after
210 // having cleared the cache. 212 // having cleared the cache.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 287
286 eval_global_.Remove(function_info); 288 eval_global_.Remove(function_info);
287 eval_contextual_.Remove(function_info); 289 eval_contextual_.Remove(function_info);
288 script_.Remove(function_info); 290 script_.Remove(function_info);
289 } 291 }
290 292
291 293
292 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript( 294 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript(
293 Handle<String> source, Handle<Object> name, int line_offset, 295 Handle<String> source, Handle<Object> name, int line_offset,
294 int column_offset, bool is_embedder_debug_script, 296 int column_offset, bool is_embedder_debug_script,
295 bool is_shared_cross_origin, Handle<Context> context) { 297 bool is_shared_cross_origin, Handle<Context> context,
298 LanguageMode language_mode) {
296 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); 299 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
297 300
298 return script_.Lookup(source, name, line_offset, column_offset, 301 return script_.Lookup(source, name, line_offset, column_offset,
299 is_embedder_debug_script, is_shared_cross_origin, 302 is_embedder_debug_script, is_shared_cross_origin,
300 context); 303 context, language_mode);
301 } 304 }
302 305
303 306
304 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( 307 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval(
305 Handle<String> source, Handle<SharedFunctionInfo> outer_info, 308 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
306 Handle<Context> context, LanguageMode language_mode, int scope_position) { 309 Handle<Context> context, LanguageMode language_mode, int scope_position) {
307 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); 310 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
308 311
309 MaybeHandle<SharedFunctionInfo> result; 312 MaybeHandle<SharedFunctionInfo> result;
310 if (context->IsNativeContext()) { 313 if (context->IsNativeContext()) {
(...skipping 11 matching lines...) Expand all
322 MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, 325 MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source,
323 JSRegExp::Flags flags) { 326 JSRegExp::Flags flags) {
324 if (!IsEnabled()) return MaybeHandle<FixedArray>(); 327 if (!IsEnabled()) return MaybeHandle<FixedArray>();
325 328
326 return reg_exp_.Lookup(source, flags); 329 return reg_exp_.Lookup(source, flags);
327 } 330 }
328 331
329 332
330 void CompilationCache::PutScript(Handle<String> source, 333 void CompilationCache::PutScript(Handle<String> source,
331 Handle<Context> context, 334 Handle<Context> context,
335 LanguageMode language_mode,
332 Handle<SharedFunctionInfo> function_info) { 336 Handle<SharedFunctionInfo> function_info) {
333 if (!IsEnabled()) return; 337 if (!IsEnabled()) return;
334 338
335 script_.Put(source, context, function_info); 339 script_.Put(source, context, language_mode, function_info);
336 } 340 }
337 341
338 342
339 void CompilationCache::PutEval(Handle<String> source, 343 void CompilationCache::PutEval(Handle<String> source,
340 Handle<SharedFunctionInfo> outer_info, 344 Handle<SharedFunctionInfo> outer_info,
341 Handle<Context> context, 345 Handle<Context> context,
342 Handle<SharedFunctionInfo> function_info, 346 Handle<SharedFunctionInfo> function_info,
343 int scope_position) { 347 int scope_position) {
344 if (!IsEnabled()) return; 348 if (!IsEnabled()) return;
345 349
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 } 402 }
399 403
400 404
401 void CompilationCache::Disable() { 405 void CompilationCache::Disable() {
402 enabled_ = false; 406 enabled_ = false;
403 Clear(); 407 Clear();
404 } 408 }
405 409
406 410
407 } } // namespace v8::internal 411 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compilation-cache.h ('k') | src/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698