| OLD | NEW |
| 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 289 |
| 290 // Caching is not worthwhile for small scripts. Do not use caching | 290 // Caching is not worthwhile for small scripts. Do not use caching |
| 291 // unless explicitly expected, indicated by the cache option. | 291 // unless explicitly expected, indicated by the cache option. |
| 292 if (code->Length() < minimalCodeLength) | 292 if (code->Length() < minimalCodeLength) |
| 293 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); | 293 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); |
| 294 | 294 |
| 295 // The cacheOptions will guide our strategy: | 295 // The cacheOptions will guide our strategy: |
| 296 switch (cacheOptions) { | 296 switch (cacheOptions) { |
| 297 case V8CacheOptionsParse: | 297 case V8CacheOptionsParse: |
| 298 // Use parser-cache; in-memory only. | 298 // Use parser-cache; in-memory only. |
| 299 return bind(compileAndConsumeOrProduce, cacheHandler, cacheTag(CacheTagP
arser, cacheHandler), v8::ScriptCompiler::kConsumeParserCache, v8::ScriptCompile
r::kProduceParserCache, CachedMetadataHandler::CacheLocally); | 299 return bind(compileAndConsumeOrProduce, wrapPersistent(cacheHandler), ca
cheTag(CacheTagParser, cacheHandler), v8::ScriptCompiler::kConsumeParserCache, v
8::ScriptCompiler::kProduceParserCache, CachedMetadataHandler::CacheLocally); |
| 300 break; | 300 break; |
| 301 | 301 |
| 302 case V8CacheOptionsDefault: | 302 case V8CacheOptionsDefault: |
| 303 case V8CacheOptionsCode: | 303 case V8CacheOptionsCode: |
| 304 case V8CacheOptionsAlways: { | 304 case V8CacheOptionsAlways: { |
| 305 // Use code caching for recently seen resources. | 305 // Use code caching for recently seen resources. |
| 306 // Use compression depending on the cache option. | 306 // Use compression depending on the cache option. |
| 307 unsigned codeCacheTag = cacheTag(CacheTagCode, cacheHandler); | 307 unsigned codeCacheTag = cacheTag(CacheTagCode, cacheHandler); |
| 308 CachedMetadata* codeCache = cacheHandler->cachedMetadata(codeCacheTag); | 308 CachedMetadata* codeCache = cacheHandler->cachedMetadata(codeCacheTag); |
| 309 if (codeCache) | 309 if (codeCache) |
| 310 return bind(compileAndConsumeCache, cacheHandler, codeCacheTag, v8::
ScriptCompiler::kConsumeCodeCache); | 310 return bind(compileAndConsumeCache, wrapPersistent(cacheHandler), co
deCacheTag, v8::ScriptCompiler::kConsumeCodeCache); |
| 311 if (cacheOptions != V8CacheOptionsAlways && !isResourceHotForCaching(cac
heHandler, hotHours)) { | 311 if (cacheOptions != V8CacheOptionsAlways && !isResourceHotForCaching(cac
heHandler, hotHours)) { |
| 312 V8ScriptRunner::setCacheTimeStamp(cacheHandler); | 312 V8ScriptRunner::setCacheTimeStamp(cacheHandler); |
| 313 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); | 313 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); |
| 314 } | 314 } |
| 315 return bind(compileAndProduceCache, cacheHandler, codeCacheTag, v8::Scri
ptCompiler::kProduceCodeCache, CachedMetadataHandler::SendToPlatform); | 315 return bind(compileAndProduceCache, wrapPersistent(cacheHandler), codeCa
cheTag, v8::ScriptCompiler::kProduceCodeCache, CachedMetadataHandler::SendToPlat
form); |
| 316 break; | 316 break; |
| 317 } | 317 } |
| 318 | 318 |
| 319 case V8CacheOptionsNone: | 319 case V8CacheOptionsNone: |
| 320 // Shouldn't happen, as this is handled above. | 320 // Shouldn't happen, as this is handled above. |
| 321 // Case is here so that compiler can check all cases are handled. | 321 // Case is here so that compiler can check all cases are handled. |
| 322 ASSERT_NOT_REACHED(); | 322 ASSERT_NOT_REACHED(); |
| 323 break; | 323 break; |
| 324 } | 324 } |
| 325 | 325 |
| 326 // All switch branches should return and we should never get here. | 326 // All switch branches should return and we should never get here. |
| 327 // But some compilers aren't sure, hence this default. | 327 // But some compilers aren't sure, hence this default. |
| 328 ASSERT_NOT_REACHED(); | 328 ASSERT_NOT_REACHED(); |
| 329 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); | 329 return bind(compileWithoutOptions, V8CompileHistogram::Cacheable); |
| 330 } | 330 } |
| 331 | 331 |
| 332 // Select a compile function for a streaming compile. | 332 // Select a compile function for a streaming compile. |
| 333 std::unique_ptr<CompileFn> selectCompileFunction(V8CacheOptions cacheOptions, Sc
riptResource* resource, ScriptStreamer* streamer) | 333 std::unique_ptr<CompileFn> selectCompileFunction(V8CacheOptions cacheOptions, Sc
riptResource* resource, ScriptStreamer* streamer) |
| 334 { | 334 { |
| 335 // We don't stream scripts which don't have a Resource. | 335 // We don't stream scripts which don't have a Resource. |
| 336 ASSERT(resource); | 336 ASSERT(resource); |
| 337 // Failed resources should never get this far. | 337 // Failed resources should never get this far. |
| 338 ASSERT(!resource->errorOccurred()); | 338 ASSERT(!resource->errorOccurred()); |
| 339 ASSERT(streamer->isFinished()); | 339 ASSERT(streamer->isFinished()); |
| 340 ASSERT(!streamer->streamingSuppressed()); | 340 ASSERT(!streamer->streamingSuppressed()); |
| 341 return WTF::bind(postStreamCompile, cacheOptions, resource->cacheHandler(),
streamer); | 341 return WTF::bind(postStreamCompile, cacheOptions, wrapPersistent(resource->c
acheHandler()), wrapPersistent(streamer)); |
| 342 } | 342 } |
| 343 } // namespace | 343 } // namespace |
| 344 | 344 |
| 345 v8::MaybeLocal<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode&
source, v8::Isolate* isolate, AccessControlStatus accessControlStatus, V8CacheO
ptions cacheOptions) | 345 v8::MaybeLocal<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode&
source, v8::Isolate* isolate, AccessControlStatus accessControlStatus, V8CacheO
ptions cacheOptions) |
| 346 { | 346 { |
| 347 if (source.source().length() >= v8::String::kMaxLength) { | 347 if (source.source().length() >= v8::String::kMaxLength) { |
| 348 V8ThrowException::throwGeneralError(isolate, "Source file too large."); | 348 V8ThrowException::throwGeneralError(isolate, "Source file too large."); |
| 349 return v8::Local<v8::Script>(); | 349 return v8::Local<v8::Script>(); |
| 350 } | 350 } |
| 351 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); | 351 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 // Store a timestamp to the cache as hint. | 575 // Store a timestamp to the cache as hint. |
| 576 void V8ScriptRunner::setCacheTimeStamp(CachedMetadataHandler* cacheHandler) | 576 void V8ScriptRunner::setCacheTimeStamp(CachedMetadataHandler* cacheHandler) |
| 577 { | 577 { |
| 578 double now = WTF::currentTime(); | 578 double now = WTF::currentTime(); |
| 579 unsigned tag = cacheTag(CacheTagTimeStamp, cacheHandler); | 579 unsigned tag = cacheTag(CacheTagTimeStamp, cacheHandler); |
| 580 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally); | 580 cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally); |
| 581 cacheHandler->setCachedMetadata(tag, reinterpret_cast<char*>(&now), sizeof(n
ow), CachedMetadataHandler::SendToPlatform); | 581 cacheHandler->setCachedMetadata(tag, reinterpret_cast<char*>(&now), sizeof(n
ow), CachedMetadataHandler::SendToPlatform); |
| 582 } | 582 } |
| 583 | 583 |
| 584 } // namespace blink | 584 } // namespace blink |
| OLD | NEW |