Chromium Code Reviews| 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( | 242 Handle<CompilationCacheTable> CompilationCacheScript::TablePut( |
| 252 Handle<String> source, | 243 Handle<String> source, |
| 253 Handle<Context> context, | 244 Handle<Context> context, |
| 254 Handle<SharedFunctionInfo> function_info) { | 245 Handle<SharedFunctionInfo> function_info) { |
| 255 CALL_HEAP_FUNCTION(isolate(), | 246 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 256 TryTablePut(source, context, function_info), | 247 return CompilationCacheTable::Put(table, source, context, function_info); |
| 257 CompilationCacheTable); | |
| 258 } | 248 } |
| 259 | 249 |
| 260 | 250 |
| 261 void CompilationCacheScript::Put(Handle<String> source, | 251 void CompilationCacheScript::Put(Handle<String> source, |
| 262 Handle<Context> context, | 252 Handle<Context> context, |
| 263 Handle<SharedFunctionInfo> function_info) { | 253 Handle<SharedFunctionInfo> function_info) { |
| 264 HandleScope scope(isolate()); | 254 HandleScope scope(isolate()); |
| 265 SetFirstTable(TablePut(source, context, function_info)); | 255 SetFirstTable(TablePut(source, context, function_info)); |
| 266 } | 256 } |
| 267 | 257 |
| 268 | 258 |
| 269 Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( | 259 Handle<SharedFunctionInfo> CompilationCacheEval::Lookup( |
| 270 Handle<String> source, | 260 Handle<String> source, |
| 271 Handle<Context> context, | 261 Handle<Context> context, |
| 272 StrictMode strict_mode, | 262 StrictMode strict_mode, |
| 273 int scope_position) { | 263 int scope_position) { |
| 274 // Make sure not to leak the table into the surrounding handle | 264 // Make sure not to leak the table into the surrounding handle |
| 275 // scope. Otherwise, we risk keeping old tables around even after | 265 // scope. Otherwise, we risk keeping old tables around even after |
| 276 // having cleared the cache. | 266 // having cleared the cache. |
| 277 Object* result = NULL; | 267 Handle<Object> result = isolate()->factory()->undefined_value(); |
| 278 int generation; | 268 int generation; |
| 279 { HandleScope scope(isolate()); | 269 { HandleScope scope(isolate()); |
| 270 Handle<Object> temp = result; | |
| 280 for (generation = 0; generation < generations(); generation++) { | 271 for (generation = 0; generation < generations(); generation++) { |
| 281 Handle<CompilationCacheTable> table = GetTable(generation); | 272 Handle<CompilationCacheTable> table = GetTable(generation); |
| 282 result = table->LookupEval( | 273 temp = table->LookupEval(source, context, strict_mode, scope_position); |
| 283 *source, *context, strict_mode, scope_position); | 274 if (temp->IsSharedFunctionInfo()) break; |
| 284 if (result->IsSharedFunctionInfo()) { | |
| 285 break; | |
| 286 } | |
| 287 } | 275 } |
| 276 if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp); | |
| 288 } | 277 } |
| 289 if (result->IsSharedFunctionInfo()) { | 278 if (result->IsSharedFunctionInfo()) { |
| 290 Handle<SharedFunctionInfo> | 279 Handle<SharedFunctionInfo> function_info = |
| 291 function_info(SharedFunctionInfo::cast(result), isolate()); | 280 Handle<SharedFunctionInfo>::cast(result); |
| 292 if (generation != 0) { | 281 if (generation != 0) { |
| 293 Put(source, context, function_info, scope_position); | 282 Put(source, context, function_info, scope_position); |
| 294 } | 283 } |
| 295 isolate()->counters()->compilation_cache_hits()->Increment(); | 284 isolate()->counters()->compilation_cache_hits()->Increment(); |
| 296 return function_info; | 285 return function_info; |
| 297 } else { | 286 } else { |
| 298 isolate()->counters()->compilation_cache_misses()->Increment(); | 287 isolate()->counters()->compilation_cache_misses()->Increment(); |
| 299 return Handle<SharedFunctionInfo>::null(); | 288 return Handle<SharedFunctionInfo>::null(); |
|
Yang
2014/04/08 09:31:11
Maybe we also should return MaybeHandle to force n
ulan
2014/04/08 10:05:59
Done.
| |
| 300 } | 289 } |
| 301 } | 290 } |
| 302 | 291 |
| 303 | 292 |
| 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( | 293 Handle<CompilationCacheTable> CompilationCacheEval::TablePut( |
| 315 Handle<String> source, | 294 Handle<String> source, |
| 316 Handle<Context> context, | 295 Handle<Context> context, |
| 317 Handle<SharedFunctionInfo> function_info, | 296 Handle<SharedFunctionInfo> function_info, |
| 318 int scope_position) { | 297 int scope_position) { |
| 319 CALL_HEAP_FUNCTION(isolate(), | 298 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 320 TryTablePut( | 299 return CompilationCacheTable::PutEval(table, source, context, |
| 321 source, context, function_info, scope_position), | 300 function_info, scope_position); |
| 322 CompilationCacheTable); | |
| 323 } | 301 } |
| 324 | 302 |
| 325 | 303 |
| 326 void CompilationCacheEval::Put(Handle<String> source, | 304 void CompilationCacheEval::Put(Handle<String> source, |
| 327 Handle<Context> context, | 305 Handle<Context> context, |
| 328 Handle<SharedFunctionInfo> function_info, | 306 Handle<SharedFunctionInfo> function_info, |
| 329 int scope_position) { | 307 int scope_position) { |
| 330 HandleScope scope(isolate()); | 308 HandleScope scope(isolate()); |
| 331 SetFirstTable(TablePut(source, context, function_info, scope_position)); | 309 SetFirstTable(TablePut(source, context, function_info, scope_position)); |
| 332 } | 310 } |
| 333 | 311 |
| 334 | 312 |
| 335 Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, | 313 Handle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, |
| 336 JSRegExp::Flags flags) { | 314 JSRegExp::Flags flags) { |
| 337 // Make sure not to leak the table into the surrounding handle | 315 // Make sure not to leak the table into the surrounding handle |
| 338 // scope. Otherwise, we risk keeping old tables around even after | 316 // scope. Otherwise, we risk keeping old tables around even after |
| 339 // having cleared the cache. | 317 // having cleared the cache. |
| 340 Object* result = NULL; | 318 Handle<Object> result = isolate()->factory()->undefined_value(); |
| 341 int generation; | 319 int generation; |
| 342 { HandleScope scope(isolate()); | 320 { HandleScope scope(isolate()); |
| 321 Handle<Object> temp = result; | |
| 343 for (generation = 0; generation < generations(); generation++) { | 322 for (generation = 0; generation < generations(); generation++) { |
| 344 Handle<CompilationCacheTable> table = GetTable(generation); | 323 Handle<CompilationCacheTable> table = GetTable(generation); |
| 345 result = table->LookupRegExp(*source, flags); | 324 temp = table->LookupRegExp(source, flags); |
| 346 if (result->IsFixedArray()) { | 325 if (temp->IsFixedArray()) { |
| 347 break; | 326 break; |
| 348 } | 327 } |
| 349 } | 328 } |
| 329 if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp); | |
| 350 } | 330 } |
| 351 if (result->IsFixedArray()) { | 331 if (result->IsFixedArray()) { |
| 352 Handle<FixedArray> data(FixedArray::cast(result), isolate()); | 332 Handle<FixedArray> data = Handle<FixedArray>::cast(result); |
| 353 if (generation != 0) { | 333 if (generation != 0) { |
| 354 Put(source, flags, data); | 334 Put(source, flags, data); |
| 355 } | 335 } |
| 356 isolate()->counters()->compilation_cache_hits()->Increment(); | 336 isolate()->counters()->compilation_cache_hits()->Increment(); |
| 357 return data; | 337 return data; |
| 358 } else { | 338 } else { |
| 359 isolate()->counters()->compilation_cache_misses()->Increment(); | 339 isolate()->counters()->compilation_cache_misses()->Increment(); |
| 360 return Handle<FixedArray>::null(); | 340 return Handle<FixedArray>::null(); |
| 361 } | 341 } |
| 362 } | 342 } |
| 363 | 343 |
| 364 | 344 |
| 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( | 345 Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut( |
| 375 Handle<String> source, | 346 Handle<String> source, |
| 376 JSRegExp::Flags flags, | 347 JSRegExp::Flags flags, |
| 377 Handle<FixedArray> data) { | 348 Handle<FixedArray> data) { |
| 378 CALL_HEAP_FUNCTION(isolate(), | 349 Handle<CompilationCacheTable> table = GetFirstTable(); |
| 379 TryTablePut(source, flags, data), | 350 return CompilationCacheTable::PutRegExp(table, source, flags, data); |
| 380 CompilationCacheTable); | |
| 381 } | 351 } |
| 382 | 352 |
| 383 | 353 |
| 384 void CompilationCacheRegExp::Put(Handle<String> source, | 354 void CompilationCacheRegExp::Put(Handle<String> source, |
| 385 JSRegExp::Flags flags, | 355 JSRegExp::Flags flags, |
| 386 Handle<FixedArray> data) { | 356 Handle<FixedArray> data) { |
| 387 HandleScope scope(isolate()); | 357 HandleScope scope(isolate()); |
| 388 SetFirstTable(TablePut(source, flags, data)); | 358 SetFirstTable(TablePut(source, flags, data)); |
| 389 } | 359 } |
| 390 | 360 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 } | 490 } |
| 521 | 491 |
| 522 | 492 |
| 523 void CompilationCache::Disable() { | 493 void CompilationCache::Disable() { |
| 524 enabled_ = false; | 494 enabled_ = false; |
| 525 Clear(); | 495 Clear(); |
| 526 } | 496 } |
| 527 | 497 |
| 528 | 498 |
| 529 } } // namespace v8::internal | 499 } } // namespace v8::internal |
| OLD | NEW |