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,
void GeneratedCodeCacheContext::InitializeOnIO(const base::FilePath& path,
int max_bytes) {
generated_js_code_cache_.reset(new GeneratedCodeCache(path, max_bytes));
generated_wasm_code_cache_.reset(new GeneratedCodeCache(path, max_bytes));
generated_js_code_cache_.reset(
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 {
......
......@@ -257,6 +257,12 @@ void RawResource::SetSerializedCachedMetadata(const char* data, size_t size) {
if (cache_handler) {
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());
......
......@@ -166,8 +166,9 @@ bool ResourceLoader::CodeCacheRequest::FetchFromCodeCache(
CodeCacheLoader::FetchCodeCacheCallback callback =
base::BindOnce(&ResourceLoader::CodeCacheRequest::DidReceiveCachedCode,
weak_ptr_factory_.GetWeakPtr(), resource_loader);
code_cache_loader_->FetchFromCodeCache(
blink::mojom::CodeCacheType::kJavascript, gurl_, std::move(callback));
auto cache_type = resource_loader->GetCodeCacheType();
code_cache_loader_->FetchFromCodeCache(cache_type, gurl_,
std::move(callback));
return true;
}
......@@ -313,12 +314,15 @@ bool ResourceLoader::ShouldFetchCodeCache() {
return false;
if (request.DownloadToBlob())
return false;
// If the resource type is script or MainResource (for inline scripts) fetch
// code cache. For others we need not fetch code cache.
if (resource_->GetType() != ResourceType::kScript &&
resource_->GetType() != ResourceType::kMainResource)
return false;
return true;
// Javascript resources have type kScript or kMainResource (for inline
// scripts). WebAssembly module resources have type kRaw. Note that since we
// can't easily distinguish WebAssembly modules from other raw resources, we
// perform a code fetch for all raw resources. These fetches should be cheap,
// however, requiring one additional IPC and no browser process disk IO since
// 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() {
......@@ -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) {
resource_->SetSerializedCachedMetadata(data, length);
}
void ResourceLoader::ClearCachedCode() {
Platform::Current()->ClearCodeCacheEntry(
Resource::ResourceTypeToCodeCacheType(resource_->GetType()),
resource_->Url());
auto cache_type = GetCodeCacheType();
Platform::Current()->ClearCodeCacheEntry(cache_type, resource_->Url());
}
void ResourceLoader::DidSendData(unsigned long long bytes_sent,
......
......@@ -130,6 +130,7 @@ class PLATFORM_EXPORT ResourceLoader final
int64_t encoded_body_length,
int64_t decoded_body_length) override;
blink::mojom::CodeCacheType GetCodeCacheType() const;
void SendCachedCodeToResource(const char* data, int size);
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