OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 bool is_shared_cross_origin, | 177 bool is_shared_cross_origin, |
178 Handle<Context> context) { | 178 Handle<Context> context) { |
179 Object* result = NULL; | 179 Object* result = NULL; |
180 int generation; | 180 int generation; |
181 | 181 |
182 // Probe the script generation tables. Make sure not to leak handles | 182 // Probe the script generation tables. Make sure not to leak handles |
183 // into the caller's handle scope. | 183 // into the caller's handle scope. |
184 { HandleScope scope(isolate()); | 184 { HandleScope scope(isolate()); |
185 for (generation = 0; generation < generations(); generation++) { | 185 for (generation = 0; generation < generations(); generation++) { |
186 Handle<CompilationCacheTable> table = GetTable(generation); | 186 Handle<CompilationCacheTable> table = GetTable(generation); |
187 Handle<Object> probe(table->Lookup(*source, *context), isolate()); | 187 Handle<Object> probe = table->Lookup(source, context); |
188 if (probe->IsSharedFunctionInfo()) { | 188 if (probe->IsSharedFunctionInfo()) { |
189 Handle<SharedFunctionInfo> function_info = | 189 Handle<SharedFunctionInfo> function_info = |
190 Handle<SharedFunctionInfo>::cast(probe); | 190 Handle<SharedFunctionInfo>::cast(probe); |
191 // Break when we've found a suitable shared function info that | 191 // Break when we've found a suitable shared function info that |
192 // matches the origin. | 192 // matches the origin. |
193 if (HasOrigin(function_info, | 193 if (HasOrigin(function_info, |
194 name, | 194 name, |
195 line_offset, | 195 line_offset, |
196 column_offset, | 196 column_offset, |
197 is_shared_cross_origin)) { | 197 is_shared_cross_origin)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 if (generation != 0) Put(source, context, shared); | 232 if (generation != 0) Put(source, context, shared); |
233 isolate()->counters()->compilation_cache_hits()->Increment(); | 233 isolate()->counters()->compilation_cache_hits()->Increment(); |
234 return shared; | 234 return shared; |
235 } else { | 235 } else { |
236 isolate()->counters()->compilation_cache_misses()->Increment(); | 236 isolate()->counters()->compilation_cache_misses()->Increment(); |
237 return Handle<SharedFunctionInfo>::null(); | 237 return Handle<SharedFunctionInfo>::null(); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 | 241 |
242 MaybeObject* CompilationCacheScript::TryTablePut( | |
243 Handle<String> source, | |
244 Handle<Context> context, | |
245 Handle<SharedFunctionInfo> function_info) { | |
246 Handle<CompilationCacheTable> table = GetFirstTable(); | |
247 return table->Put(*source, *context, *function_info); | |
248 } | |
249 | |
250 | |
251 Handle<CompilationCacheTable> CompilationCacheScript::TablePut( | |
252 Handle<String> source, | |
253 Handle<Context> context, | |
254 Handle<SharedFunctionInfo> function_info) { | |
255 CALL_HEAP_FUNCTION(isolate(), | |
256 TryTablePut(source, context, function_info), | |
257 CompilationCacheTable); | |
258 } | |
259 | |
260 | |
261 void CompilationCacheScript::Put(Handle<String> source, | 242 void CompilationCacheScript::Put(Handle<String> source, |
262 Handle<Context> context, | 243 Handle<Context> context, |
263 Handle<SharedFunctionInfo> function_info) { | 244 Handle<SharedFunctionInfo> function_info) { |
264 HandleScope scope(isolate()); | 245 HandleScope scope(isolate()); |
265 SetFirstTable(TablePut(source, context, function_info)); | 246 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 247 SetFirstTable( |
| 248 CompilationCacheTable::Put(table, source, context, function_info)); |
266 } | 249 } |
267 | 250 |
268 | 251 |
269 Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( | 252 MaybeHandle<SharedFunctionInfo> CompilationCacheEval::Lookup( |
270 Handle<String> source, | 253 Handle<String> source, |
271 Handle<Context> context, | 254 Handle<Context> context, |
272 StrictMode strict_mode, | 255 StrictMode strict_mode, |
273 int scope_position) { | 256 int scope_position) { |
274 // Make sure not to leak the table into the surrounding handle | 257 // Make sure not to leak the table into the surrounding handle |
275 // scope. Otherwise, we risk keeping old tables around even after | 258 // scope. Otherwise, we risk keeping old tables around even after |
276 // having cleared the cache. | 259 // having cleared the cache. |
277 Object* result = NULL; | 260 Handle<Object> result = isolate()->factory()->undefined_value(); |
278 int generation; | 261 int generation; |
279 { HandleScope scope(isolate()); | 262 { HandleScope scope(isolate()); |
| 263 Handle<Object> temp = result; |
280 for (generation = 0; generation < generations(); generation++) { | 264 for (generation = 0; generation < generations(); generation++) { |
281 Handle<CompilationCacheTable> table = GetTable(generation); | 265 Handle<CompilationCacheTable> table = GetTable(generation); |
282 result = table->LookupEval( | 266 temp = table->LookupEval(source, context, strict_mode, scope_position); |
283 *source, *context, strict_mode, scope_position); | 267 if (temp->IsSharedFunctionInfo()) break; |
284 if (result->IsSharedFunctionInfo()) { | |
285 break; | |
286 } | |
287 } | 268 } |
| 269 if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp); |
288 } | 270 } |
289 if (result->IsSharedFunctionInfo()) { | 271 if (result->IsSharedFunctionInfo()) { |
290 Handle<SharedFunctionInfo> | 272 Handle<SharedFunctionInfo> function_info = |
291 function_info(SharedFunctionInfo::cast(result), isolate()); | 273 Handle<SharedFunctionInfo>::cast(result); |
292 if (generation != 0) { | 274 if (generation != 0) { |
293 Put(source, context, function_info, scope_position); | 275 Put(source, context, function_info, scope_position); |
294 } | 276 } |
295 isolate()->counters()->compilation_cache_hits()->Increment(); | 277 isolate()->counters()->compilation_cache_hits()->Increment(); |
296 return function_info; | 278 return function_info; |
297 } else { | 279 } else { |
298 isolate()->counters()->compilation_cache_misses()->Increment(); | 280 isolate()->counters()->compilation_cache_misses()->Increment(); |
299 return Handle<SharedFunctionInfo>::null(); | 281 return MaybeHandle<SharedFunctionInfo>(); |
300 } | 282 } |
301 } | 283 } |
302 | 284 |
303 | 285 |
304 MaybeObject* CompilationCacheEval::TryTablePut( | |
305 Handle<String> source, | |
306 Handle<Context> context, | |
307 Handle<SharedFunctionInfo> function_info, | |
308 int scope_position) { | |
309 Handle<CompilationCacheTable> table = GetFirstTable(); | |
310 return table->PutEval(*source, *context, *function_info, scope_position); | |
311 } | |
312 | |
313 | |
314 Handle<CompilationCacheTable> CompilationCacheEval::TablePut( | |
315 Handle<String> source, | |
316 Handle<Context> context, | |
317 Handle<SharedFunctionInfo> function_info, | |
318 int scope_position) { | |
319 CALL_HEAP_FUNCTION(isolate(), | |
320 TryTablePut( | |
321 source, context, function_info, scope_position), | |
322 CompilationCacheTable); | |
323 } | |
324 | |
325 | |
326 void CompilationCacheEval::Put(Handle<String> source, | 286 void CompilationCacheEval::Put(Handle<String> source, |
327 Handle<Context> context, | 287 Handle<Context> context, |
328 Handle<SharedFunctionInfo> function_info, | 288 Handle<SharedFunctionInfo> function_info, |
329 int scope_position) { | 289 int scope_position) { |
330 HandleScope scope(isolate()); | 290 HandleScope scope(isolate()); |
331 SetFirstTable(TablePut(source, context, function_info, scope_position)); | 291 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 292 table = CompilationCacheTable::PutEval(table, source, context, |
| 293 function_info, scope_position); |
| 294 SetFirstTable(table); |
332 } | 295 } |
333 | 296 |
334 | 297 |
335 Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, | 298 MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup( |
336 JSRegExp::Flags flags) { | 299 Handle<String> source, |
| 300 JSRegExp::Flags flags) { |
337 // Make sure not to leak the table into the surrounding handle | 301 // Make sure not to leak the table into the surrounding handle |
338 // scope. Otherwise, we risk keeping old tables around even after | 302 // scope. Otherwise, we risk keeping old tables around even after |
339 // having cleared the cache. | 303 // having cleared the cache. |
340 Object* result = NULL; | 304 Handle<Object> result = isolate()->factory()->undefined_value(); |
341 int generation; | 305 int generation; |
342 { HandleScope scope(isolate()); | 306 { HandleScope scope(isolate()); |
| 307 Handle<Object> temp = result; |
343 for (generation = 0; generation < generations(); generation++) { | 308 for (generation = 0; generation < generations(); generation++) { |
344 Handle<CompilationCacheTable> table = GetTable(generation); | 309 Handle<CompilationCacheTable> table = GetTable(generation); |
345 result = table->LookupRegExp(*source, flags); | 310 temp = table->LookupRegExp(source, flags); |
346 if (result->IsFixedArray()) { | 311 if (temp->IsFixedArray()) { |
347 break; | 312 break; |
348 } | 313 } |
349 } | 314 } |
| 315 if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp); |
350 } | 316 } |
351 if (result->IsFixedArray()) { | 317 if (result->IsFixedArray()) { |
352 Handle<FixedArray> data(FixedArray::cast(result), isolate()); | 318 Handle<FixedArray> data = Handle<FixedArray>::cast(result); |
353 if (generation != 0) { | 319 if (generation != 0) { |
354 Put(source, flags, data); | 320 Put(source, flags, data); |
355 } | 321 } |
356 isolate()->counters()->compilation_cache_hits()->Increment(); | 322 isolate()->counters()->compilation_cache_hits()->Increment(); |
357 return data; | 323 return data; |
358 } else { | 324 } else { |
359 isolate()->counters()->compilation_cache_misses()->Increment(); | 325 isolate()->counters()->compilation_cache_misses()->Increment(); |
360 return Handle<FixedArray>::null(); | 326 return MaybeHandle<FixedArray>(); |
361 } | 327 } |
362 } | 328 } |
363 | 329 |
364 | 330 |
365 MaybeObject* CompilationCacheRegExp::TryTablePut( | |
366 Handle<String> source, | |
367 JSRegExp::Flags flags, | |
368 Handle<FixedArray> data) { | |
369 Handle<CompilationCacheTable> table = GetFirstTable(); | |
370 return table->PutRegExp(*source, flags, *data); | |
371 } | |
372 | |
373 | |
374 Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut( | |
375 Handle<String> source, | |
376 JSRegExp::Flags flags, | |
377 Handle<FixedArray> data) { | |
378 CALL_HEAP_FUNCTION(isolate(), | |
379 TryTablePut(source, flags, data), | |
380 CompilationCacheTable); | |
381 } | |
382 | |
383 | |
384 void CompilationCacheRegExp::Put(Handle<String> source, | 331 void CompilationCacheRegExp::Put(Handle<String> source, |
385 JSRegExp::Flags flags, | 332 JSRegExp::Flags flags, |
386 Handle<FixedArray> data) { | 333 Handle<FixedArray> data) { |
387 HandleScope scope(isolate()); | 334 HandleScope scope(isolate()); |
388 SetFirstTable(TablePut(source, flags, data)); | 335 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 336 SetFirstTable(CompilationCacheTable::PutRegExp(table, source, flags, data)); |
389 } | 337 } |
390 | 338 |
391 | 339 |
392 void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { | 340 void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { |
393 if (!IsEnabled()) return; | 341 if (!IsEnabled()) return; |
394 | 342 |
395 eval_global_.Remove(function_info); | 343 eval_global_.Remove(function_info); |
396 eval_contextual_.Remove(function_info); | 344 eval_contextual_.Remove(function_info); |
397 script_.Remove(function_info); | 345 script_.Remove(function_info); |
398 } | 346 } |
399 | 347 |
400 | 348 |
401 Handle<SharedFunctionInfo> CompilationCache::LookupScript( | 349 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript( |
402 Handle<String> source, | 350 Handle<String> source, |
403 Handle<Object> name, | 351 Handle<Object> name, |
404 int line_offset, | 352 int line_offset, |
405 int column_offset, | 353 int column_offset, |
406 bool is_shared_cross_origin, | 354 bool is_shared_cross_origin, |
407 Handle<Context> context) { | 355 Handle<Context> context) { |
408 if (!IsEnabled()) { | 356 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); |
409 return Handle<SharedFunctionInfo>::null(); | |
410 } | |
411 | 357 |
412 return script_.Lookup(source, | 358 return script_.Lookup(source, name, line_offset, column_offset, |
413 name, | 359 is_shared_cross_origin, context); |
414 line_offset, | |
415 column_offset, | |
416 is_shared_cross_origin, | |
417 context); | |
418 } | 360 } |
419 | 361 |
420 | 362 |
421 Handle<SharedFunctionInfo> CompilationCache::LookupEval( | 363 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( |
422 Handle<String> source, | 364 Handle<String> source, |
423 Handle<Context> context, | 365 Handle<Context> context, |
424 StrictMode strict_mode, | 366 StrictMode strict_mode, |
425 int scope_position) { | 367 int scope_position) { |
426 if (!IsEnabled()) { | 368 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); |
427 return Handle<SharedFunctionInfo>::null(); | |
428 } | |
429 | 369 |
430 Handle<SharedFunctionInfo> result; | 370 MaybeHandle<SharedFunctionInfo> result; |
431 if (context->IsNativeContext()) { | 371 if (context->IsNativeContext()) { |
432 result = eval_global_.Lookup( | 372 result = eval_global_.Lookup( |
433 source, context, strict_mode, scope_position); | 373 source, context, strict_mode, scope_position); |
434 } else { | 374 } else { |
435 ASSERT(scope_position != RelocInfo::kNoPosition); | 375 ASSERT(scope_position != RelocInfo::kNoPosition); |
436 result = eval_contextual_.Lookup( | 376 result = eval_contextual_.Lookup( |
437 source, context, strict_mode, scope_position); | 377 source, context, strict_mode, scope_position); |
438 } | 378 } |
439 return result; | 379 return result; |
440 } | 380 } |
441 | 381 |
442 | 382 |
443 Handle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, | 383 MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, |
444 JSRegExp::Flags flags) { | 384 JSRegExp::Flags flags) { |
445 if (!IsEnabled()) { | 385 if (!IsEnabled()) return MaybeHandle<FixedArray>(); |
446 return Handle<FixedArray>::null(); | |
447 } | |
448 | 386 |
449 return reg_exp_.Lookup(source, flags); | 387 return reg_exp_.Lookup(source, flags); |
450 } | 388 } |
451 | 389 |
452 | 390 |
453 void CompilationCache::PutScript(Handle<String> source, | 391 void CompilationCache::PutScript(Handle<String> source, |
454 Handle<Context> context, | 392 Handle<Context> context, |
455 Handle<SharedFunctionInfo> function_info) { | 393 Handle<SharedFunctionInfo> function_info) { |
456 if (!IsEnabled()) return; | 394 if (!IsEnabled()) return; |
457 | 395 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 } | 458 } |
521 | 459 |
522 | 460 |
523 void CompilationCache::Disable() { | 461 void CompilationCache::Disable() { |
524 enabled_ = false; | 462 enabled_ = false; |
525 Clear(); | 463 Clear(); |
526 } | 464 } |
527 | 465 |
528 | 466 |
529 } } // namespace v8::internal | 467 } } // namespace v8::internal |
OLD | NEW |