Commit f27eb243 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[caching] Allow WebAssembly fetches to use code cache.

Fixes a few problems preventing the WASM cache from working.
- Routes raw resource metadata to the WASM code cache.
- Separates JS and WASM generated code caches. They can't share
  a directory.
- Allow cached metadata to be set on RawResources.

Bug: chromium:719172
Change-Id: I0f3709340948bb25d134504bb03632eb1ce24196
Reviewed-on: https://chromium-review.googlesource.com/c/1255963
Commit-Queue: Bill Budge <bbudge@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596779}
parent ecbc1581
...@@ -26,8 +26,10 @@ void GeneratedCodeCacheContext::Initialize(const base::FilePath& path, ...@@ -26,8 +26,10 @@ void GeneratedCodeCacheContext::Initialize(const base::FilePath& path,
void GeneratedCodeCacheContext::InitializeOnIO(const base::FilePath& path, void GeneratedCodeCacheContext::InitializeOnIO(const base::FilePath& path,
int max_bytes) { int max_bytes) {
generated_js_code_cache_.reset(new GeneratedCodeCache(path, max_bytes)); generated_js_code_cache_.reset(
generated_wasm_code_cache_.reset(new GeneratedCodeCache(path, max_bytes)); new GeneratedCodeCache(path.AppendASCII("js"), max_bytes));
generated_wasm_code_cache_.reset(
new GeneratedCodeCache(path.AppendASCII("wasm"), max_bytes));
} }
GeneratedCodeCache* GeneratedCodeCacheContext::generated_js_code_cache() const { GeneratedCodeCache* GeneratedCodeCacheContext::generated_js_code_cache() const {
......
...@@ -257,6 +257,12 @@ void RawResource::SetSerializedCachedMetadata(const char* data, size_t size) { ...@@ -257,6 +257,12 @@ void RawResource::SetSerializedCachedMetadata(const char* data, size_t size) {
if (cache_handler) { if (cache_handler) {
cache_handler->SetSerializedCachedMetadata(data, size); cache_handler->SetSerializedCachedMetadata(data, size);
} }
} else if (GetType() == ResourceType::kRaw) {
ScriptCachedMetadataHandler* cache_handler =
static_cast<ScriptCachedMetadataHandler*>(Resource::CacheHandler());
if (cache_handler) {
cache_handler->SetSerializedCachedMetadata(data, size);
}
} }
ResourceClientWalker<RawResourceClient> w(Clients()); ResourceClientWalker<RawResourceClient> w(Clients());
......
...@@ -166,8 +166,9 @@ bool ResourceLoader::CodeCacheRequest::FetchFromCodeCache( ...@@ -166,8 +166,9 @@ bool ResourceLoader::CodeCacheRequest::FetchFromCodeCache(
CodeCacheLoader::FetchCodeCacheCallback callback = CodeCacheLoader::FetchCodeCacheCallback callback =
base::BindOnce(&ResourceLoader::CodeCacheRequest::DidReceiveCachedCode, base::BindOnce(&ResourceLoader::CodeCacheRequest::DidReceiveCachedCode,
weak_ptr_factory_.GetWeakPtr(), resource_loader); weak_ptr_factory_.GetWeakPtr(), resource_loader);
code_cache_loader_->FetchFromCodeCache( auto cache_type = resource_loader->GetCodeCacheType();
blink::mojom::CodeCacheType::kJavascript, gurl_, std::move(callback)); code_cache_loader_->FetchFromCodeCache(cache_type, gurl_,
std::move(callback));
return true; return true;
} }
...@@ -313,12 +314,15 @@ bool ResourceLoader::ShouldFetchCodeCache() { ...@@ -313,12 +314,15 @@ bool ResourceLoader::ShouldFetchCodeCache() {
return false; return false;
if (request.DownloadToBlob()) if (request.DownloadToBlob())
return false; return false;
// If the resource type is script or MainResource (for inline scripts) fetch // Javascript resources have type kScript or kMainResource (for inline
// code cache. For others we need not fetch code cache. // scripts). WebAssembly module resources have type kRaw. Note that since we
if (resource_->GetType() != ResourceType::kScript && // can't easily distinguish WebAssembly modules from other raw resources, we
resource_->GetType() != ResourceType::kMainResource) // perform a code fetch for all raw resources. These fetches should be cheap,
return false; // however, requiring one additional IPC and no browser process disk IO since
return true; // the cache index is in memory and the resource key should not be present.
return resource_->GetType() == ResourceType::kScript ||
resource_->GetType() == ResourceType::kMainResource ||
resource_->GetType() == ResourceType::kRaw;
} }
void ResourceLoader::Start() { void ResourceLoader::Start() {
...@@ -692,14 +696,17 @@ void ResourceLoader::DidReceiveCachedMetadata(const char* data, int length) { ...@@ -692,14 +696,17 @@ void ResourceLoader::DidReceiveCachedMetadata(const char* data, int length) {
} }
} }
blink::mojom::CodeCacheType ResourceLoader::GetCodeCacheType() const {
return Resource::ResourceTypeToCodeCacheType(resource_->GetType());
}
void ResourceLoader::SendCachedCodeToResource(const char* data, int length) { void ResourceLoader::SendCachedCodeToResource(const char* data, int length) {
resource_->SetSerializedCachedMetadata(data, length); resource_->SetSerializedCachedMetadata(data, length);
} }
void ResourceLoader::ClearCachedCode() { void ResourceLoader::ClearCachedCode() {
Platform::Current()->ClearCodeCacheEntry( auto cache_type = GetCodeCacheType();
Resource::ResourceTypeToCodeCacheType(resource_->GetType()), Platform::Current()->ClearCodeCacheEntry(cache_type, resource_->Url());
resource_->Url());
} }
void ResourceLoader::DidSendData(unsigned long long bytes_sent, void ResourceLoader::DidSendData(unsigned long long bytes_sent,
......
...@@ -130,6 +130,7 @@ class PLATFORM_EXPORT ResourceLoader final ...@@ -130,6 +130,7 @@ class PLATFORM_EXPORT ResourceLoader final
int64_t encoded_body_length, int64_t encoded_body_length,
int64_t decoded_body_length) override; int64_t decoded_body_length) override;
blink::mojom::CodeCacheType GetCodeCacheType() const;
void SendCachedCodeToResource(const char* data, int size); void SendCachedCodeToResource(const char* data, int size);
void ClearCachedCode(); void ClearCachedCode();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment