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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8ScriptRunner.cpp

Issue 1916283003: [K6] Replace bind() + GCed pointers with retainedRef() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Kuroneko_5c
Patch Set: Rebase Created 4 years, 7 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 | « no previous file | third_party/WebKit/Source/core/dom/ExecutionContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 256
257 typedef Function<v8::MaybeLocal<v8::Script>(v8::Isolate*, v8::Local<v8::String>, v8::ScriptOrigin)> CompileFn; 257 typedef Function<v8::MaybeLocal<v8::Script>(v8::Isolate*, v8::Local<v8::String>, v8::ScriptOrigin)> CompileFn;
258 258
259 // A notation convenience: WTF::bind<...> needs to be given the right argument 259 // A notation convenience: WTF::bind<...> needs to be given the right argument
260 // types. We have an awful lot of bind calls below, all with the same types, so 260 // types. We have an awful lot of bind calls below, all with the same types, so
261 // this local bind lets WTF::bind to all the work, but 'knows' the right 261 // this local bind lets WTF::bind to all the work, but 'knows' the right
262 // parameter types. 262 // parameter types.
263 // This version isn't quite as smart as the real WTF::bind, though, so you 263 // This version isn't quite as smart as the real WTF::bind, though, so you
264 // sometimes may still have to call the original. 264 // sometimes may still have to call the original.
265 template<typename... A> 265 template<typename... A>
266 PassOwnPtr<CompileFn> bind(const A&... args) 266 PassOwnPtr<CompileFn> bind(A&&... args)
267 { 267 {
268 return WTF::bind<v8::Isolate*, v8::Local<v8::String>, v8::ScriptOrigin>(args ...); 268 return WTF::bind<v8::Isolate*, v8::Local<v8::String>, v8::ScriptOrigin>(std: :forward<A>(args)...);
269 } 269 }
270 270
271 // Select a compile function from any of the above, mainly depending on 271 // Select a compile function from any of the above, mainly depending on
272 // cacheOptions. 272 // cacheOptions.
273 PassOwnPtr<CompileFn> selectCompileFunction(V8CacheOptions cacheOptions, CachedM etadataHandler* cacheHandler, v8::Local<v8::String> code, V8CompileHistogram::Ca cheability cacheabilityIfNoHandler) 273 PassOwnPtr<CompileFn> selectCompileFunction(V8CacheOptions cacheOptions, CachedM etadataHandler* cacheHandler, v8::Local<v8::String> code, V8CompileHistogram::Ca cheability cacheabilityIfNoHandler)
274 { 274 {
275 static const int minimalCodeLength = 1024; 275 static const int minimalCodeLength = 1024;
276 static const int hotHours = 72; 276 static const int hotHours = 72;
277 277
278 // Caching is not available in this case. 278 // Caching is not available in this case.
279 if (!cacheHandler) 279 if (!cacheHandler)
280 return bind(compileWithoutOptions, cacheabilityIfNoHandler); 280 return bind(compileWithoutOptions, cacheabilityIfNoHandler);
281 281
282 if (cacheOptions == V8CacheOptionsNone) 282 if (cacheOptions == V8CacheOptionsNone)
283 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); 283 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable);
284 284
285 // Caching is not worthwhile for small scripts. Do not use caching 285 // Caching is not worthwhile for small scripts. Do not use caching
286 // unless explicitly expected, indicated by the cache option. 286 // unless explicitly expected, indicated by the cache option.
287 if (code->Length() < minimalCodeLength) 287 if (code->Length() < minimalCodeLength)
288 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); 288 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable);
289 289
290 // The cacheOptions will guide our strategy: 290 // The cacheOptions will guide our strategy:
291 switch (cacheOptions) { 291 switch (cacheOptions) {
292 case V8CacheOptionsParse: 292 case V8CacheOptionsParse:
293 // Use parser-cache; in-memory only. 293 // Use parser-cache; in-memory only.
294 return bind(compileAndConsumeOrProduce, cacheHandler, cacheTag(CacheTagP arser, cacheHandler), v8::ScriptCompiler::kConsumeParserCache, v8::ScriptCompile r::kProduceParserCache, CachedMetadataHandler::CacheLocally); 294 return bind(compileAndConsumeOrProduce, retainedRef(cacheHandler), cache Tag(CacheTagParser, cacheHandler), v8::ScriptCompiler::kConsumeParserCache, v8:: ScriptCompiler::kProduceParserCache, CachedMetadataHandler::CacheLocally);
295 break; 295 break;
296 296
297 case V8CacheOptionsDefault: 297 case V8CacheOptionsDefault:
298 case V8CacheOptionsCode: { 298 case V8CacheOptionsCode: {
299 // Use code caching for recently seen resources. 299 // Use code caching for recently seen resources.
300 // Use compression depending on the cache option. 300 // Use compression depending on the cache option.
301 unsigned codeCacheTag = cacheTag(CacheTagCode, cacheHandler); 301 unsigned codeCacheTag = cacheTag(CacheTagCode, cacheHandler);
302 CachedMetadata* codeCache = cacheHandler->cachedMetadata(codeCacheTag); 302 CachedMetadata* codeCache = cacheHandler->cachedMetadata(codeCacheTag);
303 if (codeCache) 303 if (codeCache)
304 return bind(compileAndConsumeCache, cacheHandler, codeCacheTag, v8:: ScriptCompiler::kConsumeCodeCache); 304 return bind(compileAndConsumeCache, retainedRef(cacheHandler), codeC acheTag, v8::ScriptCompiler::kConsumeCodeCache);
305 if (!isResourceHotForCaching(cacheHandler, hotHours)) { 305 if (!isResourceHotForCaching(cacheHandler, hotHours)) {
306 V8ScriptRunner::setCacheTimeStamp(cacheHandler); 306 V8ScriptRunner::setCacheTimeStamp(cacheHandler);
307 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); 307 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable);
308 } 308 }
309 return bind(compileAndProduceCache, cacheHandler, codeCacheTag, v8::Scri ptCompiler::kProduceCodeCache, CachedMetadataHandler::SendToPlatform); 309 return bind(compileAndProduceCache, retainedRef(cacheHandler), codeCache Tag, v8::ScriptCompiler::kProduceCodeCache, CachedMetadataHandler::SendToPlatfor m);
310 break; 310 break;
311 } 311 }
312 312
313 case V8CacheOptionsNone: 313 case V8CacheOptionsNone:
314 // Shouldn't happen, as this is handled above. 314 // Shouldn't happen, as this is handled above.
315 // Case is here so that compiler can check all cases are handled. 315 // Case is here so that compiler can check all cases are handled.
316 ASSERT_NOT_REACHED(); 316 ASSERT_NOT_REACHED();
317 break; 317 break;
318 } 318 }
319 319
320 // All switch branches should return and we should never get here. 320 // All switch branches should return and we should never get here.
321 // But some compilers aren't sure, hence this default. 321 // But some compilers aren't sure, hence this default.
322 ASSERT_NOT_REACHED(); 322 ASSERT_NOT_REACHED();
323 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); 323 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable);
324 } 324 }
325 325
326 // Select a compile function for a streaming compile. 326 // Select a compile function for a streaming compile.
327 PassOwnPtr<CompileFn> selectCompileFunction(V8CacheOptions cacheOptions, ScriptR esource* resource, ScriptStreamer* streamer) 327 PassOwnPtr<CompileFn> selectCompileFunction(V8CacheOptions cacheOptions, ScriptR esource* resource, ScriptStreamer* streamer)
328 { 328 {
329 // We don't stream scripts which don't have a Resource. 329 // We don't stream scripts which don't have a Resource.
330 ASSERT(resource); 330 ASSERT(resource);
331 // Failed resources should never get this far. 331 // Failed resources should never get this far.
332 ASSERT(!resource->errorOccurred()); 332 ASSERT(!resource->errorOccurred());
333 ASSERT(streamer->isFinished()); 333 ASSERT(streamer->isFinished());
334 ASSERT(!streamer->streamingSuppressed()); 334 ASSERT(!streamer->streamingSuppressed());
335 return WTF::bind<v8::Isolate*, v8::Local<v8::String>, v8::ScriptOrigin>(post StreamCompile, cacheOptions, resource->cacheHandler(), streamer); 335 return WTF::bind<v8::Isolate*, v8::Local<v8::String>, v8::ScriptOrigin>(post StreamCompile, cacheOptions, retainedRef(resource->cacheHandler()), retainedRef( streamer));
336 } 336 }
337 } // namespace 337 } // namespace
338 338
339 v8::MaybeLocal<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode& source, v8::Isolate* isolate, AccessControlStatus accessControlStatus, V8CacheO ptions cacheOptions) 339 v8::MaybeLocal<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode& source, v8::Isolate* isolate, AccessControlStatus accessControlStatus, V8CacheO ptions cacheOptions)
340 { 340 {
341 if (source.source().length() >= v8::String::kMaxLength) { 341 if (source.source().length() >= v8::String::kMaxLength) {
342 V8ThrowException::throwGeneralError(isolate, "Source file too large."); 342 V8ThrowException::throwGeneralError(isolate, "Source file too large.");
343 return v8::Local<v8::Script>(); 343 return v8::Local<v8::Script>();
344 } 344 }
345 return compileScript(v8String(isolate, source.source()), source.url(), sourc e.sourceMapUrl(), source.startPosition(), isolate, source.resource(), source.str eamer(), source.resource() ? source.resource()->cacheHandler() : nullptr, access ControlStatus, cacheOptions); 345 return compileScript(v8String(isolate, source.source()), source.url(), sourc e.sourceMapUrl(), source.startPosition(), isolate, source.resource(), source.str eamer(), source.resource() ? source.resource()->cacheHandler() : nullptr, access ControlStatus, cacheOptions);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 // Store a timestamp to the cache as hint. 523 // Store a timestamp to the cache as hint.
524 void V8ScriptRunner::setCacheTimeStamp(CachedMetadataHandler* cacheHandler) 524 void V8ScriptRunner::setCacheTimeStamp(CachedMetadataHandler* cacheHandler)
525 { 525 {
526 double now = WTF::currentTime(); 526 double now = WTF::currentTime();
527 unsigned tag = cacheTag(CacheTagTimeStamp, cacheHandler); 527 unsigned tag = cacheTag(CacheTagTimeStamp, cacheHandler);
528 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally); 528 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally);
529 cacheHandler->setCachedMetadata(tag, reinterpret_cast<char*>(&now), sizeof(n ow), CachedMetadataHandler::SendToPlatform); 529 cacheHandler->setCachedMetadata(tag, reinterpret_cast<char*>(&now), sizeof(n ow), CachedMetadataHandler::SendToPlatform);
530 } 530 }
531 531
532 } // namespace blink 532 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/ExecutionContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698